Repository navigation
fix(frontend): keep data branch update staging retryable - #28271
Conversation
0e8bb63 to
8c553a0
Compare
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head 8c553a07dd76d870bbeb627562a174f9df862028 against base 4f90107c8c486369b58cda81837ded520d86c21a.
The root-cause analysis and retry ownership are sound: update-stage INSERT/UPDATE JOIN statements do need the existing frontend statement/compile retry boundary, and this PR correctly avoids replaying the whole merge transaction. One counterexample in the broadened detector is merge-blocking.
[P1][correctness / streaming / memory] Matching every __mo_diff_ identifier misroutes legitimate user SQL and can silently produce an empty streamed result.
containsDataBranchTempTableName now accepts any identifier beginning __mo_diff_ (pkg/frontend/data_branch_helpers.go:129-134), not just the generated del_, ins_, and upd_ apply tables. That prefix is not globally reserved or rejected by DDL: the existing feature itself exposes __mo_diff_source / __mo_diff_flag columns, and users can create a database/table such as __mo_diff_orders.
The concrete failure is a Data Branch CSV diff whose target table (or database) is named __mo_diff_orders. writeCSV executes SELECT * FROM <target> with streamChan/errChan (pkg/frontend/data_branch_output.go:1612-1625, 1755-1767). The broad predicate routes it to BackExec. That branch ignores the streaming channels and returns collected batches (data_branch_helpers.go:321-366), while the caller discards the returned executor.Result and consumes only streamChan. The goroutine then closes an empty channel, so the operation can report success with an empty CSV. It also replaces bounded streaming with full BackExec result materialization, adding an O(result-size) memory/OOM risk. DATA BRANCH PICK ... KEYS (<subquery mentioning such an identifier>) has the same discarded-result shape at data_branch_pick.go:815-855.
Please keep the shared generation prefix if useful, but route only the actual apply-table families (__mo_diff_del_, __mo_diff_ins_, __mo_diff_upd_) or, preferably, pass an explicit execution mode from the generator instead of re-parsing SQL text. Add negative detector tests for ordinary __mo_diff_* database/table/column names and a public streaming regression proving CSV/PICK rows are preserved for such a user schema. The new update-stage tests should still prove both the stage INSERT and base UPDATE JOIN use BackExec.
Unhappy-path closure:
| Check | Result |
|---|---|
| Q1 cleanup ownership | No resource-owner transfer changed; existing result cleanup remains valid on correctly classified paths. |
| Q2 wait/retry termination | No new retry loop; compile owns the bounded statement retry. The misclassified streaming path terminates, but with lost output. |
| Q3 accumulation bound | Fails for the counterexample: a streamable result is materialized by BackExec and the returned batches are discarded by the caller. |
Exact-head UT, BVT, SCA, coverage, and build checks are green; they do not cover a legitimate user identifier under the broadened prefix. No other confirmed retry-generation, atomicity, cleanup, or performance blocker was found in the three-file diff.
9cbac83 to
6893b29
Compare
|
The failed PROXY BVT is unrelated to this PR and is tracked by #28277. The execution CN detected the expected composite-key duplicate, but the remote pipeline failed to deliver its terminal error and mo-tester received |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review of exact head 6893b29 against current main 109bf92.
The previous P1 is fixed at the correct ownership boundary. Generated delete, insert, and update staging DDL/DML now opt into the existing retry-capable frontend statement path explicitly; generic SQL no longer infers execution mode from tokens in SQL text. This preserves CSV and PICK streaming for legitimate database, table, and column names beginning with _mo_diff, while both update-stage INSERT and base-table UPDATE JOIN remain retryable.
I read the complete six-file diff and traced online merge, PICK, portable-SQL output, staging initialization, flush, clear, and deferred cleanup. Counterexamples checked include quoted and schema-qualified user identifiers, empty statements, write-file mode, partial apply failure, retry during stage insert/update/delete, cleanup after an earlier error, and repeated execution in one transaction.
Unhappy-path closure:
- Q1: executor.Result batches remain closed by the statement owner; generated-table cleanup stays in the existing deferred owner, and write-file mode transfers ownership to the output file without invoking either executor.
- Q2: this adds no retry loop. Retry remains bounded by the existing frontend statement/compile boundary and caller context; streaming callers retain their original channel/cancellation path.
- Q3: ordinary CSV/PICK reads remain streaming and no longer risk accidental BackExec materialization. Staging value buffers retain their existing size/count flush bounds.
The focused route tests, public CSV and PICK regressions, merge/schema-evolution coverage, and exact-head green UT/SCA/BVT/coverage align with the implementation. I found no remaining correctness, atomicity, retry-generation, performance, leak, hang, or unbounded-growth blocker.
Merge Queue Status
This pull request spent 16 seconds in the queue, including 1 second running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
Related to #24099
What this PR does / why we need it:
Root cause
Data branch merge applies row diffs through generated staging-table DDL and DML. The generic internal SQL executor disables statement increments, so it also bypasses the existing compile retry for
ErrTxnNeedRetryWithDefChanged. Under multi-CN pessimistic catalog contention, that error could therefore escape from an apply statement.The prior routing recognized delete and insert staging names by re-parsing SQL text. Extending that predicate to every
__mo_diff_identifier fixed update staging but also classified legitimate user database, table, and column names. Streaming CSV diff and PICK callers discard collected BackExec batches and consume their stream channels, so such misclassification could silently lose rows and materialize an otherwise streamed result.Changes
__mo_diff_.Retry remains owned by the existing statement/compile boundary; this PR does not replay the merge transaction or add a retry loop.
Issue-to-test proof
__mo_diff_*database/table/column case entering BackExec and failing before the streaming executor was reached. The final unit cases prove those statements stay on internal execution while all generated delete/insert/update staging forms use BackExec.TestDataBranchDiffAsFile/csv_user_diff_prefix_identifierproves two CSV rows are streamed, reloaded, and equal to a user table named__mo_diff_orders.pick_5.sqlproves a KEYS subquery using database__mo_diff_orders, table__mo_diff_keys, and column__mo_diff_flagpreserves and applies rows 2 and 3. The checked-in result was inspected and matches the intended final rows 1, 2, and 3.merge_1.sqlcovers the reportedDATA BRANCH MERGE t2 INTO t1reproduction.merge_schema_evolve.sqlcovers insert/update/delete, composite-key, schema-evolution, rejection, and atomicity boundaries.Tests run
make build— passed.pkg/frontend— passed (30.769son latest rebased head).pkg/sql/compile— passed (7.786son latest rebased head).13.449son latest rebased head).pick_5.sql, twice on the same instance —94/94each run; both error reports were empty.merge_1.sql, substring-matchedmerge_10.sql, andmerge_schema_evolve.sql—244/244; the error report was empty.Rebase follow-up
origin/mainat109bf926fdwithout conflicts.git range-diffshows both PR commits are patch-identical after the rebase.6893b29606, the focused routing/output tests, full frontend and compile packages, and embedded CSV streaming regression all passed. The pushed head also restarts repository CI, including multi-CN PESSIMISTIC BVT.Residual risks
The catalog conflict is nondeterministic. Deterministic unit coverage proves retry-capable routing for every generated apply family, while end-to-end BVT proves merge and streaming semantics. The pushed head will also run the repository's multi-CN PESSIMISTIC CI. No storage format, transaction-level retry, concurrency state, or resource ownership changes are introduced; #24099 remains open for manual validation.