Skip to content

fix: serialize CREATE INDEX with concurrent DDL and DML - #29235

Merged
XuPeng-SH merged 3 commits into
mainfrom
fix/28928-28931-index-ddl-races
Sep 23, 2026
Merged

XuPeng-SH merged 3 commits into
mainfrom
fix/28928-28931-index-ddl-races

Conversation

@aptend

@aptend aptend commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

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:

  • converts mo_tables lock refreshes into definition-change retries so a waiting CREATE INDEX rebuilds its plan and reruns duplicate-name validation;
  • acquires an exclusive definition-change fence on the base relation before index construction;
  • advances the transaction snapshot through the TN-ordered logtail read barrier while both locks are held, with an HLC/logtail fallback for rolling upgrades;
  • adds deterministic two-CN regression coverage for identical and different duplicate index definitions, regular-index UPDATE visibility, and conflicting unique-index updates;
  • covers the rolling-upgrade snapshot fence and its fail-closed boundaries with focused unit tests.

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/compile
  • changed-code coverage: 42/51 (82.35%), calculated by unioning the prior CI pr_coverage.out with the new full pkg/sql/compile coverage profile on identical block ranges
  • GOWORK=off go vet -mod=readonly ./pkg/sql/compile ./pkg/tests/issues
  • golangci-lint run -c .golangci.yml --new-from-rev $(git merge-base HEAD origin/main) ./pkg/sql/compile ./pkg/tests/issues

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH 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.

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.

@mergify mergify Bot added the queued label Sep 23, 2026
@mergify

mergify Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-23 05:28 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-23 05:51 UTC · at df40c7f398028052d650c0feeb79d04084a47ca3

This pull request spent 23 minutes 36 seconds in the queue, with no time running CI.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Reason

Pull request #29235 has been merged manually at *3ab5a06612d86ddf52b8c2877aa08e77a56b1b32*

Hint

You were too fast!

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 3ab5a06 into main Sep 23, 2026
28 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/28928-28931-index-ddl-races branch September 23, 2026 05:51
@mergify mergify Bot removed the queued label Sep 23, 2026
XuPeng-SH added a commit that referenced this pull request Nov 11, 2026
## 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]>

This branch was previously deployed

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

Labels

kind/bug Something isn't working kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants