Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import com.google.common.annotations.VisibleForTesting;
import jakarta.annotation.Nonnull;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -125,11 +127,14 @@ private void deleteCheckpointDirectory(OMMetadataManager omMetadataManager,
boolean acquiredSnapshotLock = omLockDetails.isLockAcquired();
if (acquiredSnapshotLock) {
Path snapshotDirPath = OmSnapshotManager.getSnapshotPath(omMetadataManager, snapshotInfo);
Path snapshotLocalDataPath = Paths.get(
OmSnapshotManager.getSnapshotLocalPropertyYamlPath(omMetadataManager, snapshotInfo));
try {
FileUtils.deleteDirectory(snapshotDirPath.toFile());
Files.deleteIfExists(snapshotLocalDataPath);
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The YAML file deletion should be included in the same try-catch block as the directory deletion to ensure consistent error handling and logging for both operations.

Copilot uses AI. Check for mistakes.
} catch (IOException ex) {
LOG.error("Failed to delete snapshot directory {} for snapshot {}",
snapshotDirPath, snapshotInfo.getTableKey(), ex);
LOG.error("Failed to delete snapshot directory {} and/or local data file {} for snapshot {}",
snapshotDirPath, snapshotLocalDataPath, snapshotInfo.getTableKey(), ex);
} finally {
omMetadataManager.getLock().releaseWriteLock(SNAPSHOT_DB_LOCK, snapshotInfo.getSnapshotId().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -46,6 +47,7 @@
import org.apache.hadoop.hdds.utils.db.CodecException;
import org.apache.hadoop.hdds.utils.db.Table;
import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
import org.apache.hadoop.ozone.om.OmSnapshotManager;
import org.apache.hadoop.ozone.om.SnapshotChainManager;
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.ozone.om.request.OMRequestTestUtils;
Expand Down Expand Up @@ -157,6 +159,14 @@ public void testValidateAndUpdateCache() throws Exception {

List<String> snapshotDbKeysToPurge = createSnapshots(10);
assertFalse(getOmMetadataManager().getSnapshotInfoTable().isEmpty());

// Check if all the checkpoints are created.
for (Path checkpoint : checkpointPaths) {
assertTrue(Files.exists(checkpoint));
assertTrue(Files.exists(Paths.get(
OmSnapshotManager.getSnapshotLocalPropertyYamlPath(checkpoint))));
}

OMRequest snapshotPurgeRequest = createPurgeKeysRequest(
snapshotDbKeysToPurge);

Expand All @@ -180,6 +190,8 @@ public void testValidateAndUpdateCache() throws Exception {
// Check if all the checkpoints are cleared.
for (Path checkpoint : checkpointPaths) {
assertFalse(Files.exists(checkpoint));
assertFalse(Files.exists(Paths.get(
OmSnapshotManager.getSnapshotLocalPropertyYamlPath(checkpoint))));
}
assertEquals(initialSnapshotPurgeCount + 1, getOmSnapshotIntMetrics().getNumSnapshotPurges());
assertEquals(initialSnapshotPurgeFailCount, getOmSnapshotIntMetrics().getNumSnapshotPurgeFails());
Expand Down