rdblue commented on code in PR #8644: URL: https://github.com/apache/iceberg/pull/8644#discussion_r1336453506
########## core/src/main/java/org/apache/iceberg/io/AsyncFileIO.java: ########## @@ -0,0 +1,269 @@ +/* + * 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.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.github.benmanes.caffeine.cache.RemovalListener; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import org.apache.iceberg.Files; +import org.apache.iceberg.exceptions.RuntimeIOException; +import org.apache.iceberg.relocated.com.google.common.hash.Hashing; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.apache.iceberg.util.PropertyUtil; +import org.apache.iceberg.util.SerializableMap; +import org.apache.iceberg.util.ThreadPools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** A {@link FileIO} implementation that caches files when an {@link InputFile} is created. */ +public class AsyncFileIO extends ResolvingFileIO { + private static final Logger LOG = LoggerFactory.getLogger(AsyncFileIO.class); + + private static final String FILE_PREFIX = "file:"; + private static final String ASYNC_ENABLED = "async.enabled"; + private static final String CACHE_LOCATION = "async.cache-location"; + + // Using a holder instead of double-checked locking + // see https://stackoverflow.com/questions/6189099/ + private static final class SharedPools { + static final ExecutorService DOWNLOAD_POOL = ThreadPools.newWorkerPool("async-file-io"); + } + + private SerializableMap<String, String> properties = null; + private FileIO local = null; + private boolean enabled = true; + private String cacheLocation = null; + + private transient LoadingCache<String, InputFile> lazyCache = null; + + // detect when this has been serialized using a transient variable + private transient Boolean isRemote = false; + + @Override + public InputFile newInputFile(String path) { + if (enabled /*&& null == isRemote*/) { Review Comment: This is where I'd like to have a mode that detects whether this has been serialized and only caches if it has. Maybe there's a better way to detect being on a worker rather than the driver? Or maybe we don't need that 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-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org