HBASE-16649 Truncate table with splits preserved can cause both data loss and truncated data appeared again

This commit is contained in:
Matteo Bertozzi 2016-09-26 12:58:04 -07:00
parent 43f47a8e73
commit f06c0060aa
6 changed files with 45 additions and 4 deletions

View File

@ -213,6 +213,8 @@ public class CatalogJanitor extends ScheduledChore {
HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, regionA);
HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, regionB);
MetaTableAccessor.deleteMergeQualifiers(services.getConnection(), mergedRegion);
services.getServerManager().removeRegion(regionA);
services.getServerManager().removeRegion(regionB);
return true;
}
return false;
@ -357,6 +359,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;

View File

@ -1184,4 +1184,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<HRegionInfo> regions) {
for (HRegionInfo hri: regions) {
removeRegion(hri);
}
}
}

View File

@ -363,6 +363,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,

View File

@ -107,6 +107,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;
@ -256,6 +258,14 @@ public class TruncateTableProcedure
}
}
private static List<HRegionInfo> recreateRegionInfo(final List<HRegionInfo> regions) {
ArrayList<HRegionInfo> newRegions = new ArrayList<HRegionInfo>(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());

View File

@ -91,6 +91,7 @@ public class TestCatalogJanitor {
private final ClusterConnection connection;
private final MasterFileSystem mfs;
private final AssignmentManager asm;
private final ServerManager sm;
MockMasterServices(final HBaseTestingUtility htu) throws IOException {
super(htu.getConfiguration());
@ -134,6 +135,7 @@ public class TestCatalogJanitor {
this.mfs = new MasterFileSystem(this);
this.asm = Mockito.mock(AssignmentManager.class);
this.sm = Mockito.mock(ServerManager.class);
}
@Override
@ -156,6 +158,11 @@ public class TestCatalogJanitor {
return ServerName.valueOf("mockserver.example.org", 1234, -1L);
}
@Override
public ServerManager getServerManager() {
return this.sm;
}
@Override
public CoordinatedStateManager getCoordinatedStateManager() {
BaseCoordinatedStateManager m = Mockito.mock(BaseCoordinatedStateManager.class);

View File

@ -165,10 +165,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(
@ -231,10 +231,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(