Skip to content

Commit 9e0d6b7

Browse files
committed
HBASE-25745 Deprecate/Rename config hbase.normalizer.min.region.count to hbase.normalizer.merge.min.region.count
1 parent 8e08952 commit 9e0d6b7

File tree

5 files changed

+115
-38
lines changed

5 files changed

+115
-38
lines changed

hbase-common/src/main/resources/hbase-default.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -638,12 +638,6 @@ possible configurations would overwhelm and obscure the important.
638638
<value>true</value>
639639
<description>Whether to merge a region as part of normalization.</description>
640640
</property>
641-
<property>
642-
<name>hbase.normalizer.min.region.count</name>
643-
<value>3</value>
644-
<description>The minimum number of regions in a table to consider it for merge
645-
normalization.</description>
646-
</property>
647641
<property>
648642
<name>hbase.normalizer.merge.min_region_age.days</name>
649643
<value>3</value>

hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ class SimpleRegionNormalizer implements RegionNormalizer, ConfigurationObserver
6565
static final boolean DEFAULT_SPLIT_ENABLED = true;
6666
static final String MERGE_ENABLED_KEY = "hbase.normalizer.merge.enabled";
6767
static final boolean DEFAULT_MERGE_ENABLED = true;
68-
// TODO: after HBASE-24416, `min.region.count` only applies to merge plans; should
69-
// deprecate/rename the configuration key.
68+
/**
69+
* @deprecated since 2.5.0 and will be removed in 4.0.0.
70+
* Use {@link SimpleRegionNormalizer#MERGE_MIN_REGION_COUNT_KEY} instead.
71+
* @see <a href="https://issues.apache.org/jira/browse/HBASE-25745">HBASE-25745</a>
72+
*/
73+
@Deprecated
7074
static final String MIN_REGION_COUNT_KEY = "hbase.normalizer.min.region.count";
71-
static final int DEFAULT_MIN_REGION_COUNT = 3;
75+
static final String MERGE_MIN_REGION_COUNT_KEY = "hbase.normalizer.merge.min.region.count";
76+
static final int DEFAULT_MERGE_MIN_REGION_COUNT = 3;
7277
static final String MERGE_MIN_REGION_AGE_DAYS_KEY = "hbase.normalizer.merge.min_region_age.days";
7378
static final int DEFAULT_MERGE_MIN_REGION_AGE_DAYS = 3;
7479
static final String MERGE_MIN_REGION_SIZE_MB_KEY = "hbase.normalizer.merge.min_region_size.mb";
@@ -101,11 +106,21 @@ public void onConfigurationChange(Configuration conf) {
101106
setConf(conf);
102107
}
103108

