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

JingsongLi 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 6753043d7c [core] Retry missing snapshot files in fromPath (#11276)
6753043d7c is described below

commit 6753043d7c9572aa2eada4c88d1d12ca549e0ff9
Author: umi <[email protected]>
AuthorDate: Fri Nov 20 12:18:47 2026 +0800

    [core] Retry missing snapshot files in fromPath (#11276)
---
 .../org/apache/paimon/utils/SnapshotManager.java   | 37 ++++++++----
 .../apache/paimon/utils/SnapshotManagerTest.java   | 70 ++++++++++++++++++++++
 2 files changed, 95 insertions(+), 12 deletions(-)

diff --git 
a/paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java 
b/paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java
index 8693d11dac..1e2485121d 100644
--- a/paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java
+++ b/paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java
@@ -844,18 +844,31 @@ public class SnapshotManager implements Serializable {
     }
 
     public static Snapshot fromPath(FileIO fileIO, Path path) {
-        try {
-            return tryFromPath(fileIO, path);
-        } catch (FileNotFoundException e) {
-            String errorMessage =
-                    String.format(
-                            "Snapshot file %s does not exist. "
-                                    + "It might have been expired by other 
jobs operating on this table. "
-                                    + "In this case, you can avoid concurrent 
modification issues by configuring "
-                                    + "write-only = true and use a dedicated 
compaction job, or configuring "
-                                    + "different expiration thresholds for 
different jobs.",
-                            path);
-            throw new RuntimeException(errorMessage, e);
+        int retryNumber = 0;
+        while (true) {
+            try {
+                return tryFromPath(fileIO, path);
+            } catch (FileNotFoundException e) {
+                if (++retryNumber < SNAPSHOT_EXISTS_MAX_ATTEMPTS) {
+                    // Catalog metadata may become visible before the snapshot 
file is published.
+                    try {
+                        Thread.sleep(300);
+                    } catch (InterruptedException ie) {
+                        Thread.currentThread().interrupt();
+                        throw new RuntimeException(ie);
+                    }
+                    continue;
+                }
+                String errorMessage =
+                        String.format(
+                                "Snapshot file %s does not exist. "
+                                        + "It might have been expired by other 
jobs operating on this table. "
+                                        + "In this case, you can avoid 
concurrent modification issues by configuring "
+                                        + "write-only = true and use a 
dedicated compaction job, or configuring "
+                                        + "different expiration thresholds for 
different jobs.",
+                                path);
+                throw new RuntimeException(errorMessage, e);
+            }
         }
     }
 
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/utils/SnapshotManagerTest.java 
b/paimon-core/src/test/java/org/apache/paimon/utils/SnapshotManagerTest.java
index 99484eb5f4..39dfc869eb 100644
--- a/paimon-core/src/test/java/org/apache/paimon/utils/SnapshotManagerTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/utils/SnapshotManagerTest.java
@@ -73,6 +73,75 @@ public class SnapshotManagerTest {
                 .hasMessageContaining("Retry fail after 10 times");
     }
 
+    @Test
+    public void testFromPathRetriesMissingAndIncompleteFile() throws 
IOException {
+        FileIO fileIO = Mockito.mock(FileIO.class);
+        Path path = new Path(tempDir.toString(), "snapshot-1");
+        Snapshot snapshot = createSnapshotWithMillis(1, 1000);
+        Mockito.when(fileIO.readFileUtf8(path))
+                .thenThrow(new FileNotFoundException(path.toString()))
+                .thenReturn("", snapshot.toJson());
+
+        assertThat(SnapshotManager.fromPath(fileIO, path)).isEqualTo(snapshot);
+        Mockito.verify(fileIO, Mockito.times(3)).readFileUtf8(path);
+    }
+
+    @Test
+    public void testFromPathFailsWhenFileNotFoundAfterRetries() throws 
IOException {
+        FileIO fileIO = Mockito.mock(FileIO.class);
+        Path path = new Path(tempDir.toString(), "snapshot-1");
+        FileNotFoundException failure = new 
FileNotFoundException(path.toString());
+        Mockito.when(fileIO.readFileUtf8(path)).thenThrow(failure);
+
+        assertThatThrownBy(() -> SnapshotManager.fromPath(fileIO, path))
+                .isInstanceOf(RuntimeException.class)
+                .hasMessageContaining("Snapshot file " + path + " does not 
exist.")
+                .hasCause(failure);
+        Mockito.verify(fileIO, Mockito.times(3)).readFileUtf8(path);
+    }
+
+    @Test
+    public void testTryFromPathDoesNotRetryMissingFile() throws IOException {
+        FileIO fileIO = Mockito.mock(FileIO.class);
+        Path path = new Path(tempDir.toString(), "snapshot-1");
+        FileNotFoundException failure = new 
FileNotFoundException(path.toString());
+        Mockito.when(fileIO.readFileUtf8(path)).thenThrow(failure);
+
+        assertThatThrownBy(() -> SnapshotManager.tryFromPath(fileIO, 
path)).isSameAs(failure);
+        Mockito.verify(fileIO).readFileUtf8(path);
+    }
+
+    @Test
+    public void testFromPathDoesNotRetryOtherIOException() throws IOException {
+        FileIO fileIO = Mockito.mock(FileIO.class);
+        Path path = new Path(tempDir.toString(), "snapshot-1");
+        IOException failure = new IOException("Read failure");
+        Mockito.when(fileIO.readFileUtf8(path)).thenThrow(failure);
+
+        assertThatThrownBy(() -> SnapshotManager.fromPath(fileIO, path))
+                .hasMessageContaining("Fails to read snapshot from path " + 
path)
+                .hasCause(failure);
+        Mockito.verify(fileIO).readFileUtf8(path);
+    }
+
+    @Test
+    public void testFromPathRestoresInterruptedStatus() throws IOException {
+        FileIO fileIO = Mockito.mock(FileIO.class);
+        Path path = new Path(tempDir.toString(), "snapshot-1");
+        Mockito.when(fileIO.readFileUtf8(path))
+                .thenThrow(new FileNotFoundException(path.toString()));
+
+        Thread.currentThread().interrupt();
+        try {
+            assertThatThrownBy(() -> SnapshotManager.fromPath(fileIO, path))
+                    .hasCauseInstanceOf(InterruptedException.class);
+            assertThat(Thread.currentThread().isInterrupted()).isTrue();
+            Mockito.verify(fileIO).readFileUtf8(path);
+        } finally {
+            Thread.interrupted();
+        }
+    }
+
     @Test
     public void testSnapshotPath() {
         SnapshotManager snapshotManager =
@@ -93,6 +162,7 @@ public class SnapshotManagerTest {
 
         
assertThat(snapshotManager.snapshotsWithId(Collections.singletonList(1L)).hasNext())
                 .isFalse();
+        Mockito.verify(fileIO).readFileUtf8(snapshotManager.snapshotPath(1L));
     }
 
     @Test

Reply via email to