hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhang...@apache.org
Subject hbase git commit: HBASE-14178 regionserver blocks because of waiting for offsetLock
Date Thu, 06 Aug 2015 09:20:29 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 edc48c10f -> 0dfd2cea4


HBASE-14178 regionserver blocks because of waiting for offsetLock

Signed-off-by: zhangduo <zhangduo@apache.org>


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

Branch: refs/heads/0.98
Commit: 0dfd2cea4a6be3d98bbf5b0ef9769a584dd1986c
Parents: edc48c1
Author: chenheng <chenheng@fenbi.com>
Authored: Thu Aug 6 16:26:34 2015 +0800
Committer: zhangduo <zhangduo@apache.org>
Committed: Thu Aug 6 17:18:24 2015 +0800

----------------------------------------------------------------------
 .../hadoop/hbase/io/hfile/CacheConfig.java      | 42 ++++++++++++++++++++
 .../hadoop/hbase/io/hfile/HFileReaderV2.java    | 20 +++++-----
 2 files changed, 52 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/0dfd2cea/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java
index 8c222ea..376df07 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java
@@ -364,6 +364,48 @@ public class CacheConfig {
     return isBlockCacheEnabled() && this.prefetchOnOpen;
   }
 
+  /**
+   * Return true if we may find this type of block in block cache.
+   * <p>
+   * TODO: today {@code family.isBlockCacheEnabled()} only means {@code cacheDataOnRead},
so here we
+   * consider lots of other configurations such as {@code cacheDataOnWrite}. We should fix
this in
+   * the future, {@code cacheDataOnWrite} should honor the CF level {@code isBlockCacheEnabled}
+   * configuration.
+   */
+  public boolean shouldReadBlockFromCache(BlockType blockType) {
+    if (!isBlockCacheEnabled()) {
+      return false;
+    }
+    if (cacheDataOnRead) {
+      return true;
+    }
+    if (prefetchOnOpen) {
+      return true;
+    }
+    if (cacheDataOnWrite) {
+      return true;
+    }
+    if (blockType == null) {
+      return true;
+    }
+    if (blockType.getCategory() == BlockCategory.BLOOM ||
+            blockType.getCategory() == BlockCategory.INDEX) {
+      return true;
+    }
+    return false;
+  }
+
+  /**
+   * If we make sure the block could not be cached, we will not acquire the lock
+   * otherwise we will acquire lock
+   */
+  public boolean shouldLockOnCacheMiss(BlockType blockType) {
+    if (blockType == null) {
+      return true;
+    }
+    return shouldCacheBlockOnRead(blockType.getCategory());
+  }
+
   @Override
   public String toString() {
     if (!isBlockCacheEnabled()) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/0dfd2cea/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
index 4cd4d7a..718c285 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
@@ -350,12 +350,11 @@ public class HFileReaderV2 extends AbstractHFileReader {
     TraceScope traceScope = Trace.startSpan("HFileReaderV2.readBlock");
     try {
       while (true) {
-        if (useLock) {
-          lockEntry = offsetLock.getLockEntry(dataBlockOffset);
-        }
-
         // Check cache for block. If found return.
-        if (cacheConf.isBlockCacheEnabled()) {
+        if (cacheConf.shouldReadBlockFromCache(expectedBlockType)) {
+          if (useLock) {
+            lockEntry = offsetLock.getLockEntry(dataBlockOffset);
+          }
           // Try and get the block from the block cache. If the useLock variable is true
then this
           // is the second time through the loop and it should not be counted as a block
cache miss.
           HFileBlock cachedBlock = (HFileBlock) cacheConf.getBlockCache().getBlock(cacheKey,

@@ -381,13 +380,14 @@ public class HFileReaderV2 extends AbstractHFileReader {
             }
             return cachedBlock;
           }
+          if (!useLock && cacheBlock && cacheConf.shouldLockOnCacheMiss(expectedBlockType))
{
+            // check cache again with lock
+            useLock = true;
+            continue;
+          }
           // Carry on, please load.
         }
-        if (!useLock) {
-          // check cache again with lock
-          useLock = true;
-          continue;
-        }
+
         if (Trace.isTracing()) {
           traceScope.getSpan().addTimelineAnnotation("blockCacheMiss");
         }


Mime
View raw message