You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "wg1026688210 (via GitHub)" <gi...@apache.org> on 2024/03/03 06:32:45 UTC
[PR] [Core]add cache for SchemaManager [incubator-paimon]
wg1026688210 opened a new pull request, #2939:
URL: https://github.com/apache/incubator-paimon/pull/2939
<!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
### Purpose
RecordReader loads the schema of the split from the FileSystem when reads a split .
The pr is for adding the cache of TableSchema for SchemaManager to reduce the access of FileSystem.
<!-- Linking this pull request to the issue -->
<!-- What is the purpose of the change -->
### Tests
SchemaManagerTest#testCache
<!-- 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 table schema cache for SchemaManager [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #2939:
URL: https://github.com/apache/incubator-paimon/pull/2939#discussion_r1519166980
##########
paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java:
##########
@@ -97,6 +100,7 @@ protected AbstractFileStoreTable(
}
this.tableSchema = tableSchema;
this.catalogEnvironment = catalogEnvironment;
+ tableSchemaManager = new SchemaManager(fileIO, path, new ConcurrentHashMap<>());
Review Comment:
Just use `public SchemaManager(FileIO fileIO, Path tableRoot)`
--
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 table schema cache for SchemaManager [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #2939:
URL: https://github.com/apache/incubator-paimon/pull/2939#issuecomment-2003101245
At present, this solution is relatively obscure. Generally speaking, it is difficult to accept a solution where the cache is serialized and reused by distributed tasks.
Considering that https://github.com/apache/incubator-paimon/pull/3021 has already been merged and can solve most problems in most cases (without schema changes), I am considering closing this PR.
You can reopen this PR at any time if you have any further needs.
--
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 SchemaManager [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #2939:
URL: https://github.com/apache/incubator-paimon/pull/2939#discussion_r1514221161
##########
paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java:
##########
@@ -82,6 +85,8 @@ abstract class AbstractFileStoreTable implements FileStoreTable {
protected final TableSchema tableSchema;
protected final CatalogEnvironment catalogEnvironment;
+ protected final Map<Long, TableSchema> schemaCache;
Review Comment:
or just store `SchemaManager` here?
--
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 table schema cache for SchemaManager [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #2939:
URL: https://github.com/apache/incubator-paimon/pull/2939#issuecomment-1999202777
See https://github.com/apache/incubator-paimon/pull/3021
--
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 SchemaManager [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #2939:
URL: https://github.com/apache/incubator-paimon/pull/2939#discussion_r1510254435
##########
paimon-core/src/main/java/org/apache/paimon/schema/SchemaCache.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.schema;
+
+import org.apache.paimon.annotation.VisibleForTesting;
+
+import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Cache;
+import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Caffeine;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+
+/**
+ * The class is responsible for providing a schemaManager with a concurrent and serializable schema
+ * cache.
+ */
+public class SchemaCache implements Serializable {
Review Comment:
You don't need to introduce this class, just merge this into `SchemaManager`.
--
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 SchemaManager [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #2939:
URL: https://github.com/apache/incubator-paimon/pull/2939#discussion_r1510254604
##########
paimon-core/src/main/java/org/apache/paimon/schema/SchemaCache.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.schema;
+
+import org.apache.paimon.annotation.VisibleForTesting;
+
+import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Cache;
+import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Caffeine;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+
+/**
+ * The class is responsible for providing a schemaManager with a concurrent and serializable schema
+ * cache.
+ */
+public class SchemaCache implements Serializable {
+ private transient Cache<Long, TableSchema> cache;
+
+ public SchemaCache() {
+ buildCache();
+ }
+
+ private void buildCache() {
+ this.cache = Caffeine.newBuilder().maximumSize(10).build();
+ }
+
+ public TableSchema getSchema(Long id, Function<Long, TableSchema> schemaLoader) {
+ return cache.get(id, schemaLoader);
+ }
+
+ public void deleteSchema(Long id) {
+ cache.invalidate(id);
+ }
+
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ Map<Long, TableSchema> map = new HashMap<>(cache.asMap());
Review Comment:
I think we don't need serialize this cache.
--
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 table schema cache for SchemaManager [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #2939:
URL: https://github.com/apache/incubator-paimon/pull/2939#discussion_r1519167258
##########
paimon-core/src/test/java/org/apache/paimon/schema/SchemaManagerTest.java:
##########
@@ -94,6 +95,27 @@ public void afterEach() {
}
}
+ @Test
+ public void testCache() throws Exception {
+ Path path = new Path(tempDir.toString());
+ SchemaManager manager =
+ new SchemaManager(FileIOFinder.find(path), path, new ConcurrentHashMap<>());
+ // schema-0
+ manager.createTable(schema);
+ // schema-1
+ manager.commitChanges(SchemaChange.setOption("aaa", "bbb"));
+ // schema-2
+ manager.commitChanges(SchemaChange.setOption("ccc", "ddd"));
+
+ Map<Long, TableSchema> cachedSchema = manager.getCachedSchema();
+ assertThat(cachedSchema).hasSize(3);
Review Comment:
You don't need to `getCachedSchema`.
You can just verify same instances.
--
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 SchemaManager [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #2939:
URL: https://github.com/apache/incubator-paimon/pull/2939#discussion_r1514219416
##########
paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java:
##########
@@ -97,6 +102,17 @@ protected AbstractFileStoreTable(
}
this.tableSchema = tableSchema;
this.catalogEnvironment = catalogEnvironment;
+ schemaCache = loadSchemaCache(fileIO, path);
+ }
+
+ @NotNull
+ private Map<Long, TableSchema> loadSchemaCache(FileIO fileIO, Path path) {
+ Map<Long, TableSchema> schemaCache = new ConcurrentHashMap<>();
+ SchemaManager schemaManager = new SchemaManager(fileIO, path);
+ for (TableSchema schema : schemaManager.listAll()) {
Review Comment:
Why we need to list all at first?
--
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 table schema cache for SchemaManager [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #2939:
URL: https://github.com/apache/incubator-paimon/pull/2939#discussion_r1519166539
##########
paimon-core/src/main/java/org/apache/paimon/schema/SchemaManager.java:
##########
@@ -80,9 +80,16 @@ public class SchemaManager implements Serializable {
@Nullable private transient Lock lock;
+ private final Map<Long, TableSchema> cache;
+
public SchemaManager(FileIO fileIO, Path tableRoot) {
+ this(fileIO, tableRoot, null);
Review Comment:
new hash map? just keep cache not null?
--
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 table schema cache for SchemaManager [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi closed pull request #2939: [Core]add table schema cache for SchemaManager
URL: https://github.com/apache/incubator-paimon/pull/2939
--
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