From ba37032a7282575507551acfd51910265f64dea3 Mon Sep 17 00:00:00 2001 From: Enis Soztutar Date: Wed, 15 May 2013 06:57:37 +0000 Subject: [PATCH] HBASE-8547 Fix java.lang.RuntimeException: Cached an already cached block git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1482697 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/hadoop/hbase/io/hfile/LruBlockCache.java | 4 +++- .../apache/hadoop/hbase/io/hfile/TestLruBlockCache.java | 3 ++- .../test/java/org/apache/hadoop/hbase/util/TestIdLock.java | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) 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 bd14524fc33..0270bb4c796 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 @@ -292,7 +292,9 @@ public class LruBlockCache implements BlockCache, HeapSize { public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory) { CachedBlock cb = map.get(cacheKey); if(cb != null) { - throw new RuntimeException("Cached an already cached block"); + String msg = "Cached an already cached block: " + cacheKey + " cb:" + cb.getCacheKey(); + LOG.warn(msg); + assert false : msg; } cb = new CachedBlock(cacheKey, buf, count.incrementAndGet(), inMemory); long newSize = updateSizeMetrics(cb, false); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java index 174a7737ec9..dbe03c40c41 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java @@ -123,8 +123,9 @@ public class TestLruBlockCache { try { cache.cacheBlock(block.cacheKey, block); assertTrue("Cache should not allow re-caching a block", false); - } catch(RuntimeException re) { + } catch(AssertionError re) { // expected + assertTrue(re.getMessage().contains("Cached an already cached block")); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestIdLock.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestIdLock.java index bbf4bba2006..9951cd0fe48 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestIdLock.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestIdLock.java @@ -19,6 +19,8 @@ package org.apache.hadoop.hbase.util; +import static org.junit.Assert.assertTrue; + import java.util.Map; import java.util.Random; import java.util.concurrent.Callable; @@ -27,12 +29,10 @@ import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import static org.junit.Assert.*; - import org.apache.hadoop.hbase.MediumTests; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -105,6 +105,7 @@ public class TestIdLock { idLock.assertMapEmpty(); } finally { exec.shutdown(); + exec.awaitTermination(5000, TimeUnit.MILLISECONDS); } }