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 4a0978a..beabe2e 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 @@ -140,6 +140,9 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { static final boolean DEFAULT_IN_MEMORY_FORCE_MODE = false; + /** hard capacity limit */ + private final float hardCapacityLimitFactor = 1.2f; + /** Statistics thread */ static final int statThreadPeriod = 60 * 5; @@ -338,6 +341,22 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { LOG.warn(msg); return; } + long currentSize = size.get(); + long hardLimitSize = (long) (hardCapacityLimitFactor * acceptableSize()); + + if (currentSize > hardLimitSize) { + if (LOG.isTraceEnabled()) { + LOG.trace("LruBlockCache current size " + StringUtils.byteDesc(currentSize) + + " has exceeded acceptable size " + StringUtils.byteDesc(acceptableSize()) + " too many." + + " the hard limit size is " + StringUtils.byteDesc(hardLimitSize) + ", failed to put cacheKey:" + + cacheKey + " into LruBlockCache."); + } + if (!evictionInProgress) { + runEviction(); + } + + return; + } cb = new LruCachedBlock(cacheKey, buf, count.incrementAndGet(), inMemory); long newSize = updateSizeMetrics(cb, false); map.put(cacheKey, cb); @@ -346,9 +365,6 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { long size = map.size(); assertCounterSanity(size, val); } - if (newSize > acceptableSize() && !evictionInProgress) { - runEviction(); - } } /**