ndimiduk commented on a change in pull request #2523: URL: https://github.com/apache/hbase/pull/2523#discussion_r514493750
########## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java ########## @@ -71,38 +76,78 @@ static final String MERGE_MIN_REGION_SIZE_MB_KEY = "hbase.normalizer.merge.min_region_size.mb"; static final int DEFAULT_MERGE_MIN_REGION_SIZE_MB = 1; - private Configuration conf; private MasterServices masterServices; - private boolean splitEnabled; - private boolean mergeEnabled; - private int minRegionCount; - private Period mergeMinRegionAge; - private int mergeMinRegionSizeMb; + + /** Ensure configuration changes are applied atomically. */ + private final ReadWriteLock configUpdateLock = new ReentrantReadWriteLock(); + @GuardedBy("configUpdateLock") private Configuration conf; + @GuardedBy("configUpdateLock") private boolean splitEnabled; + @GuardedBy("configUpdateLock") private boolean mergeEnabled; + @GuardedBy("configUpdateLock") private int minRegionCount; + @GuardedBy("configUpdateLock") private Period mergeMinRegionAge; + @GuardedBy("configUpdateLock") private int mergeMinRegionSizeMb; public SimpleRegionNormalizer() { - splitEnabled = DEFAULT_SPLIT_ENABLED; - mergeEnabled = DEFAULT_MERGE_ENABLED; - minRegionCount = DEFAULT_MIN_REGION_COUNT; - mergeMinRegionAge = Period.ofDays(DEFAULT_MERGE_MIN_REGION_AGE_DAYS); - mergeMinRegionSizeMb = DEFAULT_MERGE_MIN_REGION_SIZE_MB; + final Lock writeLock = configUpdateLock.writeLock(); + writeLock.lock(); + try { + splitEnabled = DEFAULT_SPLIT_ENABLED; + mergeEnabled = DEFAULT_MERGE_ENABLED; + minRegionCount = DEFAULT_MIN_REGION_COUNT; + mergeMinRegionAge = Period.ofDays(DEFAULT_MERGE_MIN_REGION_AGE_DAYS); + mergeMinRegionSizeMb = DEFAULT_MERGE_MIN_REGION_SIZE_MB; + } finally { + writeLock.unlock(); + } } @Override public Configuration getConf() { - return conf; + final Lock readLock = configUpdateLock.readLock(); + readLock.lock(); + try { + return conf; + } finally { + readLock.unlock(); + } } @Override public void setConf(final Configuration conf) { if (conf == null) { return; } - this.conf = conf; - splitEnabled = conf.getBoolean(SPLIT_ENABLED_KEY, DEFAULT_SPLIT_ENABLED); - mergeEnabled = conf.getBoolean(MERGE_ENABLED_KEY, DEFAULT_MERGE_ENABLED); - minRegionCount = parseMinRegionCount(conf); - mergeMinRegionAge = parseMergeMinRegionAge(conf); - mergeMinRegionSizeMb = parseMergeMinRegionSizeMb(conf); + + final Lock writeLock = configUpdateLock.writeLock(); + writeLock.lock(); Review comment: Sure @bharathv , I think that's a nice suggestion. I agree that the strict ordering guarantees provided by explicit locking are not needed here. I've pushed a new commit that unwinds the locking and uses atomic instance assignment as you suggest. Let me know what you think. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org