HBASE-8402 ScanMetrics depends on number of rpc calls to the server
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1490094 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d6550253a7
commit
c10195177d
|
@ -64,7 +64,8 @@ public class ClientScanner extends AbstractClientScanner {
|
|||
private final HConnection connection;
|
||||
private final byte[] tableName;
|
||||
private final int scannerTimeout;
|
||||
|
||||
private boolean scanMetricsPublished = false;
|
||||
|
||||
/**
|
||||
* Create a new ClientScanner for the specified table. An HConnection will be
|
||||
* retrieved using the passed Configuration.
|
||||
|
@ -243,12 +244,13 @@ public class ClientScanner extends AbstractClientScanner {
|
|||
*
|
||||
* scan.setAttribute(SCAN_ATTRIBUTES_METRICS_ENABLE, Bytes.toBytes(Boolean.TRUE))
|
||||
*/
|
||||
private void writeScanMetrics() throws IOException {
|
||||
if (this.scanMetrics == null) {
|
||||
private void writeScanMetrics() {
|
||||
if (this.scanMetrics == null || scanMetricsPublished) {
|
||||
return;
|
||||
}
|
||||
MapReduceProtos.ScanMetrics pScanMetrics = ProtobufUtil.toScanMetrics(scanMetrics);
|
||||
scan.setAttribute(Scan.SCAN_ATTRIBUTES_METRICS_DATA, pScanMetrics.toByteArray());
|
||||
scanMetricsPublished = true;
|
||||
}
|
||||
|
||||
public Result next() throws IOException {
|
||||
|
@ -390,6 +392,7 @@ public class ClientScanner extends AbstractClientScanner {
|
|||
}
|
||||
|
||||
public void close() {
|
||||
if (!scanMetricsPublished) writeScanMetrics();
|
||||
if (callable != null) {
|
||||
callable.setClose();
|
||||
try {
|
||||
|
@ -399,13 +402,6 @@ public class ClientScanner extends AbstractClientScanner {
|
|||
// have since decided that it's not nice for a scanner's close to
|
||||
// throw exceptions. Chances are it was just an UnknownScanner
|
||||
// exception due to lease time out.
|
||||
} finally {
|
||||
// we want to output the scan metrics even if an error occurred on close
|
||||
try {
|
||||
writeScanMetrics();
|
||||
} catch (IOException e) {
|
||||
// As above, we still don't want the scanner close() method to throw.
|
||||
}
|
||||
}
|
||||
callable = null;
|
||||
}
|
||||
|
|
|
@ -4618,9 +4618,8 @@ public class TestFromClientSide {
|
|||
for (Result result : scanner.next(numRecords - 1)) {
|
||||
}
|
||||
scanner.close();
|
||||
// need to have at one next roundtrip in order to collect metrics
|
||||
// here we have less than <numRecord>+1 KVs, so no metrics were collected
|
||||
assertNull(scan.getAttribute(Scan.SCAN_ATTRIBUTES_METRICS_DATA));
|
||||
// closing the scanner will set the metrics.
|
||||
assertNotNull(scan.getAttribute(Scan.SCAN_ATTRIBUTES_METRICS_DATA));
|
||||
|
||||
// set caching to 1, becasue metrics are collected in each roundtrip only
|
||||
scan = new Scan();
|
||||
|
|
Loading…
Reference in New Issue