Peter Somogyi created HBASE-30584:
-------------------------------------
Summary: LruBlockCache and LruAdaptiveBlockCache leak size
accounting when an existing block is replaced
Key: HBASE-30584
URL: https://issues.apache.org/jira/browse/HBASE-30584
Project: HBase
Issue Type: Bug
Components: BlockCache
Reporter: Peter Somogyi
Assignee: Peter Somogyi
When {{cacheBlock}} is called for a key that is already cached and
{{BlockCacheUtil.shouldReplaceExistingCacheBlock}} returns true,
{{LruBlockCache.cacheBlock}} adds the new block's heap size to the size counter
and calls {{{}map.put{}}}, but never subtracts the block it overwrites. The
element counters are incremented again as well.
{{LruAdaptiveBlockCache.cacheBlock}} has the same code.
Each replace permanently inflates the cache's size by one block. The leaked
bytes are not in the map, so eviction cannot free them. Once the counter
reaches the hard limit ({{{}hbase.lru.blockcache.hard.capacity.limit.factor{}}}
x acceptable size), inserts are rejected even though the cache holds few or no
blocks.
h3. Why this became common
The replace path used to be rare (HBASE-20447, split daughters racing on the
same block). Since {{BlockCacheUtil.getBlockForCaching}} preserves
{{nextBlockOnDiskSize}} (HBASE-29288 on branch-2/branch-3/master, HBASE-29398
on branch-2.6), it is hit routinely with CombinedBlockCache:
# Index and bloom blocks are cached in L1 at write time with
{{nextBlockOnDiskSize}} unset (cache-on-write for indexes/blooms, or
{{{}hbase.rs.cachecompactedblocksonwrite{}}}).
# Prefetch on open re-reads those blocks. {{HFilePreadReader}} only skips
blocks that BucketCache already has, and {{readBlock}} with {{cacheOnly=true}}
does not check the cache first.
# The prefetched copy has {{nextBlockOnDiskSize}} set, so
{{shouldReplaceExistingCacheBlock}} returns true and the L1 block is replaced,
leaking its size.
This repeats for every flushed or compacted file, so the L1 size counter grows
until the cache stops accepting blocks.
h3. Impact
With L1 unable to hold index and bloom blocks, every read of them goes to the
filesystem under the per-offset {{IdLock}} in
{{{}HFileReaderImpl.readBlock{}}}. On a cluster reading from S3 we saw RPC
handlers blocked in {{IdLock.getLockEntry}} / {{HFileReaderImpl.readBlock}} and
a RegionServer slowdown.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)