HBASE-25513 When the table is turned on normalize, the first region may not be merged even the size is 0 (#2887)

Signed-off-by: Nick Dimiduk <ndimiduk@apache.org>
This commit is contained in:
Baiqiang Zhao 2021-01-19 23:53:51 +08:00 committed by GitHub
parent 6c3861f65d
commit bc4f5c2709
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -364,6 +364,10 @@ class SimpleRegionNormalizer implements RegionNormalizer, ConfigurationObserver
if (rangeMembers.isEmpty() // when there are no range members, seed the range with whatever if (rangeMembers.isEmpty() // when there are no range members, seed the range with whatever
// we have. this way we're prepared in case the next region is // we have. this way we're prepared in case the next region is
// 0-size. // 0-size.
|| (rangeMembers.size() == 1 && sumRangeMembersSizeMb == 0) // when there is only one
// region and the size is 0,
// seed the range with
// whatever we have.
|| regionSizeMb == 0 // always add an empty region to the current range. || regionSizeMb == 0 // always add an empty region to the current range.
|| (regionSizeMb + sumRangeMembersSizeMb <= avgRegionSizeMb)) { // add the current region || (regionSizeMb + sumRangeMembersSizeMb <= avgRegionSizeMb)) { // add the current region
// to the range when // to the range when

View File

@ -448,6 +448,38 @@ public class TestSimpleRegionNormalizer {
.build())); .build()));
} }
@Test
public void testMergeEmptyRegions2() {
conf.setBoolean(SPLIT_ENABLED_KEY, false);
conf.setInt(MERGE_MIN_REGION_SIZE_MB_KEY, 0);
final TableName tableName = name.getTableName();
final List<RegionInfo> regionInfos = createRegionInfos(tableName, 8);
final Map<byte[], Integer> regionSizes =
createRegionSizesMap(regionInfos, 0, 10, 1, 0, 9, 0, 10, 0);
setupMocksForNormalizer(regionSizes, regionInfos);
assertFalse(normalizer.isSplitEnabled());
assertEquals(0, normalizer.getMergeMinRegionSizeMb());
List<NormalizationPlan> plans = normalizer.computePlansForTable(tableName);
assertThat(plans, contains(
new MergeNormalizationPlan.Builder()
.addTarget(regionInfos.get(0), 0)
.addTarget(regionInfos.get(1), 10)
.build(),
new MergeNormalizationPlan.Builder()
.addTarget(regionInfos.get(2), 1)
.addTarget(regionInfos.get(3), 0)
.build(),
new MergeNormalizationPlan.Builder()
.addTarget(regionInfos.get(4), 9)
.addTarget(regionInfos.get(5), 0)
.build(),
new MergeNormalizationPlan.Builder()
.addTarget(regionInfos.get(6), 10)
.addTarget(regionInfos.get(7), 0)
.build()));
}
@Test @Test
public void testSplitAndMultiMerge() { public void testSplitAndMultiMerge() {
conf.setInt(MERGE_MIN_REGION_SIZE_MB_KEY, 0); conf.setInt(MERGE_MIN_REGION_SIZE_MB_KEY, 0);