hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1151559 - in /hbase/trunk: CHANGES.txt src/main/java/org/apache/hadoop/hbase/regionserver/KeyValueSkipListSet.java src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java
Date Wed, 27 Jul 2011 17:50:37 GMT
Author: stack
Date: Wed Jul 27 17:50:36 2011
New Revision: 1151559

URL: http://svn.apache.org/viewvc?rev=1151559&view=rev
Log:
HBASE-1938 Make in-memory table scanning faster

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/KeyValueSkipListSet.java
    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=1151559&r1=1151558&r2=1151559&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Wed Jul 27 17:50:36 2011
@@ -339,6 +339,7 @@ Release 0.91.0 - Unreleased
    HBASE-4142  Advise against large batches in javadoc for HTable#put(List<Put>)
    HBASE-4139  [stargate] Update ScannerModel with support for filter package
                additions
+   HBASE-1938  Make in-memory table scanning faster (nkeywal)
 
   TASKS
    HBASE-3559  Move report of split to master OFF the heartbeat channel

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/KeyValueSkipListSet.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/KeyValueSkipListSet.java?rev=1151559&r1=1151558&r2=1151559&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/KeyValueSkipListSet.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/KeyValueSkipListSet.java
Wed Jul 27 17:50:36 2011
@@ -24,7 +24,6 @@ import org.apache.hadoop.hbase.KeyValue;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.NavigableSet;
 import java.util.SortedSet;
 import java.util.concurrent.ConcurrentNavigableMap;
@@ -55,37 +54,12 @@ class KeyValueSkipListSet implements Nav
     this.delegatee = m;
   }
 
