Class ClusterTool

java.lang.Object
io.aeron.cluster.ClusterTool

public class ClusterTool extends Object
Tool for control and investigating the state of a cluster node.
 Usage: ClusterTool <cluster-dir> <command> [options]
                         describe: prints out all descriptors in the mark file.
                              pid: prints PID of cluster component.
                    recovery-plan: [service count] prints recovery plan of cluster component.
                    recording-log: prints recording log of cluster component.
               sort-recording-log: reorders entries in the recording log to match the order in memory.
 seed-recording-log-from-snapshot: creates a new recording log based on the latest valid snapshot.
                           errors: prints Aeron and cluster component error logs.
                     list-members: prints leader memberId and active members.
                     backup-query: [delay] get, or set, time of next backup query.
       invalidate-latest-snapshot: marks the latest snapshot as a invalid so the previous is loaded.
                         snapshot: triggers a snapshot on the leader.
                 standby-snapshot: triggers a snapshot on cluster standby nodes.
                          suspend: suspends appending to the log.
                           resume: resumes reading from the log.
                         shutdown: initiates an orderly stop of the cluster with a snapshot.
                            abort: stops the cluster without a snapshot.
      describe-latest-cm-snapshot: prints the contents of the latest valid consensus module snapshot.
                        is-leader: returns zero if the cluster node is leader, non-zero if not
 
  • Field Details

    • AERON_CLUSTER_TOOL_TIMEOUT_PROP_NAME

      public static final String AERON_CLUSTER_TOOL_TIMEOUT_PROP_NAME
      Timeout in nanoseconds for the tool to wait while trying to perform an operation.
      See Also:
    • AERON_CLUSTER_TOOL_DELAY_PROP_NAME

      public static final String AERON_CLUSTER_TOOL_DELAY_PROP_NAME
      Delay in nanoseconds to be applied to an operation such as when the new cluster backup query will occur.
      See Also:
    • AERON_CLUSTER_TOOL_REPLAY_CHANNEL_PROP_NAME

      public static final String AERON_CLUSTER_TOOL_REPLAY_CHANNEL_PROP_NAME
      Property name for setting the channel used for archive replays.
      See Also:
    • AERON_CLUSTER_TOOL_REPLAY_CHANNEL_DEFAULT

      public static final String AERON_CLUSTER_TOOL_REPLAY_CHANNEL_DEFAULT
      Default channel used for archive replays.
      See Also:
    • AERON_CLUSTER_TOOL_REPLAY_CHANNEL

      public static final String AERON_CLUSTER_TOOL_REPLAY_CHANNEL
      Channel used for archive replays.
    • AERON_CLUSTER_TOOL_REPLAY_STREAM_ID_PROP_NAME

      public static final String AERON_CLUSTER_TOOL_REPLAY_STREAM_ID_PROP_NAME
      Property name for setting the stream id used for archive replays.
      See Also:
    • AERON_CLUSTER_TOOL_REPLAY_STREAM_ID_DEFAULT

      public static final int AERON_CLUSTER_TOOL_REPLAY_STREAM_ID_DEFAULT
      Default stream id used for archive replays.
      See Also:
    • AERON_CLUSTER_TOOL_REPLAY_STREAM_ID

      public static final int AERON_CLUSTER_TOOL_REPLAY_STREAM_ID
      Stream id used for archive replays.
    • TIMEOUT_MS

      public static final long TIMEOUT_MS
      Timeout in milliseconds used by the tool for operations.
  • Constructor Details

    • ClusterTool

      public ClusterTool()
  • Method Details

    • main

      public static void main(String[] args)
      Main method for launching the process.
      Parameters:
      args - passed to the process.
    • describe

      public static void describe(PrintStream out, File clusterDir)
      Print out the descriptors in the ClusterMarkFiles.
      Parameters:
      out - to print the output to.
      clusterDir - where the cluster is running.
    • pid

      public static void pid(PrintStream out, File clusterDir)
      Print out the PID of the cluster process.
      Parameters:
      out - to print the output to.
      clusterDir - where the cluster is running.
    • recoveryPlan

      public static void 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.
    • recordingLog

      public static void recordingLog(PrintStream out, File clusterDir)
      Print out the RecordingLog for the cluster.
      Parameters:
      out - to print the output to.
      clusterDir - where the cluster is running.
    • sortRecordingLog

      public static boolean 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:
      true if file contents was changed or false if it was already in the correct order.
    • seedRecordingLogFromSnapshot

      public static void 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.
    • errors

      public static void errors(PrintStream out, File clusterDir)
      Print out the errors in the error logs for the cluster components.
      Parameters:
      out - to print the output to.
      clusterDir - where the cluster is running.
    • listMembers

      public static void listMembers(PrintStream out, File clusterDir)
      Print out a list of the current members of the cluster.
      Parameters:
      out - to print the output to.
      clusterDir - where the cluster is running.
    • printNextBackupQuery

      public static void printNextBackupQuery(PrintStream out, File clusterDir)
      Print out the time of the next backup query.
      Parameters:
      out - to print the output to.
      clusterDir - where the cluster backup is running.
    • nextBackupQuery

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

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

      public static int isLeader(PrintStream out, File clusterDir)
      Determine if a given node is a leader.
      Parameters:
      out - to print the output to.
      clusterDir - where the cluster is running.
      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

      public static 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

      public static 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

      public static 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

      public static 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

      public static 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

      public static 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

      public static 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

      public static 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

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

      public static boolean describeLatestConsensusModuleSnapshot(PrintStream out, File clusterDir)
      Print out a summary of the state captured in the latest consensus module snapshot.
      Parameters:
      out - to print the operation result.
      clusterDir - where the cluster is running.
      Returns:
      true if the snapshot was successfully described false otherwise.
    • describeLatestConsensusModuleSnapshot

      public static boolean describeLatestConsensusModuleSnapshot(PrintStream out, File clusterDir, BiConsumer<Image,Aeron> postConsensusImageDescriber)
      Print out a summary of the state captured in the latest consensus module snapshot.
      Parameters:
      out - to print the operation result.
      clusterDir - where the cluster is running.
      postConsensusImageDescriber - describe the data after the snapshot used for extensions.
      Returns:
      true if the snapshot was successfully described false otherwise.
    • snapshot

      public static boolean 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:
      true is the operation was successfully requested.
    • suspend

      public static boolean 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:
      true is the operation was successfully requested.
    • resume

      public static boolean 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:
      true is the operation was successfully requested.
    • shutdown

      public static boolean 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:
      true is the operation was successfully requested.
    • abort

      public static boolean 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:
      true is the operation was successfully requested.
    • commands

      public static Map<String,ClusterToolCommand> commands()
      Cluster Tool commands map. This is to allow other tools to simply extend ClusterTool

      Note that the map is cloned and both key and value are Java immutable objects.

      Returns:
      a clone of Cluster Tool commands map