diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java index fc8f4d569176..475a22703e14 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java @@ -73,6 +73,10 @@ public class CacheConfig implements PropagatingConfigurationObserver { */ public static final String EVICT_BLOCKS_ON_CLOSE_KEY = "hbase.rs.evictblocksonclose"; + /** + * Configuration key to evict all blocks of a parent region from the block cache when the region + * split or merge. + */ public static final String EVICT_BLOCKS_ON_SPLIT_KEY = "hbase.rs.evictblocksonsplit"; /** @@ -146,6 +150,11 @@ public class CacheConfig implements PropagatingConfigurationObserver { /** Whether blocks of a file should be evicted when the file is closed */ private volatile boolean evictOnClose; + /** + * Whether blocks of a parent region should be evicted from cache when the region split or merge + */ + private boolean evictOnSplit; + /** Whether data blocks should be stored in compressed and/or encrypted form in the cache */ private boolean cacheDataCompressed; @@ -202,17 +211,18 @@ public CacheConfig(Configuration conf, ColumnFamilyDescriptor family, BlockCache // if they are enabled in the global configuration. this.cacheDataOnWrite = conf.getBoolean(CACHE_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_DATA_ON_WRITE) - || (family == null ? false : family.isCacheDataOnWrite()); + || (family != null && family.isCacheDataOnWrite()); this.cacheIndexesOnWrite = conf.getBoolean(CACHE_INDEX_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_INDEXES_ON_WRITE) - || (family == null ? false : family.isCacheIndexesOnWrite()); + || (family != null && family.isCacheIndexesOnWrite()); this.cacheBloomsOnWrite = conf.getBoolean(CACHE_BLOOM_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_BLOOMS_ON_WRITE) - || (family == null ? false : family.isCacheBloomsOnWrite()); + || (family != null && family.isCacheBloomsOnWrite()); this.evictOnClose = conf.getBoolean(EVICT_BLOCKS_ON_CLOSE_KEY, DEFAULT_EVICT_ON_CLOSE) - || (family == null ? false : family.isEvictBlocksOnClose()); + || (family != null && family.isEvictBlocksOnClose()); + this.evictOnSplit = conf.getBoolean(EVICT_BLOCKS_ON_SPLIT_KEY, DEFAULT_EVICT_ON_SPLIT); this.prefetchOnOpen = conf.getBoolean(PREFETCH_BLOCKS_ON_OPEN_KEY, DEFAULT_PREFETCH_ON_OPEN) - || (family == null ? false : family.isPrefetchBlocksOnOpen()); + || (family != null && family.isPrefetchBlocksOnOpen()); this.cacheCompactedDataOnWrite = conf.getBoolean(CACHE_COMPACTED_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_COMPACTED_BLOCKS_ON_WRITE); this.cacheCompactedDataOnWriteThreshold = getCacheCompactedBlocksOnWriteThreshold(conf); @@ -233,6 +243,7 @@ public CacheConfig(CacheConfig cacheConf) { this.cacheIndexesOnWrite = cacheConf.cacheIndexesOnWrite; this.cacheBloomsOnWrite = cacheConf.cacheBloomsOnWrite; this.evictOnClose = cacheConf.evictOnClose; + this.evictOnSplit = cacheConf.evictOnSplit; this.cacheDataCompressed = cacheConf.cacheDataCompressed; this.prefetchOnOpen = cacheConf.prefetchOnOpen; this.cacheCompactedDataOnWrite = cacheConf.cacheCompactedDataOnWrite; @@ -250,9 +261,11 @@ private CacheConfig() { this.cacheIndexesOnWrite = false; this.cacheBloomsOnWrite = false; this.evictOnClose = false; + this.evictOnSplit = false; this.cacheDataCompressed = false; this.prefetchOnOpen = false; this.cacheCompactedDataOnWrite = false; + this.cacheCompactedDataOnWriteThreshold = DEFAULT_CACHE_COMPACTED_BLOCKS_ON_WRITE_THRESHOLD; this.dropBehindCompaction = false; this.blockCache = null; this.byteBuffAllocator = ByteBuffAllocator.HEAP; @@ -284,7 +297,7 @@ public boolean shouldCacheBlockOnRead(BlockCategory category) { public boolean shouldCacheBlockOnRead(BlockCategory category, HFileInfo hFileInfo, Configuration conf) { Optional cacheFileBlock = Optional.of(true); - // For DATA blocks only, if BuckeCache is in use, we don't need to cache block again + // For DATA blocks only, if BucketCache is in use, we don't need to cache block again if (getBlockCache().isPresent() && category.equals(BlockCategory.DATA)) { Optional result = getBlockCache().get().shouldCacheFile(hFileInfo, conf); if (result.isPresent()) { @@ -349,7 +362,6 @@ public boolean shouldEvictOnClose() { } /** - * Only used for testing. * @param evictOnClose whether blocks should be evicted from the cache when an HFile reader is * closed */ @@ -357,13 +369,21 @@ public void setEvictOnClose(boolean evictOnClose) { this.evictOnClose = evictOnClose; } + /** + * @return true if blocks of parent region should be evicted from the cache when the region split + * or merge, false if not + */ + public boolean shouldEvictOnSplit() { + return this.evictOnSplit; + } + /** Returns true if data blocks should be compressed in the cache, false if not */ public boolean shouldCacheDataCompressed() { return this.cacheDataOnRead && this.cacheDataCompressed; } /** - * Returns true if this {@link BlockCategory} should be compressed in blockcache, false otherwise + * Returns true if this {@link BlockCategory} should be compressed in BlockCache, false otherwise */ public boolean shouldCacheCompressed(BlockCategory category) { switch (category) { @@ -481,8 +501,12 @@ public String toString() { return "cacheDataOnRead=" + shouldCacheDataOnRead() + ", cacheDataOnWrite=" + shouldCacheDataOnWrite() + ", cacheIndexesOnWrite=" + shouldCacheIndexesOnWrite() + ", cacheBloomsOnWrite=" + shouldCacheBloomsOnWrite() + ", cacheEvictOnClose=" - + shouldEvictOnClose() + ", cacheDataCompressed=" + shouldCacheDataCompressed() - + ", prefetchOnOpen=" + shouldPrefetchOnOpen(); + + shouldEvictOnClose() + ", cacheEvictOnSplit=" + shouldEvictOnSplit() + + ", cacheDataCompressed=" + shouldCacheDataCompressed() + ", prefetchOnOpen=" + + shouldPrefetchOnOpen() + ", cacheCompactedDataOnWrite=" + + shouldCacheCompactedBlocksOnWrite() + ", cacheCompactedDataOnWriteThreshold=" + + getCacheCompactedBlocksOnWriteThreshold() + ", dropBehindCompaction=" + + shouldDropBehindCompaction(); } @Override diff --git a/hbase-server/src/main/resources/hbase-webapps/regionserver/blockCacheConfig.jsp b/hbase-server/src/main/resources/hbase-webapps/regionserver/blockCacheConfig.jsp index d73652de4cb2..43f204b89e08 100644 --- a/hbase-server/src/main/resources/hbase-webapps/regionserver/blockCacheConfig.jsp +++ b/hbase-server/src/main/resources/hbase-webapps/regionserver/blockCacheConfig.jsp @@ -40,7 +40,7 @@ if (cacheConfig == null) { %> Cache DATA on Write <%= cacheConfig.shouldCacheDataOnWrite() %> - True if DATA blocks are cached on write. + True if DATA blocks are cached on write Cache INDEX on Write @@ -58,6 +58,12 @@ if (cacheConfig == null) { %> True if blocks are evicted from cache when an HFile reader is closed + + Evict blocks on Split + <%= cacheConfig.shouldEvictOnSplit() %> + True if blocks of the parent region are evicted + from the cache when split or merge + Cache DATA in compressed format <%= cacheConfig.shouldCacheDataCompressed() %> @@ -68,5 +74,16 @@ if (cacheConfig == null) { %> <%= cacheConfig.shouldPrefetchOnOpen() %> True if blocks are prefetched into cache on open + + Cache compacted data on Write + <%= cacheConfig.shouldCacheCompactedBlocksOnWrite() %> + True if blocks are cached while writing during compaction + + + Cache compacted data on Write Threshold + <%= cacheConfig.getCacheCompactedBlocksOnWriteThreshold() %> + Total file size in bytes threshold for caching + while writing during compaction + <% } %>