hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From la...@apache.org
Subject svn commit: r1570756 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/client/ClientScanner.java test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
Date Sat, 22 Feb 2014 00:06:31 GMT
Author: larsh
Date: Sat Feb 22 00:06:31 2014
New Revision: 1570756

URL: http://svn.apache.org/r1570756
Log:
HBASE-10583 backport HBASE-8402 to 0.94 - ScanMetrics depends on number of rpc calls to the
server. (Liu Shaohui and Himanshu Vashishtha)

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java?rev=1570756&r1=1570755&r2=1570756&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java Sat
Feb 22 00:06:31 2014
@@ -58,7 +58,8 @@ public class ClientScanner extends Abstr
     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.
@@ -240,12 +241,13 @@ public class ClientScanner extends Abstr
      * scan.setAttribute(SCAN_ATTRIBUTES_METRICS_ENABLE, Bytes.toBytes(Boolean.TRUE))
      */
     protected void writeScanMetrics() throws IOException {
-      if (this.scanMetrics == null) {
+      if (this.scanMetrics == null || scanMetricsPublished) {
         return;
       }
       final DataOutputBuffer d = new DataOutputBuffer();
       scanMetrics.write(d);
       scan.setAttribute(Scan.SCAN_ATTRIBUTES_METRICS_DATA, d.getData());
+      scanMetricsPublished = true;
     }
 
     public Result next() throws IOException {
@@ -362,6 +364,13 @@ public class ClientScanner extends Abstr
     }
 
     public void close() {
+      if (!scanMetricsPublished){
+        try {
+          writeScanMetrics();
+        } catch (IOException e) {
+        }
+      }
+      
       if (callable != null) {
         callable.setClose();
         try {
@@ -371,13 +380,6 @@ public class ClientScanner extends Abstr
           // 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;
       }

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=1570756&r1=1570755&r2=1570756&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
(original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
Sat Feb 22 00:06:31 2014
@@ -4576,6 +4576,19 @@ public class TestFromClientSide {
     assertEquals("Did not access all the regions in the table", numOfRegions,
         scanMetrics.countOfRegions.getCurrentIntervalValue());
 
+    // set caching to 100
+    scan = new Scan();
+    scan.setCaching(100);
+    scan.setAttribute(Scan.SCAN_ATTRIBUTES_METRICS_ENABLE, Bytes.toBytes(Boolean.TRUE));
+    scanner = ht.getScanner(scan);
+    for (Result result : scanner.next(numRecords - 1)) {
+    }
+    scanner.close();
+    
+    scanMetrics = getScanMetrics(scan);
+    assertEquals("Did not access all the regions in the table", numOfRegions,
+        scanMetrics.countOfRegions.getCurrentIntervalValue());
+    
     // 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();



Mime
View raw message