924060929 commented on code in PR #70860: URL: https://github.com/apache/doris/pull/70860#discussion_r4662645976
########## fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/cache/IcebergScanFileIO.java: ########## @@ -0,0 +1,167 @@ +// 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.doris.datasource.iceberg.cache; + +import org.apache.iceberg.CatalogProperties; +import org.apache.iceberg.DataFile; +import org.apache.iceberg.DeleteFile; +import org.apache.iceberg.ManifestFile; +import org.apache.iceberg.ManifestListFile; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.io.SeekableInputStream; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** Request-local reads: cancellation never enters a catalog's shared FileIO or Doris manifest-cache loader. */ +final class IcebergScanFileIO implements FileIO { + private final FileIO delegate; + private final Runnable checkCancelled; + + IcebergScanFileIO(FileIO delegate, Runnable checkCancelled) { + this.delegate = delegate; + this.checkCancelled = checkCancelled; + } + + @Override + public InputFile newInputFile(String path) { + checkCancelled.run(); + return guarded(delegate.newInputFile(path)); + } + + @Override + public InputFile newInputFile(String path, long length) { + checkCancelled.run(); + return guarded(delegate.newInputFile(path, length)); + } + + @Override + public InputFile newInputFile(DataFile file) { + checkCancelled.run(); + return guarded(delegate.newInputFile(file)); + } + + @Override + public InputFile newInputFile(DeleteFile file) { + checkCancelled.run(); + return guarded(delegate.newInputFile(file)); + } + + @Override + public InputFile newInputFile(ManifestFile file) { + checkCancelled.run(); + return guarded(delegate.newInputFile(file)); + } + + @Override + public InputFile newInputFile(ManifestListFile file) { + checkCancelled.run(); + return guarded(delegate.newInputFile(file)); + } + + private InputFile guarded(InputFile input) { + return new InputFile() { + @Override + public long getLength() { + checkCancelled.run(); Review Comment: Fixed: `IcebergScanFileIO` now tracks opened `SeekableInputStream`s per manifest load and closes any unclosed streams in `close()` (without closing the shared delegate `FileIO`), wrapped with try-with-resources in `IcebergManifestLoader.uncachedLoader`. Added a close-count unit test covering cancellation between `newStream()` and `getLength()`, and added `clusterBy` + snapshot-ID assertions to the rewritten-manifest test. -- 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]
