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 f89a6194cefb..7fb1f1ec85bd 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 @@ -20,6 +20,7 @@ import java.util.Optional; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; +import org.apache.hadoop.hbase.conf.ConfigurationObserver; import org.apache.hadoop.hbase.io.ByteBuffAllocator; import org.apache.hadoop.hbase.io.hfile.BlockType.BlockCategory; import org.apache.yetus.audience.InterfaceAudience; @@ -30,7 +31,7 @@ * Stores all of the cache objects and configuration for a single HFile. */ @InterfaceAudience.Private -public class CacheConfig { +public class CacheConfig implements ConfigurationObserver { private static final Logger LOG = LoggerFactory.getLogger(CacheConfig.class.getName()); /** @@ -124,13 +125,13 @@ public class CacheConfig { * turned off on a per-family or per-request basis). If off we will STILL cache meta blocks; i.e. * INDEX and BLOOM types. This cannot be disabled. */ - private final boolean cacheDataOnRead; + private volatile boolean cacheDataOnRead; /** 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 written */ - private boolean cacheDataOnWrite; + private volatile boolean cacheDataOnWrite; /** Whether index blocks should be cached when new files are written */ private boolean cacheIndexesOnWrite; @@ -139,7 +140,7 @@ public class CacheConfig { private boolean cacheBloomsOnWrite; /** Whether blocks of a file should be evicted when the file is closed */ - private boolean evictOnClose; + private volatile boolean evictOnClose; /** Whether data blocks should be stored in compressed and/or encrypted form in the cache */ private final boolean cacheDataCompressed; @@ -464,4 +465,16 @@ public String toString() { + shouldEvictOnClose() + ", cacheDataCompressed=" + shouldCacheDataCompressed() + ", prefetchOnOpen=" + shouldPrefetchOnOpen(); } + + @Override + public void onConfigurationChange(Configuration conf) { + cacheDataOnRead = conf.getBoolean(CACHE_DATA_ON_READ_KEY, DEFAULT_CACHE_DATA_ON_READ); + cacheDataOnWrite = conf.getBoolean(CACHE_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_DATA_ON_WRITE); + evictOnClose = conf.getBoolean(EVICT_BLOCKS_ON_CLOSE_KEY, DEFAULT_EVICT_ON_CLOSE); + LOG.info( + "Config hbase.block.data.cacheonread is changed to {}, " + + "hbase.rs.cacheblocksonwrite is changed to {}, " + + "hbase.rs.evictblocksonclose is changed to {}", + cacheDataOnRead, cacheDataOnWrite, evictOnClose); + } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java index 43a63359961e..9954c78142e9 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java @@ -2186,7 +2186,10 @@ public void onConfigurationChange(Configuration conf) { */ @Override public void registerChildren(ConfigurationManager manager) { - // No children to register + CacheConfig cacheConfig = this.storeContext.getCacheConf(); + if (cacheConfig != null) { + manager.registerObserver(cacheConfig); + } } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java index 2e999dfaa455..e888639eac4a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java @@ -17,6 +17,12 @@ */ package org.apache.hadoop.hbase.regionserver; +import static org.apache.hadoop.hbase.io.hfile.CacheConfig.CACHE_BLOCKS_ON_WRITE_KEY; +import static org.apache.hadoop.hbase.io.hfile.CacheConfig.CACHE_DATA_ON_READ_KEY; +import static org.apache.hadoop.hbase.io.hfile.CacheConfig.DEFAULT_CACHE_DATA_ON_READ; +import static org.apache.hadoop.hbase.io.hfile.CacheConfig.DEFAULT_CACHE_DATA_ON_WRITE; +import static org.apache.hadoop.hbase.io.hfile.CacheConfig.DEFAULT_EVICT_ON_CLOSE; +import static org.apache.hadoop.hbase.io.hfile.CacheConfig.EVICT_BLOCKS_ON_CLOSE_KEY; import static org.apache.hadoop.hbase.regionserver.DefaultStoreEngine.DEFAULT_COMPACTION_POLICY_CLASS_KEY; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -2604,6 +2610,9 @@ public void testOnConfigurationChange() throws IOException { Configuration conf = HBaseConfiguration.create(); conf.setInt(CompactionConfiguration.HBASE_HSTORE_COMPACTION_MAX_KEY, COMMON_MAX_FILES_TO_COMPACT); + conf.setBoolean(CACHE_DATA_ON_READ_KEY, false); + conf.setBoolean(CACHE_BLOCKS_ON_WRITE_KEY, true); + conf.setBoolean(EVICT_BLOCKS_ON_CLOSE_KEY, true); ColumnFamilyDescriptor hcd = ColumnFamilyDescriptorBuilder.newBuilder(family) .setConfiguration(CompactionConfiguration.HBASE_HSTORE_COMPACTION_MAX_KEY, String.valueOf(STORE_MAX_FILES_TO_COMPACT)) @@ -2614,8 +2623,19 @@ public void testOnConfigurationChange() throws IOException { conf.setInt(CompactionConfiguration.HBASE_HSTORE_COMPACTION_MAX_KEY, NEW_COMMON_MAX_FILES_TO_COMPACT); this.store.onConfigurationChange(conf); + assertEquals(STORE_MAX_FILES_TO_COMPACT, store.getStoreEngine().getCompactionPolicy().getConf().getMaxFilesToCompact()); + + assertEquals(conf.getBoolean(CACHE_DATA_ON_READ_KEY, DEFAULT_CACHE_DATA_ON_READ), false); + assertEquals(conf.getBoolean(CACHE_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_DATA_ON_WRITE), true); + assertEquals(conf.getBoolean(EVICT_BLOCKS_ON_CLOSE_KEY, DEFAULT_EVICT_ON_CLOSE), true); + + // reset to default values + conf.getBoolean(CACHE_DATA_ON_READ_KEY, DEFAULT_CACHE_DATA_ON_READ); + conf.getBoolean(CACHE_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_DATA_ON_WRITE); + conf.getBoolean(EVICT_BLOCKS_ON_CLOSE_KEY, DEFAULT_EVICT_ON_CLOSE); + this.store.onConfigurationChange(conf); } /**