You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "JingsongLi (via GitHub)" <gi...@apache.org> on 2024/11/21 07:10:01 UTC

[PR] [WIP][core] Add cache for snapshots and tags and schemas [paimon]

JingsongLi opened a new pull request, #4565:
URL: https://github.com/apache/paimon/pull/4565

   <!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
   
   ### Purpose
   
   <!-- Linking this pull request to the issue -->
   
   <!-- What is the purpose of the change -->
   
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   
   ### Documentation
   
   <!-- Does this change introduce a new feature -->
   


-- 
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-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Add cache for snapshots in CachingCatalog [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
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:
   `tryFromPath` is just for `FileNotFoundException`, invoker can know the file does not exists.



##########
paimon-core/src/main/java/org/apache/paimon/catalog/CachingCatalog.java:
##########
@@ -316,4 +319,36 @@ public void refreshPartitions(Identifier identifier) throws TableNotExistExcepti
             partitionCache.put(identifier, result);
         }
     }
+
+    // ====================== cache for snapshot and schema files ================================
+
+    public static final Cache<Path, Snapshot> SNAPSHOT_CACHE =
+            Caffeine.newBuilder()
+                    .softValues()
+                    .expireAfterAccess(Duration.ofMinutes(10))
+                    .maximumSize(300)
+                    .executor(Runnable::run)
+                    .build();
+
+    public static final Cache<Path, TableSchema> SCHEMA_CACHE =
+            Caffeine.newBuilder()
+                    .softValues()
+                    .expireAfterAccess(Duration.ofMinutes(10))
+                    .maximumSize(100)
+                    .executor(Runnable::run)
+                    .build();
+
+    public static void invalidateMetaCacheForPrefix(Path tablePath) {
+        String path = tablePath.toString();
+        invalidateMetaCacheForPrefix(SNAPSHOT_CACHE, path);
+        invalidateMetaCacheForPrefix(SCHEMA_CACHE, path);
+    }
+
+    private static void invalidateMetaCacheForPrefix(Cache<Path, ?> cache, String tablePath) {

Review Comment:
   deleted



-- 
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-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Add cache for snapshots and schemas [paimon]

Posted by "wwj6591812 (via GitHub)" <gi...@apache.org>.
wwj6591812 commented on code in PR #4565:
URL: https://github.com/apache/paimon/pull/4565#discussion_r1853175781


##########
paimon-core/src/main/java/org/apache/paimon/catalog/CachingCatalog.java:
##########
@@ -316,4 +319,36 @@ public void refreshPartitions(Identifier identifier) throws TableNotExistExcepti
             partitionCache.put(identifier, result);
         }
     }
