Package org.apache.beam.sdk.io.range
Class ByteKeyRangeTracker
java.lang.Object
org.apache.beam.sdk.io.range.ByteKeyRangeTracker
- All Implemented Interfaces:
RangeTracker<ByteKey>
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the approximate fraction of positions in the source that have been consumed by successfulRangeTracker.tryReturnRecordAt(boolean, PositionT)calls, or 0.0 if no such calls have happened.getRange()Returns the current range.longReturns the starting position of the current range, inclusive.Returns the ending position of the current range, exclusive.booleanisDone()booleanmarkDone()Marks this range tracker as being done.static ByteKeyRangeTrackerof(ByteKeyRange range) Instantiates a newByteKeyRangeTrackerwith the specified range.toString()booleantryReturnRecordAt(boolean isAtSplitPoint, ByteKey recordStart) Atomically determines whether a record at the given position can be returned and updates internal state.booleantrySplitAtPosition(ByteKey splitPosition) Atomically splits the current range [RangeTracker.getStartPosition(),RangeTracker.getStopPosition()) into a "primary" part [RangeTracker.getStartPosition(),splitPosition) and a "residual" part [splitPosition,RangeTracker.getStopPosition()), assuming the current last-consumed position is within [RangeTracker.getStartPosition(), splitPosition) (i.e.,splitPositionhas not been consumed yet).
-
Method Details
-
of
Instantiates a newByteKeyRangeTrackerwith the specified range. -
isDone
public boolean isDone() -
getStartPosition
Description copied from interface:RangeTrackerReturns the starting position of the current range, inclusive.- Specified by:
getStartPositionin interfaceRangeTracker<ByteKey>
-
getStopPosition
Description copied from interface:RangeTrackerReturns the ending position of the current range, exclusive.- Specified by:
getStopPositionin interfaceRangeTracker<ByteKey>
-
getRange
Returns the current range. -
tryReturnRecordAt
Description copied from interface:RangeTrackerAtomically determines whether a record at the given position can be returned and updates internal state. In particular:- If
isAtSplitPointistrue, andrecordStartis outside the current range, returnsfalse; - Otherwise, updates the last-consumed position to
recordStartand returnstrue.
This method MUST be called on all split point records. It may be called on every record.
- Specified by:
tryReturnRecordAtin interfaceRangeTracker<ByteKey>
- If
-
trySplitAtPosition
Description copied from interface:RangeTrackerAtomically splits the current range [RangeTracker.getStartPosition(),RangeTracker.getStopPosition()) into a "primary" part [RangeTracker.getStartPosition(),splitPosition) and a "residual" part [splitPosition,RangeTracker.getStopPosition()), assuming the current last-consumed position is within [RangeTracker.getStartPosition(), splitPosition) (i.e.,splitPositionhas not been consumed yet).Updates the current range to be the primary and returns
true. This means that all further calls on the current object will interpret their arguments relative to the primary range.If the split position has already been consumed, or if no
RangeTracker.tryReturnRecordAt(boolean, PositionT)call was made yet, returnsfalse. The second condition is to prevent dynamic splitting during reader start-up.- Specified by:
trySplitAtPositionin interfaceRangeTracker<ByteKey>
-
getFractionConsumed
public double getFractionConsumed()Description copied from interface:RangeTrackerReturns the approximate fraction of positions in the source that have been consumed by successfulRangeTracker.tryReturnRecordAt(boolean, PositionT)calls, or 0.0 if no such calls have happened.- Specified by:
getFractionConsumedin interfaceRangeTracker<ByteKey>
-
getSplitPointsConsumed
public long getSplitPointsConsumed() -
markDone
public boolean markDone()Marks this range tracker as being done. Specifically, this will mark the current split point, if one exists, as being finished.Always returns false, so that it can be used in an implementation of
Source.Reader.start()orSource.Reader.advance()as follows:public boolean start() { return startImpl() && rangeTracker.tryReturnRecordAt(isAtSplitPoint, position) || rangeTracker.markDone(); } -
toString
-