Skip to content

[fix](iceberg) Backport external write hardening to branch-4.1 - #66825

Open
Gabriel39 wants to merge 10 commits into
apache:branch-4.1from
Gabriel39:dev/forward-port-iceberg-paimon-fixes-branch-4.1
Open

[fix](iceberg) Backport external write hardening to branch-4.1#66825
Gabriel39 wants to merge 10 commits into
apache:branch-4.1from
Gabriel39:dev/forward-port-iceberg-paimon-fixes-branch-4.1

Conversation

@Gabriel39

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

This is a semantic backport of the external-write and schema-evolution fixes from #66345, #66348, #66408, #66529, and #66750 to branch-4.1.

The source PRs were implemented on the connector-plugin architecture, while branch-4.1 still uses the legacy external-table stack. This change ports the invariants and failure handling to the branch-specific owners instead of mechanically cherry-picking plugin classes.

Key behavior preserved on branch-4.1:

  • Keep Iceberg planning, serialization, and commit on one metadata generation; add exact snapshot/branch overwrite OCC checks and retry-state reset.
  • Handle nested schema evolution safely, including typed initial defaults, required-field history, alias collisions, nested partition sources, stable nested IDs, and collection parent null masks.
  • Transfer external-file ownership only through the final bounded report, retain rollback ownership until FE acknowledgement, and keep rolling compatibility for non-Iceberg report vectors.
  • Bound asynchronous writer and multi-partition sorter memory, including queue admission ownership and largest-sorter revocation.
  • Preserve writer close errors and file sizes; harden Iceberg data/delete-file cleanup and Hive deferred multipart validation/rollback.
  • Isolate Azure multipart writers with UUID-namespaced block IDs and commit the exact staged IDs.
  • Make orphan-file deletion retained-snapshot-aware, prefix-safe, GC-enabled, and bounded.
  • Preserve nested comments as SQL literals and isolate MTMV test job lookup.

The Paimon validation-detail fix from #66408 and canonical Paimon capitalization from #66750 are already present in the legacy Paimon paths on branch-4.1; their observable contracts were verified and no plugin-only code was introduced.

Architecture-specific notes

  • The Iceberg scan compatibility gate evaluates historical schema/default/equality-delete requirements only while a smooth-upgrade source BE exists. Equality deletes are still checked across every delete manifest in the selected snapshot.
  • Empty overwrite scans the retained target branch rather than the main branch, so divergent branch files cannot be mixed into the delete set.
  • The legacy Hive planner explicitly advertises deferred Azure multipart support, matching the connector-planner handshake from the source change.

Tests

  • FE focused reactor suite: 174 tests, 0 failures, 0 errors, 1 skipped.
  • Target-branch overwrite regression verified red/green against a divergent main branch.
  • Regression framework SuiteJobLookupTest: 1 test passed.
  • All 35 changed C++ translation units present in the ASAN compile database built successfully.
  • Azure BE source passed a syntax-only compile with the repository C++ flags (it is excluded from the local build configuration).
  • clang-format 16 check passed for all 63 changed C/C++ source and header files.
  • FE Checkstyle passed with 0 violations.

The full local BE unit-test link is unavailable because the configured third-party Arrow bundle lacks a header required by an unchanged source file; targeted compilation covers every changed translation unit.

Pick from master: #66345 #66348 #66408 #66529 #66750

@Gabriel39
Gabriel39 requested a review from yiguolei as a code owner August 17, 2026 03:56
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 77.48% (1909/2464)
Line Coverage 64.30% (34172/53141)
Region Coverage 64.44% (17299/26845)
Branch Coverage 53.98% (9267/17166)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: this review found 11 actionable correctness and rolling-compatibility defects.

The blocking paths group into four areas: external-file report ownership can delete committed Iceberg files or strand Hive multipart uploads; mixed-version Hive/Iceberg writes can fail after staging or silently use the wrong partition source; Scanner V2 loses or misinterprets Iceberg requiredness and initial defaults; and current nested non-identity merge routing constructs transforms from the wrong type.

Critical-checkpoint summary: reader lifecycle and collection parent-null handling were cleared; async reservation transfer, spill accounting, and dependency wakeups were cleared; overwrite OCC/branch behavior and the orphan-file action remained fail-closed; but schema mapping/default materialization, external compatibility, nested partition routing, and report ownership have the inline blockers below. No additional user-provided focus was supplied. The review converged in Round 2 after both full-scope passes and the separate risk challenge returned no new valuable findings. Per the review workflow, no builds or source modifications were performed.

