Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2A7A4200CFE for ; Fri, 8 Sep 2017 20:24:50 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 293411610AA; Fri, 8 Sep 2017 18:24:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 494B7160F79 for ; Fri, 8 Sep 2017 20:24:49 +0200 (CEST) Received: (qmail 85978 invoked by uid 500); 8 Sep 2017 18:24:48 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 85969 invoked by uid 99); 8 Sep 2017 18:24:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Sep 2017 18:24:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F1B61F3292; Fri, 8 Sep 2017 18:24:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tedyu@apache.org To: commits@hbase.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-18641 Include block content verification logic used in lruCache in bucketCache Date: Fri, 8 Sep 2017 18:24:47 +0000 (UTC) archived-at: Fri, 08 Sep 2017 18:24:50 -0000 Repository: hbase Updated Branches: refs/heads/master 359fed7b4 -> af2157242 HBASE-18641 Include block content verification logic used in lruCache in bucketCache Signed-off-by: tedyu Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/af215724 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/af215724 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/af215724 Branch: refs/heads/master Commit: af2157242759e5e50ddeab3c1c6b03b41080372f Parents: 359fed7 Author: Biju Nair Authored: Thu Aug 24 13:14:57 2017 -0400 Committer: tedyu Committed: Fri Sep 8 11:24:31 2017 -0700 ---------------------------------------------------------------------- .../hadoop/hbase/io/hfile/BlockCacheUtil.java | 11 +++++++++++ .../hadoop/hbase/io/hfile/LruBlockCache.java | 13 ++----------- .../hadoop/hbase/io/hfile/bucket/BucketCache.java | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/af215724/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockCacheUtil.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockCacheUtil.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockCacheUtil.java index 5c306c0..f5f3d7f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockCacheUtil.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockCacheUtil.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hbase.io.hfile; import java.io.IOException; +import java.nio.ByteBuffer; import java.util.NavigableMap; import java.util.NavigableSet; import java.util.concurrent.ConcurrentSkipListMap; @@ -26,6 +27,7 @@ import java.util.concurrent.ConcurrentSkipListSet; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.metrics.impl.FastLongHistogram; +import org.apache.hadoop.hbase.util.Bytes; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.map.JsonMappingException; @@ -172,6 +174,15 @@ public class BlockCacheUtil { return cbsbf; } + public static int compareCacheBlock(Cacheable left, Cacheable right) { + ByteBuffer l = ByteBuffer.allocate(left.getSerializedLength()); + left.serialize(l); + ByteBuffer r = ByteBuffer.allocate(right.getSerializedLength()); + right.serialize(r); + return Bytes.compareTo(l.array(), l.arrayOffset(), l.limit(), + r.array(), r.arrayOffset(), r.limit()); + } + /** * Use one of these to keep a running account of cached blocks by file. Throw it away when done. * This is different than metrics in that it is stats on current state of a cache. http://git-wip-us.apache.org/repos/asf/hbase/blob/af215724/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 04aed06..56996a4 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 @@ -379,7 +379,7 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { LruCachedBlock cb = map.get(cacheKey); if (cb != null) { // compare the contents, if they are not equal, we are in big trouble - if (compare(buf, cb.getBuffer()) != 0) { + if (BlockCacheUtil.compareCacheBlock(buf, cb.getBuffer()) != 0) { throw new RuntimeException("Cached block contents differ, which should not have happened." + "cacheKey:" + cacheKey); } @@ -439,15 +439,6 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { } } - private int compare(Cacheable left, Cacheable right) { - ByteBuffer l = ByteBuffer.allocate(left.getSerializedLength()); - left.serialize(l); - ByteBuffer r = ByteBuffer.allocate(right.getSerializedLength()); - right.serialize(r); - return Bytes.compareTo(l.array(), l.arrayOffset(), l.limit(), - r.array(), r.arrayOffset(), r.limit()); - } - /** * Cache the block with the specified name and buffer. *

@@ -589,7 +580,7 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { boolean wait = getCurrentSize() < acceptableSize(); boolean inMemory = block.getPriority() == BlockPriority.MEMORY; ((BucketCache) victimHandler).cacheBlockWithWait(block.getCacheKey(), block.getBuffer(), - inMemory, wait); + inMemory, true, wait); } else { victimHandler.cacheBlock(block.getCacheKey(), block.getBuffer()); } http://git-wip-us.apache.org/repos/asf/hbase/blob/af215724/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java index 58f3223..aca8d7f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java @@ -411,7 +411,7 @@ public class BucketCache implements BlockCache, HeapSize { @Override public void cacheBlock(BlockCacheKey cacheKey, Cacheable cachedItem, boolean inMemory, final boolean cacheDataInL1) { - cacheBlockWithWait(cacheKey, cachedItem, inMemory, wait_when_cache); + cacheBlockWithWait(cacheKey, cachedItem, inMemory, cacheDataInL1, wait_when_cache); } /** @@ -422,13 +422,26 @@ public class BucketCache implements BlockCache, HeapSize { * @param wait if true, blocking wait when queue is full */ public void cacheBlockWithWait(BlockCacheKey cacheKey, Cacheable cachedItem, boolean inMemory, - boolean wait) { + boolean cacheDataInL1, boolean wait) { if (LOG.isTraceEnabled()) LOG.trace("Caching key=" + cacheKey + ", item=" + cachedItem); if (!cacheEnabled) { return; } if (backingMap.containsKey(cacheKey)) { + /* + * Compare already cached block only if lruBlockCache is not used to cache data blocks + */ + if (!cacheDataInL1) { + Cacheable existingBlock = getBlock(cacheKey, false, false, false); + if (BlockCacheUtil.compareCacheBlock(cachedItem, existingBlock) != 0) { + throw new RuntimeException("Cached block contents differ, which should not have happened." + + "cacheKey:" + cacheKey); + } + } + String msg = "Caching an already cached block: " + cacheKey; + msg += ". This is harmless and can happen in rare cases (see HBASE-8547)"; + LOG.warn(msg); return; }