hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From la...@apache.org
Subject svn commit: r1535781 - in /hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io: encoding/BufferedDataBlockEncoder.java encoding/DataBlockEncoder.java hfile/HFileReaderV2.java
Date Fri, 25 Oct 2013 16:58:40 GMT
Author: larsh
Date: Fri Oct 25 16:58:39 2013
New Revision: 1535781

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

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java?rev=1535781&r1=1535780&r2=1535781&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
Fri Oct 25 16:58:39 2013
@@ -125,6 +125,11 @@ abstract class BufferedDataBlockEncoder 
     }
 
     @Override
+    public int compareKey(RawComparator<byte[]> comparator, byte[] key, int offset,
int length) {
+      return comparator.compare(key,  offset, length, current.keyBuffer, 0, current.keyLength);
+    }
+
+    @Override
     public void setCurrentBuffer(ByteBuffer buffer) {
       currentBuffer = buffer;
       decodeFirst();

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java?rev=1535781&r1=1535780&r2=1535781&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java
Fri Oct 25 16:58:39 2013
@@ -156,5 +156,15 @@ public interface DataBlockEncoder {
      */
     public 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(RawComparator<byte []> comparator, byte[] key, int offset,
int length);
   }
 }

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java?rev=1535781&r1=1535780&r2=1535781&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
Fri Oct 25 16:58:39 2013
@@ -38,6 +38,7 @@ import org.apache.hadoop.hbase.io.hfile.
 import org.apache.hadoop.hbase.io.hfile.HFile.FileInfo;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.IdLock;
+import org.apache.hadoop.io.RawComparator;
 import org.apache.hadoop.io.WritableUtils;
 
 /**
@@ -514,9 +515,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().compare(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.
@@ -608,6 +607,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(RawComparator<byte[]> comparator, byte[] key, int
offset,
+        int length);
   }
 
   /**
@@ -647,6 +656,12 @@ public class HFileReaderV2 extends Abstr
     }
 
     @Override
+    public int compareKey(RawComparator<byte []> comparator, byte[] key, int offset,
int length) {
+      return comparator.compare(key, offset, length, blockBuffer.array(), blockBuffer.arrayOffset()
+          + blockBuffer.position() + KEY_VALUE_LEN_SIZE, currKeyLen);
+      }
+
+    @Override
     public ByteBuffer getValue() {
       assertSeeked();
       return ByteBuffer.wrap(
@@ -1042,6 +1057,11 @@ public class HFileReaderV2 extends Abstr
     }
 
     @Override
+    public int compareKey(RawComparator<byte []> 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