-  /**
-   * Iterator that maps Iterator calls to return the value component of the
-   * passed-in Map.Entry Iterator.
-   */
-  static class MapEntryIterator implements Iterator<KeyValue> {
-    private final Iterator<Map.Entry<KeyValue, KeyValue>> iterator;
-
-    MapEntryIterator(final Iterator<Map.Entry<KeyValue, KeyValue>> i) {
-      this.iterator = i;
-    }
-
-    public boolean hasNext() {
-      return this.iterator.hasNext();
-    }
-
-    public KeyValue next() {
-      return this.iterator.next().getValue();
-    }
-
-    public void remove() {
-      this.iterator.remove();
-    }
-  }
-
   public KeyValue ceiling(KeyValue e) {
     throw new UnsupportedOperationException("Not implemented");
   }
 
   public Iterator<KeyValue> descendingIterator() {
-    return new MapEntryIterator(this.delegatee.descendingMap().entrySet().
-      iterator());
+    return this.delegatee.descendingMap().values().iterator();
   }
 
   public NavigableSet<KeyValue> descendingSet() {
@@ -110,7 +84,7 @@ class KeyValueSkipListSet implements Nav
   }
 
   public Iterator<KeyValue> iterator() {
-    return new MapEntryIterator(this.delegatee.entrySet().iterator());
+    return this.delegatee.values().iterator();
   }
 
   public KeyValue lower(KeyValue e) {

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=1151559&r1=1151558&r2=1151559&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 Wed Jul 27
17:50:36 2011
@@ -646,11 +646,15 @@ public class MemStore implements HeapSiz
     private KeyValue snapshotNextRow = null;
 
     // iterator based scanning.
-    Iterator<KeyValue> kvsetIt;
-    Iterator<KeyValue> snapshotIt;
+    private Iterator<KeyValue> kvsetIt;
+    private Iterator<KeyValue> snapshotIt;
 
     // number of iterations in this reseek operation
-    int numIterReseek;
+    private int numIterReseek;
+
+
+    // the pre-calculated KeyValue to be returned by peek() or next()
+    private KeyValue theNext;
     
     /*
     Some notes...
@@ -676,9 +680,9 @@ public class MemStore implements HeapSiz
       //DebugPrint.println(" MS new@" + hashCode());
     }
 
-    protected KeyValue getNext(Iterator<KeyValue> it) {
+    protected KeyValue getNext(Iterator<KeyValue> it, long readPoint) {
       KeyValue ret = null;
-      long readPoint = ReadWriteConsistencyControl.getThreadReadPoint();
+      //long readPoint = ReadWriteConsistencyControl.getThreadReadPoint();
       //DebugPrint.println( " MS@" + hashCode() + ": threadpoint = " + readPoint);
 
       while (ret == null && it.hasNext()) {
@@ -710,9 +714,11 @@ public class MemStore implements HeapSiz
       kvsetIt = kvTail.iterator();
       snapshotIt = snapshotTail.iterator();
 
-      kvsetNextRow = getNext(kvsetIt);
-      snapshotNextRow = getNext(snapshotIt);
+      long readPoint = ReadWriteConsistencyControl.getThreadReadPoint();
+      kvsetNextRow = getNext(kvsetIt, readPoint);
+      snapshotNextRow = getNext(snapshotIt, readPoint);
 
+      theNext = getLowest();
 
       //long readPoint = ReadWriteConsistencyControl.getThreadReadPoint();
       //DebugPrint.println( " MS@" + hashCode() + " kvset seek: " + kvsetNextRow + " with
size = " +
@@ -720,19 +726,18 @@ public class MemStore implements HeapSiz
       //DebugPrint.println( " MS@" + hashCode() + " snapshot seek: " + snapshotNextRow +
" with size = " +
       //    snapshot.size() + " threadread = " + readPoint);
 
-
-      KeyValue lowest = getLowest();
-
-      // has data := (lowest != null)
-      return lowest != null;
+      // has data
+      return (theNext != null);
     }
 
     @Override
-    public boolean reseek(KeyValue key) {
+    public synchronized boolean reseek(KeyValue key) {
+
       numIterReseek = reseekNumKeys;
       while (kvsetNextRow != null &&
           comparator.compare(kvsetNextRow, key) < 0) {
-        kvsetNextRow = getNext(kvsetIt);
+        kvsetNextRow = getNext(kvsetIt,
+          ReadWriteConsistencyControl.getThreadReadPoint());
         // 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.
@@ -743,7 +748,8 @@ public class MemStore implements HeapSiz
 
       while (snapshotNextRow != null &&
           comparator.compare(snapshotNextRow, key) < 0) {
-        snapshotNextRow = getNext(snapshotIt);
+        snapshotNextRow = getNext(snapshotIt,
+          ReadWriteConsistencyControl.getThreadReadPoint());
         // 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.
@@ -751,38 +757,48 @@ public class MemStore implements HeapSiz
           return seek(key);
         }
       }
-      return (kvsetNextRow != null || snapshotNextRow != null);
+
+      // Calculate the next value
+      theNext = getLowest();
+
+      return (theNext != null);
     }
 
+    @Override
     public synchronized KeyValue peek() {
       //DebugPrint.println(" MS@" + hashCode() + " peek = " + getLowest());
-      return getLowest();
+      return theNext;
     }
 
 
+    @Override
     public synchronized KeyValue next() {
-      KeyValue theNext = getLowest();
 
       if (theNext == null) {
           return null;
       }
 
+      KeyValue ret = theNext;
+
       // Advance one of the iterators
+      long readPoint = ReadWriteConsistencyControl.getThreadReadPoint();
       if (theNext == kvsetNextRow) {
-        kvsetNextRow = getNext(kvsetIt);
+        kvsetNextRow = getNext(kvsetIt, readPoint);
       } else {
-        snapshotNextRow = getNext(snapshotIt);
+        snapshotNextRow = getNext(snapshotIt, readPoint);
       }
 
-      //long readpoint = ReadWriteConsistencyControl.getThreadReadPoint();
-      //DebugPrint.println(" MS@" + hashCode() + " next: " + theNext + " next_next: " +
-      //    getLowest() + " threadpoint=" + readpoint);
-      return theNext;
+      // Calculate the next value
+      theNext = getLowest();
+
+      //readpoint = ReadWriteConsistencyControl.getThreadReadPoint();
+      //DebugPrint.println(" MS@" + hashCode() + " next: " + theNext +
+      //    " next_next: " + getLowest() + " threadpoint=" + readpoint);
+      return ret;
     }
 
     protected KeyValue getLowest() {
-      return getLower(kvsetNextRow,
-          snapshotNextRow);
+      return getLower(kvsetNextRow, snapshotNextRow);
     }
 
     /*
@@ -791,14 +807,15 @@ public class MemStore implements HeapSiz
      * comparator.
      */
     protected KeyValue getLower(KeyValue first, KeyValue second) {
-      if (first == null && second == null) {
-        return null;
+      if (first == null) {
+        return second;
       }
-      if (first != null && second != null) {
-        int compare = comparator.compare(first, second);
-        return (compare <= 0 ? first : second);
+      if (second == null) {
+        return first;
       }
-      return (first != null ? first : second);
+
+      int compare = comparator.compare(first, second);
+      return (compare <= 0 ? first : second);
     }
 
     public synchronized void close() {



Mime
View raw message