ggershinsky commented on code in PR #9592: URL: https://github.com/apache/iceberg/pull/9592#discussion_r1483931060
########## core/src/main/java/org/apache/iceberg/ManifestFiles.java: ########## @@ -345,34 +345,24 @@ private static ManifestFile copyManifestInternal( return writer.toManifestFile(); } - private static InputFile newInputFile(FileIO io, String path, long length) { - boolean enabled; - - try { - enabled = cachingEnabled(io); - } catch (UnsupportedOperationException e) { - // There is an issue reading io.properties(). Disable caching. - enabled = false; - } - - if (enabled) { - ContentCache cache = contentCache(io); - Preconditions.checkNotNull( - cache, - "ContentCache creation failed. Check that all manifest caching configurations has valid value."); - LOG.debug("FileIO-level cache stats: {}", CONTENT_CACHES.stats()); - return cache.tryCache(io, path, length); + private static InputFile newInputFile(FileIO io, ManifestFile manifest) { + InputFile input = io.newInputFile(manifest); Review Comment: Not sure I'm correct - but I thought the goal of the contentCache was to skip creation of InputFile objects if they are requested more than once? ########## api/src/main/java/org/apache/iceberg/encryption/EncryptingFileIO.java: ########## @@ -0,0 +1,210 @@ +/* + * 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.encryption; + +import java.io.Closeable; +import java.io.IOException; +import java.io.Serializable; +import java.io.UncheckedIOException; +import java.nio.ByteBuffer; +import java.util.Map; +import org.apache.iceberg.ContentFile; +import org.apache.iceberg.DataFile; +import org.apache.iceberg.DeleteFile; +import org.apache.iceberg.ManifestFile; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.relocated.com.google.common.collect.Iterables; + +public class EncryptingFileIO implements FileIO, Serializable { + public static EncryptingFileIO create(FileIO io, EncryptionManager em) { + return new EncryptingFileIO(io, em); + } + + private final FileIO io; + private final EncryptionManager em; + + EncryptingFileIO(FileIO io, EncryptionManager em) { + this.io = io; + this.em = em; + } + + public Map<String, InputFile> bulkDecrypt(Iterable<? extends ContentFile<?>> files) { + Iterable<InputFile> decrypted = em.decrypt(Iterables.transform(files, this::wrap)); + + ImmutableMap.Builder<String, InputFile> builder = ImmutableMap.builder(); + for (InputFile in : decrypted) { + builder.put(in.location(), in); + } + + return builder.buildKeepingLast(); + } + + public EncryptionManager encryptionManager() { + return em; + } + + @Override + public InputFile newInputFile(String path) { + return io.newInputFile(path); + } + + @Override + public InputFile newInputFile(String path, long length) { + return io.newInputFile(path, length); + } + + @Override + public InputFile newInputFile(DataFile file) { + return newInputFile((ContentFile<?>) file); + } + + @Override + public InputFile newInputFile(DeleteFile file) { + return newInputFile((ContentFile<?>) file); + } + + private InputFile newInputFile(ContentFile<?> file) { + if (file.keyMetadata() != null) { + return newDecryptingInputFile( + file.path().toString(), file.fileSizeInBytes(), file.keyMetadata()); + } else { + return newInputFile(file.path().toString(), file.fileSizeInBytes()); + } + } + + @Override + public InputFile newInputFile(ManifestFile manifest) { + if (manifest.keyMetadata() != null) { + return newDecryptingInputFile(manifest.path(), manifest.length(), manifest.keyMetadata()); + } else { + return newInputFile(manifest.path(), manifest.length()); + } + } + + public InputFile newDecryptingInputFile(String path, ByteBuffer buffer) { + return em.decrypt(wrap(io.newInputFile(path), buffer)); + } + + public InputFile newDecryptingInputFile(String path, long length, ByteBuffer buffer) { + // TODO: is the length correct for the encrypted file? It may be the length of the plaintext + // stream Review Comment: Yep, this is the plaintext stream length (which is recored in the DataFile and ManifestFile objects). I have updated the AesGcmInput classes to work with the verified plaintext length values (instead of untrusted file length values) - actually, the code becomes more compact and intuitive. I'll send this patch along with other e2e updates next week. -- 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