-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-26510 Separate the blockcache enabled key and cache data on read key #3893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
75235d8
b476238
f2d0b59
7b65765
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,8 +40,12 @@ public class CacheConfig { | |
| public static final CacheConfig DISABLED = new CacheConfig(); | ||
|
|
||
| /** | ||
| * Configuration key to cache data blocks on read. Bloom blocks and index blocks are always be | ||
| * cached if the block cache is enabled. | ||
| * Configuration key to turn on block cache. There are separate switches for read and write. | ||
| */ | ||
| public static final String BLOCKCACHE_ENABLED = "hbase.block.enabled"; | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you meet some issues that make you separate these configs to resolve them? I don't think an additional "hbase.block.enabled" is needed, this will make users confused with which meaning of 'block' here. For the meta blocks the cache should not be disabled, and this is the original design. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I got your point. Let me consider this for a while. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, these changes seems a little bit superfluous. In this case, may I just close this MR and the corresponding jira ticket? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, thanks. |
||
| /** | ||
| * Configuration key to cache data blocks on read. | ||
| */ | ||
| public static final String CACHE_DATA_ON_READ_KEY = "hbase.block.data.cacheonread"; | ||
|
|
||
|
|
@@ -96,6 +100,7 @@ public class CacheConfig { | |
| "hbase.hfile.drop.behind.compaction"; | ||
|
|
||
| // Defaults | ||
| public static final boolean DEFAULT_BLOCKCACHE_ENABLED = true; | ||
| public static final boolean DEFAULT_CACHE_DATA_ON_READ = true; | ||
| public static final boolean DEFAULT_CACHE_DATA_ON_WRITE = false; | ||
| public static final boolean DEFAULT_IN_MEMORY = false; | ||
|
|
@@ -114,11 +119,14 @@ public class CacheConfig { | |
| * If off we will STILL cache meta blocks; i.e. INDEX and BLOOM types. | ||
| * This cannot be disabled. | ||
| */ | ||
| private final boolean cacheDataOnRead; | ||
| private final boolean blockCacheEnabled; | ||
|
|
||
| /** Whether blocks should be flagged as in-memory when being cached */ | ||
| private final boolean inMemory; | ||
|
|
||
| /** Whether data blocks should be cached when new files are read */ | ||
| private boolean cacheDataOnRead; | ||
|
|
||
| /** Whether data blocks should be cached when new files are written */ | ||
| private boolean cacheDataOnWrite; | ||
|
|
||
|
|
@@ -175,15 +183,17 @@ public CacheConfig(Configuration conf, BlockCache blockCache) { | |
| */ | ||
| public CacheConfig(Configuration conf, ColumnFamilyDescriptor family, BlockCache blockCache, | ||
| ByteBuffAllocator byteBuffAllocator) { | ||
| this.cacheDataOnRead = conf.getBoolean(CACHE_DATA_ON_READ_KEY, DEFAULT_CACHE_DATA_ON_READ) && | ||
| (family == null ? true : family.isBlockCacheEnabled()); | ||
| this.blockCacheEnabled = conf.getBoolean(BLOCKCACHE_ENABLED, DEFAULT_BLOCKCACHE_ENABLED) && | ||
| (family == null || family.isBlockCacheEnabled()); | ||
| this.inMemory = family == null ? DEFAULT_IN_MEMORY : family.isInMemory(); | ||
| this.cacheDataCompressed = | ||
| conf.getBoolean(CACHE_DATA_BLOCKS_COMPRESSED_KEY, DEFAULT_CACHE_DATA_COMPRESSED); | ||
| this.dropBehindCompaction = | ||
| conf.getBoolean(DROP_BEHIND_CACHE_COMPACTION_KEY, DROP_BEHIND_CACHE_COMPACTION_DEFAULT); | ||
| // For the following flags we enable them regardless of per-schema settings | ||
| // if they are enabled in the global configuration. | ||
| this.cacheDataOnRead = conf.getBoolean(CACHE_DATA_ON_READ_KEY, DEFAULT_CACHE_DATA_ON_READ) || | ||
| (family != null && family.isCacheDataOnRead()); | ||
| this.cacheDataOnWrite = | ||
| conf.getBoolean(CACHE_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_DATA_ON_WRITE) || | ||
| (family == null ? false : family.isCacheDataOnWrite()); | ||
|
|
@@ -209,8 +219,9 @@ public CacheConfig(Configuration conf, ColumnFamilyDescriptor family, BlockCache | |
| * @param cacheConf | ||
| */ | ||
| public CacheConfig(CacheConfig cacheConf) { | ||
| this.cacheDataOnRead = cacheConf.cacheDataOnRead; | ||
| this.blockCacheEnabled = cacheConf.blockCacheEnabled; | ||
| this.inMemory = cacheConf.inMemory; | ||
| this.cacheDataOnRead = cacheConf.cacheDataOnRead; | ||
| this.cacheDataOnWrite = cacheConf.cacheDataOnWrite; | ||
| this.cacheIndexesOnWrite = cacheConf.cacheIndexesOnWrite; | ||
| this.cacheBloomsOnWrite = cacheConf.cacheBloomsOnWrite; | ||
|
|
@@ -225,8 +236,9 @@ public CacheConfig(CacheConfig cacheConf) { | |
| } | ||
|
|
||
| private CacheConfig() { | ||
| this.cacheDataOnRead = false; | ||
| this.blockCacheEnabled = false; | ||
| this.inMemory = false; | ||
| this.cacheDataOnRead = false; | ||
| this.cacheDataOnWrite = false; | ||
| this.cacheIndexesOnWrite = false; | ||
| this.cacheBloomsOnWrite = false; | ||
|
|
@@ -245,7 +257,7 @@ private CacheConfig() { | |
| * @return true if blocks should be cached on read, false if not | ||
| */ | ||
| public boolean shouldCacheDataOnRead() { | ||
| return cacheDataOnRead; | ||
| return blockCacheEnabled && cacheDataOnRead; | ||
| } | ||
|
|
||
| public boolean shouldDropBehindCompaction() { | ||
|
|
@@ -258,8 +270,10 @@ public boolean shouldDropBehindCompaction() { | |
| * available. | ||
| */ | ||
| public boolean shouldCacheBlockOnRead(BlockCategory category) { | ||
| return cacheDataOnRead || category == BlockCategory.INDEX || category == BlockCategory.BLOOM || | ||
| (prefetchOnOpen && (category != BlockCategory.META && category != BlockCategory.UNKNOWN)); | ||
| return blockCacheEnabled && | ||
| (cacheDataOnRead || category == BlockCategory.INDEX || category == BlockCategory.BLOOM || | ||
| category == BlockCategory.META) || | ||
| (prefetchOnOpen && (category != BlockCategory.META && category != BlockCategory.UNKNOWN)); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -285,6 +299,14 @@ public void setCacheDataOnWrite(boolean cacheDataOnWrite) { | |
| this.cacheDataOnWrite = cacheDataOnWrite; | ||
| } | ||
|
|
||
| /** | ||
| * @param cacheDataOnRead whether data blocks should be written to the cache | ||
| * when an HFile is read. | ||
| */ | ||
| public void setCacheDataOnRead(boolean cacheDataOnRead) { | ||
| this.cacheDataOnRead = cacheDataOnRead; | ||
| } | ||
|
|
||
| /** | ||
| * Enable cache on write including: | ||
| * cacheDataOnWrite | ||
|
|
@@ -334,7 +356,7 @@ public void setEvictOnClose(boolean evictOnClose) { | |
| * @return true if data blocks should be compressed in the cache, false if not | ||
| */ | ||
| public boolean shouldCacheDataCompressed() { | ||
| return this.cacheDataOnRead && this.cacheDataCompressed; | ||
| return this.blockCacheEnabled && this.cacheDataCompressed; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -343,7 +365,7 @@ public boolean shouldCacheDataCompressed() { | |
| public boolean shouldCacheCompressed(BlockCategory category) { | ||
| switch (category) { | ||
| case DATA: | ||
| return this.cacheDataOnRead && this.cacheDataCompressed; | ||
| return this.blockCacheEnabled && this.cacheDataCompressed; | ||
| default: | ||
| return false; | ||
| } | ||
|
|
@@ -371,30 +393,9 @@ public long getCacheCompactedBlocksOnWriteThreshold() { | |
| } | ||
| /** | ||
| * Return true if we may find this type of block in block cache. | ||
| * <p> | ||
| * TODO: today {@code family.isBlockCacheEnabled()} only means {@code cacheDataOnRead}, so here we | ||
| * consider lots of other configurations such as {@code cacheDataOnWrite}. We should fix this in | ||
| * the future, {@code cacheDataOnWrite} should honor the CF level {@code isBlockCacheEnabled} | ||
| * configuration. | ||
| */ | ||
| public boolean shouldReadBlockFromCache(BlockType blockType) { | ||
| if (cacheDataOnRead) { | ||
| return true; | ||
| } | ||
| if (prefetchOnOpen) { | ||
| return true; | ||
| } | ||
| if (cacheDataOnWrite) { | ||
| return true; | ||
| } | ||
| if (blockType == null) { | ||
| return true; | ||
| } | ||
| if (blockType.getCategory() == BlockCategory.BLOOM || | ||
| blockType.getCategory() == BlockCategory.INDEX) { | ||
| return true; | ||
| } | ||
| return false; | ||
| return blockCacheEnabled; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.