Repository navigation
[4.2-dev] fix ODKU metadata ownership and parent-owned index drop - #29749
Conversation
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 13a8e134caac6647d8328686d9e3b0b094a3e1c2: APPROVE recommendation; no blocking findings.
- Design: scan-local
NotLockMetano longer mutates write-target references. ALTER reuses the existing parent-owned child deletion sequence, removing nested child metadata admission, duplicate CDC deletion and redundant relation lookup. No new state machine or blanket missing-table retry. - Correctness/unhappy paths: reviewed metadata admission before pipeline initialization, RC definition-change rebuild, transaction-owned auto-increment/table deletion, and failure-before-alias-cleanup ordering. Public controls cover commit, rollback, late admission, DDL-first, neighboring index preservation and qualified ALTER without a session database.
- Engineering/test quality: production +38/-29 (net +9), tests +533/-1, BVT +2, documentation unchanged. The test increment covers distinct contracts with one existing shared cluster, deterministic scheduling and bounded worker cleanup. The three prior local review findings are fixed.
- Performance: one ObjectRef copy per pessimistic INSERT scan during compilation; no per-row copy or added SELECT allocation. Removing nested SQL avoids its compilation/admission work. Aggregate throughput was not benchmarked, so zero performance regression is not claimed.
Validation evidence was checked against the unchanged source/log fingerprints: 43 race repetitions, related race consumers, BVT 97/97 and incremental SCA pass. Full compile-package race still fails three pre-existing Parquet assertions, reproduced on the exact baseline; the package passes with only those three excluded. Full unfiltered package success is not claimed. Remote CI was pending at review time.
At review time there were no human code-review threads, only the Qodo paused notice. This review was performed directly without subagents. Scope is this PR's ODKU/ALTER DROP INDEX correction.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Follow-up senior QA on 13a8e134ca: confirmed P2 historical gap in stale hidden-index generation handling. This narrows the earlier systemic-completion assessment; the original scan-alias and nested-DROP corrections remain valid. The new failure is also reproduced on the exact target baseline, so it is not identified as a regression introduced by this PR.
Trigger and actual result
- CN0 compiles
ALTER TABLE t ADD COLUMN z INT(COPY), orALTER TABLE t ADD INDEX keepidx(v)(INPLACE), whileukexists. Pause before parent metadata admission using the existing observational hook. - CN1 commits
ALTER TABLE t DROP INDEX uk. - Resume CN0. Both statements fail with 1146, old
__mo_index_unique_*table not found, instead of rebuilding against the new schema. A cancellation/recovery SQL probe also reached this failure. The deterministic reproduction does not require cancellation.
White-box root cause
alter.go:1089 and ddl.go:632 retain a parent definition-change retry result, but execution continues through old child relation resolution. alter.go:1108-1126 and ddl.go:647-659 treat ErrNoSuchTable as a terminal error, masking the pending replan. Both ALTER consumers need the same coherent generation/error contract.
Causal controls
- COPY reproduction also fails on pristine base
2e24395c2e, with all four changed compile source/test files restored and a selected DDL database. - Both current-head COPY and INPLACE fail under
-racewith observable barriers and unmodified lock results. - A read-only overlay reusing the main #27799 hidden-index generation classifier makes both tests pass under
-race. This is causal evidence, not a fully validated production backport.
Recommend narrowly reusing the existing generation classifier for both ALTER paths. Preserve errors for genuinely unchanged missing generations, and validate multi-table index identity and retry termination; do not blanket retry 1146 or wholesale backport unrelated #27799 changes. Under the requested systemic fix criterion, this adjacent failure needs an explicit correction or follow-up disposition.
Other new public QA controls passed under -race: DDL rollback restoring uniqueness and auto-increment continuation, prepared ODKU across DROP, nullable/composite unique mixed batches, multiple indexes dropped by one ALTER, neighboring index preservation, and temporary-table shadowing/rollback/repeated DROP without changing the persistent table.
Standalone DROP INDEX ... ON ... also bypasses the parent metadata wait in both current and baseline probes. Subsequent ODKU, commit and final row results succeeded; I am recording an admission-protocol difference, not claiming a demonstrated SQL/data bug from that observation. No throughput non-regression claim is made. PR source and commits were not changed; no subagent was used.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Review verdict: APPROVE — no verified new blocker in commit a83d102.
Black-box and white-box QA supplement:
- Public MySQL tests under -race pass same-transaction DML → standalone DROP INDEX lock upgrade, rollback/commit, exact 1062 UK/PK checks, auto-increment continuity and neighboring regular-index queries.
- Cross-CN prepared ODKU passes index DROP → rebuild → DROP, with row-count/value checks at each generation.
- Two concurrent DROP INDEX IF EXISTS statements queue behind a held writer, both terminate successfully, and subsequent index rebuild/drop succeeds.
- Lock ordering, transaction-owned release, serialized-vector/expression ownership and complete-pair cache publication show no new verified deadlock, leak or duplicate cleanup. No new SELECT/DML work is introduced by the standalone DROP admission gates.
- Reused matching-source evidence includes incremental SCA, compile normal/race, 25/20 concurrency repetitions, cancellation/temp-table QA and two complete DDL atomicity BVT rounds (97/97 each). Three proven baseline Parquet exclusions and six unchanged baseline molint diagnostics remain explicitly scoped.
Performance: isolated remote-lock ABBA comparison against preceding revision 7a161ca uses six samples per variant, 1000 operations per sample. Observed medians: UPDATE +3.55%, INSERT SELECT -0.49%, transaction UK ODKU +1.18%; untouched SELECT control +5.54%. No attributable DML regression was demonstrated. These local measurements do not guarantee fleet throughput, tail latency or universal zero regression. Standalone DROP pays two necessary admission gates; the small mixed DDL/DML run had large unchanged-control outliers and cannot reliably quantify that cost.
The partitioned standalone DROP INDEX UpdateConstraint/not-implemented failure is confirmed on the target baseline as well as this head. Per the author's explicit disposition, this historical P2 is outside the current fix and does not block this review; it is not claimed fixed.
GitHub does not allow authors to formally approve their own PR. This COMMENT records the APPROVE recommendation and completed QA evidence. No code commit or CI rerun is requested or performed.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review verdict: APPROVE recommendation for a83d102. No new verified blocking findings. Performed directly without subagents.
Design and ownership: Compile isolates scan-local ObjectRefs and owns existing plan rebuild; parent DDL owns hidden-child cleanup; LockMeta/expression executors own serialized keys; transactions own lock release. The change removes nested child DROP, duplicate CDC deletion and redundant relation lookup without introducing another state machine, storage path or execution framework.
Previous review requests are closed: COPY/INPLACE return parent definition-change retries before resolving stale hidden relations, and standalone pessimistic DROP joins parent catalog/storage admission before constraint reads and side effects. Deterministic public tests cover both ordering directions; unchanged-parent missing children still produce terminal 1146. There are no new unresolved inline code comments. The baseline partitioned standalone DROP UpdateConstraint P2 is explicitly excluded by the author's decision and is not claimed fixed.
Correctness/unhappy paths: commit/rollback, same-transaction lock upgrade, cancellation followed by progress, temporary-table shadowing, cross-CN prepared ODKU across index generations, concurrent IF EXISTS DROP and schema reuse were checked. No new verified lock-order cycle, leak or duplicate cleanup was found. Test hook access is synchronized; worker/barrier cleanup is bounded.
Increment reviewed separately: production +130/-101 (net29), Go tests +1006/-1 (net1005), BVT +2, tracked documentation0. The test growth covers distinct ownership/admission/generation/error contracts through lightweight UTs and one existing shared authenticated three-CN fixture, observable barriers and durable data/schema/error oracles.
Evidence reuse: latest head/base and all ten source fingerprints match the validated revision; sealed validation/QA log hashes were rechecked. Incremental SCA, owning compile normal/race, focused race repetitions, related public consumers and two complete DDL atomicity BVT rounds (97/97 each with teardown) remain valid. Three proven baseline Parquet exclusions and six unchanged molint diagnostics remain scoped; unfiltered full-suite success is not claimed. No redundant tests or CI reruns were initiated during this review.
Performance: shared metadata preparation reduces warm allocation work. The new standalone DROP admission gates do not execute on SELECT/DML; necessary restored metadata locking and INSERT scan copies remain part of the complete PR cost. Controlled measurements did not demonstrate an attributable latest-revision DML regression, but do not guarantee whole-PR zero regression versus base, fleet throughput or tail latency. The additional DROP lock cost was not reliably quantified by the noisy small-sample run. CI is still running and was not awaited.
GitHub prevents the PR author from approving their own PR; this COMMENT records the APPROVE recommendation.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review verdict: APPROVE recommendation (self-authored PR; COMMENT) on a83d102963c9f42d4ac5db78372c1c531e5396eb. Performed directly without subagents.
Ownership and design: existing Compile/transaction/LockMeta owners remain authoritative. Scan-local ObjectRefs are isolated, hidden-child deletion uses parent DDL ownership, and standalone pessimistic DROP now joins existing parent catalog/storage admission before schema reads and side effects. No duplicate state machine, storage path or execution framework is added.
Exact-head local race validation passes the four COPY/INPLACE standalone admission ordering cases and an independent authenticated three-CN MySQL challenge: held prepared ODKU -> observed DROP waiter -> server KILL QUERY -> rollback -> reuse the same prepared statement -> successful later standalone DROP -> replan and exactly-once row/value checks. The process completes20.024s. Earlier ALTER cancellation/ownership evidence and byte-matching source evidence were reconciled rather than relabeled as new runs.
Current increment: production +130/-101, Go tests +1006/-1, BVT +2, docs0. The tests cover distinct admission/generation/ownership/failure contracts through the existing shared fixture. Historical actionable requests are closed. The partitioned standalone DROP UpdateConstraint/not-implemented issue is accepted as a baseline exclusion by the author and is not claimed fixed.
Performance: warm metadata preparation reduces repeat allocation work; standalone DROP pays two necessary admission gates that do not execute on SELECT/DML. Scoped author measurements do not demonstrate an attributable latest-revision DML regression and do not establish whole-PR or fleet zero regression. Latest-head CI was still running at the review refresh.
GitHub prevents authors from formally approving their own PR. This submitted COMMENT records the completed review and APPROVE recommendation; it is not an independent GitHub APPROVE event.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29715 for
4.2-dev. The corresponding ownership corrections already exist on main (#27792 and #28265).What this PR does / why we need it:
Concurrent ODKU and
ALTER TABLE ... DROP INDEXcan lose write-target metadata protection on 4.2. INSERT scans share ObjectRefs with write contexts, so marking a scanNotLockMetain place also suppresses the base/index write targets' metadata locks.Restoring those locks alone is insufficient: ALTER's nested
DROP TABLEthen acquires child metadata after parent metadata, reversing DML admission order. A controlled public SQL test reproduces deadlock 20701 when only that old nested path is restored.Copy scan ObjectRefs before setting the scan-local flag. Base and hidden-index write targets retain their existing metadata admission and retry behavior.
Reuse the existing parent-owned DROP INDEX child cleanup sequence from both ALTER and standalone DROP INDEX. Preserve auto-increment cleanup, transactional deletion, temporary aliases and error propagation; remove the duplicate CDC drop call and redundant relation lookup.
Stop COPY and INPLACE ALTER as soon as parent/table admission requests a plan rebuild, before looking up hidden relations from the stale plan. Public concurrent DROP/ADD regressions verify schema and data; an unchanged missing child still terminates with 1146.
Close the historical standalone DROP INDEX admission gap: after resolving the parent, acquire its existing catalog Exclusive and storage definition-change locks before reading constraints, draining CDC or deleting index children. Either retry code immediately requests a fresh logical plan; terminal errors retain their identity. Optimistic transactions keep their prior path and IF EXISTS no-op remains early. No new state machine or per-row DML work is introduced.
Isolate the strict privilege-cache zero-allocation assertion in a bounded child process running the same race/coverage-instrumented test binary. This prevents preceding frontend tests' background workers from contributing to process-wide allocation counts; assertion failures and child coverage counters propagate to the parent.
Add two existing-session commit waits to the DDL atomicity BVT now that the missing metadata protection is restored.
Reuse serialized metadata keys within the existing LockMeta owner until its dependency set changes. Invalidate both key vectors on new membership and before freeing their expression executors; publish the pair only after both evaluations succeed. Preserve each catalog Relation.Reset, both lock admissions, ordering, single-database policy, retry behavior and Batch.SetVector allocation policy. Use one local borrowed batch view without adding persistent fields.
Complete production delta is +130/-101 (net +29 lines). This optimization itself removes six net production lines and adds 175 focused test/benchmark lines. It affects the shared metadata admission owner used by write paths, not only INSERT. No successful-lock cache, skipped catalog Reset, blanket missing-table retry or new lifecycle framework is introduced.
Performance
Standalone pessimistic DROP now pays two necessary parent admission gates; this fixes exclusion and stale-generation correctness, and is not advertised as a DROP latency improvement. SELECT/DML do not execute these new gates. The shared metadata preparation optimization remains unchanged.
Compared with the preceding PR revision
66b7d318, isolated warm metadata preparation removes 4–5 allocations and 256–384 bytes per call for 1/2/8 dependencies. Median preparation time decreases approximately 5–6%; this is an owner microbenchmark, not SQL throughput.Actual three-CN SQL benchmarks use eight independent ABBA processes, split by local versus remote catalog-lock ownership, with stable binding guards and final row/value checks. Local-lock write-path latency medians improve 0.2–2.4%; SELECT changes +0.7%. Remote-lock writes show no material regression, but untouched SELECT also improves 3.4%, so remote gains cannot all be attributed to this change. Initial mixed-owner results are invalidated, not used for acceptance. These measurements do not establish fleet, high-concurrency or tail-latency performance.
Validation
Validated on Linux/amd64, Go 1.26.4, against target base
2e24395c2e6e25d32a628abe663826178feff0a7, with this worktree's native CGo libraries.Original diagnostic workload: 10 rounds, two concurrent writers × 100 ODKU each; correct 20 rows and sum(v)=200 each round. The same probabilistic test also passed unfixed baseline, so causal evidence comes from the deterministic controls below.
Public three-CN regression for both ALTER and standalone DROP INDEX: commit, rollback, late writer admission/replan, and DDL admitted first; verify exactly-once results, removed unique-index catalog entry and continued operation of a neighboring regular index. Qualified ALTER and standalone DROP without a session database also pass.
Negative controls: unfixed baseline misses the held writer's base metadata lock; restoring only nested DROP makes the new DDL-first test fail with deadlock 20701.
Cleanup UT exercises relation lookup failure, auto-increment failure, delete failure, temporary success and persistent success, preserving unrelated aliases. The fixture uses a minimal process and starts no auto-increment background service.
go test -racepasses the new public tests and existing fulltext cancel/retry and prepared-statement replan consumers.Full compile-package race run has three pre-existing Parquet assertion failures, reproduced identically with all four changed compile source/test files restored to the target baseline. No race report occurred. The full package passes
-racewhen excluding exactlyTestCompileExternScanParquetLoadUsesRowGroupFanoutWithEmptyFiles,TestCompileExternScanParquetRowGroupFanoutValidatesEmptyFileColumnCount, andTestCompileExternScanParquetLoadUsesFileFanoutMainPath.Both stale-plan COPY ADD COLUMN and INPLACE ADD INDEX pass public multi-CN tests under
-race: a concurrent DROP commits before the old plan reaches parent admission, the ADD replans successfully, existing rows survive, and the removed unique constraint is not resurrected. The same tests require terminal 1146 for an unchanged parent with a missing child and roll back the diagnostic deletion. Each case also passes three repetitions for fixture/retry cleanup reuse.QA continuation also passes after canceling a metadata-blocked ALTER and rolling back the writer: subsequent ADD COLUMN succeeds with the original row intact. Temporary-table shadowing and DDL rollback remain isolated from the persistent table.
Frontend owning-package race and atomic-coverage runs pass. The isolated allocation assertion passes ten coverage repetitions; injected real allocations fail all 12 cells and propagate a nonzero child exit. The final coverage profile records 12,120 executions each of cache lookup and invalidation (10 × 12 × 101), proving child counters are included. Ten subprocess invocations take 0.465s locally; no production allocation or synchronization is added by this test fix.
Actual mo-tester run of the complete
pessimistic_transaction/ddl_atomicity.sqlpasses 100% golden validation.Incremental SCA:
go vetpasses; configured golangci-lint v2.6.2 reports 0 new issues; molint exits 0 with the same six recover diagnostics (five compile, one frontend) as a separate pristine baseline worktree, and no new diagnostics.Final frozen-source validation reruns compile normal/race with the same three explicit baseline exclusions; focused metadata reuse/failure coverage passes
-race -count=100. Tests decode actual serialized keys, check duplicate/new membership, separate account owners, Reset failure, either executor failure, complete-pair publication and owner cleanup/rebuild.Public normal/race consumers, INSERT SELECT self-scan/foreign-key/rollback, fulltext child cleanup and cross-database prepared UPDATE after schema refresh pass. The actual complete DDL atomicity BVT and incremental vet/configured lint/molint are rerun successfully on the final source. Existing unchanged frontend coverage/race evidence above is reused.
The tests change +1006/-1 lines across focused alias/cleanup UTs and one shared public cluster fixture; production net size and test size were reviewed separately. Design and final overall review use explicitly selected gpt-6.1-sol/xhigh. Local evidence is complete; CI for the updated revision remains pending and has not been awaited.
Standalone admission completion
The previous reviewed revision and an exact production-baseline overlay both reproduce the historical failure when standalone DROP commits after COPY/INPLACE ALTER already owns parent metadata: COPY panics with 20101 and INPLACE fails with internal delete-rowid duplicate 1062. Updated deterministic public tests now verify that DROP actually queues behind that parent before release, then both operations complete correctly. A separate pre-admission order still verifies stale-plan rebuild. Four COPY/INPLACE/order cases, schema/index/data checks and unchanged-parent missing-child 1146 are retained.
Focused gate UT covers both retry codes at either gate, terminal errors, real temporary aliases, qualified database and optimistic behavior. Additional QA exercises standalone temporary-index rollback/shadowing, server KILL QUERY while metadata-blocked (verifying waiter departure before writer release), subsequent DDL progress and IF EXISTS reuse. New concurrency tests use the existing three-CN fixture and lock-state probes, with bounded workers and cleanup joins.
New exact race repetitions pass: parent gate/error UT ×100, standalone admission ×25 and eight-order ODKU ×20, using measured per-test durations and a 30-second adaptive stress budget (cluster startup adds overhead). A client context cancellation alone is not treated as proof of server rollback; the cancellation oracle explicitly kills the server query and observes lock-wait termination.
The complete DDL atomicity mo-tester BVT passes twice on the same embedded instance, explicitly disabling fault injection, dropping db1 and verifying catalog absence after each round. Final source fingerprints cover all ten changed files; prior unchanged frontend coverage and metadata benchmarks are reused explicitly.