Index: src/main/java/org/apache/hadoop/hbase/HConstants.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/HConstants.java (revision 1400720) +++ src/main/java/org/apache/hadoop/hbase/HConstants.java (working copy) @@ -505,6 +505,16 @@ public static int DEFAULT_HBASE_CLIENT_PREFETCH_LIMIT = 10; /** + * Parameter name to set the default scanner caching for all clients. + */ + public static String HBASE_CLIENT_SCANNER_CACHING = "hbase.client.scanner.caching"; + + /** + * Default value for {@link #HBASE_CLIENT_SCANNER_CACHING} + */ + public static int DEFAULT_HBASE_CLIENT_SCANNER_CACHING = 10; + + /** * Parameter name for number of rows that will be fetched when calling next on * a scanner if it is not served from memory. Higher caching values will * enable faster scanners but will eat up more memory and some calls of next Index: src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java (revision 1400720) +++ src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java (working copy) @@ -113,7 +113,9 @@ if (this.scan.getCaching() > 0) { this.caching = this.scan.getCaching(); } else { - this.caching = conf.getInt("hbase.client.scanner.caching", 1); + this.caching = conf.getInt( + HConstants.HBASE_CLIENT_SCANNER_CACHING, + HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING); } // initialize the scanner Index: src/main/java/org/apache/hadoop/hbase/client/HTable.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/HTable.java (revision 1400720) +++ src/main/java/org/apache/hadoop/hbase/client/HTable.java (working copy) @@ -241,7 +241,8 @@ this.autoFlush = true; this.currentWriteBufferSize = 0; this.scannerCaching = this.configuration.getInt( - "hbase.client.scanner.caching", 1); + HConstants.HBASE_CLIENT_SCANNER_CACHING, + HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING); this.maxKeyValueSize = this.configuration.getInt( "hbase.client.keyvalue.maxsize", -1); Index: src/main/resources/hbase-default.xml =================================================================== --- src/main/resources/hbase-default.xml (revision 1400720) +++ src/main/resources/hbase-default.xml (working copy) @@ -140,7 +140,7 @@ hbase.client.scanner.caching - 1 + 10 Number of rows that will be fetched when calling next on a scanner if it is not served from (local, client) memory. Higher caching values will enable faster scanners but will eat up more memory Index: src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (revision 1400720) +++ src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (working copy) @@ -4515,7 +4515,20 @@ // turn on scan metrics Scan scan = new Scan(); scan.setAttribute(Scan.SCAN_ATTRIBUTES_METRICS_ENABLE, Bytes.toBytes(Boolean.TRUE)); + scan.setCaching(numRecords+1); ResultScanner scanner = ht.getScanner(scan); + 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 +1 KVs, so no metrics were collected + assertNull(scan.getAttribute(Scan.SCAN_ATTRIBUTES_METRICS_DATA)); + + // set caching to 1, becasue metrics are collected in each roundtrip only + scan = new Scan(); + scan.setAttribute(Scan.SCAN_ATTRIBUTES_METRICS_ENABLE, Bytes.toBytes(Boolean.TRUE)); + scan.setCaching(1); + scanner = ht.getScanner(scan); // per HBASE-5717, this should still collect even if you don't run all the way to // the end of the scanner. So this is asking for 2 of the 3 rows we inserted. for (Result result : scanner.next(numRecords - 1)) { @@ -4529,6 +4542,7 @@ // 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 Scan scanWithoutClose = new Scan(); + scanWithoutClose.setCaching(1); scanWithoutClose.setAttribute(Scan.SCAN_ATTRIBUTES_METRICS_ENABLE, Bytes.toBytes(Boolean.TRUE)); ResultScanner scannerWithoutClose = ht.getScanner(scanWithoutClose); for (Result result : scannerWithoutClose.next(numRecords + 1)) { @@ -4540,6 +4554,8 @@ // finally, test that the metrics are collected correctly if you both run past all the records, // AND close the scanner Scan scanWithClose = new Scan(); + // make sure we can set caching up to the number of a scanned values + scanWithClose.setCaching(numRecords); scanWithClose.setAttribute(Scan.SCAN_ATTRIBUTES_METRICS_ENABLE, Bytes.toBytes(Boolean.TRUE)); ResultScanner scannerWithClose = ht.getScanner(scanWithClose); for (Result result : scannerWithClose.next(numRecords + 1)) {