You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2011/05/06 16:44:07 UTC

svn commit: r1100236 - in /hbase/trunk: CHANGES.txt src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java

Author: stack
Date: Fri May  6 14:44:07 2011
New Revision: 1100236

URL: http://svn.apache.org/viewvc?rev=1100236&view=rev
Log:
HBASE-3855 Performance degradation of memstore because reseek is linear

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java

Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1100236&r1=1100235&r2=1100236&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Fri May  6 14:44:07 2011
@@ -207,6 +207,8 @@ Release 0.91.0 - Unreleased
                (Harsh J Chouraria)
    HBASE-3835  Switch master and region server pages to Jamon-based templates
    HBASE-3721  Speedup LoadIncrementalHFiles (Ted Yu)
+   HBASE-3855  Performance degradation of memstore because reseek is linear
+               (dhruba borthakur)
 
   TASKS
    HBASE-3559  Move report of split to master OFF the heartbeat channel

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java?rev=1100236&r1=1100235&r2=1100236&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java Fri May  6 14:44:07 2011
@@ -62,6 +62,9 @@ public class MemStore implements HeapSiz
     "hbase.hregion.memstore.mslab.enabled";
   private static final boolean USEMSLAB_DEFAULT = false;
 
+  static final String RESEEKMAX_KEY =
+    "hbase.hregion.memstore.reseek.maxkeys";
+  private static final int RESEEKMAX_DEFAULT = 32;
 
   private Configuration conf;
 
@@ -93,6 +96,11 @@ public class MemStore implements HeapSiz
   
   MemStoreLAB allocator;
 
+  // if a reseek has to scan over more than these number of keys, then
+  // it morphs into a seek. A seek does a tree map-search while 
+  // reseek does a linear scan.
+  int reseekNumKeys;
+
   /**
    * Default constructor. Used for tests.
    */
@@ -121,6 +129,7 @@ public class MemStore implements HeapSiz
     } else {
       this.allocator = null;
     }
+    this.reseekNumKeys = conf.getInt(RESEEKMAX_KEY, RESEEKMAX_DEFAULT);
   }
 
   void dump() {
@@ -643,6 +652,9 @@ public class MemStore implements HeapSiz
     Iterator<KeyValue> kvsetIt;
     Iterator<KeyValue> snapshotIt;
 
+    // number of iterations in this reseek operation
+    int numIterReseek;
+    
     /*
     Some notes...
 
@@ -678,6 +690,10 @@ public class MemStore implements HeapSiz
           // keep it.
           ret = v;
         }
+        numIterReseek--;
+        if (numIterReseek == 0) {
+          break;
+        }
       }
       return ret;
     }
@@ -687,6 +703,7 @@ public class MemStore implements HeapSiz
         close();
         return false;
       }
+      numIterReseek = 0;
 
       // kvset and snapshot will never be empty.
       // if tailSet cant find anything, SS is empty (not null).
@@ -715,14 +732,27 @@ public class MemStore implements HeapSiz
 
     @Override
     public boolean reseek(KeyValue key) {
+      numIterReseek = reseekNumKeys;
       while (kvsetNextRow != null &&
           comparator.compare(kvsetNextRow, key) < 0) {
         kvsetNextRow = getNext(kvsetIt);
+        // if we scanned enough entries but still not able to find the
+        // kv we are looking for, better cut our costs and do a tree
+        // scan using seek.
+        if (kvsetNextRow == null && numIterReseek == 0) {
+          return seek(key);
+        }
       }
 
       while (snapshotNextRow != null &&
           comparator.compare(snapshotNextRow, key) < 0) {
         snapshotNextRow = getNext(snapshotIt);
+        // if we scanned enough entries but still not able to find the
+        // kv we are looking for, better cut our costs and do a tree
+        // scan using seek.
+        if (snapshotNextRow == null && numIterReseek == 0) {
+          return seek(key);
+        }
       }
       return (kvsetNextRow != null || snapshotNextRow != null);
     }