From 073f23e2bdb861548e78e29f499d4d53ef041a27 Mon Sep 17 00:00:00 2001 From: Baiqiang Zhao Date: Tue, 19 Jan 2021 23:53:51 +0800 Subject: [PATCH] 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 --- .../normalizer/SimpleRegionNormalizer.java | 4 +++ .../TestSimpleRegionNormalizer.java | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java index b6d74ec9581..a4a5c5c3dcb 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java @@ -382,6 +382,10 @@ class SimpleRegionNormalizer implements RegionNormalizer, ConfigurationObserver 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 // 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 + sumRangeMembersSizeMb <= avgRegionSizeMb)) { // add the current region // to the range when diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java index 33b32972542..70f5a87ac42 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java @@ -448,6 +448,38 @@ public class TestSimpleRegionNormalizer { .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 regionInfos = createRegionInfos(tableName, 8); + final Map regionSizes = + createRegionSizesMap(regionInfos, 0, 10, 1, 0, 9, 0, 10, 0); + setupMocksForNormalizer(regionSizes, regionInfos); + + assertFalse(normalizer.isSplitEnabled()); + assertEquals(0, normalizer.getMergeMinRegionSizeMb()); + List 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 public void testSplitAndMultiMerge() { conf.setInt(MERGE_MIN_REGION_SIZE_MB_KEY, 0);