Comment thread be/src/format_v2/column_mapper.cpp
Comment thread be/src/exec/pipeline/pipeline_fragment_context.cpp
Comment thread be/src/exec/pipeline/pipeline_fragment_context.cpp
Comment thread fe/fe-core/src/main/java/org/apache/doris/planner/HiveTableSink.java Outdated
Comment thread be/src/format/transformer/iceberg_partition_function.cpp
Comment thread be/src/format_v2/column_mapper.cpp
Comment thread be/src/format_v2/column_mapper.cpp
Comment thread be/src/format_v2/table/iceberg_reader.cpp
Comment thread be/src/format_v2/table/iceberg_reader.cpp
Comment thread be/src/exec/sink/writer/iceberg/viceberg_table_writer.cpp
@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: this review found seven additional actionable defects.

Critical-checkpoint summary:

  • Correctness and data safety: top-level non-finite Iceberg defaults fail in FE before the new BE parser is reachable; orphan deletion can race a concurrent commit; and rejected final reports can leave prepared Paimon files without an abort owner.
  • Resource lifetime and admission: cold partition fan-out and the final spill merger can both allocate far beyond their successful reservations.
  • External compatibility and performance: a positive equality-delete summary still causes unnecessary remote manifest traversal during rolling-upgrade checks.
  • Tests: the expanded complex-evolution suite has stale and missing golden results, so its checked-in expectations cannot pass.

The final-report state machine for the other inspected Iceberg/Hive/MaxCompute paths, nested partition routing, object-store publication, branch overwrite/OCC, reader lifecycle, and collection null handling were cleared. All 115 changed paths were reviewed, all 11 existing inline threads were duplicate-fenced, and two additional concerns were dismissed as pre-existing after authoritative-preimage checks. No additional user-provided focus was supplied. Three full rounds converged unanimously with no new valuable findings in the final round. Per the review instructions, no builds or source modifications were performed.

Comment thread be/src/format_v2/table/iceberg_reader.cpp
Comment thread be/src/exec/operator/spill_iceberg_table_sink_operator.cpp
Comment thread be/src/exec/operator/iceberg_sorter_reserve_memory.h Outdated
Comment thread be/src/runtime/runtime_state.cpp
@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 31.84% (213/669) 🎉
Increment coverage report
Complete coverage report

@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: seven additional, distinct defects remain (five P1, two P2).

Findings:

  1. [P1] Failed rewrite actions can permanently retain the new Iceberg commit fence.
  2. [P1] Target-file rollover can invoke a full sort without reserving destination/permutation workspace.
  3. [P1] Nontrivial ARRAY/MAP rematerialization still allocates an entry-sized parent mask when no descendant consumes it.
  4. [P1] Paimon backend close failures are discarded after FE has accepted commit payloads.
  5. [P1] Cold-writer reserve estimation copies a potentially huge first value before memory admission.
  6. [P2] The V2 gate rejects selected-snapshot/ref scans based on schemas that cannot contribute reachable files.
  7. [P2] The V2 gate expands a nested-pruned root to unrequested descendants, so an unused sibling can reject a V1-safe scan.

Review checkpoints:

  • Architecture and layer boundaries: traced Scanner/TableReader/mapper/file-reader responsibilities and FE-to-Thrift-to-BE ownership. No separate boundary inversion survived review; the schema-gate and materialization defects are called out inline.
  • Reader and transaction lifecycle/contracts: checked split/EOF/error cleanup, async queue tokens, report ACK/retry/finalizers, Iceberg fence/OCC paths, and writer close/rollback. The rewrite-fence leak and post-ACK Paimon close regression remain blocking.
  • Schema mapping/materialization: checked stable field IDs, recursive defaults/optionality/binary markers, nested projection, ARRAY/MAP offsets/null maps, selected schemas, and partition paths. Three projection/materialization defects remain inline.
  • Filtering, deletes, and pushdown: traced predicates plus equality/position-delete paths and row/schema alignment; no additional nonduplicate issue survived beyond prior live threads and the V2 projection gates above.
  • Format boundaries and external compatibility: checked Iceberg V1/V2 rolling upgrade, time travel/refs, external schema evolution, Hive/Paimon reporting, nested partitions, and Azure/S3 multipart identity. The two mixed-version false rejections are inline; other reproduced compatibility concerns are already threaded.
  • Performance and observability: reviewed admission, sorter rollover/spill/final merge, hot-path collection masks, report-size handling, counters, and cleanup visibility. Three unreserved/unbounded allocation paths remain inline.
  • Tests: reviewed all changed BE/FE/regression tests. Coverage does not exercise the seven reported witnesses; no builds or tests were run, as required by the review prompt.
  • User focus: no additional user-provided focus was supplied.

