public class TimestampRangeTracker extends RestrictionTracker<TimestampRange,com.google.cloud.Timestamp> implements 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
.
RestrictionTracker.HasProgress, RestrictionTracker.IsBounded, RestrictionTracker.Progress, 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 |
Constructor and Description |
---|
TimestampRangeTracker(TimestampRange range) |
Modifier and Type | Method and Description |
---|---|
void |
checkDone()
Checks if the restriction has been processed successfully.
|
TimestampRange |
currentRestriction()
Returns a restriction accurately describing the full range of work the current
DoFn.ProcessElement call will do, including already completed work. |
RestrictionTracker.Progress |
getProgress()
Returns the progress made within the restriction so far.
|
RestrictionTracker.IsBounded |
isBounded()
Return the boundedness of the current restriction.
|
boolean |
tryClaim(com.google.cloud.Timestamp position)
Attempts to claim the given position.
|
@Nullable 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
public TimestampRangeTracker(TimestampRange range)
public boolean tryClaim(com.google.cloud.Timestamp position)
IllegalArgumentException
will be thrown
IllegalArgumentException
will be thrown
lastAttemptedPosition
.tryClaim
in class RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>
true
if the position was successfully claimed, false
otherwisepublic @Nullable 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 = primaryIf the
splitPosition
is greater than the range.to
, null
will be
returned. For checkpoints the fractionOfRemainder
will always be zero.trySplit
in class RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>
fractionOfRemainder
- A hint as to the fraction of work the primary restriction should
represent based upon the current known remaining amount of work.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 RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>
java.lang.IllegalStateException
public RestrictionTracker.Progress getProgress()
If no position was attempted, it will return workCompleted
as 0 and workRemaining
as 1. If a position was attempted, it will return the fraction of work completed
and work remaining based on the offset the position represents in the restriction range. If the
last position attempted was greater than the end of the restriction range, it will return
workCompleted
as 1 and workRemaining
as 0.
getProgress
in interface RestrictionTracker.HasProgress
public TimestampRange currentRestriction()
RestrictionTracker
DoFn.ProcessElement
call 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.
currentRestriction
in class RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>
public RestrictionTracker.IsBounded isBounded()
RestrictionTracker
RestrictionTracker.IsBounded.BOUNDED
. Otherwise, it should return
RestrictionTracker.IsBounded.UNBOUNDED
.
It is valid to return RestrictionTracker.IsBounded.BOUNDED
after returning RestrictionTracker.IsBounded.UNBOUNDED
once the end of a restriction is discovered. It is not valid to return RestrictionTracker.IsBounded.UNBOUNDED
after returning RestrictionTracker.IsBounded.BOUNDED
.
This method is required to be implemented.
isBounded
in class RestrictionTracker<TimestampRange,com.google.cloud.Timestamp>