SaketaChalamchala commented on code in PR #10821:
URL: https://github.com/apache/ozone/pull/10821#discussion_r3761023010
##########
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:
The intention if the read lock is to not block an overlapping OM
bootstrap(which acquires an exclusive lock to collect the files to be
transferred). Orphan Cleanup does not require an exclusive lock because no
other background service (except file pruners) would need to access these files.
Read lock here is a cheap way to future proof against future callers that
may overlap and to be code consistent.
--
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]