github-actions[bot] commented on code in PR #70860:
URL: https://github.com/apache/doris/pull/70860#discussion_r4661787296


##########
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:
   [P2] Close streams when cancellation interrupts reader initialization
   
   Iceberg 1.11's 
[AvroIterable.newFileReader](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/avro/AvroIterable.java)
 evaluates `file.newStream()` before `file.getLength()`. If query cancellation 
lands between those calls, this guard throws `CancellationException` after the 
delegate stream has opened but before the SDK assigns its stream variable or 
registers reader ownership. Its initialization cleanup catches only 
`IOException`, so neither it nor the surrounding `ManifestReader` cleanup 
closes that stream. This can leak HDFS handles or broker resources across 
cancelled scans. Ensure the request-local wrapper closes opened streams when 
cancellation escapes before SDK ownership is established, and cover this 
interleaving with a close-count test; the current pre-cancelled test never 
opens a stream.



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