Repository: hbase
Updated Branches:
  refs/heads/0.98 7f28fcf42 -> 23a4181d1
  refs/heads/branch-1 4b2f43faf -> fc27fb024
  refs/heads/master bb1d95385 -> 5ad6098b5


HBASE-11876 RegionScanner.nextRaw should not update metrics


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/5ad6098b
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/5ad6098b
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/5ad6098b

Branch: refs/heads/master
Commit: 5ad6098b52fe3b046ff11ffe518ca8a096b7343e
Parents: bb1d953
Author: Andrew Purtell <apurt...@apache.org>
Authored: Tue Sep 2 18:28:56 2014 -0700
Committer: Andrew Purtell <apurt...@apache.org>
Committed: Tue Sep 2 18:28:56 2014 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/regionserver/HRegion.java      | 10 -------
 .../hbase/regionserver/RSRpcServices.java       | 29 ++++++++++++--------
 .../hbase/regionserver/RegionScanner.java       |  1 +
 3 files changed, 19 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/5ad6098b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
index 04ad9a3..b879e8a 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
@@ -4018,19 +4018,9 @@ public class HRegion implements HeapSize { // , Writable{
       if (isFilterDoneInternal()) {
         returnResult = false;
       }
-      if (region != null && region.metricsRegion != null) {
-        long totalSize = 0;
-        for(Cell c:outResults) {
-          // TODO clean up.  Find way to remove this ensureKeyValue
-          KeyValue kv = KeyValueUtil.ensureKeyValue(c);
-          totalSize += kv.getLength();
-        }
-        region.metricsRegion.updateScanNext(totalSize);
-      }
       return returnResult;
     }
 
-
     private void populateFromJoinedHeap(List<Cell> results, int limit)
         throws IOException {
       assert joinedContinuationRow != null;

http://git-wip-us.apache.org/repos/asf/hbase/blob/5ad6098b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
index 9087a30..22e4d88 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
@@ -49,6 +49,7 @@ import org.apache.hadoop.hbase.HBaseIOException;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.MetaTableAccessor;
 import org.apache.hadoop.hbase.NotServingRegionException;
@@ -1965,6 +1966,7 @@ public class RSRpcServices implements 
HBaseRPCErrorHandler,
           lease = regionServer.leases.removeLease(scannerName);
           List<Result> results = new ArrayList<Result>(rows);
           long currentScanResultSize = 0;
+          long totalKvSize = 0;
 
           boolean done = false;
           // Call coprocessor. Get region info from scanner.
@@ -1973,10 +1975,10 @@ public class RSRpcServices implements 
HBaseRPCErrorHandler,
               scanner, results, rows);
             if (!results.isEmpty()) {
               for (Result r : results) {
-                if (maxScannerResultSize < Long.MAX_VALUE){
-                  for (Cell kv : r.rawCells()) {
-                    currentScanResultSize += 
KeyValueUtil.ensureKeyValue(kv).heapSize();
-                  }
+                for (Cell cell : r.rawCells()) {
+                  KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
+                  currentScanResultSize += kv.heapSize();
+                  totalKvSize += kv.getLength();
                 }
               }
             }
@@ -1996,15 +1998,19 @@ public class RSRpcServices implements 
HBaseRPCErrorHandler,
               int i = 0;
               synchronized(scanner) {
                 boolean stale = (region.getRegionInfo().getReplicaId() != 0);
-                for (; i < rows
-                    && currentScanResultSize < maxResultSize; ) {
+                while (i < rows) {
+                  // Stop collecting results if maxScannerResultSize is set 
and we have exceeded it
+                  if ((maxScannerResultSize < Long.MAX_VALUE) &&
+                      (currentScanResultSize >= maxResultSize)) {
+                    break;
+                  }
                   // Collect values to be returned here
                   boolean moreRows = scanner.nextRaw(values);
                   if (!values.isEmpty()) {
-                    if (maxScannerResultSize < Long.MAX_VALUE){
-                      for (Cell kv : values) {
-                        currentScanResultSize += 
KeyValueUtil.ensureKeyValue(kv).heapSize();
-                      }
+                    for (Cell cell : values) {
+                      KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
+                      currentScanResultSize += kv.heapSize();
+                      totalKvSize += kv.getLength();
                     }
                     results.add(Result.create(values, null, stale));
                     i++;
@@ -2016,6 +2022,7 @@ public class RSRpcServices implements 
HBaseRPCErrorHandler,
                 }
               }
               region.readRequestsCount.add(i);
+              region.getMetrics().updateScanNext(totalKvSize);
             } finally {
               region.closeRegionOperation();
             }
@@ -2035,7 +2042,7 @@ public class RSRpcServices implements 
HBaseRPCErrorHandler,
           } else {
             addResults(builder, results, controller, 
RegionReplicaUtil.isDefaultReplica(region.getRegionInfo()));
           }
-        } finally {
+        } finally { 
           // We're done. On way out re-add the above removed lease.
           // Adding resets expiration time on lease.
           if (scanners.containsKey(scannerName)) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/5ad6098b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionScanner.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionScanner.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionScanner.java
index 07cbc4c..f75b9a2 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionScanner.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionScanner.java
@@ -69,6 +69,7 @@ public interface RegionScanner extends InternalScanner {
    * to return.
    * This is a special internal method to be called from coprocessor hooks to 
avoid expensive setup.
    * Caller must set the thread's readpoint, start and close a region 
operation, an synchronize on the scanner object.
+   * Caller should maintain and update metrics.
    * See {@link #nextRaw(List, int)}
    * @param result return output array
    * @return true if more rows exist after this one, false if scanner is done

Reply via email to