104-
private static int parseMinRegionCount(final Configuration conf) {
105-
final int parsedValue = conf.getInt(MIN_REGION_COUNT_KEY, DEFAULT_MIN_REGION_COUNT);
109+
private static int parseMergeMinRegionCount(final Configuration conf) {
110+
String parsedStringValue = conf.get(MERGE_MIN_REGION_COUNT_KEY);
111+
if (parsedStringValue == null) {
112+
parsedStringValue = conf.get(MIN_REGION_COUNT_KEY);
113+
if (parsedStringValue != null) {
114+
LOG.warn("The config key {} is deprecated. Instead please use {}. In future release we "
115+
+ "will remove the deprecated config.", MIN_REGION_COUNT_KEY,
116+
MERGE_MIN_REGION_COUNT_KEY);
117+
}
118+
}
119+
final int parsedValue = parsedStringValue == null ? DEFAULT_MERGE_MIN_REGION_COUNT :
120+
Integer.parseInt(parsedStringValue);
106121
final int settledValue = Math.max(1, parsedValue);
107122
if (parsedValue != settledValue) {
108-
warnInvalidValue(MIN_REGION_COUNT_KEY, parsedValue, settledValue);
123+
warnInvalidValue(MERGE_MIN_REGION_COUNT_KEY, parsedValue, settledValue);
109124
}
110125
return settledValue;
111126
}
@@ -158,10 +173,10 @@ public boolean isMergeEnabled() {
158173
}
159174

160175
/**
161-
* Return this instance's configured value for {@value #MIN_REGION_COUNT_KEY}.
176+
* Return this instance's configured value for {@value #MERGE_MIN_REGION_COUNT_KEY}.
162177
*/
163-
public int getMinRegionCount() {
164-
return normalizerConfiguration.getMinRegionCount();
178+
public int getMergeMinRegionCount() {
179+
return normalizerConfiguration.getMergeMinRegionCount();
165180
}
166181

167182
/**
@@ -340,10 +355,10 @@ private boolean skipForMerge(
340355
*/
341356
private List<NormalizationPlan> computeMergeNormalizationPlans(final NormalizeContext ctx) {
342357
final NormalizerConfiguration configuration = normalizerConfiguration;
343-
if (ctx.getTableRegions().size() < configuration.getMinRegionCount(ctx)) {
358+
if (ctx.getTableRegions().size() < configuration.getMergeMinRegionCount(ctx)) {
344359
LOG.debug("Table {} has {} regions, required min number of regions for normalizer to run"
345360
+ " is {}, not computing merge plans.", ctx.getTableName(),
346-
ctx.getTableRegions().size(), configuration.getMinRegionCount());
361+
ctx.getTableRegions().size(), configuration.getMergeMinRegionCount());
347362
return Collections.emptyList();
348363
}
349364

@@ -493,15 +508,15 @@ private static final class NormalizerConfiguration {
493508
private final Configuration conf;
494509
private final boolean splitEnabled;
495510
private final boolean mergeEnabled;
496-
private final int minRegionCount;
511+
private final int mergeMinRegionCount;
497512
private final Period mergeMinRegionAge;
498513
private final long mergeMinRegionSizeMb;
499514

500515
private NormalizerConfiguration() {
501516
conf = null;
502517
splitEnabled = DEFAULT_SPLIT_ENABLED;
503518
mergeEnabled = DEFAULT_MERGE_ENABLED;
504-
minRegionCount = DEFAULT_MIN_REGION_COUNT;
519+
mergeMinRegionCount = DEFAULT_MERGE_MIN_REGION_COUNT;
505520
mergeMinRegionAge = Period.ofDays(DEFAULT_MERGE_MIN_REGION_AGE_DAYS);
506521
mergeMinRegionSizeMb = DEFAULT_MERGE_MIN_REGION_SIZE_MB;
507522
}
@@ -513,15 +528,15 @@ private NormalizerConfiguration(
513528
this.conf = conf;
514529
splitEnabled = conf.getBoolean(SPLIT_ENABLED_KEY, DEFAULT_SPLIT_ENABLED);
515530
mergeEnabled = conf.getBoolean(MERGE_ENABLED_KEY, DEFAULT_MERGE_ENABLED);
516-
minRegionCount = parseMinRegionCount(conf);
531+
mergeMinRegionCount = parseMergeMinRegionCount(conf);
517532
mergeMinRegionAge = parseMergeMinRegionAge(conf);
518533
mergeMinRegionSizeMb = parseMergeMinRegionSizeMb(conf);
519534
logConfigurationUpdated(SPLIT_ENABLED_KEY, currentConfiguration.isSplitEnabled(),
520535
splitEnabled);
521536
logConfigurationUpdated(MERGE_ENABLED_KEY, currentConfiguration.isMergeEnabled(),
522537
mergeEnabled);
523-
logConfigurationUpdated(MIN_REGION_COUNT_KEY, currentConfiguration.getMinRegionCount(),
524-
minRegionCount);
538+
logConfigurationUpdated(MERGE_MIN_REGION_COUNT_KEY,
539+
currentConfiguration.getMergeMinRegionCount(), mergeMinRegionCount);
525540
logConfigurationUpdated(MERGE_MIN_REGION_AGE_DAYS_KEY,
526541
currentConfiguration.getMergeMinRegionAge(), mergeMinRegionAge);
527542
logConfigurationUpdated(MERGE_MIN_REGION_SIZE_MB_KEY,
@@ -540,24 +555,34 @@ public boolean isMergeEnabled() {
540555
return mergeEnabled;
541556
}
542557

543-
public int getMinRegionCount() {
544-
return minRegionCount;
558+
public int getMergeMinRegionCount() {
559+
return mergeMinRegionCount;
545560
}
546561

547-
public int getMinRegionCount(NormalizeContext context) {
548-
int minRegionCount = context.getOrDefault(MIN_REGION_COUNT_KEY, Integer::parseInt, 0);
549-
if (minRegionCount <= 0) {
550-
minRegionCount = getMinRegionCount();
562+
public int getMergeMinRegionCount(NormalizeContext context) {
563+
String stringValue = context.getOrDefault(MERGE_MIN_REGION_COUNT_KEY,
564+
Function.identity(), null);
565+
if (stringValue == null) {
566+
stringValue = context.getOrDefault(MIN_REGION_COUNT_KEY, Function.identity(), null);
567+
if (stringValue != null) {
568+
LOG.debug("The config key {} in table descriptor is deprecated. Instead please use {}. "
569+
+ "In future release we will remove the deprecated config.", MIN_REGION_COUNT_KEY,
570+
MERGE_MIN_REGION_COUNT_KEY);
571+
}
572+
}
573+
final int mergeMinRegionCount = stringValue == null ? 0 : Integer.parseInt(stringValue);
574+
if (mergeMinRegionCount <= 0) {
575+
return getMergeMinRegionCount();
551576
}
552-
return minRegionCount;
577+
return mergeMinRegionCount;
553578
}
554579

555580
public Period getMergeMinRegionAge() {
556581
return mergeMinRegionAge;
557582
}
558583

559584
public Period getMergeMinRegionAge(NormalizeContext context) {
560-
int mergeMinRegionAge = context.getOrDefault(MERGE_MIN_REGION_AGE_DAYS_KEY,
585+
final int mergeMinRegionAge = context.getOrDefault(MERGE_MIN_REGION_AGE_DAYS_KEY,
561586
Integer::parseInt, -1);
562587
if (mergeMinRegionAge < 0) {
563588
return getMergeMinRegionAge();
@@ -570,10 +595,10 @@ public long getMergeMinRegionSizeMb() {
570595
}
571596

572597
public long getMergeMinRegionSizeMb(NormalizeContext context) {
573-
long mergeMinRegionSizeMb = context.getOrDefault(MERGE_MIN_REGION_SIZE_MB_KEY,
598+
final long mergeMinRegionSizeMb = context.getOrDefault(MERGE_MIN_REGION_SIZE_MB_KEY,
574599
Long::parseLong, (long)-1);
575600
if (mergeMinRegionSizeMb < 0) {
576-
mergeMinRegionSizeMb = getMergeMinRegionSizeMb();
601+
return getMergeMinRegionSizeMb();
577602
}
578603
return mergeMinRegionSizeMb;
579604
}

hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
* default: {@value org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer#DEFAULT_MERGE_ENABLED}.
4848
* </li>
4949
* <li>The minimum number of regions in a table to consider it for merge normalization.
50-
* Configuration: {@value org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer#MIN_REGION_COUNT_KEY},
51-
* default: {@value org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer#DEFAULT_MIN_REGION_COUNT}.
50+
* Configuration: {@value org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer#MERGE_MIN_REGION_COUNT_KEY},
51+
* default: {@value org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer#DEFAULT_MERGE_MIN_REGION_COUNT}.
5252
* </li>
5353
* <li>The minimum age for a region to be considered for a merge, in days. Configuration:
5454
* {@value org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer#MERGE_MIN_REGION_AGE_DAYS_KEY},

hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerManagerConfigurationObserver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ public void before() {
7777
@Test
7878
public void test() {
7979
assertTrue(normalizer.isMergeEnabled());
80-
assertEquals(3, normalizer.getMinRegionCount());
80+
assertEquals(3, normalizer.getMergeMinRegionCount());
8181
assertEquals(1_000_000L, parseConfiguredRateLimit(worker.getRateLimiter()));
8282

8383
final Configuration newConf = new Configuration(conf);
8484
// configs on SimpleRegionNormalizer
8585
newConf.setBoolean("hbase.normalizer.merge.enabled", false);
86-
newConf.setInt("hbase.normalizer.min.region.count", 100);
86+
newConf.setInt("hbase.normalizer.merge.min.region.count", 100);
8787
// config on RegionNormalizerWorker
8888
newConf.set("hbase.normalizer.throughput.max_bytes_per_sec", "12g");
8989

9090
configurationManager.notifyAllObservers(newConf);
9191
assertFalse(normalizer.isMergeEnabled());
92-
assertEquals(100, normalizer.getMinRegionCount());
92+
assertEquals(100, normalizer.getMergeMinRegionCount());
9393
assertEquals(12_884L, parseConfiguredRateLimit(worker.getRateLimiter()));
9494
}
9595

hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer.DEFAULT_MERGE_MIN_REGION_AGE_DAYS;
2222
import static org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer.MERGE_ENABLED_KEY;
2323
import static org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer.MERGE_MIN_REGION_AGE_DAYS_KEY;
24+
import static org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer.MERGE_MIN_REGION_COUNT_KEY;
2425
import static org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer.MERGE_MIN_REGION_SIZE_MB_KEY;
2526
import static org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer.MIN_REGION_COUNT_KEY;
2627
import static org.apache.hadoop.hbase.master.normalizer.SimpleRegionNormalizer.SPLIT_ENABLED_KEY;
@@ -137,7 +138,7 @@ private void noNormalizationOnTransitioningRegions(final RegionState.State state
137138
when(masterServices.getAssignmentManager().getRegionStates()
138139
.getRegionState(any(RegionInfo.class)))
139140
.thenReturn(RegionState.createForTesting(null, state));
140-
assertThat(normalizer.getMinRegionCount(), greaterThanOrEqualTo(regionInfos.size()));
141+
assertThat(normalizer.getMergeMinRegionCount(), greaterThanOrEqualTo(regionInfos.size()));
141142

142143
List<NormalizationPlan> plans = normalizer.computePlansForTable(tableDescriptor);
143144
assertThat(format("Unexpected plans for RegionState %s", state), plans, empty());
@@ -370,6 +371,35 @@ public void testHonorsMergeEnabledInTD() {
370371

371372
@Test
372373
public void testHonorsMinimumRegionCount() {
374+
conf.setInt(MERGE_MIN_REGION_COUNT_KEY, 1);
375+
final TableName tableName = name.getTableName();
376+
final List<RegionInfo> regionInfos = createRegionInfos(tableName, 3);
377+
// create a table topology that results in both a merge plan and a split plan. Assert that the
378+
// merge is only created when the when the number of table regions is above the region count
379+
// threshold, and that the split plan is create in both cases.
380+
final Map<byte[], Integer> regionSizes = createRegionSizesMap(regionInfos, 1, 1, 10);
381+
setupMocksForNormalizer(regionSizes, regionInfos);
382+
383+
List<NormalizationPlan> plans = normalizer.computePlansForTable(tableDescriptor);
384+
assertThat(plans, contains(
385+
new SplitNormalizationPlan(regionInfos.get(2), 10),
386+
new MergeNormalizationPlan.Builder()
387+
.addTarget(regionInfos.get(0), 1)
388+
.addTarget(regionInfos.get(1), 1)
389+
.build()));
390+
391+
// have to call setupMocks again because we don't have dynamic config update on normalizer.
392+
conf.setInt(MERGE_MIN_REGION_COUNT_KEY, 4);
393+
setupMocksForNormalizer(regionSizes, regionInfos);
394+
assertThat(normalizer.computePlansForTable(tableDescriptor), contains(
395+
new SplitNormalizationPlan(regionInfos.get(2), 10)));
396+
}
397+
398+
/**
399+
* Test the backward compatibility of the deprecated MIN_REGION_COUNT_KEY configuration.
400+
*/
401+
@Test
402+
public void testHonorsOldMinimumRegionCount() {
373403
conf.setInt(MIN_REGION_COUNT_KEY, 1);
374404
final TableName tableName = name.getTableName();
375405
final List<RegionInfo> regionInfos = createRegionInfos(tableName, 3);
@@ -396,6 +426,34 @@ public void testHonorsMinimumRegionCount() {
396426

397427
@Test
398428
public void testHonorsMinimumRegionCountInTD() {
429+
conf.setInt(MERGE_MIN_REGION_COUNT_KEY, 1);
430+
final TableName tableName = name.getTableName();
431+
final List<RegionInfo> regionInfos = createRegionInfos(tableName, 3);
432+
// create a table topology that results in both a merge plan and a split plan. Assert that the
433+
// merge is only created when the when the number of table regions is above the region count
434+
// threshold, and that the split plan is create in both cases.
435+
final Map<byte[], Integer> regionSizes = createRegionSizesMap(regionInfos, 1, 1, 10);
436+
setupMocksForNormalizer(regionSizes, regionInfos);
437+
438+
List<NormalizationPlan> plans = normalizer.computePlansForTable(tableDescriptor);
439+
assertThat(plans, contains(
440+
new SplitNormalizationPlan(regionInfos.get(2), 10),
441+
new MergeNormalizationPlan.Builder()
442+
.addTarget(regionInfos.get(0), 1)
443+
.addTarget(regionInfos.get(1), 1)
444+
.build()));
445+
446+
when(tableDescriptor.getValue(MIN_REGION_COUNT_KEY)).thenReturn("4");
447+
assertThat(normalizer.computePlansForTable(tableDescriptor), contains(
448+
new SplitNormalizationPlan(regionInfos.get(2), 10)));
449+
}
450+
451+
/**
452+
* Test the backward compatibility of the deprecated MIN_REGION_COUNT_KEY configuration in table
453+
* descriptor.
454+
*/
455+
@Test
456+
public void testHonorsOldMinimumRegionCountInTD() {
399457
conf.setInt(MIN_REGION_COUNT_KEY, 1);
400458
final TableName tableName = name.getTableName();
401459
final List<RegionInfo> regionInfos = createRegionInfos(tableName, 3);

0 commit comments

Comments
 (0)