HBASE-26615 Snapshot referenced data files are deleted when delete a table with merge regions (#3976)
Signed-off-by: GeorryHuang <huangzhuoyue@apache.org>
This commit is contained in:
parent
c6ac99684c
commit
7fcf8e84a5
|
@ -56,6 +56,7 @@ import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.DeleteTableState;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.DeleteTableState;
|
||||||
|
import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils;
|
||||||
|
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class DeleteTableProcedure
|
public class DeleteTableProcedure
|
||||||
|
@ -317,9 +318,18 @@ public class DeleteTableProcedure
|
||||||
|
|
||||||
// Archive regions from FS (temp directory)
|
// Archive regions from FS (temp directory)
|
||||||
if (archive) {
|
if (archive) {
|
||||||
List<Path> regionDirList = regions.stream().filter(RegionReplicaUtil::isDefaultReplica)
|
List<Path> regionDirList = new ArrayList<>();
|
||||||
.map(region -> FSUtils.getRegionDirFromTableDir(tempTableDir, region))
|
for (RegionInfo region : regions) {
|
||||||
.collect(Collectors.toList());
|
if (RegionReplicaUtil.isDefaultReplica(region)) {
|
||||||
|
regionDirList.add(FSUtils.getRegionDirFromTableDir(tempTableDir, region));
|
||||||
|
List<RegionInfo> mergeRegions = MetaTableAccessor
|
||||||
|
.getMergeRegions(env.getMasterServices().getConnection(), region.getRegionName());
|
||||||
|
if (!CollectionUtils.isEmpty(mergeRegions)) {
|
||||||
|
mergeRegions.stream()
|
||||||
|
.forEach(r -> regionDirList.add(FSUtils.getRegionDirFromTableDir(tempTableDir, r)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
HFileArchiver.archiveRegions(env.getMasterConfiguration(), fs, mfs.getRootDir(), tempTableDir,
|
HFileArchiver.archiveRegions(env.getMasterConfiguration(), fs, mfs.getRootDir(), tempTableDir,
|
||||||
regionDirList);
|
regionDirList);
|
||||||
if (!regionDirList.isEmpty()) {
|
if (!regionDirList.isEmpty()) {
|
||||||
|
|
|
@ -470,6 +470,48 @@ public class TestTableSnapshotScanner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteTableWithMergedRegions() throws Exception {
|
||||||
|
setupCluster();
|
||||||
|
final TableName tableName = TableName.valueOf(this.name.getMethodName());
|
||||||
|
String snapshotName = tableName.getNameAsString() + "_snapshot";
|
||||||
|
Configuration conf = UTIL.getConfiguration();
|
||||||
|
try (Admin admin = UTIL.getConnection().getAdmin()) {
|
||||||
|
// disable compaction
|
||||||
|
admin.compactionSwitch(false,
|
||||||
|
admin.getRegionServers().stream().map(s -> s.getServerName()).collect(Collectors.toList()));
|
||||||
|
// create table
|
||||||
|
Table table = UTIL.createTable(tableName, FAMILIES, 1, bbb, yyy, 3);
|
||||||
|
List<RegionInfo> regions = admin.getRegions(tableName);
|
||||||
|
Assert.assertEquals(3, regions.size());
|
||||||
|
// write some data
|
||||||
|
UTIL.loadTable(table, FAMILIES);
|
||||||
|
// merge region
|
||||||
|
admin.mergeRegionsAsync(new byte[][] { regions.get(0).getEncodedNameAsBytes(),
|
||||||
|
regions.get(1).getEncodedNameAsBytes() },
|
||||||
|
false).get();
|
||||||
|
regions = admin.getRegions(tableName);
|
||||||
|
Assert.assertEquals(2, regions.size());
|
||||||
|
// snapshot
|
||||||
|
admin.snapshot(snapshotName, tableName);
|
||||||
|
// verify snapshot
|
||||||
|
try (TableSnapshotScanner scanner =
|
||||||
|
new TableSnapshotScanner(conf, UTIL.getDataTestDirOnTestFS(snapshotName), snapshotName,
|
||||||
|
new Scan().withStartRow(bbb).withStopRow(yyy))) {
|
||||||
|
verifyScanner(scanner, bbb, yyy);
|
||||||
|
}
|
||||||
|
// drop table
|
||||||
|
admin.disableTable(tableName);
|
||||||
|
admin.deleteTable(tableName);
|
||||||
|
// verify snapshot
|
||||||
|
try (TableSnapshotScanner scanner =
|
||||||
|
new TableSnapshotScanner(conf, UTIL.getDataTestDirOnTestFS(snapshotName), snapshotName,
|
||||||
|
new Scan().withStartRow(bbb).withStopRow(yyy))) {
|
||||||
|
verifyScanner(scanner, bbb, yyy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void traverseAndSetFileTime(Path path, long time) throws IOException {
|
private void traverseAndSetFileTime(Path path, long time) throws IOException {
|
||||||
fs.setTimes(path, time, -1);
|
fs.setTimes(path, time, -1);
|
||||||
if (fs.isDirectory(path)) {
|
if (fs.isDirectory(path)) {
|
||||||
|
|
Loading…
Reference in New Issue