bvaradar commented on a change in pull request #4910: URL: https://github.com/apache/hudi/pull/4910#discussion_r831650856
########## File path: hudi-common/src/main/java/org/apache/hudi/common/util/TableInternalSchemaUtils.java ########## @@ -0,0 +1,140 @@ +/* + * 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.hudi.common.util; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hudi.common.model.HoodieCommitMetadata; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.timeline.HoodieInstant; +import org.apache.hudi.common.table.timeline.HoodieTimeline; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.exception.HoodieException; +import org.apache.hudi.internal.schema.InternalSchema; +import org.apache.hudi.internal.schema.io.FileBasedInternalSchemaStorageManager; +import org.apache.hudi.internal.schema.utils.SerDeHelper; + +import java.util.List; +import java.util.TreeMap; +import java.util.stream.Collectors; + +public class TableInternalSchemaUtils { + // use segment lock to reduce competition. + // the lock size should be powers of 2 for better hash. + private static Object[] lockList = new Object[16]; + + static { + for (int i = 0; i < lockList.length; i++) { + lockList[i] = new Object(); + } + } + + // historySchemas cache maintain a map about (tablePath, HistorySchemas). + // this is a Global cache, all threads in one container/executor share the same cache. Review comment: @xiarixiaoyao : InternalSchemaCache.searchSchemaAndCache has the folllowing doc: /** * search internalSchema based on versionID. * first step: try to get internalSchema from hoodie commit files, we no need to add lock. * if we cannot get internalSchema by first step, then we try to get internalSchema from cache. * */ When do we miss the schema from commit file but find in cache. Also, As we are anyway performing a read operation, Can we read the history schema as well. We would need to rewrite History schema management part anyways to use Hoodie Metadata log. Also, in case of Presto queries, the worker are long running JVMs where this cache will be stored. Even though the cache is bounded in number of entries, we would need a config to turn on/off this cache (in case we run into issues) with default being turned off. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
