Gabriel39 commented on code in PR #71239:
URL: https://github.com/apache/doris/pull/71239#discussion_r4795474243


##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergFileEncryption.java:
##########
@@ -44,10 +65,15 @@ static IcebergFileEncryption fromMetadata(ByteBuffer 
metadata) {
 
     TFileEncryptionInfo toThrift() {
         TFileEncryptionInfo info = new TFileEncryptionInfo();
-        info.setVersion(1);
+        info.setVersion(2);
         // Thrift binary fields are mutable; one split's serialization must 
not mutate another's key.
         info.setKey(key.clone());
         info.setAadPrefix(aad.clone());
+        if (!columnKeys.isEmpty()) {
+            Map<Integer, ByteBuffer> snapshot = new LinkedHashMap<>();
+            columnKeys.forEach((ordinal, bytes) -> snapshot.put(ordinal, 
ByteBuffer.wrap(bytes.clone())));
+            info.setColumnKeys(snapshot);

Review Comment:
   Fixed in 
https://github.com/apache/doris/commit/8ee918488e8dae929d4880dfa577d734ccf3c4b6.
 Byte ranges now share immutable file-level column-key storage with disposable 
Thrift buffers; compaction copies only envelopes and the range list. Native 
position-delete slices also resolve their parent key once, even without a 
statement-cache hit. Regression coverage includes 16,384 keys, concurrent 
Binary/Compact serialization, and four real SDK slices sharing one 
authenticated-footer resolution.



##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergMetadataSplitSource.java:
##########
@@ -0,0 +1,226 @@
+// 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.connector.iceberg;
+
+import org.apache.doris.connector.spi.ConnectorContext;
+import org.apache.doris.connector.spi.scan.ConnectorScanContext;
+import org.apache.doris.connector.spi.scan.ConnectorScanRange;
+import org.apache.doris.connector.spi.scan.ConnectorSplitSource;
+
+import org.apache.iceberg.DorisMetadataRows;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.CloseableIterator;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.concurrent.Callable;
+import java.util.function.IntPredicate;
+import java.util.function.Supplier;
+
+/** Pulls authenticated metadata on the FE and publishes only bounded, 
sanitized row batches. */
+final class IcebergMetadataSplitSource implements ConnectorSplitSource {
+    private static final int MAX_BATCH_ROWS = 256;
+    private static final long TARGET_BATCH_BYTES = 1L << 20;
+    private static final int MAX_SERIALIZED_BYTES = 6 << 20;
+    private final Supplier<CloseableIterable<FileScanTask>> loader;
+    private final Schema schema;
+    private final IntPredicate keyFields;
+    private final ConnectorScanContext scanContext;
+    private final ConnectorContext context;
+    private CloseableIterable<FileScanTask> tasks;
+    private CloseableIterator<FileScanTask> taskIterator;
+    private CloseableIterable<StructLike> rows;
+    private CloseableIterator<StructLike> rowIterator;
+    private DorisMetadataRows.CopiedRow pending;
+    private ConnectorScanRange next;
+    private long batchOrdinal;
+    private boolean closed;
+
+    IcebergMetadataSplitSource(Supplier<CloseableIterable<FileScanTask>> 
loader, Schema schema,
+            ConnectorScanContext scanContext, ConnectorContext context) {
+        this(loader, schema, schema, scanContext, context);
+    }
+
+    IcebergMetadataSplitSource(Supplier<CloseableIterable<FileScanTask>> 
loader, Schema schema, Schema metadataSchema,
+            ConnectorScanContext scanContext, ConnectorContext context) {
+        this.loader = loader;
+        this.schema = schema;
+        // Resolve carriers before projection can promote a nested user field 
named key_metadata to the root.
+        this.keyFields = DorisMetadataRows.keyFieldFilter(metadataSchema);
+        this.scanContext = scanContext;
+        this.context = context;
+    }
+
+    @Override
+    public boolean hasNext() {
+        if (closed) {
+            return false;
+        }
+        try {
+            return authenticated(this::advance);
+        } catch (RuntimeException failure) {
+            try {
+                close();
+            } catch (IOException cleanup) {
+                failure.addSuppressed(cleanup);
+            }
+            throw failure;
+        }
+    }
+
+    private boolean advance() throws IOException {
+        scanContext.checkCancelled();
+        if (next != null) {
+            return true;
+        }
+        if (tasks == null) {
+            tasks = loader.get();
+            scanContext.checkCancelled();
+            taskIterator = tasks.iterator();
+        }
+        List<StructLike> batch = new ArrayList<>();
+        long bytes = 0;
+        while (batch.size() < MAX_BATCH_ROWS) {
+            scanContext.checkCancelled();
+            if (pending == null) {
+                while (rowIterator == null || !rowIterator.hasNext()) {
+                    // Empty manifests must not keep a cancelled producer 
opening more tasks.
+                    scanContext.checkCancelled();
+                    closeRows();
+                    if (!taskIterator.hasNext()) {
+                        break;
+                    }
+                    scanContext.checkCancelled();
+                    rows = taskIterator.next().asDataTask().rows();
+                    scanContext.checkCancelled();
+                    rowIterator = rows.iterator();
+                }
+                if (rowIterator == null) {
+                    break;
+                }
+                pending = DorisMetadataRows.copy(rowIterator.next(), schema, 
keyFields);
+            }
+            if (!batch.isEmpty() && bytes + pending.bytes() > 
TARGET_BATCH_BYTES) {
+                break;
+            }
+            batch.add(pending.row());
+            bytes += pending.bytes();
+            pending = null;
+        }
+        if (batch.isEmpty()) {
+            close();
+            return false;
+        }
+        String serialized = 
IcebergSystemTableSerialization.serializeMetadataRows(
+                // Scheduling hashes the serialized task. A projected constant 
must not send every
+                // otherwise identical batch to one backend; the ordinal is 
stable for this source.
+                DorisMetadataRows.task(schema, batch, batchOrdinal), 
MAX_SERIALIZED_BYTES);

Review Comment:
   Fixed in 
https://github.com/apache/doris/commit/8ee918488e8dae929d4880dfa577d734ccf3c4b6.
 Lazy responses and backend queues now account for generated Binary-protocol 
bytes, including protected key maps and Base64 metadata. Responses target less 
than 8 MiB, queues target 32 MiB, and the first non-fitting range remains 
queued; a legal large single range is sent alone. The regression drains all 40 
large metadata ranges without loss or duplication and checks actual serialized 
responses. A separate per-task key/carrier budget stops oversized 
materialization before later delete-footer work.



##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergScanPlanProvider.java:
##########
@@ -2145,21 +2163,34 @@ private PerFileScratch computePerFileInvariants(Table 
table, Schema scanSchema,
      * mirroring legacy {@code IcebergScanNode.getDeleteFileFilters} + {@code 
IcebergDeleteFileFilter}. Empty
      * for v1 / no-delete files (v1 has no delete files, so {@code 
task.deletes()} is always empty there).
      */
-    private List<IcebergScanRange.DeleteFile> buildDeleteFiles(FileScanTask 
task,
+    private List<IcebergScanRange.DeleteFile> buildDeleteFiles(FileScanTask 
task, Table table,
             UnaryOperator<String> uriNormalizer) {
         List<DeleteFile> deletes = task.deletes();
         if (deletes == null || deletes.isEmpty()) {
             return Collections.emptyList();
         }
         List<IcebergScanRange.DeleteFile> result = new 
ArrayList<>(deletes.size());
         for (DeleteFile delete : deletes) {
-            result.add(convertDelete(delete, uriNormalizer));
+            result.add(convertDelete(delete, uriNormalizer, 
fileEncryption(delete, table)));

Review Comment:
   Fixed in 
https://github.com/apache/doris/commit/8ee918488e8dae929d4880dfa577d734ccf3c4b6.
 Cancellation now reaches request-local footer IO, delete/encryption-preflight 
loops, provider callbacks, and each KMS unwrap, with checks after callbacks 
return. Real encrypted-file tests cancel between providers and during the first 
unwrap, proving that later providers/unwraps/footers are not invoked and owned 
resources close. All related FE tests and the nine normal-comparison PME suites 
passed locally; SQL coverage uses current FE/Java JNI with the previously built 
feature ASAN native BE.



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