wchevreuil commented on code in PR #8939:
URL: https://github.com/apache/hbase/pull/8939#discussion_r4741765588
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruAdaptiveBlockCache.java:
##########
@@ -538,7 +538,19 @@ public void cacheBlock(BlockCacheKey cacheKey, Cacheable
buf, boolean inMemory)
buf = asReferencedHeapBlock(buf);
cb = new LruCachedBlock(cacheKey, buf, count.incrementAndGet(), inMemory);
long newSize = updateSizeMetrics(cb, false);
- map.put(cacheKey, cb);
+ LruCachedBlock previous = map.put(cacheKey, cb);
+ if (previous != null) {
+ // We replaced an existing block (see
BlockCacheUtil#shouldReplaceExistingCacheBlock), so
+ // take the replaced block out of the size and element counters,
otherwise it is counted
+ // forever and the cache fills up with blocks it no longer holds.
+ newSize = updateSizeMetrics(previous, true);
+ elements.decrementAndGet();
+ if (previous.getBuffer().getBlockType().isData()) {
+ dataBlockElements.decrement();
+ }
+ // The cache no longer references the replaced block.
+ previous.getBuffer().release();
+ }
Review Comment:
Sounds good to me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]