@@ -73,6 +73,10 @@ public class CacheConfig implements PropagatingConfigurationObserver {
7373 */
7474 public static final String EVICT_BLOCKS_ON_CLOSE_KEY = "hbase.rs.evictblocksonclose" ;
7575
76+ /**
77+ * Configuration key to evict all blocks of a parent region from the block cache when the region
78+ * split or merge.
79+ */
7680 public static final String EVICT_BLOCKS_ON_SPLIT_KEY = "hbase.rs.evictblocksonsplit" ;
7781
7882 /**
@@ -146,6 +150,11 @@ public class CacheConfig implements PropagatingConfigurationObserver {
146150 /** Whether blocks of a file should be evicted when the file is closed */
147151 private volatile boolean evictOnClose ;
148152
153+ /**
154+ * Whether blocks of a parent region should be evicted from cache when the region split or merge
155+ */
156+ private boolean evictOnSplit ;
157+
149158 /** Whether data blocks should be stored in compressed and/or encrypted form in the cache */
150159 private boolean cacheDataCompressed ;
151160
@@ -202,17 +211,18 @@ public CacheConfig(Configuration conf, ColumnFamilyDescriptor family, BlockCache
202211 // if they are enabled in the global configuration.
203212 this .cacheDataOnWrite =
204213 conf .getBoolean (CACHE_BLOCKS_ON_WRITE_KEY , DEFAULT_CACHE_DATA_ON_WRITE )
205- || (family == null ? false : family .isCacheDataOnWrite ());
214+ || (family != null && family .isCacheDataOnWrite ());
206215 this .cacheIndexesOnWrite =
207216 conf .getBoolean (CACHE_INDEX_BLOCKS_ON_WRITE_KEY , DEFAULT_CACHE_INDEXES_ON_WRITE )
208- || (family == null ? false : family .isCacheIndexesOnWrite ());
217+ || (family != null && family .isCacheIndexesOnWrite ());
209218 this .cacheBloomsOnWrite =
210219 conf .getBoolean (CACHE_BLOOM_BLOCKS_ON_WRITE_KEY , DEFAULT_CACHE_BLOOMS_ON_WRITE )
211- || (family == null ? false : family .isCacheBloomsOnWrite ());
220+ || (family != null && family .isCacheBloomsOnWrite ());
212221 this .evictOnClose = conf .getBoolean (EVICT_BLOCKS_ON_CLOSE_KEY , DEFAULT_EVICT_ON_CLOSE )
213- || (family == null ? false : family .isEvictBlocksOnClose ());
222+ || (family != null && family .isEvictBlocksOnClose ());
223+ this .evictOnSplit = conf .getBoolean (EVICT_BLOCKS_ON_SPLIT_KEY , DEFAULT_EVICT_ON_SPLIT );
214224 this .prefetchOnOpen = conf .getBoolean (PREFETCH_BLOCKS_ON_OPEN_KEY , DEFAULT_PREFETCH_ON_OPEN )
215- || (family == null ? false : family .isPrefetchBlocksOnOpen ());
225+ || (family != null && family .isPrefetchBlocksOnOpen ());
216226 this .cacheCompactedDataOnWrite = conf .getBoolean (CACHE_COMPACTED_BLOCKS_ON_WRITE_KEY ,
217227 DEFAULT_CACHE_COMPACTED_BLOCKS_ON_WRITE );
218228 this .cacheCompactedDataOnWriteThreshold = getCacheCompactedBlocksOnWriteThreshold (conf );
@@ -233,6 +243,7 @@ public CacheConfig(CacheConfig cacheConf) {
233243 this .cacheIndexesOnWrite = cacheConf .cacheIndexesOnWrite ;
234244 this .cacheBloomsOnWrite = cacheConf .cacheBloomsOnWrite ;
235245 this .evictOnClose = cacheConf .evictOnClose ;
246+ this .evictOnSplit = cacheConf .evictOnSplit ;
236247 this .cacheDataCompressed = cacheConf .cacheDataCompressed ;
237248 this .prefetchOnOpen = cacheConf .prefetchOnOpen ;
238249 this .cacheCompactedDataOnWrite = cacheConf .cacheCompactedDataOnWrite ;
@@ -250,9 +261,11 @@ private CacheConfig() {
250261 this .cacheIndexesOnWrite = false ;
251262 this .cacheBloomsOnWrite = false ;
252263 this .evictOnClose = false ;
264+ this .evictOnSplit = false ;
253265 this .cacheDataCompressed = false ;
254266 this .prefetchOnOpen = false ;
255267 this .cacheCompactedDataOnWrite = false ;
268+ this .cacheCompactedDataOnWriteThreshold = DEFAULT_CACHE_COMPACTED_BLOCKS_ON_WRITE_THRESHOLD ;
256269 this .dropBehindCompaction = false ;
257270 this .blockCache = null ;
258271 this .byteBuffAllocator = ByteBuffAllocator .HEAP ;
@@ -284,7 +297,7 @@ public boolean shouldCacheBlockOnRead(BlockCategory category) {
284297 public boolean shouldCacheBlockOnRead (BlockCategory category , HFileInfo hFileInfo ,
285298 Configuration conf ) {
286299 Optional <Boolean > cacheFileBlock = Optional .of (true );
287- // For DATA blocks only, if BuckeCache is in use, we don't need to cache block again
300+ // For DATA blocks only, if BucketCache is in use, we don't need to cache block again
288301 if (getBlockCache ().isPresent () && category .equals (BlockCategory .DATA )) {
289302 Optional <Boolean > result = getBlockCache ().get ().shouldCacheFile (hFileInfo , conf );
290303 if (result .isPresent ()) {
@@ -349,21 +362,28 @@ public boolean shouldEvictOnClose() {
349362 }
350363
351364 /**
352- * Only used for testing.
353365 * @param evictOnClose whether blocks should be evicted from the cache when an HFile reader is
354366 * closed
355367 */
356368 public void setEvictOnClose (boolean evictOnClose ) {
357369 this .evictOnClose = evictOnClose ;
358370 }
359371
372+ /**
373+ * @return true if blocks of parent region should be evicted from the cache when the region split
374+ * or merge, false if not
375+ */
376+ public boolean shouldEvictOnSplit () {
377+ return this .evictOnSplit ;
378+ }
379+
360380 /** Returns true if data blocks should be compressed in the cache, false if not */
361381 public boolean shouldCacheDataCompressed () {
362382 return this .cacheDataOnRead && this .cacheDataCompressed ;
363383 }
364384
365385 /**
366- * Returns true if this {@link BlockCategory} should be compressed in blockcache , false otherwise
386+ * Returns true if this {@link BlockCategory} should be compressed in BlockCache , false otherwise
367387 */
368388 public boolean shouldCacheCompressed (BlockCategory category ) {
369389 switch (category ) {
@@ -481,8 +501,12 @@ public String toString() {
481501 return "cacheDataOnRead=" + shouldCacheDataOnRead () + ", cacheDataOnWrite="
482502 + shouldCacheDataOnWrite () + ", cacheIndexesOnWrite=" + shouldCacheIndexesOnWrite ()
483503 + ", cacheBloomsOnWrite=" + shouldCacheBloomsOnWrite () + ", cacheEvictOnClose="
484- + shouldEvictOnClose () + ", cacheDataCompressed=" + shouldCacheDataCompressed ()
485- + ", prefetchOnOpen=" + shouldPrefetchOnOpen ();
504+ + shouldEvictOnClose () + ", cacheEvictOnSplit=" + shouldEvictOnSplit ()
505+ + ", cacheDataCompressed=" + shouldCacheDataCompressed () + ", prefetchOnOpen="
506+ + shouldPrefetchOnOpen () + ", cacheCompactedDataOnWrite="
507+ + shouldCacheCompactedBlocksOnWrite () + ", cacheCompactedDataOnWriteThreshold="
508+ + getCacheCompactedBlocksOnWriteThreshold () + ", dropBehindCompaction="
509+ + shouldDropBehindCompaction ();
486510 }
487511
488512 @ Override
0 commit comments