hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-16502 Reduce garbage in BufferedDataBlockEncoder - addendum adopts Hiroshi's suggestion (binlijin)
Date Wed, 31 Aug 2016 01:06:30 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 57c6384b0 -> 9907a7e2a


HBASE-16502 Reduce garbage in BufferedDataBlockEncoder - addendum adopts Hiroshi's suggestion
(binlijin)


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

Branch: refs/heads/branch-1
Commit: 9907a7e2a216a7b3b97d17d74d2c426dbfb96c7f
Parents: 57c6384
Author: tedyu <yuzhihong@gmail.com>
Authored: Tue Aug 30 18:06:24 2016 -0700
Committer: tedyu <yuzhihong@gmail.com>
Committed: Tue Aug 30 18:06:24 2016 -0700

----------------------------------------------------------------------
 .../io/encoding/BufferedDataBlockEncoder.java   | 31 +++++---------------
 .../hbase/io/encoding/DiffKeyDeltaEncoder.java  |  6 ++--
 .../hbase/io/encoding/FastDiffDeltaEncoder.java |  6 ++--
 .../encoding/TestBufferedDataBlockEncoder.java  |  3 +-
 4 files changed, 15 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/9907a7e2/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 6e06bfc..8c77010 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
@@ -94,19 +94,14 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
     protected boolean uncompressTags = true;
 
     /** We need to store a copy of the key. */
-    protected byte[] keyBuffer = new byte[INITIAL_KEY_BUFFER_SIZE];
-    protected byte[] tagsBuffer = null;
+    protected byte[] keyBuffer = HConstants.EMPTY_BYTE_ARRAY;
+    protected byte[] tagsBuffer = HConstants.EMPTY_BYTE_ARRAY;
 
     protected long memstoreTS;
     protected int nextKvOffset;
     protected KeyValue.KeyOnlyKeyValue currentKey = new KeyValue.KeyOnlyKeyValue();
 
-    public SeekerState(boolean tagsCompressed) {
-      if (tagsCompressed) {
-        tagsBuffer = new byte[INITIAL_KEY_BUFFER_SIZE];
-      } else {
-        tagsBuffer = HConstants.EMPTY_BYTE_ARRAY;
-      }
+    public SeekerState() {
     }
 
     protected boolean isValid() {
@@ -123,11 +118,8 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
 
     protected void ensureSpaceForKey() {
       if (keyLength > keyBuffer.length) {
-        // rare case, but we need to handle arbitrary length of key
-        int newKeyBufferLength = Math.max(keyBuffer.length, 1) * 2;
-        while (keyLength > newKeyBufferLength) {
-          newKeyBufferLength *= 2;
-        }
+        int newKeyBufferLength = Integer.highestOneBit(Math.max(
+            INITIAL_KEY_BUFFER_SIZE, keyLength) - 1) << 1;
         byte[] newKeyBuffer = new byte[newKeyBufferLength];
         System.arraycopy(keyBuffer, 0, newKeyBuffer, 0, keyBuffer.length);
         keyBuffer = newKeyBuffer;
@@ -136,11 +128,8 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
 
     protected void ensureSpaceForTags() {
       if (tagsLength > tagsBuffer.length) {
-        // rare case, but we need to handle arbitrary length of tags
-        int newTagsBufferLength = Math.max(tagsBuffer.length, 1) * 2;
-        while (tagsLength > newTagsBufferLength) {
-          newTagsBufferLength *= 2;
-        }
+        int newTagsBufferLength = Integer.highestOneBit(Math.max(
+            INITIAL_KEY_BUFFER_SIZE, tagsLength) - 1) << 1;
         byte[] newTagsBuffer = new byte[newTagsBufferLength];
         System.arraycopy(tagsBuffer, 0, newTagsBuffer, 0, tagsBuffer.length);
         tagsBuffer = newTagsBuffer;
@@ -562,10 +551,6 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
       return this.decodingCtx.getHFileContext().isIncludesTags();
     }
 
-    protected boolean tagsCompressed() {
-      return this.decodingCtx.getHFileContext().isCompressTags();
-    }
-
     @Override
     public int compareKey(KVComparator comparator, byte[] key, int offset, int length) {
       return comparator.compareFlatKey(key, offset, length,
@@ -818,7 +803,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
     protected STATE createSeekerState() {
       // This will fail for non-default seeker state if the subclass does not
       // override this method.
-      return (STATE) new SeekerState(this.tagsCompressed());
+      return (STATE) new SeekerState();
     }
 
     abstract protected void decodeFirst();

http://git-wip-us.apache.org/repos/asf/hbase/blob/9907a7e2/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 e8540b3..6144478 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
@@ -362,8 +362,8 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
     private int rowLengthWithSize;
     private long timestamp;
 
-    public DiffSeekerState(boolean tagsCompressed) {
-      super(tagsCompressed);
+    public DiffSeekerState() {
+      super();
     }
 
     @Override
@@ -501,7 +501,7 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
 
       @Override
       protected DiffSeekerState createSeekerState() {
-        return new DiffSeekerState(this.tagsCompressed());
+        return new DiffSeekerState();
       }
     };
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/9907a7e2/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 258e699..c14b542 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
@@ -379,8 +379,8 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
     private int rowLengthWithSize;
     private int familyLengthWithSize;
 
-    public FastDiffSeekerState(boolean tagsCompressed) {
-      super(tagsCompressed);
+    public FastDiffSeekerState() {
+      super();
     }
 
     @Override
@@ -522,7 +522,7 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
 
       @Override
       protected FastDiffSeekerState createSeekerState() {
-        return new FastDiffSeekerState(this.tagsCompressed());
+        return new FastDiffSeekerState();
       }
     };
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/9907a7e2/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java
index 44ae89d..fb9253e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java
@@ -27,8 +27,7 @@ public class TestBufferedDataBlockEncoder {
 
   @Test
   public void testEnsureSpaceForKey() {
-    BufferedDataBlockEncoder.SeekerState state = new BufferedDataBlockEncoder.SeekerState(
-        false);
+    BufferedDataBlockEncoder.SeekerState state = new BufferedDataBlockEncoder.SeekerState();
     for (int i = 1; i <= 65536; ++i) {
       state.keyLength = i;
       state.ensureSpaceForKey();


Mime
View raw message