Class ClusterMarkFile

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

public final class ClusterMarkFile extends Object implements AutoCloseable
Used to indicate if a cluster component is running and what configuration it is using. Errors encountered by the service are recorded within this file by a DistinctErrorLog.
  • Field Details

    • MAJOR_VERSION

      public static final int MAJOR_VERSION
      Major version.
      See Also:
    • MINOR_VERSION

      public static final int MINOR_VERSION
      Minor version.
      See Also:
    • PATCH_VERSION

      public static final int PATCH_VERSION
      Patch version.
      See Also:
    • SEMANTIC_VERSION

      public static final int SEMANTIC_VERSION
      Full semantic version.
    • HEADER_LENGTH

      public static final int HEADER_LENGTH
      Length of the header section.
      See Also:
    • VERSION_FAILED

      public static final int VERSION_FAILED
      Special version to indicate that component failed to start.
      See Also:
    • ERROR_BUFFER_MIN_LENGTH

      public static final int ERROR_BUFFER_MIN_LENGTH
      Min length for the error log buffer.
      See Also:
    • ERROR_BUFFER_MAX_LENGTH

      public static final int ERROR_BUFFER_MAX_LENGTH
      Max allowed length for the error log buffer.
      See Also:
    • FILE_EXTENSION

      public static final String FILE_EXTENSION
      File extension used by the mark file.
      See Also:
    • FILENAME

      public static final String FILENAME
      Mark file name.
      See Also:
    • SERVICE_FILENAME_PREFIX

      public static final String SERVICE_FILENAME_PREFIX
      Service mark file name.
      See Also:
  • Constructor Details

    • ClusterMarkFile

      @Deprecated(forRemoval=true) public ClusterMarkFile(File file, io.aeron.cluster.codecs.mark.ClusterComponentType type, int errorBufferLength, EpochClock epochClock, long timeoutMs)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Create new MarkFile for a cluster component but check if an existing component is active.
      Parameters:
      file - full qualified file to the MarkFile.
      type - of cluster component the MarkFile represents.
      errorBufferLength - for storing the error log.
      epochClock - for checking liveness against.
      timeoutMs - for the activity check on an existing MarkFile.
    • ClusterMarkFile

      public ClusterMarkFile(File file, io.aeron.cluster.codecs.mark.ClusterComponentType type, int errorBufferLength, EpochClock epochClock, long timeoutMs, int filePageSize)
      Create new MarkFile for a cluster component but check if an existing component is active.
      Parameters:
      file - full qualified file to the MarkFile.
      type - of cluster component the MarkFile represents.
      errorBufferLength - for storing the error log.
      epochClock - for checking liveness against.
      timeoutMs - for the activity check on an existing MarkFile.
      filePageSize - for aligning file length to.
      Since:
      1.48.0
    • ClusterMarkFile

      public ClusterMarkFile(File directory, String filename, EpochClock epochClock, long timeoutMs, Consumer<String> logger)
      Construct to read the status of an existing MarkFile for a cluster component.
      Parameters:
      directory - in which the mark file exists.
      filename - for the MarkFile.
      epochClock - to be used for checking liveness.
      timeoutMs - to wait for file to exist.
      logger - to which debug information will be written if an issue occurs.
  • Method Details

    • parentDirectory

      public File parentDirectory()
      Get the parent directory containing the mark file.
      Returns:
      parent directory of the mark file.
      See Also:
    • isServiceMarkFile

      public static boolean isServiceMarkFile(Path path, BasicFileAttributes attributes)
      Determines if this path name matches the service mark file name pattern.
      Parameters:
      path - to examine.
      attributes - ignored, only needed for BiPredicate signature matching.
      Returns:
      true if the name matches.
    • isConsensusModuleMarkFile

      public static boolean isConsensusModuleMarkFile(Path path, BasicFileAttributes attributes)
      Determines if this path name matches the consensus module file name pattern.
      Parameters:
      path - to examine.
      attributes - ignored, only needed for BiPredicate signature matching.
      Returns:
      true if the name matches.
    • close

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

      public boolean isClosed()
      Check if the MarkFile is closed.
      Returns:
      true if the MarkFile is closed.
    • candidateTermId

      public long candidateTermId()
      Get the current value of a candidate term id if a vote is placed in an election with volatile semantics.
      Returns:
      the current candidate term id within an election after voting or Aeron.NULL_VALUE if no voting phase of an election is currently active.
    • memberId

      public int memberId()
      Cluster member id.
      Returns:
      cluster member id.
    • memberId

      public void memberId(int memberId)
      Member id assigned as part of active join to the log in a clustered service.
      Parameters:
      memberId - assigned as part of active join to the log in a clustered service.
    • clusterId

      public int clusterId()
      Identity of the cluster instance so multiple clusters can run on the same driver.
      Returns:
      id of the cluster instance so multiple clusters can run on the same driver.
    • clusterId

      public void clusterId(int clusterId)
      Identity of the cluster instance so multiple clusters can run on the same driver.
      Parameters:
      clusterId - of the cluster instance so multiple clusters can run on the same driver.
    • signalReady

      @Deprecated(forRemoval=true) public void signalReady()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use signalReady(long) instead.
      Signal the cluster component has concluded successfully and ready to start.
    • signalReady

      public void signalReady(long activityTimestamp)
      Signal the cluster component has concluded successfully and ready to start.
      Parameters:
      activityTimestamp - to be used.
    • signalFailedStart

      public void signalFailedStart()
      Signal the cluster component has failed to conclude and cannot start.
    • signalTerminated

      public void signalTerminated()
      Signal the cluster component has been terminated.
    • updateActivityTimestamp

      public void updateActivityTimestamp(long nowMs)
      Update the activity timestamp as a proof of life.
      Parameters:
      nowMs - activity timestamp as a proof of life.
    • activityTimestampVolatile

      public long activityTimestampVolatile()
      Read the activity timestamp of the cluster component with volatile semantics.
      Returns:
      the activity timestamp of the cluster component with volatile semantics.
    • encoder

      public io.aeron.cluster.codecs.mark.MarkFileHeaderEncoder encoder()
      The encoder for writing the MarkFile header.
      Returns:
      the encoder for writing the MarkFile header.
    • decoder

      public io.aeron.cluster.codecs.mark.MarkFileHeaderDecoder decoder()
      The decoder for reading the MarkFile header.
      Returns:
      the decoder for reading the MarkFile header.
    • errorBuffer

      public AtomicBuffer errorBuffer()
      The direct buffer which wraps the region of the MarkFile which contains the error log.
      Returns:
      the direct buffer which wraps the region of the MarkFile which contains the error log.
    • saveExistingErrors

      public static void saveExistingErrors(File markFile, AtomicBuffer errorBuffer, io.aeron.cluster.codecs.mark.ClusterComponentType type, PrintStream logger)
      Save the existing errors from a MarkFile to a PrintStream for logging.
      Parameters:
      markFile - which contains the error buffer.
      errorBuffer - which wraps the error log.
      type - type of the mark file being checked.
      logger - to which the existing errors will be printed.
    • checkHeaderLength

      public static void checkHeaderLength(String aeronDirectory, String controlChannel, String ingressChannel, String serviceName, String authenticator)
      Check if the header length is sufficient for encoding the provided properties.
      Parameters:
      aeronDirectory - for the media driver.
      controlChannel - for the consensus module.
      ingressChannel - from the cluster clients.
      serviceName - for the application service.
      authenticator - for the application service.
    • markFilenameForService

      public static String markFilenameForService(int serviceId)
      The filename to be used for the mark file given a service id.
      Parameters:
      serviceId - of the service the ClusterMarkFile represents.
      Returns:
      the filename to be used for the mark file given a service id.
    • linkFilenameForService

      public static String linkFilenameForService(int serviceId)
      The filename to be used for the link file given a service id.
      Parameters:
      serviceId - of the service the ClusterMarkFile represents.
      Returns:
      the filename to be used for the link file given a service id.
    • loadControlProperties

      public ClusterNodeControlProperties loadControlProperties()
      The control properties for communicating between the consensus module and the services.
      Returns:
      the control properties for communicating between the consensus module and the services or null if mark file was already closed.
    • force

      public void force()
      Forces any changes made to the mark file's content to be written to the storage device containing the mapped file.
      Since:
      1.44.0
    • toString

      public String toString()
      Overrides:
      toString in class Object