Class ClusterToolOperator

java.lang.Object
io.aeron.cluster.ClusterToolOperator

public class ClusterToolOperator extends Object
Actions for an operator tool to control cluster. This class is used by ClusterTool by Aeron but also allows to be used / extended by other tools.
See Also:
  • Field Details

    • SUCCESS

      public static final int SUCCESS
      Successful action return value = exist status.
      See Also:
  • Constructor Details

    • ClusterToolOperator

      protected ClusterToolOperator(String toolChannel, int toolStreamId, long timeoutMs)
      Constructor.
      Parameters:
      toolChannel - channel to use.
      toolStreamId - stream id to use.
      timeoutMs - timeout in milliseconds.
  • Method Details

    • pid

      protected int pid(File clusterDir, PrintStream out)
      Print out the PID of the cluster process.
      Parameters:
      out - to print the output to.
      clusterDir - where the cluster is running.
      Returns:
      exit status.
    • recoveryPlan

      protected int recoveryPlan(PrintStream out, File clusterDir, int serviceCount)
      Print out the RecordingLog.RecoveryPlan for the cluster.
      Parameters:
      out - to print the output to.
      clusterDir - where the cluster is running.
      serviceCount - of services running in the containers.
      Returns:
      exit status
    • recordingLog

      protected int recordingLog(File clusterDir, PrintStream out)
      Print out the RecordingLog for the cluster.
      Parameters:
      clusterDir - where the cluster is running.
      out - to print the output to.
      Returns:
      exit status
    • sortRecordingLog

      protected int sortRecordingLog(File clusterDir)
      Re-order entries in thee RecordingLog file on disc if they are not in a proper order.
      Parameters:
      clusterDir - where the cluster is running.
      Returns:
      SUCCESS if file contents was changed or FAILURE if it was already in the correct order.
    • seedRecordingLogFromSnapshot

      protected int seedRecordingLogFromSnapshot(File clusterDir)
      Create a new RecordingLog based on the latest valid snapshot whose term base and log positions are set to zero. The original recording log file is backed up as recording.log.bak.
      Parameters:
      clusterDir - where the cluster is running.
      Returns:
      exit status
    • errors

      protected int errors(File clusterDir, PrintStream out)
      Print out the errors in the error logs for the cluster components.
      Parameters:
      clusterDir - where the cluster is running.
      out - to print the output to.
      Returns:
      exit status
    • listMembers

      protected int listMembers(File clusterDir, PrintStream out)
      Print out a list of the current members of the cluster.
      Parameters:
      clusterDir - where the cluster is running.
      out - to print the output to.
      Returns:
      exit status
    • printNextBackupQuery

      protected int printNextBackupQuery(File clusterDir, PrintStream out)
      Print out the time of the next backup query.
      Parameters:
      clusterDir - where the cluster backup is running.
      out - to print the output to.
      Returns:
      exit status
    • nextBackupQuery

      protected int nextBackupQuery(File clusterDir, PrintStream out, long delayMs)
      Set the time of the next backup query for the cluster backup.
      Parameters:
      clusterDir - where the cluster is running.
      out - to print the output to.
      delayMs - from the current time for the next backup query.
      Returns:
      exit status
    • describe

      protected void describe(PrintStream out, ClusterMarkFile[] serviceMarkFiles)
      Print out the descriptors in the ClusterMarkFiles.
      Parameters:
      out - to print the output to.
      serviceMarkFiles - to query.
    • isLeader

      protected int isLeader(File clusterDir, PrintStream out)
      Determine if the given node is a leader.
      Parameters:
      clusterDir - where the cluster is running.
      out - to print the output to.
      Returns:
      0 if the node is an active leader in a closed election, 1 if not, -1 if the mark file does not exist.
    • markFileExists

      protected boolean markFileExists(File clusterDir)
      Does a ClusterMarkFile exist in the cluster directory.
      Parameters:
      clusterDir - to check for if a mark file exists.
      Returns:
      true if the cluster mark file exists.
    • listMembers

      protected boolean listMembers(ClusterMembership clusterMembership, File clusterDir, long timeoutMs)
      List the current members of a cluster.
      Parameters:
      clusterMembership - to populate.
      clusterDir - where the cluster is running.
      timeoutMs - to wait on the query completing.
      Returns:
      true if successful.
    • queryClusterMembers

      protected boolean queryClusterMembers(ClusterMarkFile markFile, long timeoutMs, ClusterMembership clusterMembership)
      Query the membership of a cluster.
      Parameters:
      markFile - for the cluster component.
      timeoutMs - to wait for the query.
      clusterMembership - to populate.
      Returns:
      true if the query was successful.
    • queryClusterMembers

      protected boolean queryClusterMembers(ClusterNodeControlProperties controlProperties, long timeoutMs, ClusterMembership clusterMembership)
      Query the membership of a cluster.
      Parameters:
      controlProperties - from a ClusterMarkFile.
      timeoutMs - to wait for the query.
      clusterMembership - to populate.
      Returns:
      true if the query was successful.
    • nextBackupQueryDeadlineMs

      protected long nextBackupQueryDeadlineMs(File clusterDir)
      Get the deadline time (MS) for the next cluster backup query.
      Parameters:
      clusterDir - where the cluster component is running.
      Returns:
      the deadline time (MS) for the next cluster backup query, or Aeron.NULL_VALUE not available.
    • nextBackupQueryDeadlineMs

      protected long nextBackupQueryDeadlineMs(ClusterMarkFile markFile)
      Get the deadline time (MS) for the next cluster backup query.
      Parameters:
      markFile - for the cluster component.
      Returns:
      the deadline time (MS) for the next cluster backup query, or Aeron.NULL_VALUE not available.
    • nextBackupQueryDeadlineMs

      protected boolean nextBackupQueryDeadlineMs(File clusterDir, long timeMs)
      Set the deadline time (MS) for the next cluster backup query.
      Parameters:
      clusterDir - where the cluster component is running.
      timeMs - to set for the next deadline.
      Returns:
      true if successful, otherwise false.
    • nextBackupQueryDeadlineMs

      protected boolean nextBackupQueryDeadlineMs(ClusterMarkFile markFile, long timeMs)
      Set the deadline time (MS) for the next cluster backup query.
      Parameters:
      markFile - for the cluster component.
      timeMs - to set for the next deadline.
      Returns:
      true if successful, otherwise false.
    • invalidateLatestSnapshot

      protected int invalidateLatestSnapshot(File clusterDir, PrintStream out)
      Invalidate the latest snapshot so recovery will use an earlier one or log if no earlier one exists.
      Parameters:
      clusterDir - where the cluster component is running.
      out - to print the operation result.
      Returns:
      SUCCESS if the latest snapshot was invalidated, else FAILURE
    • describeLatestConsensusModuleSnapshot

      protected int describeLatestConsensusModuleSnapshot(File clusterDir, PrintStream out)
      Print out a summary of the state captured in the latest consensus module snapshot.
      Parameters:
      clusterDir - where the cluster is running.
      out - where to print the operation result.
      Returns:
      SUCCESS is the operation was successfully requested, else FAILURE
    • describeLatestConsensusModuleSnapshot

      protected int describeLatestConsensusModuleSnapshot(File clusterDir, PrintStream out, BiConsumer<Image,Aeron> postConsensusImageDescriber)
      Print out a summary of the state captured in the latest consensus module snapshot.
      Parameters:
      clusterDir - where the cluster is running.
      out - where to print the operation result.
      postConsensusImageDescriber - describing of image after consensus module state
      Returns:
      SUCCESS is the operation was successfully requested, else FAILURE
    • snapshot

      protected int snapshot(File clusterDir, PrintStream out)
      Instruct the cluster to take a snapshot.
      Parameters:
      clusterDir - where the consensus module is running.
      out - to print the result of the operation.
      Returns:
      SUCCESS is the operation was successfully requested, else FAILURE
    • suspend

      protected int suspend(File clusterDir, PrintStream out)
      Instruct the cluster to suspend operation.
      Parameters:
      clusterDir - where the consensus module is running.
      out - to print the result of the operation.
      Returns:
      SUCCESS is the operation was successfully requested, else FAILURE
    • resume

      protected int resume(File clusterDir, PrintStream out)
      Instruct the cluster to resume operation.
      Parameters:
      clusterDir - where the consensus module is running.
      out - to print the result of the operation.
      Returns:
      SUCCESS is the operation was successfully requested, else FAILURE
    • shutdown

      protected int shutdown(File clusterDir, PrintStream out)
      Instruct the cluster to shut down.
      Parameters:
      clusterDir - where the consensus module is running.
      out - to print the result of the operation.
      Returns:
      SUCCESS is the operation was successfully requested, else FAILURE
    • abort

      protected int abort(File clusterDir, PrintStream out)
      Instruct the cluster to abort.
      Parameters:
      clusterDir - where the consensus module is running.
      out - to print the result of the operation.
      Returns:
      SUCCESS is the operation was successfully requested, else FAILURE
    • findLatestValidSnapshot

      protected RecordingLog.Entry findLatestValidSnapshot(File clusterDir)
      Finds the latest valid snapshot from the log file.
      Parameters:
      clusterDir - where the cluster node is running.
      Returns:
      entry or null if not found.
    • loadControlProperties

      protected ClusterNodeControlProperties loadControlProperties(File clusterDir)
      Load ClusterNodeControlProperties from the mark file.
      Parameters:
      clusterDir - where the cluster node is running.
      Returns:
      control properties.
    • describeClusterMarkFile

      protected int describeClusterMarkFile(File clusterDir, PrintStream out)
      Print out the descriptors in the ClusterMarkFiles.
      Parameters:
      clusterDir - where the cluster is running.
      out - to print the output to.
      Returns:
      exit status
    • toolChannel

      protected String toolChannel()
      Returns:
      channel to use.
    • toolStreamId

      protected int toolStreamId()
      Returns:
      stream id to use.
    • timeoutMs

      protected long timeoutMs()
      Returns:
      timeout in milliseconds to use.