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 Type
    Method
    Description
    Returns TermInfo for current term.
    @Nullable TermInfo
    Attempt to load the last persisted TermInfo, if available.
    void
    setTerm(TermInfo newTerm)
    This method updates the in-memory election term state.
    void
    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()
      Returns TermInfo for current term. Freshly-initialized instances return TermInfo.INITIAL.
      Returns:
      TermInfo for current term
    • setTerm

      void setTerm(TermInfo newTerm)
      This method updates the in-memory election term state. This method should be called when recovering election state from persistent storage.
      Parameters:
      newTerm - new TermInfo
    • storeAndSetTerm

      void storeAndSetTerm(TermInfo newTerm) throws IOException
      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 - new TermInfo
      Throws:
      IOException - if an I/O error occurs
    • loadAndSetTerm

      @Nullable TermInfo loadAndSetTerm() throws IOException
      Attempt to load the last persisted TermInfo, if available. If successful, currentTerm() is updated.
      Returns:
      the persisted TermInfo, or null of none is available
      Throws:
      IOException - if an I/O error occurs