This is an automated email from the ASF dual-hosted git repository. zhangduo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push: new 5201ae2de2b HBASE-28224 ClientSideRegionScanner appears not to shutdown MobFileCache (#5578) 5201ae2de2b is described below commit 5201ae2de2b4b4d18156ab0c00dd42e7726951c0 Author: jbewing <jbew...@live.com> AuthorDate: Fri Dec 22 10:13:36 2023 -0500 HBASE-28224 ClientSideRegionScanner appears not to shutdown MobFileCache (#5578) Signed-off-by: Duo Zhang <zhang...@apache.org> --- .../hbase/client/ClientSideRegionScanner.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/ClientSideRegionScanner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/ClientSideRegionScanner.java index 19191044140..144c01de874 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/ClientSideRegionScanner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/ClientSideRegionScanner.java @@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.PrivateCellUtil; import org.apache.hadoop.hbase.client.metrics.ScanMetrics; +import org.apache.hadoop.hbase.io.hfile.BlockCache; import org.apache.hadoop.hbase.io.hfile.BlockCacheFactory; import org.apache.hadoop.hbase.mob.MobFileCache; import org.apache.hadoop.hbase.regionserver.HRegion; @@ -46,6 +47,8 @@ public class ClientSideRegionScanner extends AbstractClientScanner { private static final Logger LOG = LoggerFactory.getLogger(ClientSideRegionScanner.class); private HRegion region; + private MobFileCache mobFileCache; + private BlockCache blockCache; RegionScanner scanner; List<Cell> values; boolean hasMore = true; @@ -69,12 +72,14 @@ public class ClientSideRegionScanner extends AbstractClientScanner { String.valueOf(HConstants.HBASE_CLIENT_SCANNER_ONHEAP_BLOCK_CACHE_FIXED_SIZE_DEFAULT)); // don't allow L2 bucket cache for non RS process to avoid unexpected disk usage. conf.unset(HConstants.BUCKET_CACHE_IOENGINE_KEY); - region.setBlockCache(BlockCacheFactory.createBlockCache(conf)); + blockCache = BlockCacheFactory.createBlockCache(conf); + region.setBlockCache(blockCache); // we won't initialize the MobFileCache when not running in RS process. so provided an // initialized cache. Consider the case: an CF was set from an mob to non-mob. if we only // initialize cache for MOB region, NPE from HMobStore will still happen. So Initialize the // cache for every region although it may hasn't any mob CF, BTW the cache is very light-weight. - region.setMobFileCache(new MobFileCache(conf)); + mobFileCache = new MobFileCache(conf); + region.setMobFileCache(mobFileCache); region.initialize(); // create an internal region scanner @@ -131,6 +136,19 @@ public class ClientSideRegionScanner extends AbstractClientScanner { LOG.warn("Exception while closing region", ex); } } + + // In typical region operation, RegionServerServices would handle the lifecycle of + // the MobFileCache and BlockCache. In ClientSideRegionScanner, we need to handle + // the lifecycle of these components ourselves to avoid resource leaks. + if (mobFileCache != null) { + mobFileCache.shutdown(); + mobFileCache = null; + } + + if (blockCache != null) { + blockCache.shutdown(); + blockCache = null; + } } HRegion getRegion() {