Status: capped/incomplete after the maximum three rounds because the final normal and final risk passes both produced new distinct findings; this is not a convergence claim.

Comment thread be/src/exec/sort/sorter.cpp Outdated
Comment thread be/src/format_v2/table_reader.h Outdated
Comment thread be/src/exec/sink/writer/paimon/paimon_table_writer.cpp
Comment thread be/src/exec/operator/spill_iceberg_table_sink_operator.cpp Outdated
@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 33.73% (252/747) 🎉
Increment coverage report
Complete coverage report

@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 33.26% (287/863) 🎉
Increment coverage report
Complete coverage report

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Review context preparation failed before Codex ran; inspect the 'Prepare authoritative PR context and required AGENTS guides' step.
Workflow run: https://github.com/apache/doris/actions/runs/32086463478

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 77.48% (1909/2464)
Line Coverage 64.30% (34169/53141)
Region Coverage 64.44% (17298/26845)
Branch Coverage 53.98% (9267/17166)

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Review step was failure (possibly timeout or cancelled)
Workflow run: https://github.com/apache/doris/actions/runs/32087723185

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: five additional, distinct P1 defects remain.

Findings:

  1. Iceberg admission still misses the pre-append per-column capacity rollover sort.
  2. A new BE can mistake a legacy FE's transport OK for durable Hive/Paimon/MaxCompute ownership acceptance.
  3. Expiring an ancestor snapshot can truncate the schema-provenance walk while files written under that schema remain live.
  4. Rewrite cache invalidation can report failure after the remote Iceberg commit is already durable.
  5. A swallowed rewrite-group failure can be counted as success, allowing source files to be deleted without replacements.

Critical-checkpoint summary:

  • Architecture and lifecycle: external-report ownership and both rewrite transaction boundaries have the three blocking defects above; new-FE retry identity/publication and the other writer-finalizer paths were cleared.
  • Schema mapping and mixed-version scanning: recursive defaults, requiredness transport, collection null propagation, projected IDs, and backend selection were cleared, but expired-parent provenance can under-gate V2 semantics.
  • Memory and performance: cold-writer fanout, target-size/EOS/final-merge accounting, async reservation transfer, and prior allocation issues were rechecked; the separate pre-append capacity rollover remains unreserved.
  • Filtering, deletes, and destructive/object-store paths: equality/position-delete handling, local maintenance fencing, and exact Azure block identity yielded no new nonduplicate issue beyond existing live threads.
  • Tests: the changed tests do not exercise the five reported witnesses; no builds or tests were run, as required.
  • User focus: no additional user-provided focus was supplied.

Status: converged in Round 3 after both normal full-scope passes and the final risk challenge returned NO_NEW_VALUABLE_FINDINGS.

Comment thread be/src/exec/sort/sorter.cpp Outdated
Comment thread be/src/exec/pipeline/pipeline_fragment_context.cpp Outdated
@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 33.26% (287/863) 🎉
Increment coverage report
Complete coverage report

@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Review step was failure (possibly timeout or cancelled)
Workflow run: https://github.com/apache/doris/actions/runs/32095092358

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 77.48% (1909/2464)
Line Coverage 64.29% (34163/53141)
Region Coverage 64.43% (17297/26845)
Branch Coverage 53.97% (9265/17166)

@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: four additional, distinct P1 defects remain.

Findings:

  1. A cancellation report can terminalize external-file ownership before the async Hive writer registers its S3 MPU cleanup owner.
  2. Cross-partition revocation can sort one Iceberg writer concurrently with async dispatch on another while admission reserves only one transient workspace.
  3. The new insert retry reset erases MTMV's captured base-table snapshots before the first planning attempt.
  4. Nested complex default reconstruction can bind a renamed field to a reused sibling name through alias-first element ordering.

