diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/region/MasterRegionFlusherAndCompactor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/region/MasterRegionFlusherAndCompactor.java index 3d4bfea146e5..c06420ea9920 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/region/MasterRegionFlusherAndCompactor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/region/MasterRegionFlusherAndCompactor.java @@ -142,8 +142,15 @@ private void moveHFileToGlobalArchiveDir() throws IOException { Path globalStoreArchiveDir = HFileArchiveUtil.getStoreArchivePathForArchivePath( globalArchivePath, region.getRegionInfo(), store.getColumnFamilyDescriptor().getName()); try { - MasterRegionUtils.moveFilesUnderDir(fs, storeArchiveDir, globalStoreArchiveDir, - archivedHFileSuffix); + if (fs.exists(storeArchiveDir)) { + MasterRegionUtils.moveFilesUnderDir(fs, storeArchiveDir, globalStoreArchiveDir, + archivedHFileSuffix); + } else { + LOG.warn( + "Archived dir {} does not exist, there is no need to move archived hfiles from {} " + + "to global dir {} .", + storeArchiveDir, storeArchiveDir, globalStoreArchiveDir); + } } catch (IOException e) { LOG.warn("Failed to move archived hfiles from {} to global dir {}", storeArchiveDir, globalStoreArchiveDir, e); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java index d244ca767be2..3d38e6589997 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java @@ -4648,6 +4648,39 @@ public void testWritesWhileScanning() throws IOException, InterruptedException { } } + @Test + public void testCloseAndArchiveCompactedFiles() throws IOException { + byte[] CF1 = Bytes.toBytes("CF1"); + byte[] CF2 = Bytes.toBytes("CF2"); + this.region = initHRegion(tableName, method, CONF, CF1, CF2); + for (int i = 0; i < 2; i++) { + int index = i; + Put put = + new Put(Bytes.toBytes(index)).addColumn(CF1, Bytes.toBytes("q"), Bytes.toBytes(index)); + region.put(put); + region.flush(true); + } + + region.compact(true); + + HStore store1 = region.getStore(CF1); + HStore store2 = region.getStore(CF2); + store1.closeAndArchiveCompactedFiles(); + store2.closeAndArchiveCompactedFiles(); + + int storefilesCount = region.getStores().stream().mapToInt(Store::getStorefilesCount).sum(); + assertTrue(storefilesCount == 1); + + FileSystem fs = region.getRegionFileSystem().getFileSystem(); + Configuration conf = region.getReadOnlyConfiguration(); + RegionInfo regionInfo = region.getRegionInfo(); + Path store1ArchiveDir = HFileArchiveUtil.getStoreArchivePath(conf, regionInfo, CF1); + assertTrue(fs.exists(store1ArchiveDir)); + // The archived dir of CF2 does not exist because this column family has no data at all + Path store2ArchiveDir = HFileArchiveUtil.getStoreArchivePath(conf, regionInfo, CF2); + assertFalse(fs.exists(store2ArchiveDir)); + } + protected class PutThread extends Thread { private volatile boolean done; private volatile int numPutsFinished = 0;