Repository navigation
fix data branch edge cases - #25471
Conversation
a9ad0cb to
cbce287
Compare
d60abf9 to
235d65c
Compare
|
@XuPeng-SH @jiangxinmeng1 Full review closure is now on
There are no unresolved inline threads, and all checks for this head are green. Re-requesting review. |
|
@XuPeng-SH @jiangxinmeng1 Synced the PR with The two conflicts were SQL literal-escaping overlaps. I kept the upstream package-level helper and routed the PR paths through it, so apostrophe/backslash behavior remains covered without parallel escape implementations. Verified with |
|
CI repair in 97d2959: The failing pessimistic Regression coverage covers the process, connector, and dispatch paths; an isolated execution of the failing SQL now returns |
jiangxinmeng1
left a comment
There was a problem hiding this comment.
Reviewed the latest head 0da39ae. I found no remaining merge-blocking issues.
The previously reported gaps are now closed: clone-view identifier quoting and
AST remapping, Decimal256/ENUM/Geometry32 handling, partitioned CDC commit
ordering and atomicity, bounded snapshot streaming, and change-handle cleanup/
error paths.
The visible Iceberg Connector E2E workflow passed, but please confirm all
required checks are green on the latest head before merging.
…t-review-20260727
XuPeng-SH
left a comment
There was a problem hiding this comment.
I found one production performance blocker on exact head 370aa7b086.
The new partition-tail merge emits one Tail_done per commit timestamp (txn_table_combined.go:387-451) and consumes each timestamp by UnionWindow followed by deleting the prefix with Shrink (txn_table_combined.go:586-620). A normal change batch can contain many ordered commit timestamps; in the common single-row-transaction case this repeatedly shifts the remainder of the same batch, making batch processing quadratic. loadPending/nextCommitTS also scan every partition for every emitted timestamp.
I reproduced this with the real combinedChangesHandle on this head using one 8192-row child batch whose rows have distinct ordered commit timestamps (the other partitions being exhausted does not change the hot path). Three one-shot runs were 34.4–35.0 ms, ~5.05 MB and ~57.4k allocations. The scaling is nonlinear: 2048 rows ~3.0 ms, 4096 ~9.7–10.1 ms, and 8192 ~34.5 ms. In addition, each of those 8192 groups is returned as a separate Tail_done, so DataProcessor.processTailDone sends a separate sink command for every source transaction instead of retaining the original bounded batch granularity.
This is a material CDC regression for partitioned tables with many small transactions. Please preserve global commit order and coalesce same-timestamp rows across partitions without repeatedly mutating/shifting the source batch or scanning all partitions per row. A cursor/window-based k-way merge (heap/frontier) that emits maximal safe ordered ranges would avoid both costs; the sink-side delete-before-insert rule must still be applied only with correct per-PK temporal semantics when a range contains multiple timestamps. Please add a mixed-timestamp 8K-scale benchmark/regression so this does not regress again.
The earlier correctness blockers (quoted restore identifiers, FULLTEXT pattern recursion, cross-partition same-TS atomicity, bounded snapshots, and terminal-cause preservation) are otherwise closed, focused race tests pass, CI is green, and the latest-main merge tree is clean.
|
Addressed in c2ffa82.
I intentionally retained one Validated with focused combined-handle tests, the 8K benchmark, |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Blocking performance issue remains in the latest head.
The heap/cursor rewrite does fix the previous O(T×P) merge CPU cost: locally, the 8,192-timestamp benchmark is now 2.9–5.0 ms/op. However, combinedChangesHandle.nextTail still unconditionally returns one Tail_done per distinct commit timestamp. The new 8K insert-only regression therefore calls Next 8,192 times. The production path maps every one of those boundaries to ChangeTypeTailDone, and DataProcessor.processTailDone transfers a fresh atomic batch to sinker.Sink each time. The author comment also confirms this is one sink command per boundary.
That is a real command/queue/SQL-processing amplification for partitioned CDC, not just an in-memory allocation concern. The ordinary non-partitioned ChangeHandler accumulates rows up to coarseMaxRow; this path turns a safe insert-only batch into O(distinct commit timestamps) sink commands. Even the in-memory benchmark already allocates about 4.66 MB / 73.7K objects for 8K rows, while downstream command processing is much more expensive.
The temporal-order argument is valid for mixed cross-timestamp delete/insert conflicts, but it does not justify splitting insert-only or delete-only ranges. Please emit maximal safe ordered ranges—at minimum coalesce consecutive insert-only/delete-only timestamps and retain per-TS boundaries only where mixed operations require them, or introduce an ordered operation representation in the sink. Add an end-to-end/counting regression that bounds sink-command growth for the 8K insert-only case, in addition to the merge microbenchmark.
I rechecked head 67cafa0dcfd67f7f4c2daada311c9ff7970b8a57. CI is green; local tests for cdc, container/types, frontend, compile, parser, plan, and disttae all pass.
|
Fixed in 3e895d2 and then merged through upstream/main f6dab28.
Validated with full disttae and CDC package tests, focused race coverage, the 8K benchmark, build/vet of the affected packages, and diff checks. |
…t-review-20260727
…t-review-20260727 # Conflicts: # pkg/sql/plan/build_show_util.go
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes on exact head 0f2a8a4f433ae634dcd566fe4d235b9983c686d6: the new pure-range coalescing reduces the number of Sink calls, but it does not close the downstream SQL-processing amplification from my previous review.
DataProcessor still calls AtomicBatch.Append once for every per-timestamp batch, and AtomicBatch.Append retains every source batch in AtomicBatch.Batches (pkg/cdc/types.go:418-455). The MySQL sinker then iterates that slice and calls BuildInsertSQL followed by ExecSQL separately for every source batch (pkg/cdc/sinker_v2.go:722-740).
I verified this on the current head by extending the new 8,192-row regression: its single sink command has len(calls[0].insertAtmBatch.Batches) == 8192, not a bounded/coalesced batch count. Therefore the insert-only case still builds and executes about 8,192 one-row INSERT/REPLACE statements; only the queue-command count changed from 8,192 to 1. The added test checks only Sink call count and total rows, so it cannot detect the remaining amplification.
Please coalesce the insert rows into bounded source batches (or build SQL from the ordered atomic rows) and make the regression assert the actual SQL/executor call count, not only the number of Sink calls. The new ordering/coalescing tests and the unmodified focused tests pass, CI is green, and the current head is mergeable; this performance closure gap is the remaining blocker I found.
|
@XuPeng-SH Fixed in The MySQL tail path now builds SQL from Coverage now proves:
Validated with focused CDC tests and |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review complete on exact head 181c23daaf. The previous CDC amplification blocker is closed: atomic inserts are built from the ordered/deduplicated AtomicBatch row iterator, so the 8K pure range now stays bounded at both the sink-command and SQL-executor layers while preserving commit order and duplicate semantics. I rechecked clone/remap/quoting, tuple encoding, partition-tail ordering/atomicity, snapshot streaming, and error/cleanup paths; no remaining blocker found. Focused race stress (5 tests ×100), full owning-package race tests, build/vet, and the 8K benchmark all pass. The exact head merges cleanly with current main; CI is still running and was intentionally not awaited.
|
Queued — the merge queue status continues in this comment ↓. |
…t-review-20260727 # Conflicts: # pkg/frontend/clone.go # pkg/sql/compile/ddl.go # pkg/sql/compile/ddl_test.go
Merge Queue Status
This pull request spent 34 minutes 41 seconds in the queue, including 34 minutes 13 seconds running CI. Required conditions to merge
|
What this PR does / why we need it:
This PR completes Data Branch edge-case handling and the related CDC change-stream correctness work: it preserves semantic identifiers while cloning/restoring objects, handles snapshot/PITR and DIFF/MERGE boundaries safely, keeps complex values representable, and makes partitioned CDC snapshots and tails bounded and commit-order correct. The changes close data-loss, malformed-SQL, stale-metadata, and unbounded-memory risks that arise at those boundaries.
Summary
sqlquote.Identhelper.FullTextMatchExpr.Pattern; a direct-AST regression keeps the walker correct even though current SQL grammar admits only literal or parameterAGAINSTpatterns.CollectChangeswith a heap-frontier, cursor-based commit-timestamp merge: each timestamp is emitted only after all partitions contribute, without prefix copying or per-timestamp full-partition scans.st_geomfromtextoutput used by the implementation.Upstream sync and conflict resolution
Merged
upstream/mainthrough83a090b5d1.The two semantic conflicts both involved SQL string-literal construction. The resolution keeps the upstream package-level
quoteSQLStringLiteralhelper and routes the PR's branch-protect snapshot and foreign-key SQL through it, preserving apostrophe and backslash handling without duplicate package-local escape paths.The latest sync had one result-file conflict: upstream changed the BVT table-output layout while this PR corrected cloned-view SQL to quote identifiers. The merged result keeps the upstream layout and the PR's exact
create view \v1` as select * from `t1`;` expectation.The current sync had four code conflicts. PITR and snapshot foreign-key discovery now use the upstream shared
quoteSQLStringLiteralhelper. Connector and dispatch collided with upstream #26324, which already provides the centralResolvePipelineSpoolAbortErrorimplementation; the earlier duplicate PR-local pipeline implementation is intentionally absent from the final diff.The latest sync had one test-only conflict in
build_dml_util_test.go. It keeps this PR's FK string-literal escaping regressions and upstream #26330's ALTER COPY FK-transfer regression; the production implementation is upstream's single shared SQL-quoting path.The subsequent sync through
f6dab28046merged automatically. It includes upstream snapshot, DDL, parser, and plan changes without replacing this PR's branch/CDC behavior.The sync through
66142a6f7dmerged automatically. It contains the latest mainline frontend, aggregate, catalog, and plan work; this PR's final diff remains limited to its Data Branch and CDC scope.The latest sync through
52ea9f874fhad one semantic conflict with upstream #26292 (cyclic database-clone foreign keys). The result retains upstream's same-source-database reference rewrite to the destination schema, including forward references while foreign-key checks are scoped off, and retains this PR's sharedsqlquote.Ident/QualifiedIdentformatting. Thus circular FK metadata points at the cloned database without regressing quoted or special identifiers.The latest sync through
83a090b5d1merged automatically. It includes mainline HAKeeper, aggregate, plan/protobuf, and TAE updates without replacing this PR's branch or CDC behavior.Validation
go test ./pkg/container/typesgo test ./pkg/frontendgo test ./pkg/vm/engine/disttaego test ./pkg/cdcgo vet ./pkg/container/types ./pkg/frontend ./pkg/vm/engine/disttae ./pkg/cdc-race -count=5coverage for partition tail ordering, partition moves, bounded snapshots, and close-error cleanup.go test -count=1 ./pkg/frontend ./pkg/sql/plango vet ./pkg/frontend ./pkg/sql/plangit diff --checkLatest review closure
restoreViewswith the sharedsqlquote.Identhelper, including embedded backticks and whitespace.FullTextMatchExpr.Pattern; direct-AST coverage verifies a qualified pattern remaps fromsrc.docs.patterntodst.docs.pattern.search_patterngrammar accepts onlySTRING | VALUE_ARG;AGAINST(src.docs.pattern)is therefore not a valid user SQL input today.Shrinkand full-partition timestamp scan with a heap frontier and per-source cursors. The 8K regression uses eight interleaved partitions and checks every emitted commit timestamp and row.Tail_wipranges (at mostobjectio.BlockMaxRows, 8192 rows), so an 8K pure range produces one sink boundary instead of 8K commands. A timestamp containing both operations, or a change between operation kinds, remains aTail_doneboundary because the sink applies all deletes before all inserts and must not invert a later delete over an earlier insert for the same primary key.AtomicBatchordered and deduplicated row iterator rather than once per source batch. This keeps the temporal order, preserves the existingmaxSQLSizebound, and prevents an 8K pure range from becoming 8K downstreamExecSQLcalls.Latest focused validation
go test -count=1 ./pkg/frontend -run 'TestApplyRemapDbExpressionContainers|TestRemapDbInFullTextMatchPattern|Test_restoreViews'go test -count=1 ./pkg/frontendgo vet ./pkg/frontendgit diff --checkLatest CDC sink coalescing validation
(TS, PK)source rows also execute once, matchingAtomicBatch's existing deduplication contract.go test -count=1 ./pkg/cdc ./pkg/vm/engine/disttaego test -race -count=1 ./pkg/cdcfor atomic SQL construction, insert/delete handling, and the 8K processor range.go build ./pkg/cdc,go vet ./pkg/cdc, andgit diff --check.Current upstream-sync validation
go build ./pkg/vm/process ./pkg/sql/colexec/connector ./pkg/sql/colexec/dispatch ./pkg/frontendgo vet ./pkg/vm/process ./pkg/sql/colexec/connector ./pkg/sql/colexec/dispatch ./pkg/frontendgo test -count=1 ./pkg/vm/process ./pkg/sql/colexec/connector ./pkg/sql/colexec/dispatch ./pkg/frontendgo test -race -count=1 ./pkg/sql/colexec/connector ./pkg/sql/colexec/dispatchgit diff --check upstream/main...HEADCurrent CDC merge validation
go test -v -count=1 ./pkg/vm/engine/disttae -run 'TestCombined(TxnTable|Changes)'go test -race -count=1 ./pkg/vm/engine/disttae -run '^TestCombinedChangesHandleTailManyCommitTimestamps$'go test -count=1 ./pkg/vm/engine/disttaego test -run '^$' -bench BenchmarkCombinedChangesHandleTail8KDistinctCommitTimestamps -benchtime=1x ./pkg/vm/engine/disttaego vet ./pkg/vm/engine/disttaeCurrent CI closure
loadPendingPartition, resolving SCA/staticcheckSA4004without changing the one-read, empty-batch cleanup, or close semantics.pkg/tests/txnexecutor.TestPreparedParams, not a CDC or Data Branch assertion. Its log shows the embedded cluster's HAKeeper/raft request timeouts and connection-ID allocation failure. The branch already contains mainline#25869, which prevents a caller deadline from closing the shared HAKeeper client; no PR-local workaround is added for this non-reproducing cluster interruption.TestPreparedParamspassed three consecutive ordinary runs and three consecutive race-detector runs.go build ./pkg/vm/engine/disttae ./pkg/sql/plan ./pkg/frontend ./pkg/sql/compilego vet ./pkg/vm/engine/disttae ./pkg/sql/plan ./pkg/frontend ./pkg/sql/compilego test -count=1 ./pkg/vm/engine/disttae ./pkg/sql/plan ./pkg/frontend ./pkg/sql/compile-race8K partition-tail regression andgit diff --check.Latest conflict validation
go test -count=1 ./pkg/sql/plango test -count=1 ./pkg/frontend -run '^(TestCloneFkTableOrder|TestBackSessionInheritsForeignKeyChecks)$'go test -count=1 ./pkg/tests/issues -run '^TestIssue26111DataBranchDatabaseWithCyclicForeignKeys$'go vet ./pkg/sql/plan ./pkg/frontend ./pkg/tests/issuesgit diff --checkLatest CDC range validation
Tail_done; a two-block input emits exactly two bounded ranges.Tail_doneboundaries.DataProcessorreceives 8KTail_wip/final-Tail_doneinsert batches and sends exactly one sink output with 8K rows.go test -count=1 ./pkg/vm/engine/disttae ./pkg/cdc, focused-race,go build,go vet, andgit diff --check.Latest upstream conflict resolution
upstream/mainthrough2e68774061, including feat(frontend): support schema evolution in data branch diff/merge #25882's Data Branch schema-evolution work.Latest conflict validation
go test -count=1 -timeout 240s ./pkg/frontend ./pkg/sql/compilego test -count=1 -race ./pkg/sql/compile -run 'Test(PitrInternalSQLEscapesStringLiterals|PreparePitrPublicationSerializesCopyAlter|ResolveCurrentPitrObjectIDRefreshesPlannedTableID)$'go vet ./pkg/frontend ./pkg/sql/compileandgit diff --check.