From 28f291c90a7d9b81e6ec7311c4e98505e1979758 Mon Sep 17 00:00:00 2001 From: yuzelin Date: Wed, 16 Oct 2024 16:19:12 +0800 Subject: [PATCH] [core] Rollback action write hint first --- .../apache/paimon/table/RollbackHelper.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/table/RollbackHelper.java b/paimon-core/src/main/java/org/apache/paimon/table/RollbackHelper.java index 374d71e9e2aa..1eb4ccf00136 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/RollbackHelper.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/RollbackHelper.java @@ -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 cleanSnapshotsDataFiles(Snapshot retainedSnapshot) { @@ -114,6 +107,13 @@ private List 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 toBeCleaned = new ArrayList<>(); @@ -149,24 +149,13 @@ private List cleanLongLivedChangelogDataFiles(Snapshot retainedSnapsh return Collections.emptyList(); } - // delete changelog files first, cannot be read now // it is possible that some snapshots have been expired List 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) { @@ -182,6 +171,17 @@ private List 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; }