This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new a9395f1ae6 [core] Use latestSnapshotIdFromFileSystem in 
NextSnapshotFetcher
a9395f1ae6 is described below

commit a9395f1ae6746d55202531e8f900911d1427a6af
Author: JingsongLi <jingsongl...@gmail.com>
AuthorDate: Tue Jul 22 17:12:39 2025 +0800

    [core] Use latestSnapshotIdFromFileSystem in NextSnapshotFetcher
---
 .../org/apache/paimon/utils/NextSnapshotFetcher.java   | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git 
a/paimon-core/src/main/java/org/apache/paimon/utils/NextSnapshotFetcher.java 
b/paimon-core/src/main/java/org/apache/paimon/utils/NextSnapshotFetcher.java
index 772942e4a4..addc24707d 100644
--- a/paimon-core/src/main/java/org/apache/paimon/utils/NextSnapshotFetcher.java
+++ b/paimon-core/src/main/java/org/apache/paimon/utils/NextSnapshotFetcher.java
@@ -26,8 +26,6 @@ import org.slf4j.LoggerFactory;
 
 import javax.annotation.Nullable;
 
-import java.io.FileNotFoundException;
-
 /** Fetcher for getting the next snapshot by snapshot id. */
 public class NextSnapshotFetcher {
 
@@ -48,27 +46,21 @@ public class NextSnapshotFetcher {
 
     @Nullable
     public Snapshot getNextSnapshot(long nextSnapshotId) {
-        Snapshot latest = snapshotManager.latestSnapshot();
-
-        if (latest != null && latest.id() == nextSnapshotId) {
-            return latest;
-        }
-
-        try {
-            return snapshotManager.tryGetSnapshot(nextSnapshotId);
-        } catch (FileNotFoundException ignored) {
+        if (snapshotManager.snapshotExists(nextSnapshotId)) {
+            return snapshotManager.snapshot(nextSnapshotId);
         }
 
         Long earliestSnapshotId = snapshotManager.earliestSnapshotId();
+        Long latestSnapshotId = 
snapshotManager.latestSnapshotIdFromFileSystem();
         // No snapshot now
         if (earliestSnapshotId == null || earliestSnapshotId <= 
nextSnapshotId) {
             if ((earliestSnapshotId == null && nextSnapshotId > 1)
-                    || (latest != null && nextSnapshotId > latest.id() + 1)) {
+                    || (latestSnapshotId != null && nextSnapshotId > 
latestSnapshotId + 1)) {
                 throw new OutOfRangeException(
                         String.format(
                                 "The next expected snapshot is too big! Most 
possible cause might be the table had been recreated."
                                         + "The next snapshot id is %d, while 
the latest snapshot id is %s",
-                                nextSnapshotId, latest == null ? "none" : 
latest.id()));
+                                nextSnapshotId, latestSnapshotId));
             }
 
             LOG.debug(

Reply via email to