HBASE-22537 Split happened Replica region can not be deleted after deleting table successfully and restarting RegionServer

Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
This commit is contained in:
sreenivasulureddy 2019-07-18 15:24:32 +01:00 committed by Wellington Chevreuil
parent 22a991e8b6
commit 2fa6d062f5
1 changed files with 67 additions and 6 deletions

View File

@ -27,16 +27,25 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.master.assignment.AssignmentTestingUtil;
import org.apache.hadoop.hbase.master.assignment.SplitTableRegionProcedure;
import org.apache.hadoop.hbase.master.procedure.DeleteTableProcedure;
import org.apache.hadoop.hbase.master.procedure.DisableTableProcedure;
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Threads;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
@ -60,16 +69,16 @@ public class TestSplitOrMergeStatus {
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
@Before
public void setUp() throws Exception {
TEST_UTIL.startMiniCluster(2);
}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
@After
public void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@ -162,6 +171,58 @@ public class TestSplitOrMergeStatus {
admin.close();
}
@Test
public void testSplitRegionReplicaRitRecovery() throws Exception {
int startRowNum = 11;
int rowCount = 60;
final TableName tableName = TableName.valueOf(name.getMethodName());
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
TEST_UTIL.getAdmin().createTable(TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).setRegionReplication(2).build());
TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
ServerName serverName =
RegionReplicaTestHelper.getRSCarryingReplica(TEST_UTIL, tableName, 1).get();
List<RegionInfo> regions = TEST_UTIL.getAdmin().getRegions(tableName);
insertData(tableName, startRowNum, rowCount);
int splitRowNum = startRowNum + rowCount / 2;
byte[] splitKey = Bytes.toBytes("" + splitRowNum);
// Split region of the table
long procId = procExec.submitProcedure(
new SplitTableRegionProcedure(procExec.getEnvironment(), regions.get(0), splitKey));
// Wait the completion
ProcedureTestingUtility.waitProcedure(procExec, procId);
// Disable the table
long procId1 = procExec
.submitProcedure(new DisableTableProcedure(procExec.getEnvironment(), tableName, false));
// Wait the completion
ProcedureTestingUtility.waitProcedure(procExec, procId1);
// Delete Table
long procId2 =
procExec.submitProcedure(new DeleteTableProcedure(procExec.getEnvironment(), tableName));
// Wait the completion
ProcedureTestingUtility.waitProcedure(procExec, procId2);
AssignmentTestingUtil.killRs(TEST_UTIL, serverName);
Threads.sleepWithoutInterrupt(5000);
boolean hasRegionsInTransition = TEST_UTIL.getMiniHBaseCluster().getMaster()
.getAssignmentManager().getRegionStates().hasRegionsInTransition();
assertEquals(false, hasRegionsInTransition);
}
private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() {
return TEST_UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor();
}
private void insertData(final TableName tableName, int startRow, int rowCount)
throws IOException {
Table t = TEST_UTIL.getConnection().getTable(tableName);
Put p;
for (int i = 0; i < rowCount; i++) {
p = new Put(Bytes.toBytes("" + (startRow + i)));
p.addColumn(FAMILY, Bytes.toBytes("q1"), Bytes.toBytes(i));
t.put(p);
}
}
private void initSwitchStatus(Admin admin) throws IOException {
if (!admin.isSplitOrMergeEnabled(MasterSwitchType.SPLIT)) {
admin.setSplitOrMergeEnabled(true, false, MasterSwitchType.SPLIT);