Skip to content

Commit 6c834b9

Browse files
virajjasaniapurtell
authored andcommitted
HBASE-22643 : Delete region without archiving only if regiondir is present
Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org> Signed-off-by: Xu Cang <xucang@apache.org>
1 parent 76c080b commit 6c834b9

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

hbase-server/src/main/java/org/apache/hadoop/hbase/backup/HFileArchiver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ public static boolean archiveRegion(FileSystem fs, Path rootdir, Path tableDir,
120120
if (tableDir == null || regionDir == null) {
121121
LOG.error("No archive directory could be found because tabledir (" + tableDir
122122
+ ") or regiondir (" + regionDir + "was null. Deleting files instead.");
123-
deleteRegionWithoutArchiving(fs, regionDir);
123+
if (regionDir != null) {
124+
deleteRegionWithoutArchiving(fs, regionDir);
125+
}
124126
// we should have archived, but failed to. Doesn't matter if we deleted
125127
// the archived files correctly or not.
126128
return false;

hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestHFileArchiving.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,50 @@ public void testCleaningRace() throws Exception {
517517
}
518518
}
519519

520+
@Test
521+
public void testArchiveRegionTableAndRegionDirsNull() throws IOException {
522+
Path rootDir = UTIL.getDataTestDirOnTestFS("testCleaningRace");
523+
FileSystem fileSystem = UTIL.getTestFileSystem();
524+
// Try to archive the file but with null regionDir, can't delete sourceFile
525+
assertFalse(HFileArchiver.archiveRegion(fileSystem, rootDir, null, null));
526+
}
527+
528+
@Test
529+
public void testArchiveRegionWithTableDirNull() throws IOException {
530+
Path regionDir = new Path(FSUtils.getTableDir(new Path("./"),
531+
TableName.valueOf(name.getMethodName())), "xyzabc");
532+
Path familyDir = new Path(regionDir, "rd");
533+
Path rootDir = UTIL.getDataTestDirOnTestFS("testCleaningRace");
534+
Path file = new Path(familyDir, "1");
535+
Path sourceFile = new Path(rootDir, file);
536+
FileSystem fileSystem = UTIL.getTestFileSystem();
537+
fileSystem.createNewFile(sourceFile);
538+
Path sourceRegionDir = new Path(rootDir, regionDir);
539+
fileSystem.mkdirs(sourceRegionDir);
540+
// Try to archive the file
541+
assertFalse(HFileArchiver.archiveRegion(fileSystem, rootDir, null, sourceRegionDir));
542+
assertFalse(fileSystem.exists(sourceRegionDir));
543+
}
544+
545+
@Test
546+
public void testArchiveRegionWithRegionDirNull() throws IOException {
547+
Path regionDir = new Path(FSUtils.getTableDir(new Path("./"),
548+
TableName.valueOf(name.getMethodName())), "elgn4nf");
549+
Path familyDir = new Path(regionDir, "rdar");
550+
Path rootDir = UTIL.getDataTestDirOnTestFS("testCleaningRace");
551+
Path file = new Path(familyDir, "2");
552+
Path sourceFile = new Path(rootDir, file);
553+
FileSystem fileSystem = UTIL.getTestFileSystem();
554+
fileSystem.createNewFile(sourceFile);
555+
Path sourceRegionDir = new Path(rootDir, regionDir);
556+
fileSystem.mkdirs(sourceRegionDir);
557+
// Try to archive the file but with null regionDir, can't delete sourceFile
558+
assertFalse(HFileArchiver.archiveRegion(fileSystem, rootDir, sourceRegionDir.getParent(),
559+
null));
560+
assertTrue(fileSystem.exists(sourceRegionDir));
561+
fileSystem.delete(sourceRegionDir, true);
562+
}
563+
520564
private void clearArchiveDirectory() throws IOException {
521565
UTIL.getTestFileSystem().delete(
522566
new Path(UTIL.getDefaultRootDirPath(), HConstants.HFILE_ARCHIVE_DIRECTORY), true);

0 commit comments

Comments
 (0)