hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From la...@apache.org
Subject svn commit: r1535782 - in /hbase/branches/0.96: hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/ hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/ hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/
Date Fri, 25 Oct 2013 16:59:20 GMT
Author: larsh
Date: Fri Oct 25 16:59:20 2013
New Revision: 1535782

URL: http://svn.apache.org/r1535782
Log:
HBASE-9807 block encoder unnecessarily copies the key for each reseek

Modified:
    hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
    hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
    hbase/branches/0.96/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeSeeker.java
    hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java

Modified: hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java?rev=1535782&r1=1535781&r2=1535782&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
(original)
+++ hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
Fri Oct 25 16:59:20 2013
@@ -130,6 +130,12 @@ abstract class BufferedDataBlockEncoder 
     }
 
     @Override
+    public int compareKey(KVComparator comparator, byte[] key, int offset, int length) {
+      return comparator.compareFlatKey(key, offset, length,
+          current.keyBuffer, 0, current.keyLength);
+    }
+
+    @Override
     public void setCurrentBuffer(ByteBuffer buffer) {
       currentBuffer = buffer;
       decodeFirst();

Modified: hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java?rev=1535782&r1=1535781&r2=1535782&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
(original)
+++ hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
Fri Oct 25 16:59:20 2013
@@ -205,5 +205,15 @@ public interface DataBlockEncoder {
     int seekToKeyInBlock(
       byte[] key, int offset, int length, boolean seekBefore
     );
+
+    /**
+     * Compare the given key against the current key
+     * @param comparator
+     * @param key
+     * @param offset
+     * @param length
+     * @return -1 is the passed key is smaller than the current key, 0 if equal and 1 if
greater
+     */
+    public int compareKey(KVComparator comparator, byte[] key, int offset, int length);
   }
 }

Modified: hbase/branches/0.96/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeSeeker.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeSeeker.java?rev=1535782&r1=1535781&r2=1535782&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeSeeker.java
(original)
+++ hbase/branches/0.96/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeSeeker.java
Fri Oct 25 16:59:20 2013
@@ -25,6 +25,7 @@ import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.KeyValueUtil;
+import org.apache.hadoop.hbase.KeyValue.KVComparator;
 import org.apache.hadoop.hbase.codec.prefixtree.decode.DecoderFactory;
 import org.apache.hadoop.hbase.codec.prefixtree.decode.PrefixTreeArraySearcher;
 import org.apache.hadoop.hbase.codec.prefixtree.scanner.CellScannerPosition;
@@ -218,4 +219,10 @@ public class PrefixTreeSeeker implements
     throw new RuntimeException("unexpected CellScannerPosition:"+position);
   }
 
+  @Override
+  public int compareKey(KVComparator comparator, byte[] key, int offset, int length) {
+    // can't optimize this, make a copy of the key
+    ByteBuffer bb = getKeyDeepCopy();
+    return comparator.compareFlatKey(key, offset, length, bb.array(), bb.arrayOffset(), bb.limit());
+  }
 }

Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java?rev=1535782&r1=1535781&r2=1535782&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
(original)
+++ hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
Fri Oct 25 16:59:20 2013
@@ -31,6 +31,7 @@ import org.apache.hadoop.fs.FSDataInputS
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.KeyValue.KVComparator;
 import org.apache.hadoop.hbase.fs.HFileSystem;
 import org.apache.hadoop.hbase.io.encoding.DataBlockEncoder;
 import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
@@ -504,9 +505,7 @@ public class HFileReaderV2 extends Abstr
     public int reseekTo(byte[] key, int offset, int length) throws IOException {
       int compared;
       if (isSeeked()) {
-        ByteBuffer bb = getKey();
-        compared = reader.getComparator().compareFlatKey(key, offset,
-            length, bb.array(), bb.arrayOffset(), bb.limit());
+        compared = compareKey(reader.getComparator(), key, offset, length);
         if (compared < 1) {
           // If the required key is less than or equal to current key, then
           // don't do anything.
@@ -598,6 +597,16 @@ public class HFileReaderV2 extends Abstr
 
       return curBlock;
     }
+    /**
+     * Compare the given key against the current key
+     * @param comparator
+     * @param key
+     * @param offset
+     * @param length
+     * @return -1 is the passed key is smaller than the current key, 0 if equal and 1 if
greater
+     */
+    public abstract int compareKey(KVComparator comparator, byte[] key, int offset,
+        int length);
   }
 
   /**
@@ -637,6 +646,12 @@ public class HFileReaderV2 extends Abstr
     }
 
     @Override
+    public int compareKey(KVComparator comparator, byte[] key, int offset, int length) {
+      return comparator.compareFlatKey(key, offset, length, blockBuffer.array(),
+          blockBuffer.arrayOffset() + blockBuffer.position() + KEY_VALUE_LEN_SIZE, currKeyLen);
+    }
+
+    @Override
     public ByteBuffer getValue() {
       assertSeeked();
       return ByteBuffer.wrap(
@@ -1036,6 +1051,11 @@ public class HFileReaderV2 extends Abstr
     }
 
     @Override
+    public int compareKey(KVComparator comparator, byte[] key, int offset, int length) {
+      return seeker.compareKey(comparator, key, offset, length);
+    }
+
+    @Override
     public ByteBuffer getValue() {
       assertValidSeek();
       return seeker.getValueShallowCopy();



Mime
View raw message