Skip to content

Commit

Permalink
[core] Rollback action write hint first (apache#4331)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzelin authored Oct 20, 2024
1 parent 8489a2d commit 87321e1
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ public void cleanLargerThan(Snapshot retainedSnapshot) {
}
tagDeletion.cleanUnusedManifests(snapshot, manifestsSkippingSet);
}

// modify the latest hint
try {
snapshotManager.commitLatestHint(retainedSnapshot.id());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private List<Snapshot> cleanSnapshotsDataFiles(Snapshot retainedSnapshot) {
Expand All @@ -114,6 +107,13 @@ private List<Snapshot> cleanSnapshotsDataFiles(Snapshot retainedSnapshot) {
long latest =
checkNotNull(snapshotManager.latestSnapshotId(), "Cannot find latest snapshot.");

// modify the latest hint
try {
snapshotManager.commitLatestHint(retainedSnapshot.id());
} catch (IOException e) {
throw new UncheckedIOException(e);
}

// delete snapshot files first, cannot be read now
// it is possible that some snapshots have been expired
List<Snapshot> toBeCleaned = new ArrayList<>();
Expand Down Expand Up @@ -149,24 +149,13 @@ private List<Changelog> cleanLongLivedChangelogDataFiles(Snapshot retainedSnapsh
return Collections.emptyList();
}

// delete changelog files first, cannot be read now
// it is possible that some snapshots have been expired
List<Changelog> toBeCleaned = new ArrayList<>();
long to = Math.max(earliest, retainedSnapshot.id() + 1);
for (long i = latest; i >= to; i--) {
toBeCleaned.add(snapshotManager.changelog(i));
fileIO.deleteQuietly(snapshotManager.longLivedChangelogPath(i));
}

// delete data files of changelog
for (Changelog changelog : toBeCleaned) {
// clean the deleted file
changelogDeletion.cleanUnusedDataFiles(changelog, manifestEntry -> false);
}

// delete directories
snapshotDeletion.cleanEmptyDirectories();

// modify the latest hint
try {
if (toBeCleaned.size() > 0) {
Expand All @@ -182,6 +171,17 @@ private List<Changelog> cleanLongLivedChangelogDataFiles(Snapshot retainedSnapsh
throw new UncheckedIOException(e);
}

// delete data files of changelog
for (Changelog changelog : toBeCleaned) {
// delete changelog files first, cannot be read now
fileIO.deleteQuietly(snapshotManager.longLivedChangelogPath(changelog.id()));
// clean the deleted file
changelogDeletion.cleanUnusedDataFiles(changelog, manifestEntry -> false);
}

// delete directories
snapshotDeletion.cleanEmptyDirectories();

return toBeCleaned;
}

Expand Down

0 comments on commit 87321e1

Please sign in to comment.