X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FElectionTerm.java;h=61aafef51354e88ab678dcfeb4f43970e308e636;hp=2cf39b59f19e81fcfeeb7bcec83c020e848acd27;hb=HEAD;hpb=cf5be659d906cc80d52647cb516bbab435156742 diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ElectionTerm.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ElectionTerm.java index 2cf39b59f1..61aafef513 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ElectionTerm.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ElectionTerm.java @@ -5,39 +5,51 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.raft; -import java.util.concurrent.atomic.AtomicLong; +import org.eclipse.jdt.annotation.Nullable; /** * ElectionTerm contains information about a RaftActors election term. + * *

* This information includes the last known current term of the RaftActor - * and which peer was voted for by the RaftActor in that term + * and which candidate was voted for by the RaftActor in that term. + * *

- * This class ensures that election term information is persisted + * This class ensures that election term information is persisted. */ public interface ElectionTerm { /** - * latest term server has seen (initialized to 0 - * on first boot, increases monotonically) + * Returns the current leader's Raft term. + * + * @return the current leader's Raft term. */ - AtomicLong getCurrentTerm(); + long getCurrentTerm(); /** - * candidateId that received vote in current - * term (or null if none) + * Returns the id of the candidate that this server voted for in current term. + * + * @return candidate id that received the vote or null if no candidate was voted for. + */ + @Nullable String getVotedFor(); + + /** + * This method updates the in-memory election term state. This method should be called when recovering election + * state from persistent storage. + * + * @param term the election term. + * @param votedFor the candidate id that was voted for. */ - String getVotedFor(); + void update(long term, @Nullable String votedFor); /** - * Called when we need to update the current term either because we received - * a message from someone with a more uptodate term or because we just voted - * for someone + * This method updates the in-memory election term state and persists it so it can be recovered on next restart. + * This method should be called when starting a new election or when a Raft RPC message is received with a higher + * term. * - * @param currentTerm - * @param votedFor + * @param term the election term. + * @param votedFor the candidate id that was voted for. */ - void update(AtomicLong currentTerm, String votedFor); + void updateAndPersist(long term, @Nullable String votedFor); }