Class RecoveryState

java.lang.Object
io.aeron.cluster.service.RecoveryState

public final class RecoveryState extends Object
Counter representing the Recovery State for the cluster.

Key layout as follows:

   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
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                     Leadership Term ID                        |
  |                                                               |
  +---------------------------------------------------------------+
  |                  Log position for Snapshot                    |
  |                                                               |
  +---------------------------------------------------------------+
  |              Timestamp at beginning of Recovery               |
  |                                                               |
  +---------------------------------------------------------------+
  |                         Cluster ID                            |
  +---------------------------------------------------------------+
  |                     Count of Services                         |
  +---------------------------------------------------------------+
  |             Snapshot Recording ID (Service ID 0)              |
  |                                                               |
  +---------------------------------------------------------------+
  |             Snapshot Recording ID (Service ID n)              |
  |                                                               |
  +---------------------------------------------------------------+
 
  • Field Details

    • RECOVERY_STATE_TYPE_ID

      public static final int RECOVERY_STATE_TYPE_ID
      Type id of a recovery state counter.
      See Also:
    • NAME

      public static final String NAME
      Human-readable name for the counter.
      See Also:
    • LEADERSHIP_TERM_ID_OFFSET

      public static final int LEADERSHIP_TERM_ID_OFFSET
      Offset of the term-id field.
      See Also:
    • LOG_POSITION_OFFSET

      public static final int LOG_POSITION_OFFSET
      Offset of the log-position field.
      See Also:
    • TIMESTAMP_OFFSET

      public static final int TIMESTAMP_OFFSET
      Offset of the timestamp field.
      See Also:
    • CLUSTER_ID_OFFSET

      public static final int CLUSTER_ID_OFFSET
      Offset of the cluster-id field.
      See Also:
    • SERVICE_COUNT_OFFSET

      public static final int SERVICE_COUNT_OFFSET
      Offset of the service-count field.
      See Also:
    • SNAPSHOT_RECORDING_IDS_OFFSET

      public static final int SNAPSHOT_RECORDING_IDS_OFFSET
      Offset of the snapshot-recording-ids field.
      See Also:
  • Method Details

    • allocate

      public static Counter allocate(Aeron aeron, long leadershipTermId, long logPosition, long timestamp, int clusterId, long... snapshotRecordingIds)
      Allocate a counter to represent the snapshot services should load on start.
      Parameters:
      aeron - to allocate the counter.
      leadershipTermId - at which the snapshot was taken.
      logPosition - at which the snapshot was taken.
      timestamp - the snapshot was taken.
      clusterId - which identifies the cluster instance.
      snapshotRecordingIds - for the services to use during recovery indexed by service id.
      Returns:
      the Counter for the recovery state.
    • findCounterId

      public static int findCounterId(CountersReader counters, int clusterId)
      Find the active counter id for recovery state.
      Parameters:
      counters - to search within.
      clusterId - to constrain the search.
      Returns:
      the counter id if found otherwise CountersReader.NULL_COUNTER_ID.
    • getLeadershipTermId

      public static long getLeadershipTermId(CountersReader counters, int counterId)
      Get the leadership term id for the snapshot state. Aeron.NULL_VALUE if no snapshot for recovery.
      Parameters:
      counters - to search within.
      counterId - for the active recovery counter.
      Returns:
      the leadership term id if found otherwise Aeron.NULL_VALUE.
    • getLogPosition

      public static long getLogPosition(CountersReader counters, int counterId)
      Get the position at which the snapshot was taken. Aeron.NULL_VALUE if no snapshot for recovery.
      Parameters:
      counters - to search within.
      counterId - for the active recovery counter.
      Returns:
      the log position if found otherwise Aeron.NULL_VALUE.
    • getTimestamp

      public static long getTimestamp(CountersReader counters, int counterId)
      Get the timestamp at the beginning of recovery. Aeron.NULL_VALUE if no snapshot for recovery.
      Parameters:
      counters - to search within.
      counterId - for the active recovery counter.
      Returns:
      the timestamp if found otherwise Aeron.NULL_VALUE.
    • getSnapshotRecordingId

      public static long getSnapshotRecordingId(CountersReader counters, int counterId, int serviceId)
      Get the recording id of the snapshot for a service.
      Parameters:
      counters - to search within.
      counterId - for the active recovery counter.
      serviceId - for the snapshot required.
      Returns:
      the count of replay terms if found otherwise Aeron.NULL_VALUE.