diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java index a921112301b..17644eb426b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java @@ -216,8 +216,9 @@ public class CatalogJanitor extends ScheduledChore { + " from fs because merged region no longer holds references"); HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, regionA); HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, regionB); - MetaTableAccessor.deleteMergeQualifiers(server.getConnection(), - mergedRegion); + MetaTableAccessor.deleteMergeQualifiers(services.getConnection(), mergedRegion); + services.getServerManager().removeRegion(regionA); + services.getServerManager().removeRegion(regionB); return true; } return false; @@ -360,6 +361,7 @@ public class CatalogJanitor extends ScheduledChore { if (LOG.isTraceEnabled()) LOG.trace("Archiving parent region: " + parent); HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, parent); MetaTableAccessor.deleteRegion(this.connection, parent); + services.getServerManager().removeRegion(parent); result = true; } return result; @@ -461,4 +463,4 @@ public class CatalogJanitor extends ScheduledChore { return cleanMergeRegion(region, mergeRegions.getFirst(), mergeRegions.getSecond()); } -} \ No newline at end of file +} diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java index 5eb569e22e3..bcaa4d00645 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java @@ -1212,4 +1212,22 @@ public class ServerManager { deadservers.cleanAllPreviousInstances(serverName); } } + + /** + * Called by delete table and similar to notify the ServerManager that a region was removed. + */ + public void removeRegion(final HRegionInfo regionInfo) { + final byte[] encodedName = regionInfo.getEncodedNameAsBytes(); + storeFlushedSequenceIdsByRegion.remove(encodedName); + flushedSequenceIdByRegion.remove(encodedName); + } + + /** + * Called by delete table and similar to notify the ServerManager that a region was removed. + */ + public void removeRegions(final List regions) { + for (HRegionInfo hri: regions) { + removeRegion(hri); + } + } } 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 44dde9eca07..20466d1bd31 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 @@ -379,6 +379,9 @@ public class DeleteTableProcedure // Clean any remaining rows for this table. cleanAnyRemainingRows(env, tableName); + + // clean region references from the server manager + env.getMasterServices().getServerManager().removeRegions(regions); } 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 3a3739d068a..9dccef6d455 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 @@ -105,6 +105,8 @@ public class TruncateTableProcedure if (!preserveSplits) { // if we are not preserving splits, generate a new single region regions = Arrays.asList(ModifyRegionUtils.createHRegionInfos(hTableDescriptor, null)); + } else { + regions = recreateRegionInfo(regions); } setNextState(TruncateTableState.TRUNCATE_TABLE_CREATE_FS_LAYOUT); break; @@ -245,6 +247,14 @@ public class TruncateTableProcedure } } + private static List recreateRegionInfo(final List regions) { + ArrayList newRegions = new ArrayList(regions.size()); + for (HRegionInfo hri: regions) { + newRegions.add(new HRegionInfo(hri.getTable(), hri.getStartKey(), hri.getEndKey())); + } + return newRegions; + } + private boolean prepareTruncate(final MasterProcedureEnv env) throws IOException { try { env.getMasterServices().checkTableModifiable(getTableName()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java index 1fc74bc618f..13c0cb1677d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java @@ -216,10 +216,12 @@ public class TestCatalogJanitor { class MockMasterServices implements MasterServices { private final MasterFileSystem mfs; private final AssignmentManager asm; + private final ServerManager sm; MockMasterServices(final Server server) throws IOException { this.mfs = new MasterFileSystem(server, this); this.asm = Mockito.mock(AssignmentManager.class); + this.sm = Mockito.mock(ServerManager.class); } @Override @@ -289,7 +291,7 @@ public class TestCatalogJanitor { @Override public ServerManager getServerManager() { - return null; + return sm; } @Override diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTruncateTableProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTruncateTableProcedure.java index 08442ce19b0..941dd2fef6b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTruncateTableProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTruncateTableProcedure.java @@ -162,10 +162,10 @@ public class TestTruncateTableProcedure { UTIL.waitUntilAllRegionsAssigned(tableName); // validate the table regions and layout + regions = UTIL.getHBaseAdmin().getTableRegions(tableName).toArray(new HRegionInfo[0]); if (preserveSplits) { - assertEquals(1 + splitKeys.length, UTIL.getHBaseAdmin().getTableRegions(tableName).size()); + assertEquals(1 + splitKeys.length, regions.length); } else { - regions = UTIL.getHBaseAdmin().getTableRegions(tableName).toArray(new HRegionInfo[1]); assertEquals(1, regions.length); } MasterProcedureTestingUtility.validateTableCreation( @@ -229,10 +229,10 @@ public class TestTruncateTableProcedure { UTIL.waitUntilAllRegionsAssigned(tableName); // validate the table regions and layout + regions = UTIL.getHBaseAdmin().getTableRegions(tableName).toArray(new HRegionInfo[0]); if (preserveSplits) { - assertEquals(1 + splitKeys.length, UTIL.getHBaseAdmin().getTableRegions(tableName).size()); + assertEquals(1 + splitKeys.length, regions.length); } else { - regions = UTIL.getHBaseAdmin().getTableRegions(tableName).toArray(new HRegionInfo[1]); assertEquals(1, regions.length); } MasterProcedureTestingUtility.validateTableCreation(