Class TimestampRangeTracker
java.lang.Object
org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>
org.apache.beam.sdk.io.gcp.spanner.changestreams.restriction.TimestampRangeTracker
- All Implemented Interfaces:
RestrictionTracker.HasProgress
- Direct Known Subclasses:
DetectNewPartitionsRangeTracker,ReadChangeStreamPartitionRangeTracker
public class TimestampRangeTracker
extends RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>
implements RestrictionTracker.HasProgress
A
RestrictionTracker for claiming positions in a TimestampRange in a
monotonically increasing fashion.
The smallest position is Timestamp.MIN_VALUE and the largest position is
Timestamp.MAX_VALUE - 1 nanosecond.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker
RestrictionTracker.HasProgress, RestrictionTracker.IsBounded, RestrictionTracker.Progress, RestrictionTracker.TruncateResult<RestrictionT> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Nullable com.google.cloud.Timestampprotected @Nullable com.google.cloud.Timestampprotected TimestampRangeprotected Supplier<com.google.cloud.Timestamp> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks if the restriction has been processed successfully.Returns a restriction accurately describing the full range of work the currentDoFn.ProcessElementcall will do, including already completed work.Returns the progress made within the restriction so far.Return the boundedness of the current restriction.voidsetTimeSupplier(Supplier<com.google.cloud.Timestamp> timeSupplier) booleantryClaim(com.google.cloud.Timestamp position) Attempts to claim the given position.booleantryClaim(com.google.cloud.Timestamp position, PartitionMetadata partitionMetadata) trySplit(double fractionOfRemainder) Splits the restriction through the following algorithm:
-
Field Details
-
range
-
lastAttemptedPosition
-
lastClaimedPosition
-
timeSupplier
-
-
Constructor Details
-
TimestampRangeTracker
-
-
Method Details
-
setTimeSupplier
-
tryClaim
public boolean tryClaim(com.google.cloud.Timestamp position) Attempts to claim the given position. Depending on the position following outcomes are possible:- If the position is less than or equal to a previous attempted one, an
IllegalArgumentExceptionwill be thrown - If the position is less than the restriction range start, an
IllegalArgumentExceptionwill be thrown - If the position is greater than or equal to the range end, the position will not be claimed
- If the position is greater or equal to the range start and less than the range end, the position will be claimed
lastAttemptedPosition.- Specified by:
tryClaimin classRestrictionTracker<TimestampRange,com.google.cloud.Timestamp> - Returns:
trueif the position was successfully claimed,falseotherwise
- If the position is less than or equal to a previous attempted one, an
-
tryClaim
-
trySplit
Splits the restriction through the following algorithm:currentPosition = lastAttemptedPosition == null ? (from - 1ns) : lastAttemptedPosition splitPosition = currentPosition + max(1, (range.to - currentPosition) * fractionOfRemainder) primary = [range.from, splitPosition) residual = [splitPosition, range.to) this.range = primaryIf thesplitPositionis greater than therange.to,nullwill be returned. For checkpoints thefractionOfRemainderwill always be zero.- Specified by:
trySplitin classRestrictionTracker<TimestampRange,com.google.cloud.Timestamp> - Parameters:
fractionOfRemainder- A hint as to the fraction of work the primary restriction should represent based upon the current known remaining amount of work.- Returns:
- a
SplitResultif a split was possible ornullif thesplitPositionis beyond the end of the range.
-
checkDone
Checks if the restriction has been processed successfully. If not, throws anIllegalStateException.The restriction is considered processed successfully if:
- The range is empty (
range.from == range.to) - The
lastAttemptedPosition + 1ns >= range.to
- No position claim was attempted for a non-empty range
- The
lastAttemptedPosition + 1ns < range.to
- Specified by:
checkDonein classRestrictionTracker<TimestampRange,com.google.cloud.Timestamp> - Throws:
IllegalStateException
- The range is empty (
-
getProgress
Returns the progress made within the restriction so far. If lastAttemptedPosition is null, the start of the range is used as the completed work; otherwise, lastAttemptedPosition will be used. The time gap between lastAttemptedPosition and now is used as the remaining work. In this way, when the time gap becomes large, we will have more backlog to process and we should add more resources.- Specified by:
getProgressin interfaceRestrictionTracker.HasProgress- Returns:
- work completed and work remaining in seconds.
-
currentRestriction
Description copied from class:RestrictionTrackerReturns a restriction accurately describing the full range of work the currentDoFn.ProcessElementcall will do, including already completed work.The current restriction returned by method may be updated dynamically due to due to concurrent invocation of other methods of the
RestrictionTracker, For example,RestrictionTracker.trySplit(double).This method is required to be implemented.
- Specified by:
currentRestrictionin classRestrictionTracker<TimestampRange,com.google.cloud.Timestamp>
-
isBounded
Description copied from class:RestrictionTrackerReturn the boundedness of the current restriction. If the current restriction represents a finite amount of work, it should returnRestrictionTracker.IsBounded.BOUNDED. Otherwise, it should returnRestrictionTracker.IsBounded.UNBOUNDED.It is valid to return
RestrictionTracker.IsBounded.BOUNDEDafter returningRestrictionTracker.IsBounded.UNBOUNDEDonce the end of a restriction is discovered. It is not valid to returnRestrictionTracker.IsBounded.UNBOUNDEDafter returningRestrictionTracker.IsBounded.BOUNDED.This method is required to be implemented.
- Specified by:
isBoundedin classRestrictionTracker<TimestampRange,com.google.cloud.Timestamp>
-