hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject [2/2] hbase git commit: HBASE-16502 Reduce garbage in BufferedDataBlockEncoder - addendum adopts Hiroshi's suggestion (binlijin)
Date Thu, 01 Sep 2016 01:25:12 GMT
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/e792d570
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/e792d570
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/e792d570

Branch: refs/heads/0.98
Commit: e792d570a98374a9829522b22d63b90e25c89104
Parents: b861c33
Author: tedyu <yuzhihong@gmail.com>
Authored: Tue Aug 30 18:06:24 2016 -0700
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Wed Aug 31 18:12:08 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/e792d570/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 32be3c8..8d103af 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
@@ -83,18 +83,13 @@ 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;
 
-    public SeekerState(boolean tagsCompressed) {
-      if (tagsCompressed) {
-        tagsBuffer = new byte[INITIAL_KEY_BUFFER_SIZE];
-      } else {
-        tagsBuffer = HConstants.EMPTY_BYTE_ARRAY;
-      }
+    public SeekerState() {
     }
 
     protected boolean isValid() {
@@ -109,11 +104,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;
@@ -122,11 +114,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;
@@ -199,10 +188,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,
@@ -403,7 +388,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/e792d570/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 d2b93be..832d4f6 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
@@ -392,8 +392,8 @@ public class DiffKeyDeltaEncoder extends BufferedDataBlockEncoder {
     private int rowLengthWithSize;
     private long timestamp;
 
-    public DiffSeekerState(boolean tagsCompressed) {
-      super(tagsCompressed);
+    public DiffSeekerState() {
+      super();
     }
 
     @Override
@@ -531,7 +531,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/e792d570/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 d09d8d7..6f57f0f 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
@@ -404,8 +404,8 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
     private int rowLengthWithSize;
     private int familyLengthWithSize;
 
-    public FastDiffSeekerState(boolean tagsCompressed) {
-      super(tagsCompressed);
+    public FastDiffSeekerState() {
+      super();
     }
 
     @Override
@@ -547,7 +547,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/e792d570/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