From 03e4712f0ca08d57586b3fc4d93cf02c999515d8 Mon Sep 17 00:00:00 2001 From: stack Date: Fri, 4 Dec 2015 10:53:09 -0800 Subject: [PATCH] =?UTF-8?q?HBASE-4907=20NPE=20of=20MobUtils.hasMobColumns?= =?UTF-8?q?=20in=20Build=20failed=20in=20Jenkins:=20HBase-Trunk=5Fmatrix?= =?UTF-8?q?=20=C2=BB=20latest1.8,Hadoop=20#513=20(Jingcheng=20Du)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../procedure/DeleteTableProcedure.java | 23 +++----- .../procedure/TestCreateTableProcedure.java | 58 +++++++++++-------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java index 4b95fa89d74..1e86254a061 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java @@ -31,7 +31,6 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HRegionInfo; -import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotDisabledException; @@ -345,19 +344,13 @@ public class DeleteTableProcedure LOG.debug("Table '" + tableName + "' archived!"); } - // Archive the mob data if there is a mob-enabled column - HTableDescriptor htd = env.getMasterServices().getTableDescriptors().get(tableName); - boolean hasMob = MobUtils.hasMobColumns(htd); - Path mobTableDir = null; - if (hasMob) { - // Archive mob data - mobTableDir = FSUtils.getTableDir(new Path(mfs.getRootDir(), MobConstants.MOB_DIR_NAME), - tableName); - Path regionDir = - new Path(mobTableDir, MobUtils.getMobRegionInfo(tableName).getEncodedName()); - if (fs.exists(regionDir)) { - HFileArchiver.archiveRegion(fs, mfs.getRootDir(), mobTableDir, regionDir); - } + // Archive mob data + Path mobTableDir = FSUtils.getTableDir(new Path(mfs.getRootDir(), MobConstants.MOB_DIR_NAME), + tableName); + Path regionDir = + new Path(mobTableDir, MobUtils.getMobRegionInfo(tableName).getEncodedName()); + if (fs.exists(regionDir)) { + HFileArchiver.archiveRegion(fs, mfs.getRootDir(), mobTableDir, regionDir); } // Delete table directory from FS (temp directory) @@ -366,7 +359,7 @@ public class DeleteTableProcedure } // Delete the table directory where the mob files are saved - if (hasMob && mobTableDir != null && fs.exists(mobTableDir)) { + if (mobTableDir != null && fs.exists(mobTableDir)) { if (!fs.delete(mobTableDir, true)) { throw new IOException("Couldn't delete mob dir " + mobTableDir); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCreateTableProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCreateTableProcedure.java index 0aad5fa81cf..676a3f4dec9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCreateTableProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCreateTableProcedure.java @@ -195,32 +195,15 @@ public class TestCreateTableProcedure { @Test(timeout=90000) public void testRollbackAndDoubleExecution() throws Exception { final TableName tableName = TableName.valueOf("testRollbackAndDoubleExecution"); + testRollbackAndDoubleExecution(MasterProcedureTestingUtility.createHTD(tableName, "f1", "f2")); + } - // create the table - final ProcedureExecutor procExec = getMasterProcedureExecutor(); - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true); - - // Start the Create procedure && kill the executor - final byte[][] splitKeys = new byte[][] { - Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c") - }; + @Test(timeout=90000) + public void testRollbackAndDoubleExecutionOnMobTable() throws Exception { + final TableName tableName = TableName.valueOf("testRollbackAndDoubleExecutionOnMobTable"); HTableDescriptor htd = MasterProcedureTestingUtility.createHTD(tableName, "f1", "f2"); - htd.setRegionReplication(3); - HRegionInfo[] regions = ModifyRegionUtils.createHRegionInfos(htd, splitKeys); - long procId = procExec.submitProcedure( - new CreateTableProcedure(procExec.getEnvironment(), htd, regions), nonceGroup, nonce); - - // NOTE: the 4 (number of CreateTableState steps) is hardcoded, - // so you have to look at this test at least once when you add a new step. - MasterProcedureTestingUtility.testRollbackAndDoubleExecution( - procExec, procId, 4, CreateTableState.values()); - - MasterProcedureTestingUtility.validateTableDeletion( - UTIL.getHBaseCluster().getMaster(), tableName, regions, "f1", "f2"); - - // are we able to create the table after a rollback? - resetProcExecutorTestingKillFlag(); - testSimpleCreate(tableName, splitKeys); + htd.getFamily(Bytes.toBytes("f1")).setMobEnabled(true); + testRollbackAndDoubleExecution(htd); } @Test(timeout=90000) @@ -282,4 +265,31 @@ public class TestCreateTableProcedure { } } } + + private void testRollbackAndDoubleExecution(HTableDescriptor htd) throws Exception { + // create the table + final ProcedureExecutor procExec = getMasterProcedureExecutor(); + ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true); + + // Start the Create procedure && kill the executor + final byte[][] splitKeys = new byte[][] { + Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c") + }; + htd.setRegionReplication(3); + HRegionInfo[] regions = ModifyRegionUtils.createHRegionInfos(htd, splitKeys); + long procId = procExec.submitProcedure( + new CreateTableProcedure(procExec.getEnvironment(), htd, regions), nonceGroup, nonce); + + // NOTE: the 4 (number of CreateTableState steps) is hardcoded, + // so you have to look at this test at least once when you add a new step. + MasterProcedureTestingUtility.testRollbackAndDoubleExecution( + procExec, procId, 4, CreateTableState.values()); + TableName tableName = htd.getTableName(); + MasterProcedureTestingUtility.validateTableDeletion( + UTIL.getHBaseCluster().getMaster(), tableName, regions, "f1", "f2"); + + // are we able to create the table after a rollback? + resetProcExecutorTestingKillFlag(); + testSimpleCreate(tableName, splitKeys); + } }