hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anoopsamj...@apache.org
Subject git commit: HBASE-12288 Support DirectByteBuffer usage in DataBlock Encoding area.
Date Wed, 22 Oct 2014 17:03:51 GMT
Repository: hbase
Updated Branches:
  refs/heads/master deaba7814 -> d70e2b124


HBASE-12288 Support DirectByteBuffer usage in DataBlock Encoding area.


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/d70e2b12
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/d70e2b12
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/d70e2b12

Branch: refs/heads/master
Commit: d70e2b12441e7b0a45d2d026be568315c4e4cd88
Parents: deaba78
Author: anoopsjohn <anoopsamjohn@gmail.com>
Authored: Wed Oct 22 22:33:11 2014 +0530
Committer: anoopsjohn <anoopsamjohn@gmail.com>
Committed: Wed Oct 22 22:33:11 2014 +0530

----------------------------------------------------------------------
 .../io/encoding/BufferedDataBlockEncoder.java   | 31 +++++++++-----------
 .../io/encoding/CopyKeyDataBlockEncoder.java    |  9 +++---
 .../hbase/io/encoding/DiffKeyDeltaEncoder.java  |  1 +
 .../hbase/io/encoding/FastDiffDeltaEncoder.java |  6 ++--
 .../io/encoding/PrefixKeyDeltaEncoder.java      |  6 ++--
 .../hadoop/hbase/util/ByteBufferUtils.java      |  5 +++-
 6 files changed, 32 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/d70e2b12/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
index a06e0ac..be8c192 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java
@@ -137,7 +137,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
       }
     }
 
-    protected void createKeyOnlyKeyValue(byte[] keyBuffer, long memTS) {
+    protected void setKey(byte[] keyBuffer, long memTS) {
       currentKey.setKey(keyBuffer, 0, keyLength);
       memstoreTS = memTS;
     }
@@ -302,11 +302,8 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
 
     @Override
     public String toString() {
-      KeyValue kv = KeyValueUtil.copyToNewKeyValue(this);
-      if (kv == null) {
-        return "null";
-      }
-      return kv.toString();
+      return KeyValue.keyToString(this.keyBuffer, 0, KeyValueUtil.keyLength(this)) + "/vlen="
+          + getValueLength() + "/seqid=" + memstoreTS;
     }
 
     public Cell shallowCopy() {
@@ -575,7 +572,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
         current.tagCompressionContext = tagCompressionContext;
       }
       decodeFirst();
-      current.createKeyOnlyKeyValue(current.keyBuffer, current.memstoreTS);
+      current.setKey(current.keyBuffer, current.memstoreTS);
       previous.invalidate();
     }
 
@@ -588,9 +585,10 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
 
     @Override
     public ByteBuffer getValueShallowCopy() {
-      return ByteBuffer.wrap(currentBuffer.array(),
-          currentBuffer.arrayOffset() + current.valueOffset,
-          current.valueLength);
+      ByteBuffer dup = currentBuffer.duplicate();
+      dup.position(current.valueOffset);
+      dup.limit(current.valueOffset + current.valueLength);
+      return dup.slice();
     }
 
     @Override
@@ -599,8 +597,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
       kvBuffer.putInt(current.keyLength);
       kvBuffer.putInt(current.valueLength);
       kvBuffer.put(current.keyBuffer, 0, current.keyLength);
-      kvBuffer.put(currentBuffer.array(),
-          currentBuffer.arrayOffset() + current.valueOffset,
+      ByteBufferUtils.copyFromBufferToBuffer(kvBuffer, currentBuffer, current.valueOffset,
           current.valueLength);
       if (current.tagsLength > 0) {
         // Put short as unsigned
@@ -609,7 +606,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
         if (current.tagsOffset != -1) {
           // the offset of the tags bytes in the underlying buffer is marked. So the temp
           // buffer,tagsBuffer was not been used.
-          kvBuffer.put(currentBuffer.array(), currentBuffer.arrayOffset() + current.tagsOffset,
+          ByteBufferUtils.copyFromBufferToBuffer(kvBuffer, currentBuffer, current.tagsOffset,
               current.tagsLength);
         } else {
           // When tagsOffset is marked as -1, tag compression was present and so the tags
were
@@ -639,7 +636,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
         tagCompressionContext.clear();
       }
       decodeFirst();
-      current.createKeyOnlyKeyValue(current.keyBuffer, current.memstoreTS);
+      current.setKey(current.keyBuffer, current.memstoreTS);
       previous.invalidate();
     }
 
@@ -649,7 +646,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
         return false;
       }
       decodeNext();
-      current.createKeyOnlyKeyValue(current.keyBuffer, current.memstoreTS);
+      current.setKey(current.keyBuffer, current.memstoreTS);
       previous.invalidate();
       return true;
     }
