rizaon commented on code in PR #4518:
URL: https://github.com/apache/iceberg/pull/4518#discussion_r976134008


##########
core/src/main/java/org/apache/iceberg/ManifestFiles.java:
##########
@@ -44,6 +51,28 @@ private ManifestFiles() {}
               ManifestFile.PARTITION_SUMMARY_TYPE,
               GenericPartitionFieldSummary.class.getName()));
 
+  private static final Cache<FileIO, ContentCache> CONTENT_CACHES =
+      
Caffeine.newBuilder().weakKeys().maximumSize(maxFileIO()).recordStats().build();
+
+  /**
+   * Get or create a manifest file cache for a given FileIO.
+   *
+   * <p>Returned cache object will be kept in memory until {@link 
#dropCache(FileIO)} is called.
+   * Return null if the given FileIO properties does not allow caching.
+   *
+   * @param fileIO A FileIO.
+   * @return A manifest file cache or null if the given FileIO properties does 
not allow caching.
+   */
+  public static ContentCache getOrCreateCache(FileIO fileIO) {

Review Comment:
   This is still useful for testing, to gain access to values of 
`CONTENT_CACHES`. I made this to package private and rename it to 
`contentCache(FileIO io)`.



##########
core/src/main/java/org/apache/iceberg/io/ContentCache.java:
##########
@@ -0,0 +1,310 @@
+/*
+ * 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.iceberg.io;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.Weigher;
+import com.github.benmanes.caffeine.cache.stats.CacheStats;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import org.apache.iceberg.CatalogProperties;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.iceberg.exceptions.RuntimeIOException;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.util.PropertyUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ContentCache {
+  private static final Logger LOG = 
LoggerFactory.getLogger(ContentCache.class);
+  private static final int BUFFER_CHUNK_SIZE = 4 * 1024 * 1024; // 4MB
+
+  public static ContentCache createCache(Map<String, String> properties) {
+    boolean enabled =
+        PropertyUtil.propertyAsBoolean(
+            properties,
+            CatalogProperties.IO_CACHE_ENABLED,
+            CatalogProperties.IO_CACHE_ENABLED_DEFAULT);
+    long durationMs =
+        PropertyUtil.propertyAsLong(
+            properties,
+            CatalogProperties.IO_CACHE_EXPIRATION_INTERVAL_MS,
+            CatalogProperties.IO_CACHE_EXPIRATION_INTERVAL_MS_DEFAULT);
+    long totalBytes =
+        PropertyUtil.propertyAsLong(
+            properties,
+            CatalogProperties.IO_CACHE_MAX_TOTAL_BYTES,
+            CatalogProperties.IO_CACHE_MAX_TOTAL_BYTES_DEFAULT);
+    long contentLength =
+        PropertyUtil.propertyAsLong(
+            properties,
+            CatalogProperties.IO_CACHE_MAX_CONTENT_LENGTH,
+            CatalogProperties.IO_CACHE_MAX_CONTENT_LENGTH_DEFAULT);
+
+    if (!enabled) {

Review Comment:
   Done.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to