JingsongLi commented on code in PR #4565:
URL: https://github.com/apache/paimon/pull/4565#discussion_r1853475831


##########
paimon-core/src/main/java/org/apache/paimon/Snapshot.java:
##########
@@ -437,4 +413,41 @@ public enum CommitKind {
         /** Collect statistics. */
         ANALYZE
     }
+
+    // =================== Utils for reading =========================
+
+    public static Snapshot fromJson(String json) {
+        return JsonSerdeUtil.fromJson(json, Snapshot.class);
+    }
+
+    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);
+        }
+    }
+
+    public static Snapshot tryFromPath(FileIO fileIO, Path path) throws 
FileNotFoundException {
+        try {
+            Snapshot snapshot = SNAPSHOT_CACHE.getIfPresent(path);
+            if (snapshot == null) {
+                snapshot = Snapshot.fromJson(fileIO.readFileUtf8(path));
+                SNAPSHOT_CACHE.put(path, snapshot);
+            }
+            return snapshot;
+        } catch (FileNotFoundException e) {

Review Comment:
   There is no other IOException.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@paimon.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to