From 816d8602288f094eed5eaee27fa39730e0b11a98 Mon Sep 17 00:00:00 2001 From: Thiruvel Thirumoolan Date: Thu, 15 Feb 2018 01:42:31 -0800 Subject: [PATCH] HBASE-19996 Some nonce procs might not be cleaned up (follow up HBASE-19756) Signed-off-by: tedyu --- .../procedure/TestFailedProcCleanup.java | 57 +++++++++++++++---- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestFailedProcCleanup.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestFailedProcCleanup.java index 7b848f26934..bf72d331cb6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestFailedProcCleanup.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestFailedProcCleanup.java @@ -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> 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 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 getMasterObserver() { + return Optional.of(this); + } + } }