HBASE-19996 Some nonce procs might not be cleaned up (follow up HBASE-19756)

Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
Thiruvel Thirumoolan 2018-02-15 01:42:31 -08:00 committed by tedyu
parent 07e93458fe
commit 816d860228
1 changed files with 47 additions and 10 deletions

View File

@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hbase.procedure;
import static org.apache.hadoop.hbase.coprocessor.CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY;
import static org.junit.Assert.fail;
import java.io.IOException;
@ -30,7 +31,6 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.coprocessor.MasterCoprocessor;
import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
import org.apache.hadoop.hbase.coprocessor.MasterObserver;
@ -39,7 +39,7 @@ import org.apache.hadoop.hbase.procedure2.Procedure;
import org.apache.hadoop.hbase.security.AccessDeniedException;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.AfterClass;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
@ -60,28 +60,47 @@ public class TestFailedProcCleanup {
private static final Log LOG = LogFactory.getLog(TestFailedProcCleanup.class);
protected static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static Configuration conf;
private static final TableName TABLE = TableName.valueOf("test");
private static final byte[] FAMILY = Bytes.toBytesBinary("f");
private static final int evictionDelay = 10 * 1000;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
public static void setUpBeforeClass() {
conf = TEST_UTIL.getConfiguration();
conf.setInt("hbase.procedure.cleaner.evict.ttl", evictionDelay);
conf.setInt("hbase.procedure.cleaner.evict.batch.size", 1);
conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, CreateFailObserver.class.getName());
TEST_UTIL.startMiniCluster(3);
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
TEST_UTIL.cleanupTestDir();
TEST_UTIL.cleanupDataTestDirOnTestFS();
@After
public void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@Test
public void testFailCreateTable() throws Exception {
conf.set(MASTER_COPROCESSOR_CONF_KEY, CreateFailObserver.class.getName());
TEST_UTIL.startMiniCluster(3);
try {
TEST_UTIL.createTable(TABLE, FAMILY);
} catch (AccessDeniedException e) {
LOG.debug("Ignoring exception: ", e);
Thread.sleep(evictionDelay * 3);
}
List<Procedure<?>> procedureInfos =
TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getProcedures();
for (Procedure procedureInfo : procedureInfos) {
if (procedureInfo.getProcName().equals("CreateTableProcedure")
&& procedureInfo.getState() == ProcedureProtos.ProcedureState.ROLLEDBACK) {
fail("Found procedure " + procedureInfo + " that hasn't been cleaned up");
}
}
}
@Test
public void testFailCreateTableAction() throws Exception {
conf.set(MASTER_COPROCESSOR_CONF_KEY, CreateFailObserverHandler.class.getName());
TEST_UTIL.startMiniCluster(3);
try {
TEST_UTIL.createTable(TABLE, FAMILY);
fail("Table shouldn't be created");
@ -115,4 +134,22 @@ public class TestFailedProcCleanup {
return Optional.of(this);
}
}
public static class CreateFailObserverHandler implements MasterCoprocessor, MasterObserver {
@Override
public void preCreateTableAction(
final ObserverContext<MasterCoprocessorEnvironment> ctx, final TableDescriptor desc,
final RegionInfo[] regions) throws IOException {
if (desc.getTableName().equals(TABLE)) {
throw new AccessDeniedException("Don't allow creation of table");
}
}
@Override
public Optional<MasterObserver> getMasterObserver() {
return Optional.of(this);
}
}
}