SaketaChalamchala commented on code in PR #10821:
URL: https://github.com/apache/ozone/pull/10821#discussion_r3623798589
##########
hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java:
##########
@@ -1161,6 +1162,46 @@ private synchronized void
removeKeyFromCompactionLogTable(
}
}
+ /**
+ * Removes SST files from the backup directory that were hard-linked during
+ * {@code onCompactionBegin} but never recorded in the compaction log because
+ * the compaction did not complete (for example, due to an OM crash/restart).
+ */
+ @VisibleForTesting
+ void cleanupOrphanedSstBackupFiles() {
+ Path sstBackupDirPath = Paths.get(sstBackupDir);
+ if (!Files.isDirectory(sstBackupDirPath)) {
+ return;
+ }
+
+ Set<String> referencedFiles = compactionDag.getCompactionMap().keySet();
+ Set<String> orphanedFiles = new HashSet<>();
+ try (Stream<Path> pathStream = Files.list(sstBackupDirPath)) {
+ pathStream.filter(path -> path.getFileName().toString().toLowerCase()
+ .endsWith(SST_FILE_EXTENSION))
+ .forEach(path -> {
+ String fileName =
FilenameUtils.getBaseName(path.getFileName().toString());
+ if (!referencedFiles.contains(fileName)) {
+ orphanedFiles.add(fileName);
+ }
+ });
+ } catch (IOException e) {
+ LOG.warn("Failed to list SST backup directory " + sstBackupDir, e);
+ }
+
+ if (orphanedFiles.isEmpty()) {
+ return;
+ }
+
+ LOG.info("Removing orphaned SST backup files left by incomplete
compactions: {}",
+ orphanedFiles);
+ try (UncheckedAutoCloseable ignored =
getBootstrapStateLock().acquireReadLock()) {
Review Comment:
Before the final request bootstrap copies all the files in SST backup
directory without checking the referenced files in `compactionLog`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]