hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1490094 - in /hbase/trunk: hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
Date Thu, 06 Jun 2013 00:44:00 GMT
Author: stack
Date: Thu Jun  6 00:44:00 2013
New Revision: 1490094

URL: http://svn.apache.org/r1490094
Log:
HBASE-8402 ScanMetrics depends on number of rpc calls to the server

Modified:
    hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java

Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java?rev=1490094&r1=1490093&r2=1490094&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java
(original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java
Thu Jun  6 00:44:00 2013
@@ -64,7 +64,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.
@@ -243,12 +244,13 @@ public class ClientScanner extends Abstr
      *
      * 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 Abstr
     }
 
     public void close() {
+      if (!scanMetricsPublished) writeScanMetrics();
       if (callable != null) {
         callable.setClose();
         try {
@@ -399,13 +402,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/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=1490094&r1=1490093&r2=1490094&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
Thu Jun  6 00:44:00 2013
@@ -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();



Mime
View raw message