Copilot commented on code in PR #12240:
URL: https://github.com/apache/ozone/pull/12240#discussion_r4792335510


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/defrag/SnapshotDefragService.java:
##########
@@ -711,9 +711,18 @@ boolean checkAndDefragSnapshot(SnapshotChainManager 
chainManager, UUID snapshotI
     }
     LOG.info("Defragmenting snapshot: {} (ID: {})", 
snapshotInfo.getTableKey(), snapshotInfo.getSnapshotId());
     long start = Time.monotonicNow();
-    // Create a checkpoint of the previous snapshot or the current snapshot if 
it is the first snapshot in the chain.
-    SnapshotInfo checkpointSnapshotInfo = 
snapshotInfo.getPathPreviousSnapshotId() == null ? snapshotInfo :
-        SnapshotUtils.getSnapshotInfo(ozoneManager, chainManager, 
snapshotInfo.getPathPreviousSnapshotId());
+    // Use the nearest active path-previous snapshot. pathPreviousSnapshotId 
can still reference a deleted
+    // snapshot until purge rewrites the chain.
+    SnapshotInfo activePathPreviousSnapshot =
+        SnapshotUtils.getActivePathPreviousSnapshot(ozoneManager, 
chainManager, snapshotInfo);

Review Comment:
   The `previousSnapshotExists=true` cases in 
`TestSnapshotDefragService.testCheckAndDefragActiveSnapshot`, 
`testCheckAndDefragSnapshotFailure`, and `testCheckpointCleanupOnDefragFailure` 
now fail because their `SnapshotUtils` static mocks leave this helper 
unstubbed, so it returns `null`. That selects the current snapshot as the 
checkpoint base and full defrag instead of the configured incremental behavior. 
Stub `getActivePathPreviousSnapshot(ozoneManager, chainManager, snapshotInfo)` 
to return `previousSnapshotInfo` in each test, or selectively call its real 
implementation.



-- 
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]

Reply via email to