From 55d0395d2277c23df40711a97d565f5729b6cccf Mon Sep 17 00:00:00 2001 From: "jiangqiao.xu" Date: Fri, 20 Dec 2024 14:46:57 +0800 Subject: [PATCH] [flink] Bugfix expire snapshot don't work when some snapshot between earliest and latest are removed for some reason --- .../java/org/apache/paimon/table/ExpireSnapshotsImpl.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/table/ExpireSnapshotsImpl.java b/paimon-core/src/main/java/org/apache/paimon/table/ExpireSnapshotsImpl.java index dc1c2d6bdbc5..ba95bde5fc09 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/ExpireSnapshotsImpl.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/ExpireSnapshotsImpl.java @@ -115,7 +115,12 @@ public int expire() { // protected by 'snapshot.expire.limit' // (the maximum number of snapshots allowed to expire at a time) - maxExclusive = Math.min(maxExclusive, earliest + maxDeletes); + long maxExclusiveByExpireLimit = earliest + maxDeletes; + while (!snapshotManager.snapshotExists(maxExclusiveByExpireLimit)) { + // Ensure maxExclusive exist, deal some snapshot between earliest and latest is deleted + maxExclusiveByExpireLimit++; + } + maxExclusive = Math.min(maxExclusive, maxExclusiveByExpireLimit); for (long id = min; id < maxExclusive; id++) { // Early exit the loop for 'snapshot.time-retained'