@InterfaceAudience.Private class AsyncTableResultScanner extends Object implements ResultScanner, AdvancedScanResultConsumer
ResultScanner
implementation for RawAsyncTableImpl
. It will fetch data
automatically in background and cache it in memory. Typically, the maxCacheSize
will be
2 * scan.getMaxResultSize()
.AdvancedScanResultConsumer.ScanController, AdvancedScanResultConsumer.ScanResumer
Modifier and Type | Field and Description |
---|---|
private long |
cacheSize |
private boolean |
closed |
private Throwable |
error |
private static org.slf4j.Logger |
LOG |
private long |
maxCacheSize |
private Queue<Result> |
queue |
private AdvancedScanResultConsumer.ScanResumer |
resumer |
private Scan |
scan |
private ScanMetrics |
scanMetrics |
private io.opentelemetry.api.trace.Span |
span |
private TableName |
tableName |
Constructor and Description |
---|
AsyncTableResultScanner(TableName tableName,
Scan scan,
long maxCacheSize) |
Modifier and Type | Method and Description |
---|---|
private void |
addToCache(Result result) |
void |
close()
Closes the scanner and releases any resources it has allocated
|
ScanMetrics |
getScanMetrics()
Returns the scan metrics, or
null if we do not enable metrics. |
(package private) io.opentelemetry.api.trace.Span |
getSpan() |
(package private) boolean |
isSuspended() |
Result |
next()
Grab the next row's worth of values.
|
void |
onComplete()
Indicate that the scan operation is completed normally.
|
void |
onError(Throwable error)
Indicate that we hit an unrecoverable error and the scan operation is terminated.
|
void |
onHeartbeat(AdvancedScanResultConsumer.ScanController controller)
Indicate that there is a heartbeat message but we have not cumulated enough cells to call
AdvancedScanResultConsumer.onNext(Result[], ScanController) . |
void |
onNext(Result[] results,
AdvancedScanResultConsumer.ScanController controller)
Indicate that we have receive some data.
|
void |
onScanMetricsCreated(ScanMetrics scanMetrics)
If
scan.isScanMetricsEnabled() returns true, then this method will be called prior to
all other methods in this interface to give you the ScanMetrics instance for this scan
operation. |
boolean |
renewLease()
Allow the client to renew the scanner's lease on the server.
|
private void |
resumePrefetch() |
(package private) void |
setSpan(io.opentelemetry.api.trace.Span span) |
private void |
stopPrefetch(AdvancedScanResultConsumer.ScanController controller) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
iterator, next
forEach, spliterator
private static final org.slf4j.Logger LOG
private final long maxCacheSize
private ScanMetrics scanMetrics
private long cacheSize
private boolean closed
private AdvancedScanResultConsumer.ScanResumer resumer
private io.opentelemetry.api.trace.Span span
public AsyncTableResultScanner(TableName tableName, Scan scan, long maxCacheSize)
private void addToCache(Result result)
private void stopPrefetch(AdvancedScanResultConsumer.ScanController controller)
io.opentelemetry.api.trace.Span getSpan()
void setSpan(io.opentelemetry.api.trace.Span span)
public void onNext(Result[] results, AdvancedScanResultConsumer.ScanController controller)
AdvancedScanResultConsumer
onNext
in interface AdvancedScanResultConsumer
results
- the data fetched from HBase service.controller
- used to suspend or terminate the scan. Notice that the controller
instance is only valid within scope of onNext method. You can only call its
method in onNext, do NOT store it and call it later outside onNext.public void onHeartbeat(AdvancedScanResultConsumer.ScanController controller)
AdvancedScanResultConsumer
AdvancedScanResultConsumer.onNext(Result[], ScanController)
.
Note that this method will always be called when RS returns something to us but we do not have
enough cells to call AdvancedScanResultConsumer.onNext(Result[], ScanController)
. Sometimes it may not be a
'heartbeat' message for RS, for example, we have a large row with many cells and size limit is
exceeded before sending all the cells for this row. For RS it does send some data to us and the
time limit has not been reached, but we can not return the data to client so here we call this
method to tell client we have already received something.
This method give you a chance to terminate a slow scan operation.
onHeartbeat
in interface AdvancedScanResultConsumer
controller
- used to suspend or terminate the scan. Notice that the controller
instance is only valid within the scope of onHeartbeat method. You can only
call its method in onHeartbeat, do NOT store it and call it later outside
onHeartbeat.public void onError(Throwable error)
ScanResultConsumerBase
We will not call ScanResultConsumerBase.onComplete()
after calling ScanResultConsumerBase.onError(Throwable)
.
onError
in interface ScanResultConsumerBase
public void onComplete()
ScanResultConsumerBase
onComplete
in interface ScanResultConsumerBase
public void onScanMetricsCreated(ScanMetrics scanMetrics)
ScanResultConsumerBase
scan.isScanMetricsEnabled()
returns true, then this method will be called prior to
all other methods in this interface to give you the ScanMetrics
instance for this scan
operation. The ScanMetrics
instance will be updated on-the-fly during the scan, you can
store it somewhere to get the metrics at any time if you want.onScanMetricsCreated
in interface ScanResultConsumerBase
private void resumePrefetch()
public Result next() throws IOException
ResultScanner
next
in interface ResultScanner
IOException
- epublic void close()
ResultScanner
close
in interface Closeable
close
in interface AutoCloseable
close
in interface ResultScanner
public boolean renewLease()
ResultScanner
renewLease
in interface ResultScanner
boolean isSuspended()
public ScanMetrics getScanMetrics()
ResultScanner
null
if we do not enable metrics.getScanMetrics
in interface ResultScanner
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.