public class SequenceNumbersService extends AbstractIndexShardComponent
Modifier and Type | Field and Description |
---|---|
static long |
NO_OPS_PERFORMED
Represents no operations have been performed on the shard.
|
static long |
UNASSIGNED_SEQ_NO
Represents an unassigned sequence number (e.g., can be used on primary operations before they are executed).
|
deprecationLogger, indexSettings, logger, shardId
Constructor and Description |
---|
SequenceNumbersService(ShardId shardId,
IndexSettings indexSettings,
long maxSeqNo,
long localCheckpoint,
long globalCheckpoint)
Initialize the sequence number service.
|
Modifier and Type | Method and Description |
---|---|
long |
generateSeqNo()
Issue the next sequence number.
|
long |
getGlobalCheckpoint()
Returns the global checkpoint for the shard.
|
long |
getLocalCheckpoint()
Returns the local checkpoint for the shard.
|
long |
getMaxSeqNo()
The maximum sequence number issued so far.
|
void |
markAllocationIdAsInSync(java.lang.String allocationId,
long localCheckpoint)
Marks the shard with the provided allocation ID as in-sync with the primary shard.
|
void |
markSeqNoAsCompleted(long seqNo)
Marks the processing of the provided sequence number as completed as updates the checkpoint if possible.
|
boolean |
pendingInSync()
Check if there are any recoveries pending in-sync.
|
SeqNoStats |
stats()
The current sequence number stats.
|
void |
updateAllocationIdsFromMaster(java.util.Set<java.lang.String> activeAllocationIds,
java.util.Set<java.lang.String> initializingAllocationIds)
Notifies the service of the current allocation IDs in the cluster state.
|
void |
updateGlobalCheckpointOnReplica(long globalCheckpoint)
Updates the global checkpoint on a replica shard after it has been updated by the primary.
|
void |
updateLocalCheckpointForShard(java.lang.String allocationId,
long checkpoint)
Notifies the service to update the local checkpoint for the shard with the provided allocation ID.
|
void |
waitForOpsToComplete(long seqNo)
Waits for all operations up to the provided sequence number to complete.
|
indexSettings, nodeName, shardId
public static final long UNASSIGNED_SEQ_NO
public static final long NO_OPS_PERFORMED
public SequenceNumbersService(ShardId shardId, IndexSettings indexSettings, long maxSeqNo, long localCheckpoint, long globalCheckpoint)
maxSeqNo
should be set to the last sequence number assigned by this shard, or
NO_OPS_PERFORMED
, localCheckpoint
should be set to the last known local checkpoint for this
shard, or NO_OPS_PERFORMED
, and globalCheckpoint
should be set to the last known global
checkpoint for this shard, or UNASSIGNED_SEQ_NO
.shardId
- the shard this service is providing tracking local checkpoints forindexSettings
- the index settingsmaxSeqNo
- the last sequence number assigned by this shard, or NO_OPS_PERFORMED
localCheckpoint
- the last known local checkpoint for this shard, or NO_OPS_PERFORMED
globalCheckpoint
- the last known global checkpoint for this shard, or UNASSIGNED_SEQ_NO
public long generateSeqNo()
markSeqNoAsCompleted(long)
after the operation for which the
issued sequence number completes (whether or not the operation completes successfully).public long getMaxSeqNo()
LocalCheckpointTracker.getMaxSeqNo()
for additional details.public void waitForOpsToComplete(long seqNo) throws java.lang.InterruptedException
seqNo
- the sequence number that the checkpoint must advance to before this method returnsjava.lang.InterruptedException
- if the thread was interrupted while blocking on the conditionpublic void markSeqNoAsCompleted(long seqNo)
LocalCheckpointTracker.markSeqNoAsCompleted(long)
for additional details.seqNo
- the sequence number to mark as completedpublic SeqNoStats stats()
public void updateLocalCheckpointForShard(java.lang.String allocationId, long checkpoint)
GlobalCheckpointTracker.updateLocalCheckpoint(String, long)
for details.allocationId
- the allocation ID of the shard to update the local checkpoint forcheckpoint
- the local checkpoint for the shardpublic void markAllocationIdAsInSync(java.lang.String allocationId, long localCheckpoint) throws java.lang.InterruptedException
GlobalCheckpointTracker.markAllocationIdAsInSync(String, long)
for additional details.allocationId
- the allocation ID of the shard to mark as in-synclocalCheckpoint
- the current local checkpoint on the shardjava.lang.InterruptedException
public long getLocalCheckpoint()
public long getGlobalCheckpoint()
public void updateGlobalCheckpointOnReplica(long globalCheckpoint)
globalCheckpoint
- the global checkpointpublic void updateAllocationIdsFromMaster(java.util.Set<java.lang.String> activeAllocationIds, java.util.Set<java.lang.String> initializingAllocationIds)
GlobalCheckpointTracker.updateAllocationIdsFromMaster(Set, Set)
for details.activeAllocationIds
- the allocation IDs of the currently active shard copiesinitializingAllocationIds
- the allocation IDs of the currently initializing shard copiespublic boolean pendingInSync()
true
if there is at least one shard pending in-sync, otherwise false