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=264f7a5d634dfae527dbe26860012e8356dbf2da;hp=9f0d02edb9d5aa111b841f0972c0d82ca07a7df8;hb=0f02b7edeb1454c1a568f0f1b050757e7503ddf7;hpb=c222e37f2a0f0f3f6266242fbea2d3b018f4e6e3 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 9f0d02edb9..264f7a5d63 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 @@ -8,47 +8,50 @@ package org.opendaylight.controller.cluster.raft; +import javax.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. */ 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(); /** - * To be called mainly when we are recovering in-memory election state from - * persistent storage + * This method updates the in-memory election term state. This method should be called when recovering election + * state from persistent storage. * - * @param currentTerm - * @param votedFor + * @param term the election term. + * @param votedFor the candidate id that was voted for. */ - void update(long currentTerm, String votedFor); + void update(long term, @Nullable String votedFor); /** - * To be called when we need to update the current term either because we - * received a message from someone with a more up-to-date term or because we - * just voted for someone - *

- * This information needs to be persisted so that on recovery the replica - * can start itself in the right term and know if it has already voted in - * that term or not + * 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 updateAndPersist(long currentTerm, String votedFor); + void updateAndPersist(long term, @Nullable String votedFor); }