Class ReadChangeStreamPartitionProgressTracker
- java.lang.Object
-
- org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<StreamProgress,StreamProgress>
-
- org.apache.beam.sdk.io.gcp.bigtable.changestreams.restriction.ReadChangeStreamPartitionProgressTracker
-
@Internal public class ReadChangeStreamPartitionProgressTracker extends org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<StreamProgress,StreamProgress>
RestrictionTracker used byReadChangeStreamPartitionDoFnto 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker
org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.HasProgress, org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.IsBounded, org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress, org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.TruncateResult<RestrictionT extends java.lang.Object>
-
-
Constructor Summary
Constructors Constructor Description ReadChangeStreamPartitionProgressTracker(StreamProgress streamProgress)Constructs a restriction tracker with the streamProgress.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckDone()This is to signal to the runner that this restriction has completed.StreamProgresscurrentRestriction()Returns the streamProgress that was successfully claimed.org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.IsBoundedisBounded()This restriction tracker is for unbounded streams.java.lang.StringtoString()booleantryClaim(StreamProgress streamProgress)Claims a new StreamProgress to be processed.@Nullable org.apache.beam.sdk.transforms.splittabledofn.SplitResult<StreamProgress>trySplit(double fractionOfRemainder)Splits the work that's left.
-
-
-
Constructor Detail
-
ReadChangeStreamPartitionProgressTracker
public ReadChangeStreamPartitionProgressTracker(StreamProgress streamProgress)
Constructs a restriction tracker with the streamProgress.- Parameters:
streamProgress- represents a position in time of the stream.
-
-
Method Detail
-
isBounded
public org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.IsBounded isBounded()
This restriction tracker is for unbounded streams.- Specified by:
isBoundedin classorg.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<StreamProgress,StreamProgress>- Returns:
IsBounded.UNBOUNDED
-
checkDone
public void checkDone() throws java.lang.IllegalStateExceptionThis is to signal to the runner that this restriction has completed. Throw an exception if there is more work to be done, and it should not stop. A restriction tracker stops after a runner initiated checkpoint or the streamProgress contains a closeStream response and not a token.- Specified by:
checkDonein classorg.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<StreamProgress,StreamProgress>- Throws:
java.lang.IllegalStateException- when the restriction is not done and there is more work to be done.
-
tryClaim
public boolean tryClaim(StreamProgress streamProgress)
Claims a new StreamProgress to be processed. StreamProgress can either be a ContinuationToken or a CloseStream.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.
- Specified by:
tryClaimin classorg.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<StreamProgress,StreamProgress>- Parameters:
streamProgress- position in time of the stream that is being claimed.- Returns:
- true if claim was successful, otherwise false.
-
currentRestriction
public StreamProgress currentRestriction()
Returns the streamProgress that was successfully claimed.- Specified by:
currentRestrictionin classorg.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<StreamProgress,StreamProgress>- Returns:
- the streamProgress that was successfully claimed.
-
trySplit
public @Nullable org.apache.beam.sdk.transforms.splittabledofn.SplitResult<StreamProgress> trySplit(double fractionOfRemainder)
Splits the work that's left. Since the position in the stream isn't a contiguous value, we cannot estimate how much work is left or breakdown the work into smaller chunks. Therefore, there's no way to split the work. To conform to the API, we return null for the primary split and then continue the work on the residual split.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.- Specified by:
trySplitin classorg.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<StreamProgress,StreamProgress>- Parameters:
fractionOfRemainder- the fraction of work remaining, where 0 is a request to checkpoint current work.- Returns:
- split result when fractionOfRemainder = 0, otherwise null.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-