@Internal public class ReadChangeStreamPartitionProgressTracker extends RestrictionTracker<StreamProgress,StreamProgress>
ReadChangeStreamPartitionDoFn
to keep
track of the progress of the stream and to split the restriction for runner initiated
checkpoints.
StreamProgress usually is a continuation token which represents a position in time of the stream of a specific partition. The token is used to resume streaming a partition.
On ChangeStreamMutation or Heartbeat response, the tracker will try to claim the continuation token from the response. The tracker stores that continuation token (wrapped in a StreamProgress) so that if the DoFn checkpoints or restarts, the token can be used to resume the stream.
The tracker will fail to claim a token if runner has initiated a checkpoint (by calling
trySplit(0)
). This signals to the DoFn to stop.
When runner initiates a checkpoint, the tracker returns null for the primary split and the residual split includes the entire token. The next time the DoFn try to claim a new StreamProgress, it will fail, and stop. The residual will be scheduled on a new DoFn to resume the work from the previous StreamProgress
RestrictionTracker.HasProgress, RestrictionTracker.IsBounded, RestrictionTracker.Progress, RestrictionTracker.TruncateResult<RestrictionT>
Constructor and Description |
---|
ReadChangeStreamPartitionProgressTracker(StreamProgress streamProgress)
Constructs a restriction tracker with the streamProgress.
|
Modifier and Type | Method and Description |
---|---|
void |
checkDone()
This is to signal to the runner that this restriction has completed.
|
StreamProgress |
currentRestriction()
Returns the streamProgress that was successfully claimed.
|
RestrictionTracker.IsBounded |
isBounded()
This restriction tracker is for unbounded streams.
|
java.lang.String |
toString() |
boolean |
tryClaim(StreamProgress streamProgress)
Claims a new StreamProgress to be processed.
|
@Nullable SplitResult<StreamProgress> |
trySplit(double fractionOfRemainder)
Splits the work that's left.
|
public ReadChangeStreamPartitionProgressTracker(StreamProgress streamProgress)
streamProgress
- represents a position in time of the stream.public RestrictionTracker.IsBounded isBounded()
isBounded
in class RestrictionTracker<StreamProgress,StreamProgress>
IsBounded.UNBOUNDED
public void checkDone() throws java.lang.IllegalStateException
checkDone
in class RestrictionTracker<StreamProgress,StreamProgress>
java.lang.IllegalStateException
- when the restriction is not done and there is more work to be
done.public boolean tryClaim(StreamProgress streamProgress)
The claim fails if the runner has previously initiated a checkpoint. The restriction tracker respects the runner initiated checkpoint and fails to claim this streamProgress. The new split will start from the previously successfully claimed streamProgress.
tryClaim
in class RestrictionTracker<StreamProgress,StreamProgress>
streamProgress
- position in time of the stream that is being claimed.public StreamProgress currentRestriction()
currentRestriction
in class RestrictionTracker<StreamProgress,StreamProgress>
public @Nullable SplitResult<StreamProgress> trySplit(double fractionOfRemainder)
Also note that, we only accept checkpoints (fractionOfRemainder = 0). Any other value, we
reject (by returning null
) the request to split since StreamProgress cannot be
broken down into fractions.
trySplit
in class RestrictionTracker<StreamProgress,StreamProgress>
fractionOfRemainder
- the fraction of work remaining, where 0 is a request to checkpoint
current work.public java.lang.String toString()
toString
in class java.lang.Object