Interface TermInfoStore
@NonNullByDefault
public interface TermInfoStore
Storage for
TermInfo
. Provides access to current term and updates to it both transient, via
setTerm(TermInfo)
and persistent, via storeAndSetTerm(TermInfo)
.-
Method Summary
Modifier and TypeMethodDescriptionReturnsTermInfo
for current term.@Nullable TermInfo
Attempt to load the last persistedTermInfo
, if available.void
This method updates the in-memory election term state.void
storeAndSetTerm
(TermInfo newTerm) This method updates the in-memory election term state and persists it so it can be recovered on next restart.
-
Method Details
-
currentTerm
TermInfo currentTerm()ReturnsTermInfo
for current term. Freshly-initialized instances returnTermInfo.INITIAL
.- Returns:
TermInfo
for current term
-
setTerm
This method updates the in-memory election term state. This method should be called when recovering election state from persistent storage.- Parameters:
newTerm
- newTermInfo
-
storeAndSetTerm
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:
newTerm
- newTermInfo
- Throws:
IOException
- if an I/O error occurs
-
loadAndSetTerm
Attempt to load the last persistedTermInfo
, if available. If successful,currentTerm()
is updated.- Returns:
- the persisted
TermInfo
, ornull
of none is available - Throws:
IOException
- if an I/O error occurs
-