@InterfaceAudience.LimitedPrivate(value="Coprocesssor") @InterfaceStability.Evolving public class ScannerContext extends Object
InternalScanner.next(java.util.List)
and
InternalScanner.next(java.util.List)
.
A ScannerContext instance should be updated periodically throughout execution whenever progress towards a limit has been made. Each limit can be checked via the appropriate checkLimit method.
Once a limit has been reached, the scan will stop. The invoker of
InternalScanner.next(java.util.List)
or InternalScanner.next(java.util.List)
can
use the appropriate check*Limit methods to see exactly which limits have been reached.
Alternatively, checkAnyLimitReached(LimitScope)
is provided to see if ANY limit was
reached
NoLimitScannerContext.NO_LIMIT
is an immutable static definition that can be used
whenever a ScannerContext
is needed but limits do not need to be enforced.
NOTE: It is important that this class only ever expose setter methods that can be safely skipped
when limits should be NOT enforced. This is because of the necessary immutability of the class
NoLimitScannerContext
. If a setter cannot be safely skipped, the immutable nature of
NoLimitScannerContext
will lead to incorrect behavior.
Modifier and Type | Class and Description |
---|---|
static class |
ScannerContext.Builder |
private static class |
ScannerContext.LimitFields
The different fields that can be used as limits in calls to
InternalScanner.next(java.util.List) and InternalScanner.next(java.util.List) |
static class |
ScannerContext.LimitScope
The various scopes where a limit can be enforced.
|
static class |
ScannerContext.NextState
The possible states a scanner may be in following a call to
InternalScanner.next(List) |
private static class |
ScannerContext.ProgressFields |
Modifier and Type | Field and Description |
---|---|
private static boolean |
DEFAULT_KEEP_PROGRESS |
private static ScannerContext.NextState |
DEFAULT_STATE |
(package private) boolean |
keepProgress
Used as an indication to invocations of
InternalScanner.next(java.util.List) and
InternalScanner.next(java.util.List) that, if true, the progress tracked within this
ScannerContext instance should be considered while evaluating the limits. |
private Cell |
lastPeekedCell |
(package private) ScannerContext.LimitFields |
limits |
(package private) ServerSideScanMetrics |
metrics
Tracks the relevant server side metrics during scans.
|
(package private) ScannerContext.ProgressFields |
progress
A different set of progress fields.
|
private boolean |
returnImmediately |
(package private) ScannerContext.NextState |
scannerState
The state of the scanner after the invocation of
InternalScanner.next(java.util.List)
or InternalScanner.next(java.util.List) . |
Constructor and Description |
---|
ScannerContext(boolean keepProgress,
ScannerContext.LimitFields limitsToCopy,
boolean trackMetrics) |
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
checkAnyLimitReached(ScannerContext.LimitScope checkerScope) |
(package private) boolean |
checkBatchLimit(ScannerContext.LimitScope checkerScope) |
(package private) boolean |
checkSizeLimit(ScannerContext.LimitScope checkerScope) |
(package private) boolean |
checkTimeLimit(ScannerContext.LimitScope checkerScope) |
(package private) void |
clearProgress()
Clear away any progress that has been made so far.
|
(package private) int |
getBatchLimit() |
(package private) int |
getBatchProgress() |
(package private) long |
getDataSizeLimit() |
(package private) long |
getDataSizeProgress() |
(package private) long |
getHeapSizeProgress() |
(package private) boolean |
getKeepProgress() |
(package private) Cell |
getLastPeekedCell() |
ServerSideScanMetrics |
getMetrics()
Get the metrics instance.
|
(package private) long |
getTimeLimit() |
(package private) long |
getTimeProgress()
Deprecated.
will be removed in 3.0
|
(package private) boolean |
hasAnyLimit(ScannerContext.LimitScope checkerScope)
n * @return true if any limit can be enforced within the checker's scope
|
(package private) boolean |
hasBatchLimit(ScannerContext.LimitScope checkerScope)
n * @return true if the batch limit can be enforced in the checker's scope
|
(package private) boolean |
hasSizeLimit(ScannerContext.LimitScope checkerScope)
n * @return true if the size limit can be enforced in the checker's scope
|
(package private) boolean |
hasTimeLimit(ScannerContext.LimitScope checkerScope)
n * @return true if the time limit can be enforced in the checker's scope
|
(package private) void |
incrementBatchProgress(int batch)
Progress towards the batch limit has been made.
|
(package private) void |
incrementSizeProgress(long dataSize,
long heapSize)
Progress towards the size limit has been made.
|
boolean |
isTrackingMetrics() |
(package private) boolean |
mayHaveMoreCellsInRow() |
static ScannerContext.Builder |
newBuilder() |
static ScannerContext.Builder |
newBuilder(boolean keepProgress) |
(package private) void |
returnImmediately() |
(package private) void |
setBatchProgress(int batchProgress) |
(package private) void |
setKeepProgress(boolean keepProgress) |
(package private) void |
setLastPeekedCell(Cell lastPeekedCell) |
(package private) void |
setProgress(int batchProgress,
long sizeProgress,
long heapSizeProgress) |
(package private) void |
setProgress(int batchProgress,
long sizeProgress,
long heapSizeProgress,
long timeProgress)
Deprecated.
will be removed in 3.0
|
(package private) ScannerContext.NextState |
setScannerState(ScannerContext.NextState state)
Note that this is not a typical setter.
|
(package private) void |
setSizeLimitScope(ScannerContext.LimitScope scope) |
(package private) void |
setSizeProgress(long dataSizeProgress,
long heapSizeProgress) |
(package private) void |
setTimeLimitScope(ScannerContext.LimitScope scope) |
(package private) void |
setTimeProgress(long timeProgress)
Deprecated.
will be removed in 3.0
|
String |
toString() |
(package private) void |
updateTimeProgress()
Deprecated.
will be removed in 3.0
|
ScannerContext.LimitFields limits
ScannerContext.ProgressFields progress
EnvironmentEdgeManager.currentTime()
directly when check time limit.ScannerContext.NextState scannerState
InternalScanner.next(java.util.List)
or InternalScanner.next(java.util.List)
.private static final ScannerContext.NextState DEFAULT_STATE
boolean keepProgress
InternalScanner.next(java.util.List)
and
InternalScanner.next(java.util.List)
that, if true, the progress tracked within this
ScannerContext
instance should be considered while evaluating the limits. Useful for
enforcing a set of limits across multiple calls (i.e. the limit may not be reached in a single
invocation, but any progress made should be considered in future invocations)
Defaulting this value to false means that, by default, any tracked progress will be wiped clean
on invocations to InternalScanner.next(java.util.List)
and
InternalScanner.next(java.util.List)
and the call will be treated as though no progress
has been made towards the limits so far.
This is an important mechanism. Users of Internal/Region scanners expect that they can define
some limits and then repeatedly invoke InternalScanner.next(List)
or
InternalScanner.next(List)
where each invocation respects these limits separately.
For example:
ScannerContext context = new ScannerContext.newBuilder().setBatchLimit(5).build();
RegionScanner scanner = ...
List<Cell> results = new ArrayList<Cell>();
while(scanner.next(results, context)) {
// Do something with a batch of 5 cells
}
However, in the case of RPCs, the server wants to be able to define a set of limits for a
particular RPC request and have those limits respected across multiple invocations. This means
that the progress made towards the limits in earlier calls will be saved and considered in
future invocationsprivate static boolean DEFAULT_KEEP_PROGRESS
private Cell lastPeekedCell
private boolean returnImmediately
final ServerSideScanMetrics metrics
ScannerContext(boolean keepProgress, ScannerContext.LimitFields limitsToCopy, boolean trackMetrics)
public boolean isTrackingMetrics()
public ServerSideScanMetrics getMetrics()
isTrackingMetrics()
has been made to confirm that metrics are indeed being tracked.ServerSideScanMetrics
instance that is tracking metrics for this scanboolean getKeepProgress()
InternalScanner.next(java.util.List)
or
InternalScanner.next(java.util.List)
. false when the progress tracked so far
should not be considered and should instead be wiped away via clearProgress()
void setKeepProgress(boolean keepProgress)
void incrementBatchProgress(int batch)
void incrementSizeProgress(long dataSize, long heapSize)
@Deprecated void updateTimeProgress()
int getBatchProgress()
long getDataSizeProgress()
long getHeapSizeProgress()
@Deprecated long getTimeProgress()
@Deprecated void setProgress(int batchProgress, long sizeProgress, long heapSizeProgress, long timeProgress)
void setProgress(int batchProgress, long sizeProgress, long heapSizeProgress)
void setSizeProgress(long dataSizeProgress, long heapSizeProgress)
void setBatchProgress(int batchProgress)
@Deprecated void setTimeProgress(long timeProgress)
void clearProgress()
ScannerContext.NextState setScannerState(ScannerContext.NextState state)
ScannerContext.NextState
that was
passed in so that methods can be invoked against the new state. Furthermore, this pattern
allows the NoLimitScannerContext
to cleanly override this setter and simply return the
new state, thus preserving the immutability of NoLimitScannerContext
n * @return The
state that was passed in.boolean mayHaveMoreCellsInRow()
boolean hasBatchLimit(ScannerContext.LimitScope checkerScope)
boolean hasSizeLimit(ScannerContext.LimitScope checkerScope)
boolean hasTimeLimit(ScannerContext.LimitScope checkerScope)
boolean hasAnyLimit(ScannerContext.LimitScope checkerScope)
void setSizeLimitScope(ScannerContext.LimitScope scope)
scope
- The scope in which the size limit will be enforcedvoid setTimeLimitScope(ScannerContext.LimitScope scope)
scope
- The scope in which the time limit will be enforcedint getBatchLimit()
long getDataSizeLimit()
long getTimeLimit()
boolean checkBatchLimit(ScannerContext.LimitScope checkerScope)
checkerScope
- The scope that the limit is being checked fromboolean checkSizeLimit(ScannerContext.LimitScope checkerScope)
checkerScope
- The scope that the limit is being checked fromboolean checkTimeLimit(ScannerContext.LimitScope checkerScope)
checkerScope
- The scope that the limit is being checked from. The time limit is always
checked against EnvironmentEdgeManager.currentTime
boolean checkAnyLimitReached(ScannerContext.LimitScope checkerScope)
checkerScope
- The scope that the limits are being checked fromCell getLastPeekedCell()
void setLastPeekedCell(Cell lastPeekedCell)
void returnImmediately()
public static ScannerContext.Builder newBuilder()
public static ScannerContext.Builder newBuilder(boolean keepProgress)
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.