You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by mb...@apache.org on 2012/08/28 22:57:20 UTC
svn commit: r1378336 -
/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
Author: mbautin
Date: Tue Aug 28 20:57:19 2012
New Revision: 1378336
URL: http://svn.apache.org/viewvc?rev=1378336&view=rev
Log:
Reduce overhead of maintaing get/next size metric [89-fb] [HBASE-6217]
Author: mycnyc
Summary:
Accumulate increments to the metrics and apply them all at
once. [89-fb] [HBASE-6217]
Test Plan: unit tests
Reviewers: kannan, liyintang
Reviewed By: kannan
CC: hbase-eng@, michalgr
Differential Revision: https://phabricator.fb.com/D552282
Modified:
hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java?rev=1378336&r1=1378335&r2=1378336&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java Tue Aug 28 20:57:19 2012
@@ -332,105 +332,113 @@ class StoreScanner extends NonLazyKeyVal
KeyValue.KVComparator comparator =
store != null ? store.getComparator() : null;
- 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.
- if (prevKV != null && comparator != null
- && comparator.compare(prevKV, kv) > 0) {
- throw new IOException("Key " + prevKV + " followed by a " +
- "smaller key " + kv + " in cf " + store);
- }
- prevKV = copyKv;
- ScanQueryMatcher.MatchCode qcode = matcher.match(copyKv);
+ 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.
+ if (prevKV != null && comparator != null
+ && comparator.compare(prevKV, kv) > 0) {
+ throw new IOException("Key " + prevKV + " followed by a " +
+ "smaller key " + kv + " in cf " + store);
+ }
+ prevKV = copyKv;
+ ScanQueryMatcher.MatchCode qcode = matcher.match(copyKv);
+
+ switch(qcode) {
+ case INCLUDE:
+ case INCLUDE_AND_SEEK_NEXT_ROW:
+ case INCLUDE_AND_SEEK_NEXT_COL:
+ this.countPerRow++;
+ if (storeLimit > -1 &&
+ this.countPerRow > (storeLimit + storeOffset)) {
+ // do what SEEK_NEXT_ROW does.
+ if (!matcher.moreRowsMayExistAfter(kv)) {
+ outResult.addAll(results);
+ return false;
+ }
+ reseek(matcher.getKeyForNextRow(kv));
+ break LOOP;
+ }
- switch(qcode) {
- case INCLUDE:
- case INCLUDE_AND_SEEK_NEXT_ROW:
- case INCLUDE_AND_SEEK_NEXT_COL:
- this.countPerRow++;
- if (storeLimit > -1 &&
- this.countPerRow > (storeLimit + storeOffset)) {
- // do what SEEK_NEXT_ROW does.
- if (!matcher.moreRowsMayExistAfter(kv)) {
- outResult.addAll(results);
- return false;
+ // add to results only if we have skipped #rowOffset kvs
+ // also update metric accordingly
+ if (this.countPerRow > storeOffset) {
+ if (metric != null) {
+ cumulativeMetric += copyKv.getLength();
+ }
+ results.add(copyKv);
}
- reseek(matcher.getKeyForNextRow(kv));
- break LOOP;
- }
- // add to results only if we have skipped #rowOffset kvs
- // also update metric accordingly
- if (this.countPerRow > storeOffset) {
- if (metric != null) {
- HRegion.incrNumericMetric(this.metricNamePrefix + metric,
- copyKv.getLength());
+ if (qcode == ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_ROW) {
+ if (!matcher.moreRowsMayExistAfter(kv)) {
+ outResult.addAll(results);
+ return false;
+ }
+ reseek(matcher.getKeyForNextRow(kv));
+ } else if (qcode == ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_COL) {
+ reseek(matcher.getKeyForNextColumn(kv));
+ } else {
+ this.heap.next();
}
- results.add(copyKv);
- }
- if (qcode == ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_ROW) {
+ if (limit > 0 && (results.size() == limit)) {
+ break LOOP;
+ }
+ continue;
+
+ case DONE:
+ // copy jazz
+ outResult.addAll(results);
+ return true;
+
+ case DONE_SCAN:
+ close();
+
+ // copy jazz
+ outResult.addAll(results);
+
+ return false;
+
+ case SEEK_NEXT_ROW:
+ // This is just a relatively simple end of scan fix, to short-cut end
+ // us if there is an endKey in the scan.
if (!matcher.moreRowsMayExistAfter(kv)) {
outResult.addAll(results);
return false;
}
+
reseek(matcher.getKeyForNextRow(kv));
- } else if (qcode == ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_COL) {
- reseek(matcher.getKeyForNextColumn(kv));
- } else {
- this.heap.next();
- }
+ break;
- if (limit > 0 && (results.size() == limit)) {
- break LOOP;
- }
- continue;
-
- case DONE:
- // copy jazz
- outResult.addAll(results);
- return true;
-
- case DONE_SCAN:
- close();
-
- // copy jazz
- outResult.addAll(results);
-
- return false;
-
- case SEEK_NEXT_ROW:
- // This is just a relatively simple end of scan fix, to short-cut end
- // us if there is an endKey in the scan.
- if (!matcher.moreRowsMayExistAfter(kv)) {
- outResult.addAll(results);
- return false;
- }
+ case SEEK_NEXT_COL:
+ reseek(matcher.getKeyForNextColumn(kv));
+ break;
- reseek(matcher.getKeyForNextRow(kv));
- break;
+ case SKIP:
+ this.heap.next();
+ break;
- case SEEK_NEXT_COL:
- reseek(matcher.getKeyForNextColumn(kv));
- break;
-
- case SKIP:
- this.heap.next();
- break;
-
- case SEEK_NEXT_USING_HINT:
- KeyValue nextKV = matcher.getNextKeyHint(kv);
- if (nextKV != null) {
- reseek(nextKV);
- } else {
- heap.next();
- }
- break;
+ case SEEK_NEXT_USING_HINT:
+ KeyValue nextKV = matcher.getNextKeyHint(kv);
+ if (nextKV != null) {
+ reseek(nextKV);
+ } else {
+ heap.next();
+ }
+ break;
- default:
- throw new RuntimeException("UNEXPECTED");
+ default:
+ throw new RuntimeException("UNEXPECTED");
+ }
}
+ } finally {
+ // update the counter
+ if (cumulativeMetric > 0 && metric != null) {
+ HRegion.incrNumericMetric(this.metricNamePrefix + metric,
+ cumulativeMetric);
+ }
}
if (!results.isEmpty()) {