Critical-checkpoint summary:

  • External-file ownership and provider lifecycle: ACK/rejection/ambiguity, size guards, FE retry caching, Iceberg/Paimon/MaxCompute ownership, and exact Azure/S3 identities were traced; the late Hive cancellation owner remains blocking.
  • Memory and concurrency: reservation-token transfer, queue admission, cold fan-out, append/target/EOS/final-merge paths, and revocation were traced; cross-writer revocation still violates the single-workspace bound.
  • Format V2 schema mapping and external compatibility: recursive defaults, requiredness, binary/non-finite values, projection, equality/position deletes, schema history, and mixed-version gating were traced; the nested renamed/reused complex-type binding remains blocking.
  • Iceberg transaction lifecycle, nested partition routing, and orphan cleanup yielded no additional nonduplicate issue beyond existing live threads; MTMV snapshot pinning has the separate first-attempt regression above.
  • Tests: the changed coverage does not exercise the cancellation barrier, cross-writer overlap, MTMV injected-snapshot fence, or reordered complex alias collision.

No additional user-provided review focus was supplied. The review converged in Round 2 after both normal full-scope domain passes and the independent risk challenge returned NO_NEW_VALUABLE_FINDINGS. No builds or source modifications were performed, per the review contract.

Comment thread be/src/runtime/runtime_state.cpp Outdated
Comment thread be/src/exec/operator/spill_iceberg_table_sink_operator.cpp
Comment thread be/src/format_v2/table/iceberg_reader.cpp
@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review result: request changes.

I found three distinct correctness/lifecycle issues: one unreserved non-spill merge allocation, a stale default orphan-file preview, and a lost rewrite cancellation during planning.

Critical checkpoint summary:

  • BE memory and ownership: async admission, reservation transfer, dispatch/revocation locking, external report aggregation/ACK/retry, and late cleanup ownership were traced. Existing live threads cover the other previously raised cases; the non-spill EOS merge-output reservation gap remains.
  • FE transactions and maintenance: commit fencing, rollback/quiescence, report acceptance, cache/MVCC, and nested routing were traced. The dry-run refresh and cancellation-handoff issues remain.
  • Schema and compatibility: nested defaults/requiredness, field identity, projection/null maps, delete paths, nested partitions, Thrift carriers, and mixed-version gates were rechecked with no additional non-duplicate defect.
  • User focus: no additional user-provided review focus was supplied.

No builds or tests were run because the review instructions prohibit them.

Comment thread be/src/exec/sort/sorter.cpp
@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found six blocking correctness and memory-accounting issues:

  • Sort admission reduces retained sorted destinations across partitions to one transient maximum.
  • Spill-merge admission omits the serialized buffer and parsed protobuf retained by every input reader.
  • A whole-block average cannot bound an isolated oversized scalar or nested row.
  • Nested identity-partition overwrite and RowDelta predicates bind a leaf name instead of the full schema path.
  • Static syntax for a nested identity partition can label a file with a value different from the unchanged row leaf written into it.
  • The mixed-version scan gate omits schema provenance of files imported by a non-fast-forward cherry-pick.

I reviewed the full 139-file authoritative diff, the existing threads and review bodies, the required FileScanner V2 guidance, and the focused tests and ownership paths. Two independent convergence rounds completed; the final BE, external-ownership, Iceberg/FE, and risk-focused passes all returned NO_NEW_VALUABLE_FINDINGS. Existing orphan-deletion, rewrite-quiescence, caller-owned MVCC retry, and complex-default concerns were duplicate-fenced rather than resubmitted.

User focus: no additional user-provided review focus was specified. Builds and tests were not run because the review instructions prohibited builds.

Comment thread be/src/exec/operator/iceberg_sorter_reserve_memory.h
Comment thread be/src/exec/operator/iceberg_sorter_reserve_memory.h Outdated
Comment thread be/src/exec/sink/writer/iceberg/viceberg_sort_writer.cpp Outdated
Comment thread be/src/exec/sink/writer/iceberg/viceberg_table_writer.cpp
@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Review step was failure (possibly timeout or cancelled)
Workflow run: https://github.com/apache/doris/actions/runs/32121445112

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Your access token could not be refreshed because your refresh token was already used. Please log out and sign in again.
Workflow run: https://github.com/apache/doris/actions/runs/32331561171

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants