Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Rollback action write hint first #4331

Merged
merged 1 commit into from
Oct 20, 2024
Merged
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 @@ -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
Loading