@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) |
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. |
(package private) ScannerContext.LimitFields |
limits
Two sets of the same fields.
|
private static org.apache.commons.logging.Log |
LOG |
(package private) ServerSideScanMetrics |
metrics
Tracks the relevant server side metrics during scans.
|
(package private) ScannerContext.LimitFields |
progress |
(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) boolean |
getKeepProgress() |
(package private) ServerSideScanMetrics |
getMetrics()
Get the metrics instance.
|
(package private) long |
getSizeLimit() |
(package private) long |
getSizeProgress() |
(package private) long |
getTimeLimit() |
(package private) long |
getTimeProgress() |
(package private) boolean |
hasAnyLimit(ScannerContext.LimitScope checkerScope) |
(package private) boolean |
hasBatchLimit(ScannerContext.LimitScope checkerScope) |
(package private) boolean |
hasSizeLimit(ScannerContext.LimitScope checkerScope) |
(package private) boolean |
hasTimeLimit(ScannerContext.LimitScope checkerScope) |
(package private) void |
incrementBatchProgress(int batch)
Progress towards the batch limit has been made.
|
(package private) void |
incrementSizeProgress(long size)
Progress towards the size limit has been made.
|
(package private) boolean |
isTrackingMetrics() |
(package private) boolean |
midRowResultFormed() |
static ScannerContext.Builder |
newBuilder() |
static ScannerContext.Builder |
newBuilder(boolean keepProgress) |
(package private) boolean |
partialResultFormed() |
(package private) void |
setBatchProgress(int batchProgress) |
(package private) void |
setKeepProgress(boolean keepProgress) |
(package private) void |
setProgress(int batchProgress,
long sizeProgress,
long timeProgress) |
(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 sizeProgress) |
(package private) void |
setTimeLimitScope(ScannerContext.LimitScope scope) |
(package private) void |
setTimeProgress(long timeProgress) |
String |
toString() |
(package private) void |
updateTimeProgress()
Update the time progress with
System.currentTimeMillis() |
private static final org.apache.commons.logging.Log LOG
ScannerContext.LimitFields limits
ScannerContext.LimitFields progress
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:
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 invocations
ScannerContext context = new ScannerContext.newBuilder().setBatchLimit(5).build();
RegionScanner scanner = ...
List
private static boolean DEFAULT_KEEP_PROGRESS
final ServerSideScanMetrics metrics
ScannerContext(boolean keepProgress, ScannerContext.LimitFields limitsToCopy, boolean trackMetrics)
boolean isTrackingMetrics()
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 size)
void updateTimeProgress()
System.currentTimeMillis()
int getBatchProgress()
long getSizeProgress()
long getTimeProgress()
void setProgress(int batchProgress, long sizeProgress, long timeProgress)
void setSizeProgress(long sizeProgress)
void setBatchProgress(int batchProgress)
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
state
- boolean partialResultFormed()
boolean midRowResultFormed()
boolean hasBatchLimit(ScannerContext.LimitScope checkerScope)
checkerScope
- boolean hasSizeLimit(ScannerContext.LimitScope checkerScope)
checkerScope
- boolean hasTimeLimit(ScannerContext.LimitScope checkerScope)
checkerScope
- boolean hasAnyLimit(ScannerContext.LimitScope checkerScope)
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 getSizeLimit()
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 System.currentTimeMillis()
boolean checkAnyLimitReached(ScannerContext.LimitScope checkerScope)
checkerScope
- The scope that the limits are being checked frompublic static ScannerContext.Builder newBuilder()
public static ScannerContext.Builder newBuilder(boolean keepProgress)
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.