HDDS-13173. Clean up temporary checkpoint directories on snapshot defrag failure - #10774
HDDS-13173. Clean up temporary checkpoint directories on snapshot defrag failure#10774cchung100m wants to merge 13 commits into
Conversation
|
Thanks @cchung100m for working on this.
|
c263151 to
d220c6e
Compare
|
Hi @adoroszlai Sorry for the late reply and the incomplete PR before. I think the |
Thanks for the explanation, makes sense. |
smengcl
left a comment
There was a problem hiding this comment.
Thanks for the patch. I have a few comments inline
| OmMetadataManagerImpl checkpointMetadataManager = createCheckpoint(checkpointSnapshotInfo, | ||
| COLUMN_FAMILIES_TO_TRACK_IN_SNAPSHOT); | ||
| Path checkpointLocation = checkpointMetadataManager.getStore().getDbLocation().toPath(); | ||
| boolean defragSuccessful = false; |
There was a problem hiding this comment.
Could we also cover failures inside createCheckpoint()? It creates the checkpoint directory before opening, truncating, and reopening it, but this try/finally is entered only after createCheckpoint() returns. An exception during those steps still leaves a checkpoint directory under tmp_defrag, so repeated failures can reproduce the accumulation this patch is intended to fix. Please clean up once the DBCheckpoint exists and add failure coverage for this path.
…ne/om/snapshot/defrag/SnapshotDefragService.java Co-authored-by: SaketaChalamchala <saketa.chalamchala@gmail.com>
|
Hi @smengcl Thanks for detail suggestion. I had updated the part you mentioned. |
| DBCheckpoint checkpoint = snapshot.get().getMetadataManager().getStore().getCheckpoint(tmpDefragDir, true); | ||
| try (OmMetadataManagerImpl metadataManagerBeforeTruncate = | ||
| createDefragCheckpointMetadataManager(checkpoint, false)) { | ||
| DBStore dbStore = metadataManagerBeforeTruncate.getStore(); | ||
| for (String table : metadataManagerBeforeTruncate.listTableNames()) { | ||
| if (!incrementalColumnFamilies.contains(table)) { | ||
| dbStore.dropTable(table); | ||
| Path checkpointLocation = checkpoint.getCheckpointLocation(); |
There was a problem hiding this comment.
getCheckpoint() can return null after it catches an IOException. This line then throws NPE. The new cleanup block does not run, and triggerSnapshotDefragOnce() does not catch this exception. Pls report this failure as an IOException, delete any partial checkpoint directory, and add a test for this path.
| when(checkpointMetadataManager.getStore()).thenReturn(checkpointDBStore); | ||
| when(checkpointDBStore.getDbLocation()).thenReturn(checkpointPath); | ||
| doNothing().when(checkpointMetadataManager).close(); | ||
| doReturn(checkpointMetadataManager).when(spyDefragService).createCheckpoint(any(), any()); |
There was a problem hiding this comment.
The tests do not cover the two new recovery paths. testCheckpointCleanupOnDefragFailure() stubs createCheckpoint(), so it does not run the new cleanup in that method. testCheckAndDefragAlreadyDefraggedSnapshot() returns version 0, so it does not run the deletion retry. Please add a test for a failure after checkpoint creation and one test that verifies deletion is retried for an already defragmented snapshot.
smengcl
left a comment
There was a problem hiding this comment.
Thanks @cchung100m for the patch.
There was a problem hiding this comment.
Pull request overview
This PR hardens Ozone Manager’s snapshot defragmentation flow to ensure temporary RocksDB checkpoint directories are cleaned up on failures, preventing long-running clusters from accumulating orphaned checkpoint directories and exhausting disk space.
Changes:
- Add failure-safe checkpoint creation and partial-checkpoint cleanup when
DBStore#getCheckpoint(...)returnsnull. - Ensure
checkAndDefragSnapshot(...)cleans up the checkpoint directory in afinallyblock when defrag does not complete successfully, and guardsclose()/old-checkpoint deletion to avoid bypassing cleanup. - Add a parameterized test validating checkpoint directory cleanup on both full and incremental defrag failures.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/defrag/SnapshotDefragService.java | Adds multi-layer exception handling and cleanup logic for failed/partial checkpoints during snapshot defrag. |
| hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/defrag/TestSnapshotDefragService.java | Adds a new test verifying temporary checkpoint directories are deleted when defrag fails. |
Suppressed comments (1)
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/defrag/SnapshotDefragService.java:807
- PR description says cleanup failures are tracked via
incNumSnapshotDefragFails(), but this cleanup failure path only logs. If the intent is to surface orphaned-checkpoint cleanup failures via metrics, increment the counter here too (or adjust the PR description).
} catch (IOException cleanupException) {
LOG.error("Failed to delete checkpoint directory {} for snapshot: {} (ID: {}). " +
"Disk space may not be freed. Manual cleanup may be required.",
checkpointLocation, snapshotInfo.getTableKey(), snapshotInfo.getSnapshotId(), cleanupException);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Copilot comments look legit. Pls address them as well. |
Replace the Javadoc reference from `RDB_CHECKPOINT_PREFIX` to `RDB_CHECKPOINT_DIR_PREFIX` Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
What changes were proposed in this pull request?
Root Cause: When snapshot defragmentation fails due to transient errors, the temporary checkpoint directories are not cleaned up. Over 3+ days of continuous operations, these orphaned directories accumulate and exhaust disk space, causing OM startup failures.
Solution: Implement multi-layer exception handling with an explicit
defragSuccessfulflag.defragSuccessful: Initialize to false, set to true only afteratomicSwitchSnampshotDB()succeeds.!defragSuccessfulincNumSnapshotDefragFails()What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-13173
How was this patch tested?
testCheckpointCleanupOnDefragFailureto validate the exception handling