Interface ElectionTerm
-
- All Known Implementing Classes:
ImmutableElectionTerm
public interface ElectionTerm
ElectionTerm contains information about a RaftActors election term.This information includes the last known current term of the RaftActor and which candidate was voted for by the RaftActor in that term.
This class ensures that election term information is persisted.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description long
getCurrentTerm()
Returns the current leader's Raft term.@Nullable String
getVotedFor()
Returns the id of the candidate that this server voted for in current term.void
update(long term, @Nullable String votedFor)
This method updates the in-memory election term state.void
updateAndPersist(long term, @Nullable String votedFor)
This method updates the in-memory election term state and persists it so it can be recovered on next restart.
-
-
-
Method Detail
-
getCurrentTerm
long getCurrentTerm()
Returns the current leader's Raft term.- Returns:
- the current leader's Raft term.
-
getVotedFor
@Nullable String getVotedFor()
Returns the id of the candidate that this server voted for in current term.- Returns:
- candidate id that received the vote or null if no candidate was voted for.
-
update
void update(long term, @Nullable String votedFor)
This method updates the in-memory election term state. This method should be called when recovering election state from persistent storage.- Parameters:
term
- the election term.votedFor
- the candidate id that was voted for.
-
updateAndPersist
void updateAndPersist(long term, @Nullable String votedFor)
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.- Parameters:
term
- the election term.votedFor
- the candidate id that was voted for.
-
-