Package org.elasticsearch.index.seqno
Class LocalCheckpointTracker
- java.lang.Object
-
- org.elasticsearch.index.seqno.LocalCheckpointTracker
-
public class LocalCheckpointTracker extends java.lang.ObjectThis class generates sequences numbers and keeps track of the so-called "local checkpoint" which is the highest number for which all previous sequence numbers have been processed (inclusive).
-
-
Constructor Summary
Constructors Constructor Description LocalCheckpointTracker(long maxSeqNo, long localCheckpoint)Initialize the local checkpoint service.
-
Method Summary
Modifier and Type Method Description voidadvanceMaxSeqNo(long seqNo)Marks the provided sequence number as seen and updates the max_seq_no if needed.booleancontains(long seqNo)Checks if the given sequence number was marked as completed in this tracker.longgenerateSeqNo()Issue the next sequence number.longgetCheckpoint()The current checkpoint which can be advanced bymarkSeqNoAsCompleted(long).longgetMaxSeqNo()The maximum sequence number issued so far.SeqNoStatsgetStats(long globalCheckpoint)constructs aSeqNoStatsobject, using local state and the supplied global checkpoint This is needed to make sure the local checkpoint and max seq no are consistentvoidmarkSeqNoAsCompleted(long seqNo)Marks the processing of the provided sequence number as completed as updates the checkpoint if possible.voidwaitForOpsToComplete(long seqNo)Waits for all operations up to the provided sequence number to complete.
-
-
-
Constructor Detail
-
LocalCheckpointTracker
public LocalCheckpointTracker(long maxSeqNo, long localCheckpoint)Initialize the local checkpoint service. ThemaxSeqNoshould be set to the last sequence number assigned, orSequenceNumbers.NO_OPS_PERFORMEDandlocalCheckpointshould be set to the last known local checkpoint, orSequenceNumbers.NO_OPS_PERFORMED.- Parameters:
maxSeqNo- the last sequence number assigned, orSequenceNumbers.NO_OPS_PERFORMEDlocalCheckpoint- the last known local checkpoint, orSequenceNumbers.NO_OPS_PERFORMED
-
-
Method Detail
-
generateSeqNo
public long generateSeqNo()
Issue the next sequence number.- Returns:
- the next assigned sequence number
-
advanceMaxSeqNo
public void advanceMaxSeqNo(long seqNo)
Marks the provided sequence number as seen and updates the max_seq_no if needed.
-
markSeqNoAsCompleted
public void markSeqNoAsCompleted(long seqNo)
Marks the processing of the provided sequence number as completed as updates the checkpoint if possible.- Parameters:
seqNo- the sequence number to mark as completed
-
getCheckpoint
public long getCheckpoint()
The current checkpoint which can be advanced bymarkSeqNoAsCompleted(long).- Returns:
- the current checkpoint
-
getMaxSeqNo
public long getMaxSeqNo()
The maximum sequence number issued so far.- Returns:
- the maximum sequence number
-
getStats
public SeqNoStats getStats(long globalCheckpoint)
constructs aSeqNoStatsobject, using local state and the supplied global checkpoint This is needed to make sure the local checkpoint and max seq no are consistent
-
waitForOpsToComplete
public void waitForOpsToComplete(long seqNo) throws java.lang.InterruptedExceptionWaits for all operations up to the provided sequence number to complete.- Parameters:
seqNo- the sequence number that the checkpoint must advance to before this method returns- Throws:
java.lang.InterruptedException- if the thread was interrupted while blocking on the condition
-
contains
public boolean contains(long seqNo)
Checks if the given sequence number was marked as completed in this tracker.
-
-