diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientSmallScanner.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientSmallScanner.java index 8e4a0d8d6e5..e959e272b4b 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientSmallScanner.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientSmallScanner.java @@ -207,6 +207,8 @@ public class ClientSmallScanner extends ClientScanner { } else { setHasMoreResultsContext(false); } + // We need to update result metrics since we are overriding call() + updateResultsMetrics(results); return results; } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java index 6ef4fc41b56..85352ff0386 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java @@ -325,7 +325,7 @@ public class ScannerCallable extends RegionServerCallable { } } - private void updateResultsMetrics(Result[] rrs) { + protected void updateResultsMetrics(Result[] rrs) { if (this.scanMetrics == null || rrs == null || rrs.length == 0) { return; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java index 21df1e965f3..edf22935fcb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java @@ -5004,6 +5004,39 @@ public class TestFromClientSide { assertEquals("Did not access all the regions in the table", numOfRegions, scanMetrics.countOfRegions.get()); + // check byte counters + scan2 = new Scan(); + scan2.setScanMetricsEnabled(true); + scan2.setCaching(1); + scanner = ht.getScanner(scan2); + int numBytes = 0; + for (Result result : scanner.next(1)) { + for (Cell cell: result.listCells()) { + numBytes += CellUtil.estimatedSerializedSizeOf(cell); + } + } + scanner.close(); + scanMetrics = scan2.getScanMetrics(); + assertEquals("Did not count the result bytes", numBytes, + scanMetrics.countOfBytesInResults.get()); + + // check byte counters on a small scan + scan2 = new Scan(); + scan2.setScanMetricsEnabled(true); + scan2.setCaching(1); + scan2.setSmall(true); + scanner = ht.getScanner(scan2); + numBytes = 0; + for (Result result : scanner.next(1)) { + for (Cell cell: result.listCells()) { + numBytes += CellUtil.estimatedSerializedSizeOf(cell); + } + } + scanner.close(); + scanMetrics = scan2.getScanMetrics(); + assertEquals("Did not count the result bytes", numBytes, + scanMetrics.countOfBytesInResults.get()); + // now, test that the metrics are still collected even if you don't call close, but do // run past the end of all the records /** There seems to be a timing issue here. Comment out for now. Fix when time.