Repository navigation
fix: serialize CREATE INDEX with concurrent DDL and DML - #29235
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.
Reviewed the exact head and full implementation/test diff. The catalog-owner lock is followed by a base-table definition fence, and the RC snapshot refresh is ordered through the logtail barrier (with a fail-closed rolling-upgrade fallback); retrying after definition-change lock conflicts rebuilds the plan and duplicate-name validation. Deterministic multi-CN tests cover same/different duplicate indexes and DML visibility/conflicts. No blocking findings.
Merge Queue Status
This pull request spent 23 minutes 36 seconds in the queue, with no time running CI. Waiting for any of
All conditions
ReasonHintYou were too fast! Tick the box to put this pull request back in the merge queue (same as
|
## What type of PR is this? - [x] BUG - [x] Test and CI ## Which issue(s) this PR fixes: Fixes #32244 ## What this PR does / why we need it: Backport the CREATE INDEX synchronization from #29235 to `4.2-dev` and apply the corresponding snapshot handoff to in-place `ALTER TABLE ... ADD INDEX`. A writer that commits after index DDL planning must be visible to the backfill; a stale writer admitted after publication must replan and maintain the new index. The change takes the existing catalog and base-table definition locks, rebuilds on metadata conflicts, and advances the pessimistic-RC workspace snapshot through the TN's ordered logtail barrier before backfill. For rolling upgrades, the CN checks the capability advertised by its actual logtail peer. If the TN does not advertise the barrier, or the CN protocol is below 11, index DDL keeps the earlier snapshot behavior without an additional HLC wait. Errors or interrupted negotiation do not select this fallback. The barrier-based handoff applies when the peer advertises support and protocol 11 is enabled; a manually pinned lower protocol continues legacy behavior. Existing behavior is accepted while legacy nodes or transactions remain, and an index corrupted before or during that interval needs separate detection and repair. This PR targets production pessimistic RC and does not claim to repair optimistic/SI behavior or partitioned tables. The existing morpc activity test is also made deterministic by observing responses and using an isolated test socket. ## Validation - Go 1.26.4, Linux/amd64: authenticated three-CN/one-TN pessimistic-RC regressions under `-race` cover concurrent index DDL, CREATE/ALTER, regular and unique indexes, stale UPDATE admission, same-transaction writes, rollback and cancellation. Physical hidden-index keys are compared with base rows. - Full `-race -short` owning packages: `pkg/sql/compile`, `pkg/vm/engine/disttae`, and `pkg/vm/engine/tae/logtail/service`; the changed morpc test passed under `-race`. A deterministic old-peer replacement test passed `-race -count=100`. - Actual official 4.2.6 and 4.2.7 binaries in both directions (new CN / old TN and old CN / new TN): fresh bootstrap, CREATE INDEX and ALTER ADD INDEX succeeded and hidden keys matched base rows. One CN also survived 4.2.6 → candidate TN → 4.2.6 reconnects with index-key checks at each step; after upgrading the TN, fault-gated CREATE/ALTER plans included an intervening committed writer. These are mixed-version smoke checks, not a guarantee for concurrent legacy transactions. - `gofmt`, incremental `go vet`, repository-pinned `golangci-lint` v2.6.2 (zero incremental issues), and pinned `molint` passed for the affected closure. `molint` also reports existing `checkrecover` positions outside the changed hunks. Generated logtail protobuf is byte-identical to regeneration. - With a 4.2.6 TN and a configured 500 ms clock offset, a local two-row CREATE INDEX microbenchmark measured median 515.63 ms with the earlier HLC fallback and 13.93 ms with this legacy path (six samples each, ABBA). This measures the upgrade path only. Earlier testing on the prior base measured 14.03 ms base versus 17.95 ms with this PR for a cold lock binding, and 12.55 ms versus 12.40 ms for a warm binding (40 tiny-table samples per arm); these single-host measurements do not establish general throughput or a broad regression bound. - CI test synchronization: the tenant-upgrade unit test observes completion of its mock transaction instead of relying on a 20 ms deadline. The cross-CN dropped-user test fences the committing CN, confirms deletion on the receiving CN, then retains the old-session denial check. This checks authorization after visibility; it does not claim instantaneous cross-CN revocation. - CI-specific checks: bootstrap regression under `-race -count=50`, the full authorization parent test under `-race` and coverage compilation, and incremental vet and golangci-lint v2.6.2 for both affected test packages passed. The issues package has no instrumented statements, so that local `-cover` run is not a full coverage measurement. New CI is pending. --------- Co-authored-by: aptend <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
issue #28928
issue #28931
What this PR does / why we need it:
Concurrent CREATE INDEX plans can become stale between planning and lock acquisition. Two same-name builds could both publish, and a build could scan a snapshot that predates an UPDATE committed on another CN.
This PR closes both handoff gaps:
Validation:
.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 ./pkg/sql/compile.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run "^TestIssue289(28|31)" ./pkg/tests/issues.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -run "^TestIssue289(28|31)" ./pkg/tests/issues.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestAdvanceCreateIndexSnapshot(UsesRollingUpgradeFence|FailsClosed)$' ./pkg/sql/compile42/51 (82.35%), calculated by unioning the prior CIpr_coverage.outwith the new fullpkg/sql/compilecoverage profile on identical block rangesGOWORK=off go vet -mod=readonly ./pkg/sql/compile ./pkg/tests/issuesgolangci-lint run -c .golangci.yml --new-from-rev $(git merge-base HEAD origin/main) ./pkg/sql/compile ./pkg/tests/issues