Skip to content

Commit

Permalink
HBASE-28427 FNFE related to 'master:store' when moving archived hfile…
Browse files Browse the repository at this point in the history
…s to global archived dir (#5756)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
(cherry picked from commit 0c1224c)
  • Loading branch information
guluo2016 authored and Apache9 committed Mar 18, 2024
1 parent 69fd2c9 commit 75d7ae9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4642,6 +4642,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;
Expand Down

0 comments on commit 75d7ae9

Please sign in to comment.