hello-stephen commented on code in PR #71239:
URL: https://github.com/apache/doris/pull/71239#discussion_r4787672378
##########
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:
[P2] Avoid copying the full column-key map into every file split
This emits a fresh copy of every row group's keys for every byte-range of
the same file, including ranges that share an encrypted delete. A supported
file with 64 independently keyed columns, 256 row groups and 32-byte keys has
16,384 entries and 512 KiB of key bytes alone. Splitting it into one range per
row group gives 128 MiB of duplicate key bytes before Thrift overhead. Eager
plans retain those copies, and a single-backend lazy scan can exceed the
default 100 MiB Thrift receive limit in one fetch once more than 200 ranges are
queued. Split compaction keeps each range's descriptor. Share the file-level
keys across its ranges or prevent FE fan-out for these files while preserving
BE row-group parallelism.
##########
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:
[P3] Stop resolving delete keys when a lazy scan is cancelled
The lazy source checks cancellation before building the data range. Once it
reaches this loop, each uncached keyed Parquet delete can open a footer and ask
the column-key provider to unwrap keys through the original table FileIO. If
cancellation arrives during the first of several applicable deletes, the
producer can still start the remaining reads and KMS calls before releasing its
worker. Pass the scan cancellation check into delete-key materialization and
check it before further footer I/O or unwrap calls.
##########
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:
[P2] Bound lazy metadata fetches by serialized bytes
The 6 MiB cap is per task, before Base64. `SplitSource.getNextBatch()`
drains ranges by count and can return 64 on the first fetch and 1,000 on later
fetches. For example, 40 queued `$files` rows with about 2 MiB of binary bounds
each fit the per-row limit and form one task each. Base64 alone puts that
response above the BE's default 100 MiB Thrift receive limit, so a valid
metadata scan can fail even with batch mode enabled. Apply a cumulative
wire-byte budget when draining the queue, leave the next split queued for the
following fetch, and cover this with an oversized aggregate response 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]