Skip to content

Commit

Permalink
HBASE-28517 Make properties dynamically configured (#5823)
Browse files Browse the repository at this point in the history
Signed-off-by: Duo Zhang <zhangduo@apache.org>
Signed-off-by: Peter Somogyi <psomogyi@apache.org>
  • Loading branch information
kabhishek4 authored Apr 25, 2024
1 parent 6c6e776 commit 7122da5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 7122da5

Please sign in to comment.