Class NodeStateFile

java.lang.Object
io.aeron.cluster.NodeStateFile
All Implemented Interfaces:
AutoCloseable

public class NodeStateFile extends Object implements AutoCloseable
An extensible list of information relating to a specific cluster node. Used to track persistent state that is node specific and shouldn't be present in the snapshot. E.g. candidateTermId.

The structure consists of a node header at the beginning of the file followed by n entries that use the standard open framing header, followed by the message header, and finally the body.

   0                   1                   2                   3
   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                     Node State Header                         |
  +---------------------------------------------------------------+
  

Entry. All records must be laid out so that the body has an 8-byte alignment. Fields that require volatile accesses must be aligned to an 8-byte boundary. The message header is 8-bytes long to aid with this. Records are padded to a 8-byte boundary before the next record.

   0                   1                   2                   3
   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  +---------------------------------------------------------------+
  |                       Message Header                          |
  |                                                               |
  +---------------------------------------------------------------+
  |                       Message Body (Variable)               ...
  ...                                                             |
  +---------------------------------------------------------------+
 

The current structure contains:

     <Node State Header>
     <Candidate Term>
     <Cluster Members>
     <Node State Footer>
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    final class 
    Wrapper class for the candidate term.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    File name.
  • Constructor Summary

    Constructors
    Constructor
    Description
    NodeStateFile(File clusterDir, boolean createNew, int fileSyncLevel)
    Construct the NodeStateFile.
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the reference to CandidateTerm wrapper that can be used to fetch the values associated with the current candidate term.
    void
    long
    proposeMaxCandidateTermId(long candidateTermId, long logPosition, long timestampMs)
    Set the current candidate term id with associated information.
    void
    updateCandidateTermId(long candidateTermId, long logPosition, long timestampMs)
    Set the current candidate term id with associated information.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • NodeStateFile

      public NodeStateFile(File clusterDir, boolean createNew, int fileSyncLevel) throws IOException
      Construct the NodeStateFile.
      Parameters:
      clusterDir - directory containing the NodeStateFile.
      createNew - whether a new file should be created if one does not already exist.
      fileSyncLevel - whether the mapped byte buffer should be synchronised with the underlying filesystem on change.
      Throws:
      IOException - if there is an error creating the file or createNew == false and the file does not already exist.
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • updateCandidateTermId

      public void updateCandidateTermId(long candidateTermId, long logPosition, long timestampMs)
      Set the current candidate term id with associated information.
      Parameters:
      candidateTermId - current candidate term id.
      logPosition - log position where the term id change occurred.
      timestampMs - timestamp of the candidate term id change.
    • proposeMaxCandidateTermId

      public long proposeMaxCandidateTermId(long candidateTermId, long logPosition, long timestampMs)
      Set the current candidate term id with associated information.
      Parameters:
      candidateTermId - current candidate term id.
      logPosition - log position where the term id change occurred.
      timestampMs - timestamp of the candidate term id change.
      Returns:
      the new candidate term id.
    • candidateTerm

      public NodeStateFile.CandidateTerm candidateTerm()
      Get the reference to CandidateTerm wrapper that can be used to fetch the values associated with the current candidate term.
      Returns:
      the CandidateTerm wrapper.