From 0d50ce1b11e575019279352fea7038fa9c359a10 Mon Sep 17 00:00:00 2001 From: Wellington Chevreuil Date: Wed, 7 Aug 2019 15:16:29 +0100 Subject: [PATCH] HBASE-22417 DeleteTableProcedure.deleteFromMeta method should remove table from Master's table descriptors cache Signed-off-by: stack --- .../master/procedure/DeleteTableProcedure.java | 17 +++++++---------- .../procedure/TruncateTableProcedure.java | 18 +++++++++++------- .../procedure/TestDeleteTableProcedure.java | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 17 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 e3f6132cdc9..aeb48d26b6f 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 @@ -104,23 +104,18 @@ public class DeleteTableProcedure // Call coprocessors preDelete(env); - setNextState(DeleteTableState.DELETE_TABLE_REMOVE_FROM_META); - break; - case DELETE_TABLE_REMOVE_FROM_META: - LOG.debug("Deleting regions from META for {}", this); - DeleteTableProcedure.deleteFromMeta(env, getTableName(), regions); setNextState(DeleteTableState.DELETE_TABLE_CLEAR_FS_LAYOUT); break; case DELETE_TABLE_CLEAR_FS_LAYOUT: LOG.debug("Deleting regions from filesystem for {}", this); DeleteTableProcedure.deleteFromFs(env, getTableName(), regions, true); - setNextState(DeleteTableState.DELETE_TABLE_UPDATE_DESC_CACHE); - regions = null; + setNextState(DeleteTableState.DELETE_TABLE_REMOVE_FROM_META); break; - case DELETE_TABLE_UPDATE_DESC_CACHE: - LOG.debug("Deleting descriptor for {}", this); - DeleteTableProcedure.deleteTableDescriptorCache(env, getTableName()); + case DELETE_TABLE_REMOVE_FROM_META: + LOG.debug("Deleting regions from META for {}", this); + DeleteTableProcedure.deleteFromMeta(env, getTableName(), regions); setNextState(DeleteTableState.DELETE_TABLE_UNASSIGN_REGIONS); + regions = null; break; case DELETE_TABLE_UNASSIGN_REGIONS: LOG.debug("Deleting assignment state for {}", this); @@ -389,6 +384,8 @@ public class DeleteTableProcedure if (fnm != null) { fnm.deleteFavoredNodesForRegions(regions); } + + deleteTableDescriptorCache(env, tableName); } protected static void deleteAssignmentState(final MasterProcedureEnv env, diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java index d6c8607f769..061f79fa5f2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TruncateTableProcedure.java @@ -98,13 +98,10 @@ public class TruncateTableProcedure // Call coprocessors preTruncate(env); - setNextState(TruncateTableState.TRUNCATE_TABLE_REMOVE_FROM_META); - break; - case TRUNCATE_TABLE_REMOVE_FROM_META: - tableDescriptor = env.getMasterServices().getTableDescriptors() - .get(tableName); - DeleteTableProcedure.deleteFromMeta(env, getTableName(), regions); - DeleteTableProcedure.deleteAssignmentState(env, getTableName()); + //We need to cache table descriptor in the initial stage, so that it's saved within + //the procedure stage and can get recovered if the procedure crashes between + //TRUNCATE_TABLE_REMOVE_FROM_META and TRUNCATE_TABLE_CREATE_FS_LAYOUT + tableDescriptor = env.getMasterServices().getTableDescriptors().get(tableName); setNextState(TruncateTableState.TRUNCATE_TABLE_CLEAR_FS_LAYOUT); break; case TRUNCATE_TABLE_CLEAR_FS_LAYOUT: @@ -121,6 +118,13 @@ public class TruncateTableProcedure } else { regions = recreateRegionInfo(regions); } + setNextState(TruncateTableState.TRUNCATE_TABLE_REMOVE_FROM_META); + break; + case TRUNCATE_TABLE_REMOVE_FROM_META: + List originalRegions = env.getAssignmentManager() + .getRegionStates().getRegionsOfTable(getTableName()); + DeleteTableProcedure.deleteFromMeta(env, getTableName(), originalRegions); + DeleteTableProcedure.deleteAssignmentState(env, getTableName()); setNextState(TruncateTableState.TRUNCATE_TABLE_CREATE_FS_LAYOUT); break; case TRUNCATE_TABLE_CREATE_FS_LAYOUT: diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteTableProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteTableProcedure.java index 88159662bf1..fa83a932855 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteTableProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteTableProcedure.java @@ -19,9 +19,12 @@ package org.apache.hadoop.hbase.master.procedure; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.ArrayList; import java.util.List; import org.apache.hadoop.fs.FileSystem; @@ -133,6 +136,21 @@ public class TestDeleteTableProcedure extends TestTableDDLProcedureBase { testSimpleDelete(tableName, splitKeys); } + @Test + public void testDeleteFromMeta() throws Exception { + final TableName tableName = TableName.valueOf(name.getMethodName()); + RegionInfo[] regions = MasterProcedureTestingUtility.createTable( + getMasterProcedureExecutor(), tableName, null, "f1", "f2"); + List regionsList = new ArrayList<>(); + UTIL.getAdmin().disableTable(tableName); + MasterProcedureEnv procedureEnv = getMasterProcedureExecutor().getEnvironment(); + assertNotNull("Table should be on TableDescriptors cache.", + procedureEnv.getMasterServices().getTableDescriptors().get(tableName)); + DeleteTableProcedure.deleteFromMeta(procedureEnv, tableName, regionsList); + assertNull("Table shouldn't be on TableDescriptors anymore.", + procedureEnv.getMasterServices().getTableDescriptors().get(tableName)); + } + private void testSimpleDelete(final TableName tableName, byte[][] splitKeys) throws Exception { RegionInfo[] regions = MasterProcedureTestingUtility.createTable( getMasterProcedureExecutor(), tableName, splitKeys, "f1", "f2");