@@ -672,7 +669,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
         }
         current.tagsOffset = -1;
       } else {
-        // When tag compress is not used, let us not do temp copying of tags bytes into tagsBuffer.
+        // When tag compress is not used, let us not do copying of tags bytes into tagsBuffer.
         // Just mark the tags Offset so as to create the KV buffer later in getKeyValueBuffer()
         current.tagsOffset = currentBuffer.position();
         ByteBufferUtils.skip(currentBuffer, current.tagsLength);
@@ -783,7 +780,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
         if (currentBuffer.hasRemaining()) {
           previous.copyFromNext(current);
           decodeNext();
-          current.createKeyOnlyKeyValue(current.keyBuffer, current.memstoreTS);
+          current.setKey(current.keyBuffer, current.memstoreTS);
         } else {
           break;
         }

http://git-wip-us.apache.org/repos/asf/hbase/blob/d70e2b12/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/CopyKeyDataBlockEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/CopyKeyDataBlockEncoder.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/CopyKeyDataBlockEncoder.java
index b26b486..6b87c77 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/CopyKeyDataBlockEncoder.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/CopyKeyDataBlockEncoder.java
@@ -68,11 +68,13 @@ public class CopyKeyDataBlockEncoder extends BufferedDataBlockEncoder
{
   @Override
   public ByteBuffer getFirstKeyInBlock(ByteBuffer block) {
     int keyLength = block.getInt(Bytes.SIZEOF_INT);
-    return ByteBuffer.wrap(block.array(),
-        block.arrayOffset() + 3 * Bytes.SIZEOF_INT, keyLength).slice();
+    ByteBuffer dup = block.duplicate();
+    int pos = 3 * Bytes.SIZEOF_INT;
+    dup.position(pos);
+    dup.limit(pos + keyLength);
+    return dup.slice();
   }
 
-
   @Override
   public String toString() {
     return CopyKeyDataBlockEncoder.class.getSimpleName();
@@ -123,5 +125,4 @@ public class CopyKeyDataBlockEncoder extends BufferedDataBlockEncoder
{
 
     return buffer;
   }
-
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/d70e2b12/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java
index 5aa2373..4182dc4 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DiffKeyDeltaEncoder.java
@@ -317,6 +317,7 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
     ByteBuffer result = ByteBuffer.allocate(keyLength);
 
     // copy row
+    assert !(result.isDirect());
     int pos = result.arrayOffset();
     block.get(result.array(), pos, Bytes.SIZEOF_SHORT);
     pos += Bytes.SIZEOF_SHORT;

http://git-wip-us.apache.org/repos/asf/hbase/blob/d70e2b12/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java
index 5bff66a..a6f43d0 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/FastDiffDeltaEncoder.java
@@ -362,8 +362,10 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
     ByteBufferUtils.readCompressedInt(block); // commonLength
     int pos = block.position();
     block.reset();
-    return ByteBuffer.wrap(block.array(), block.arrayOffset() + pos, keyLength)
-        .slice();
+    ByteBuffer dup = block.duplicate();
+    dup.position(pos);
+    dup.limit(pos + keyLength);
+    return dup.slice();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/d70e2b12/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/PrefixKeyDeltaEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/PrefixKeyDeltaEncoder.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/PrefixKeyDeltaEncoder.java
index 51746ac..0286eca 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/PrefixKeyDeltaEncoder.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/PrefixKeyDeltaEncoder.java
@@ -184,8 +184,10 @@ public class PrefixKeyDeltaEncoder extends BufferedDataBlockEncoder {
     }
     int pos = block.position();
     block.reset();
-    return ByteBuffer.wrap(block.array(), block.arrayOffset() + pos, keyLength)
-        .slice();
+    ByteBuffer dup = block.duplicate();
+    dup.position(pos);
+    dup.limit(pos + keyLength);
+    return dup.slice();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/d70e2b12/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java
index 1cbee83..9451542 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java
@@ -331,7 +331,10 @@ public final class ByteBufferUtils {
   }
 
   /**
-   * Copy from one buffer to another from given offset
+   * Copy from one buffer to another from given offset.
+   * <p>
+   * Note : This will advance the position marker of {@code out} but not change the position
maker
+   * for {@code in}
    * @param out destination buffer
    * @param in source buffer
    * @param sourceOffset offset in the source buffer


Mime
View raw message