Skip to content

Commit 985b733

Browse files
authored
[core] Add retry for reading snapshot when encountering MismatchedInputException (#6678)
1 parent 4e04f3c commit 985b733

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.paimon.table.Instant;
2525

2626
import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Cache;
27+
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.exc.MismatchedInputException;
2728

2829
import org.slf4j.Logger;
2930
import org.slf4j.LoggerFactory;
@@ -770,12 +771,26 @@ public static Snapshot fromPath(FileIO fileIO, Path path) {
770771
}
771772

772773
public static Snapshot tryFromPath(FileIO fileIO, Path path) throws FileNotFoundException {
773-
try {
774-
return Snapshot.fromJson(fileIO.readFileUtf8(path));
775-
} catch (FileNotFoundException e) {
776-
throw e;
777-
} catch (IOException e) {
778-
throw new RuntimeException("Fails to read snapshot from path " + path, e);
774+
int retryNumber = 0;
775+
MismatchedInputException exception = null;
776+
while (retryNumber++ < 10) {
777+
try {
778+
return Snapshot.fromJson(fileIO.readFileUtf8(path));
779+
} catch (MismatchedInputException e) {
780+
// retry
781+
exception = e;
782+
try {
783+
Thread.sleep(1_000);
784+
} catch (InterruptedException ie) {
785+
Thread.currentThread().interrupt();
786+
throw new RuntimeException(ie);
787+
}
788+
} catch (FileNotFoundException e) {
789+
throw e;
790+
} catch (IOException e) {
791+
throw new RuntimeException("Fails to read snapshot from path " + path, e);
792+
}
779793
}
794+
throw new UncheckedIOException(exception);
780795
}
781796
}

0 commit comments

Comments
 (0)