public class TimestampRangeTracker extends org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<TimestampRange,com.google.cloud.Timestamp> implements org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.HasProgress
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.
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>| Modifier and Type | Field and Description |
|---|---|
protected @Nullable com.google.cloud.Timestamp |
lastAttemptedPosition |
protected @Nullable com.google.cloud.Timestamp |
lastClaimedPosition |
protected TimestampRange |
range |
protected java.util.function.Supplier<com.google.cloud.Timestamp> |
timeSupplier |
| Constructor and Description |
|---|
TimestampRangeTracker(TimestampRange range) |
| Modifier and Type | Method and Description |
|---|---|
void |
checkDone()
Checks if the restriction has been processed successfully.
|
TimestampRange |
currentRestriction() |
org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress |
getProgress()
Returns the progress made within the restriction so far.
|
org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.IsBounded |
isBounded() |
void |
setTimeSupplier(java.util.function.Supplier<com.google.cloud.Timestamp> timeSupplier) |
boolean |
tryClaim(com.google.cloud.Timestamp position)
Attempts to claim the given position.
|
@Nullable org.apache.beam.sdk.transforms.splittabledofn.SplitResult<TimestampRange> |
trySplit(double fractionOfRemainder)
Splits the restriction through the following algorithm:
|
protected TimestampRange range
protected @Nullable com.google.cloud.Timestamp lastAttemptedPosition
protected @Nullable com.google.cloud.Timestamp lastClaimedPosition
protected java.util.function.Supplier<com.google.cloud.Timestamp> timeSupplier
public TimestampRangeTracker(TimestampRange range)
public void setTimeSupplier(java.util.function.Supplier<com.google.cloud.Timestamp> timeSupplier)
public boolean tryClaim(com.google.cloud.Timestamp position)
IllegalArgumentException will be thrown
IllegalArgumentException will be thrown
lastAttemptedPosition.tryClaim in class org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>true if the position was successfully claimed, false otherwisepublic @Nullable org.apache.beam.sdk.transforms.splittabledofn.SplitResult<TimestampRange> trySplit(double fractionOfRemainder)
currentPosition = lastAttemptedPosition == null ? (from - 1ns) : lastAttemptedPosition
splitPosition = currentPosition + max(1, (range.to - currentPosition) * fractionOfRemainder)
primary = [range.from, splitPosition)
residual = [splitPosition, range.to)
this.range = primary
If the splitPosition is greater than the range.to, null will be
returned. For checkpoints the fractionOfRemainder will always be zero.trySplit in class org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>SplitResult if a split was possible or null if the splitPosition is beyond the end of the range.public void checkDone()
throws java.lang.IllegalStateException
IllegalStateException.
The restriction is considered processed successfully if:
range.from == range.to)
lastAttemptedPosition + 1ns >= range.to
lastAttemptedPosition + 1ns < range.to
checkDone in class org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>java.lang.IllegalStateExceptionpublic org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress getProgress()
getProgress in interface org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.HasProgresspublic TimestampRange currentRestriction()
currentRestriction in class org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>public org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.IsBounded isBounded()
isBounded in class org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>