From a0690a477e18be0d4f0ee5b90f3b2121dc762405 Mon Sep 17 00:00:00 2001 From: zhangduo Date: Thu, 19 Feb 2015 21:05:53 +0800 Subject: [PATCH] HBASE-13072 BucketCache.evictBlock returns true if block not exists --- .../hadoop/hbase/io/hfile/bucket/BucketCache.java | 46 ++++++++++++---------- 1 file changed, 26 insertions(+), 20 deletions(-) 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 d3b303a..7dda0e6 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 @@ -451,30 +451,36 @@ public class BucketCache implements BlockCache, HeapSize { this.heapSize.addAndGet(-1 * removedBlock.getData().heapSize()); } BucketEntry bucketEntry = backingMap.get(cacheKey); - if (bucketEntry != null) { - IdLock.Entry lockEntry = null; - try { - lockEntry = offsetLock.getLockEntry(bucketEntry.offset()); - if (bucketEntry.equals(backingMap.remove(cacheKey))) { - bucketAllocator.freeBlock(bucketEntry.offset()); - realCacheSize.addAndGet(-1 * bucketEntry.getLength()); - blocksByHFile.remove(cacheKey.getHfileName(), cacheKey); - if (removedBlock == null) { - this.blockNumber.decrementAndGet(); - } - } else { - return false; - } - } catch (IOException ie) { - LOG.warn("Failed evicting block " + cacheKey); + if (bucketEntry == null) { + if (removedBlock != null) { + cacheStats.evicted(0); + return true; + } else { return false; - } finally { - if (lockEntry != null) { - offsetLock.releaseLockEntry(lockEntry); + } + } + IdLock.Entry lockEntry = null; + try { + lockEntry = offsetLock.getLockEntry(bucketEntry.offset()); + if (bucketEntry.equals(backingMap.remove(cacheKey))) { + bucketAllocator.freeBlock(bucketEntry.offset()); + realCacheSize.addAndGet(-1 * bucketEntry.getLength()); + blocksByHFile.remove(cacheKey.getHfileName(), cacheKey); + if (removedBlock == null) { + this.blockNumber.decrementAndGet(); } + } else { + return false; + } + } catch (IOException ie) { + LOG.warn("Failed evicting block " + cacheKey); + return false; + } finally { + if (lockEntry != null) { + offsetLock.releaseLockEntry(lockEntry); } } - cacheStats.evicted(bucketEntry == null? 0: bucketEntry.getCachedTime()); + cacheStats.evicted(bucketEntry.getCachedTime()); return true; } -- 1.9.1