HBASE-22417 DeleteTableProcedure.deleteFromMeta method should remove table from Master's table descriptors cache

Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Wellington Chevreuil 2019-08-07 12:05:56 +01:00
parent 07c6bb16e7
commit a9773ec5e8
3 changed files with 36 additions and 17 deletions

View File

@ -104,23 +104,18 @@ public class DeleteTableProcedure
// Call coprocessors // Call coprocessors
preDelete(env); 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); setNextState(DeleteTableState.DELETE_TABLE_CLEAR_FS_LAYOUT);
break; break;
case DELETE_TABLE_CLEAR_FS_LAYOUT: case DELETE_TABLE_CLEAR_FS_LAYOUT:
LOG.debug("Deleting regions from filesystem for {}", this); LOG.debug("Deleting regions from filesystem for {}", this);
DeleteTableProcedure.deleteFromFs(env, getTableName(), regions, true); DeleteTableProcedure.deleteFromFs(env, getTableName(), regions, true);
setNextState(DeleteTableState.DELETE_TABLE_UPDATE_DESC_CACHE); setNextState(DeleteTableState.DELETE_TABLE_REMOVE_FROM_META);
regions = null;
break; break;
case DELETE_TABLE_UPDATE_DESC_CACHE: case DELETE_TABLE_REMOVE_FROM_META:
LOG.debug("Deleting descriptor for {}", this); LOG.debug("Deleting regions from META for {}", this);
DeleteTableProcedure.deleteTableDescriptorCache(env, getTableName()); DeleteTableProcedure.deleteFromMeta(env, getTableName(), regions);
setNextState(DeleteTableState.DELETE_TABLE_UNASSIGN_REGIONS); setNextState(DeleteTableState.DELETE_TABLE_UNASSIGN_REGIONS);
regions = null;
break; break;
case DELETE_TABLE_UNASSIGN_REGIONS: case DELETE_TABLE_UNASSIGN_REGIONS:
LOG.debug("Deleting assignment state for {}", this); LOG.debug("Deleting assignment state for {}", this);
@ -393,6 +388,8 @@ public class DeleteTableProcedure
if (fnm != null) { if (fnm != null) {
fnm.deleteFavoredNodesForRegions(regions); fnm.deleteFavoredNodesForRegions(regions);
} }
deleteTableDescriptorCache(env, tableName);
} }
protected static void deleteAssignmentState(final MasterProcedureEnv env, protected static void deleteAssignmentState(final MasterProcedureEnv env,

View File

@ -98,13 +98,10 @@ public class TruncateTableProcedure
// Call coprocessors // Call coprocessors
preTruncate(env); preTruncate(env);
setNextState(TruncateTableState.TRUNCATE_TABLE_REMOVE_FROM_META); //We need to cache table descriptor in the initial stage, so that it's saved within
break; //the procedure stage and can get recovered if the procedure crashes between
case TRUNCATE_TABLE_REMOVE_FROM_META: //TRUNCATE_TABLE_REMOVE_FROM_META and TRUNCATE_TABLE_CREATE_FS_LAYOUT
tableDescriptor = env.getMasterServices().getTableDescriptors() tableDescriptor = env.getMasterServices().getTableDescriptors().get(tableName);
.get(tableName);
DeleteTableProcedure.deleteFromMeta(env, getTableName(), regions);
DeleteTableProcedure.deleteAssignmentState(env, getTableName());
setNextState(TruncateTableState.TRUNCATE_TABLE_CLEAR_FS_LAYOUT); setNextState(TruncateTableState.TRUNCATE_TABLE_CLEAR_FS_LAYOUT);
break; break;
case TRUNCATE_TABLE_CLEAR_FS_LAYOUT: case TRUNCATE_TABLE_CLEAR_FS_LAYOUT:
@ -121,6 +118,13 @@ public class TruncateTableProcedure
} else { } else {
regions = recreateRegionInfo(regions); regions = recreateRegionInfo(regions);
} }
setNextState(TruncateTableState.TRUNCATE_TABLE_REMOVE_FROM_META);
break;
case TRUNCATE_TABLE_REMOVE_FROM_META:
List<RegionInfo> originalRegions = env.getAssignmentManager()
.getRegionStates().getRegionsOfTable(getTableName());
DeleteTableProcedure.deleteFromMeta(env, getTableName(), originalRegions);
DeleteTableProcedure.deleteAssignmentState(env, getTableName());
setNextState(TruncateTableState.TRUNCATE_TABLE_CREATE_FS_LAYOUT); setNextState(TruncateTableState.TRUNCATE_TABLE_CREATE_FS_LAYOUT);
break; break;
case TRUNCATE_TABLE_CREATE_FS_LAYOUT: case TRUNCATE_TABLE_CREATE_FS_LAYOUT:

View File

@ -19,9 +19,12 @@ package org.apache.hadoop.hbase.master.procedure;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; 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.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
@ -133,6 +136,21 @@ public class TestDeleteTableProcedure extends TestTableDDLProcedureBase {
testSimpleDelete(tableName, splitKeys); 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<RegionInfo> 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 { private void testSimpleDelete(final TableName tableName, byte[][] splitKeys) throws Exception {
RegionInfo[] regions = MasterProcedureTestingUtility.createTable( RegionInfo[] regions = MasterProcedureTestingUtility.createTable(
getMasterProcedureExecutor(), tableName, splitKeys, "f1", "f2"); getMasterProcedureExecutor(), tableName, splitKeys, "f1", "f2");