You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by an...@apache.org on 2016/10/03 10:35:18 UTC

hbase git commit: HBASE-16738 L1 cache caching shared memory HFile block when blocks promoted from L2 to L1.

Repository: hbase
Updated Branches:
  refs/heads/master ec0adbd2c -> 250ad644e


HBASE-16738 L1 cache caching shared memory HFile block when blocks promoted from L2 to L1.


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

Branch: refs/heads/master
Commit: 250ad644e4445a948d1fdc09a3e292a9dd05ffa9
Parents: ec0adbd
Author: anoopsamjohn <an...@gmail.com>
Authored: Mon Oct 3 16:04:48 2016 +0530
Committer: anoopsamjohn <an...@gmail.com>
Committed: Mon Oct 3 16:04:48 2016 +0530

----------------------------------------------------------------------
 .../apache/hadoop/hbase/io/hfile/HFileBlock.java  | 18 +++++++++++++++++-
 .../hadoop/hbase/io/hfile/LruBlockCache.java      |  3 +++
 2 files changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/250ad644/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java
index 1535fa9..9d2ccb2 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java
@@ -300,11 +300,23 @@ public class HFileBlock implements Cacheable {
    * Copy constructor. Creates a shallow copy of {@code that}'s buffer.
    */
   private HFileBlock(HFileBlock that) {
+    this(that, false);
+  }
+
+  /**
+   * Copy constructor. Creates a shallow/deep copy of {@code that}'s buffer as per the boolean
+   * param.
+   */
+  private HFileBlock(HFileBlock that,boolean bufCopy) {
     this.blockType = that.blockType;
     this.onDiskSizeWithoutHeader = that.onDiskSizeWithoutHeader;
     this.uncompressedSizeWithoutHeader = that.uncompressedSizeWithoutHeader;
     this.prevBlockOffset = that.prevBlockOffset;
-    this.buf = that.buf.duplicate();
+    if (bufCopy) {
+      this.buf = new SingleByteBuff(ByteBuffer.wrap(that.buf.toBytes(0, that.buf.limit())));
+    } else {
+      this.buf = that.buf.duplicate();
+    }
     this.offset = that.offset;
     this.onDiskDataSizeWithHeader = that.onDiskDataSizeWithHeader;
     this.fileContext = that.fileContext;
@@ -2015,4 +2027,8 @@ public class HFileBlock implements Cacheable {
                    " bytesPerChecksum " + bytesPerChecksum +
                    " onDiskDataSizeWithHeader " + onDiskDataSizeWithHeader;
   }
+
+  public HFileBlock deepClone() {
+    return new HFileBlock(this, true);
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/250ad644/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java
index 99b67ba..f454549 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java
@@ -479,6 +479,9 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
 
         // Promote this to L1.
         if (result != null && caching) {
+          if (result instanceof HFileBlock && ((HFileBlock) result).usesSharedMemory()) {
+            result = ((HFileBlock) result).deepClone();
+          }
           cacheBlock(cacheKey, result, /* inMemory = */ false, /* cacheData = */ true);
         }
         return result;