diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java b/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java index 5e280ac..66ccdd1 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java @@ -332,7 +332,11 @@ class StoreScanner extends NonLazyKeyValueScanner KeyValue.KVComparator comparator = store != null ? store.getComparator() : null; - LOOP: while((kv = this.heap.peek()) != null) { + // we accumulate the metrics in a var and apply it at the end + long cumulativeMetric = 0; + try { +LOOP: + while((kv = this.heap.peek()) != null) { // kv is no longer immutable due to KeyOnlyFilter! use copy for safety KeyValue copyKv = kv.shallowCopy(); // Check that the heap gives us KVs in an increasing order. @@ -364,8 +368,7 @@ class StoreScanner extends NonLazyKeyValueScanner // also update metric accordingly if (this.countPerRow > storeOffset) { if (metric != null) { - HRegion.incrNumericMetric(this.metricNamePrefix + metric, - copyKv.getLength()); + cumulativeMetric += copyKv.getLength(); } results.add(copyKv); } @@ -432,6 +435,13 @@ class StoreScanner extends NonLazyKeyValueScanner throw new RuntimeException("UNEXPECTED"); } } + } finally { + // update the counter + if (cumulativeMetric > 0 && metric != null) { + HRegion.incrNumericMetric(this.metricNamePrefix + metric, + cumulativeMetric); + } + } if (!results.isEmpty()) { // copy jazz