Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -284,7 +297,7 @@ public boolean shouldCacheBlockOnRead(BlockCategory category) {
public boolean shouldCacheBlockOnRead(BlockCategory category, HFileInfo hFileInfo,
Configuration conf) {
Optional<Boolean> 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<Boolean> result = getBlockCache().get().shouldCacheFile(hFileInfo, conf);
if (result.isPresent()) {
Expand Down Expand Up @@ -349,21 +362,28 @@ public boolean shouldEvictOnClose() {
}

/**
* Only used for testing.
* @param evictOnClose whether blocks should be evicted from the cache when an HFile reader is
* closed
*/
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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (cacheConfig == null) { %>
<tr>
<td>Cache DATA on Write</td>
<td><%= cacheConfig.shouldCacheDataOnWrite() %></td>
<td>True if DATA blocks are cached on write.</td>
<td>True if DATA blocks are cached on write</td>
</tr>
<tr>
<td>Cache INDEX on Write</td>
Expand All @@ -58,6 +58,12 @@ if (cacheConfig == null) { %>
<td>True if blocks are evicted from cache when an HFile
reader is closed</td>
</tr>
<tr>
<td>Evict blocks on Split</td>
<td><%= cacheConfig.shouldEvictOnSplit() %></td>
<td>True if blocks of the parent region are evicted
from the cache when split or merge</td>
</tr>
<tr>
<td>Cache DATA in compressed format</td>
<td><%= cacheConfig.shouldCacheDataCompressed() %></td>
Expand All @@ -68,5 +74,16 @@ if (cacheConfig == null) { %>
<td><%= cacheConfig.shouldPrefetchOnOpen() %></td>
<td>True if blocks are prefetched into cache on open</td>
</tr>
<tr>
<td>Cache compacted data on Write</td>
<td><%= cacheConfig.shouldCacheCompactedBlocksOnWrite() %></td>
<td>True if blocks are cached while writing during compaction</td>
</tr>
<tr>
<td>Cache compacted data on Write Threshold</td>
<td><%= cacheConfig.getCacheCompactedBlocksOnWriteThreshold() %></td>
<td>Total file size in bytes threshold for caching
while writing during compaction</td>
</tr>
</table>
<% } %>