Skip to content

Commit

Permalink
HBASE-22643 : Delete region without archiving only if regiondir is pr…
Browse files Browse the repository at this point in the history
…esent

Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
Signed-off-by: Xu Cang <xucang@apache.org>
  • Loading branch information
virajjasani authored and wchevreuil committed Jul 16, 2019
1 parent ae7ffcc commit cc38de1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public static boolean archiveRegion(FileSystem fs, Path rootdir, Path tableDir,
if (tableDir == null || regionDir == null) {
LOG.error("No archive directory could be found because tabledir (" + tableDir
+ ") or regiondir (" + regionDir + "was null. Deleting files instead.");
deleteRegionWithoutArchiving(fs, regionDir);
if (regionDir != null) {
deleteRegionWithoutArchiving(fs, regionDir);
}
// we should have archived, but failed to. Doesn't matter if we deleted
// the archived files correctly or not.
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,50 @@ public void testCleaningRace() throws Exception {
}
}

@Test
public void testArchiveRegionTableAndRegionDirsNull() throws IOException {
Path rootDir = UTIL.getDataTestDirOnTestFS("testCleaningRace");
FileSystem fileSystem = UTIL.getTestFileSystem();
// Try to archive the file but with null regionDir, can't delete sourceFile
assertFalse(HFileArchiver.archiveRegion(fileSystem, rootDir, null, null));
}

@Test
public void testArchiveRegionWithTableDirNull() throws IOException {
Path regionDir = new Path(FSUtils.getTableDir(new Path("./"),
TableName.valueOf(name.getMethodName())), "xyzabc");
Path familyDir = new Path(regionDir, "rd");
Path rootDir = UTIL.getDataTestDirOnTestFS("testCleaningRace");
Path file = new Path(familyDir, "1");
Path sourceFile = new Path(rootDir, file);
FileSystem fileSystem = UTIL.getTestFileSystem();
fileSystem.createNewFile(sourceFile);
Path sourceRegionDir = new Path(rootDir, regionDir);
fileSystem.mkdirs(sourceRegionDir);
// Try to archive the file
assertFalse(HFileArchiver.archiveRegion(fileSystem, rootDir, null, sourceRegionDir));
assertFalse(fileSystem.exists(sourceRegionDir));
}

@Test
public void testArchiveRegionWithRegionDirNull() throws IOException {
Path regionDir = new Path(FSUtils.getTableDir(new Path("./"),
TableName.valueOf(name.getMethodName())), "elgn4nf");
Path familyDir = new Path(regionDir, "rdar");
Path rootDir = UTIL.getDataTestDirOnTestFS("testCleaningRace");
Path file = new Path(familyDir, "2");
Path sourceFile = new Path(rootDir, file);
FileSystem fileSystem = UTIL.getTestFileSystem();
fileSystem.createNewFile(sourceFile);
Path sourceRegionDir = new Path(rootDir, regionDir);
fileSystem.mkdirs(sourceRegionDir);
// Try to archive the file but with null regionDir, can't delete sourceFile
assertFalse(HFileArchiver.archiveRegion(fileSystem, rootDir, sourceRegionDir.getParent(),
null));
assertTrue(fileSystem.exists(sourceRegionDir));
fileSystem.delete(sourceRegionDir, true);
}

// Avoid passing a null master to CleanerChore, see HBASE-21175
private HFileCleaner getHFileCleaner(Stoppable stoppable, Configuration conf,
FileSystem fs, Path archiveDir) throws IOException {
Expand Down

0 comments on commit cc38de1

Please sign in to comment.