+
+    // ====================== cache for snapshot and schema files ================================
+
+    public static final Cache<Path, Snapshot> SNAPSHOT_CACHE =
+            Caffeine.newBuilder()
+                    .softValues()
+                    .expireAfterAccess(Duration.ofMinutes(10))
+                    .maximumSize(300)
+                    .executor(Runnable::run)
+                    .build();
+
+    public static final Cache<Path, TableSchema> SCHEMA_CACHE =
+            Caffeine.newBuilder()
+                    .softValues()
+                    .expireAfterAccess(Duration.ofMinutes(10))
+                    .maximumSize(100)
+                    .executor(Runnable::run)
+                    .build();
+
+    public static void invalidateMetaCacheForPrefix(Path tablePath) {
+        String path = tablePath.toString();
+        invalidateMetaCacheForPrefix(SNAPSHOT_CACHE, path);
+        invalidateMetaCacheForPrefix(SCHEMA_CACHE, path);
+    }
+
+    private static void invalidateMetaCacheForPrefix(Cache<Path, ?> cache, String tablePath) {

Review Comment:
   May be invalidateMetaCacheByPrefix?



##########
paimon-core/src/main/java/org/apache/paimon/tag/Tag.java:
##########
@@ -201,4 +179,28 @@ public boolean equals(Object o) {
         return Objects.equals(tagCreateTime, that.tagCreateTime)
                 && Objects.equals(tagTimeRetained, that.tagTimeRetained);
     }
+
+    // =================== Utils for reading =========================
+
+    public static Tag fromJson(String json) {
+        return JsonSerdeUtil.fromJson(json, Tag.class);
+    }
+
+    public static Tag fromPath(FileIO fileIO, Path path) {
+        try {
+            return tryFromPath(fileIO, path);
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+    }
+
+    public static Tag tryFromPath(FileIO fileIO, Path path) throws FileNotFoundException {

Review Comment:
   Why not cache Tag and Changelog like Snapshot?



##########
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:
   May be we can only catch IOException? There's no need to catch FileNotFoundException and throw it direct?



##########
paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java:
##########
@@ -680,6 +681,9 @@ protected void dropTableImpl(Identifier identifier) {
                                     false,
                                     true));
 
+            Path path = getTableLocation(identifier);
+            invalidateMetaCacheForPrefix(path);

Review Comment:
   May invalidateMetaCacheForPrefix(path) can execute in AbstractCatalog#dropTable after dropTableImpl(identifier)?
   Because If a new Catalog @Override AbstractCatalog#dropTableImpl, it may forget to call invalidateMetaCacheForPrefix(path).
   



##########
paimon-core/src/main/java/org/apache/paimon/utils/MetaCacheManager.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.utils;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.schema.TableSchema;
+import org.apache.paimon.tag.Tag;
+
+/** Cache for {@link Snapshot} and {@link Tag} and {@link TableSchema}. */

Review Comment:
   Is this class reserved for future use?



-- 
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-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Add cache for snapshots in CachingCatalog [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4565:
URL: https://github.com/apache/paimon/pull/4565#discussion_r1853479938


##########
paimon-core/src/main/java/org/apache/paimon/tag/Tag.java:
##########
@@ -201,4 +179,28 @@ public boolean equals(Object o) {
         return Objects.equals(tagCreateTime, that.tagCreateTime)
                 && Objects.equals(tagTimeRetained, that.tagTimeRetained);
     }
+
+    // =================== Utils for reading =========================
+
+    public static Tag fromJson(String json) {
+        return JsonSerdeUtil.fromJson(json, Tag.class);
+    }
+
+    public static Tag fromPath(FileIO fileIO, Path path) {
+        try {
+            return tryFromPath(fileIO, path);
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+    }
+
+    public static Tag tryFromPath(FileIO fileIO, Path path) throws FileNotFoundException {

Review Comment:
   Tag is mutable, it is danger.



-- 
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-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Add cache for snapshots in CachingCatalog [paimon]

Posted by "ranxianglei (via GitHub)" <gi...@apache.org>.
ranxianglei commented on PR #4565:
URL: https://github.com/apache/paimon/pull/4565#issuecomment-2514250778

   mark!


-- 
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-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Add cache for snapshots in CachingCatalog [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #4565:
URL: https://github.com/apache/paimon/pull/4565


-- 
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-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Add cache for snapshots in CachingCatalog [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4565:
URL: https://github.com/apache/paimon/pull/4565#discussion_r1853478567


##########
paimon-core/src/main/java/org/apache/paimon/utils/MetaCacheManager.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.utils;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.schema.TableSchema;
+import org.apache.paimon.tag.Tag;
+
+/** Cache for {@link Snapshot} and {@link Tag} and {@link TableSchema}. */

Review Comment:
   deleted



##########
paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java:
##########
@@ -680,6 +681,9 @@ protected void dropTableImpl(Identifier identifier) {
                                     false,
                                     true));
 
+            Path path = getTableLocation(identifier);
+            invalidateMetaCacheForPrefix(path);

Review Comment:
   deleted



-- 
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-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Add cache for snapshots in CachingCatalog [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
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-unsubscribe@paimon.apache.org

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