HBASE-24588 : createTableBegsSplit should consider tuning mergeEnabled for table (ADDENDUM) (#1988)

This commit is contained in:
Viraj Jasani 2020-06-27 19:09:19 +05:30 committed by GitHub
parent af49b87367
commit 47742b2083
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 9 deletions

View File

@ -130,15 +130,23 @@ public class TestSimpleRegionNormalizerOnCluster {
public void testHonorsNormalizerTableSetting() throws Exception { public void testHonorsNormalizerTableSetting() throws Exception {
final TableName tn1 = TableName.valueOf(name.getMethodName() + "1"); final TableName tn1 = TableName.valueOf(name.getMethodName() + "1");
final TableName tn2 = TableName.valueOf(name.getMethodName() + "2"); final TableName tn2 = TableName.valueOf(name.getMethodName() + "2");
final TableName tn3 = TableName.valueOf(name.getMethodName() + "3");
try { try {
final int tn1RegionCount = createTableBegsSplit(tn1, true); final int tn1RegionCount = createTableBegsSplit(tn1, true, false);
final int tn2RegionCount = createTableBegsSplit(tn2, false); final int tn2RegionCount = createTableBegsSplit(tn2, false, false);
final int tn3RegionCount = createTableBegsSplit(tn3, true, true);
assertFalse(admin.normalizerSwitch(true)); assertFalse(admin.normalizerSwitch(true));
assertTrue(admin.normalize()); assertTrue(admin.normalize());
waitForTableSplit(tn1, tn1RegionCount + 1); waitForTableSplit(tn1, tn1RegionCount + 1);
// confirm that tn1 has (tn1RegionCount + 1) number of regions.
// tn2 has tn2RegionCount number of regions because normalizer has not been enabled on it.
// tn3 has tn3RegionCount number of regions because two plans are run:
// 1. split one region to two
// 2. merge two regions into one
// and hence, total number of regions for tn3 remains same
assertEquals( assertEquals(
tn1 + " should have split.", tn1 + " should have split.",
tn1RegionCount + 1, tn1RegionCount + 1,
@ -147,9 +155,11 @@ public class TestSimpleRegionNormalizerOnCluster {
tn2 + " should not have split.", tn2 + " should not have split.",
tn2RegionCount, tn2RegionCount,
MetaTableAccessor.getRegionCount(TEST_UTIL.getConnection(), tn2)); MetaTableAccessor.getRegionCount(TEST_UTIL.getConnection(), tn2));
waitForTableRegionCount(tn3, tn3RegionCount);
} finally { } finally {
dropIfExists(tn1); dropIfExists(tn1);
dropIfExists(tn2); dropIfExists(tn2);
dropIfExists(tn3);
} }
} }
@ -170,7 +180,7 @@ public class TestSimpleRegionNormalizerOnCluster {
? buildTableNameForQuotaTest(name.getMethodName()) ? buildTableNameForQuotaTest(name.getMethodName())
: TableName.valueOf(name.getMethodName()); : TableName.valueOf(name.getMethodName());
final int currentRegionCount = createTableBegsSplit(tableName, true); final int currentRegionCount = createTableBegsSplit(tableName, true, false);
final long existingSkippedSplitCount = master.getRegionNormalizer() final long existingSkippedSplitCount = master.getRegionNormalizer()
.getSkippedCount(PlanType.SPLIT); .getSkippedCount(PlanType.SPLIT);
assertFalse(admin.normalizerSwitch(true)); assertFalse(admin.normalizerSwitch(true));
@ -200,7 +210,7 @@ public class TestSimpleRegionNormalizerOnCluster {
final int currentRegionCount = createTableBegsMerge(tableName); final int currentRegionCount = createTableBegsMerge(tableName);
assertFalse(admin.normalizerSwitch(true)); assertFalse(admin.normalizerSwitch(true));
assertTrue(admin.normalize()); assertTrue(admin.normalize());
waitforTableMerge(tableName, currentRegionCount - 1); waitForTableMerge(tableName, currentRegionCount - 1);
assertEquals( assertEquals(
tableName + " should have merged.", tableName + " should have merged.",
currentRegionCount - 1, currentRegionCount - 1,
@ -233,8 +243,24 @@ public class TestSimpleRegionNormalizerOnCluster {
}); });
} }
private static void waitForTableRegionCount(final TableName tableName,
final int targetRegionCount) throws IOException {
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(5), new ExplainingPredicate<IOException>() {
@Override
public String explainFailure() {
return "expected " + targetRegionCount + " number of regions for table " + tableName;
}
@Override
public boolean evaluate() throws IOException {
final int currentRegionCount =
MetaTableAccessor.getRegionCount(TEST_UTIL.getConnection(), tableName);
return currentRegionCount == targetRegionCount;
}
});
}
private static void waitForTableSplit(final TableName tableName, final int targetRegionCount) private static void waitForTableSplit(final TableName tableName, final int targetRegionCount)
throws IOException { throws IOException {
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(5), new ExplainingPredicate<IOException>() { TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(5), new ExplainingPredicate<IOException>() {
@Override public String explainFailure() { @Override public String explainFailure() {
return "expected normalizer to split region."; return "expected normalizer to split region.";
@ -247,8 +273,8 @@ public class TestSimpleRegionNormalizerOnCluster {
}); });
} }
private static void waitforTableMerge(final TableName tableName, final int targetRegionCount) private static void waitForTableMerge(final TableName tableName, final int targetRegionCount)
throws IOException { throws IOException {
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(5), new ExplainingPredicate<IOException>() { TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(5), new ExplainingPredicate<IOException>() {
@Override public String explainFailure() { @Override public String explainFailure() {
return "expected normalizer to merge regions."; return "expected normalizer to merge regions.";
@ -319,14 +345,16 @@ public class TestSimpleRegionNormalizerOnCluster {
* <li>split threshold: 2.4 * 2 = 4.8</li> * <li>split threshold: 2.4 * 2 = 4.8</li>
* </ul> * </ul>
*/ */
private static int createTableBegsSplit(final TableName tableName, final boolean balancerEnabled) private static int createTableBegsSplit(final TableName tableName,
final boolean normalizerEnabled, final boolean isMergeEnabled)
throws IOException { throws IOException {
final List<HRegion> generatedRegions = generateTestData(tableName, 1, 1, 2, 3, 5); final List<HRegion> generatedRegions = generateTestData(tableName, 1, 1, 2, 3, 5);
assertEquals(5, MetaTableAccessor.getRegionCount(TEST_UTIL.getConnection(), tableName)); assertEquals(5, MetaTableAccessor.getRegionCount(TEST_UTIL.getConnection(), tableName));
admin.flush(tableName); admin.flush(tableName);
final TableDescriptor td = TableDescriptorBuilder.newBuilder(admin.getDescriptor(tableName)) final TableDescriptor td = TableDescriptorBuilder.newBuilder(admin.getDescriptor(tableName))
.setNormalizationEnabled(balancerEnabled) .setNormalizationEnabled(normalizerEnabled)
.setMergeEnabled(isMergeEnabled)
.build(); .build();
admin.modifyTable(td); admin.modifyTable(td);