Skip to content

fix(sql): scope pessimistic RC DROP branch lifecycle by component - #29457

Closed
XuPeng-SH wants to merge 22 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29400-rc-current
Closed

XuPeng-SH wants to merge 22 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29400-rc-current

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement
  • Test and CI

Which issue(s) this PR fixes:

Fixes #29400 for pessimistic RC. This draft is stacked on #29393 and targets main for review, so the comparison includes the parent. The fix must be included in #29393 before that PR merges. Keep this PR draft while the parent's separate performance gate remains open.

What this PR does / why we need it:

  • The versioned RC lifecycle protocol defines C/G/D/K/T/Q ordering, component scope, account ownership, applied-frontier identity checks, exact-row lock capacity, rollback, and full maintenance cutover. Ordinary independent branch components use scoped shared admission. Cleanup of touched ALTER history compacts the complete affected lineage synchronously and retains G exclusive; it can delay unrelated DROP work.
  • RC COPY ALTER and TRUNCATE enter G exclusive before taking target table/storage locks and re-resolve physical relation identity after the TN-applied frontier. Existing shared-G holders and public TRUNCATE keep prompt ErrLockConflict. A transaction with earlier ordinary DML may wait on its first G acquisition; another lifecycle owner can be waiting for its retained lower lock. The lock service now submits each newly published wait dependency to its existing distributed deadlock detector immediately after releasing the physical lock-table mutex. The detector aborts one whole transaction with ErrDeadLockDetected, allowing the survivor to proceed. Periodic detection remains a bounded fallback when prompt submission is busy. This preserves normal waits such as generated DATA BRANCH DIFF replay without introducing a second wait graph or transaction marker.
  • RC multi-table DROP admits the complete persistent domain once at the first live persistent member, preserving preceding temporary/no-op SQL order and retry-safe retirement. Named-snapshot and subscription CLONE use the correct resolver, subscriber and publisher account identities. Four snapshot-view SQL changes now have matching .result fixtures; they retain the expected missing-table/database checks.

The current full comparison against main is +7,535/−1,071 (net +6,464) lines. That includes net +2,069 from stacked #29393 and net +4,395 from this RC series; across the full comparison, production Go is net +2,903 and Go tests net +2,982. Independent QA reviewed the large lifecycle and hot-path additions, including apparent frontend/compile similarities, and found no safe production deletion without weakening distinct transaction ownership or existing performance improvements. The current correction adds four production Go lines; the added SQL and lockservice tests cover two G modes, victim rollback, prompt detection, and the previously failing explicit-transaction control.

Verification and remaining gates

  • Focused two-CN lifecycle regression, full TestDataBranchDiffAsFile, selected lockservice deadlock/cancel/wait tests, and the prompt-detection test passed. The prompt test suppresses the lazy tick for 30 seconds and passed in normal and race modes; it fails as expected when the four-line production call is removed. All eight changed BVT SQL/result pairs passed the actual mo-tester parser. git diff --check passed. Independent QA and GPT-6 medium final review found no material blocker at this commit.
  • Full multi-CN BVT and contested-lock throughput have not been measured locally for this revision. Current CI is not claimed as acceptance and is intentionally not awaited. fix(sql): reuse ordered cleanup for DROP DATABASE #29393 still requires its separate 1,000/2,000-table, three-sample ≥25% end-to-end performance gate. First activation requires the approved full maintenance cutover with old writers drained and no mixed-version restart.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit-bound deep review · 3983ea44ad1

Reviewed the four issue commits 4233217baff..3983ea44ad1 after final rebase onto the current #29393 head. Verdict for the approved pessimistic RC + full maintenance cutover scope: no remaining confirmed production blocker. This is a COMMENT review by the PR author, not self approval. PR stays draft pending its CI and parent #29393.

The first component commit f4fdf1c7387 was REQUEST_CHANGES in independent Astra xhigh review. Two concrete findings were reproduced and fixed in 3983ea44ad1:

  1. Partitioned DATA BRANCH DELETE TABLE and DELETE DATABASE passed the outer branch-only receipt into internal partition child DROP, causing a false target-change error. The receipt is now shadowed only at the internal ps.Delete boundary. Both public SQL paths pass the new regression test.
  2. At max-row-lock-count=2, ordinary branch reclaim DML widened to a Range on the hidden mo_snapshots.snapshot_id index, blocking an interleaved unrelated branch until A committed. The corrected path exact-admits affected branch rows, bounds DML batches, and uses scoped exact-row locking for UPDATE/DELETE and their hidden index targets; capacity failure cannot upgrade to table/range. In the same low-budget interleaved A/B workload, B completed before A's explicit COMMIT and both catalog postconditions were zero. Focused lockop UT verifies row granularity, KeepRows and no fallback.

Final-head evidence: full frontend, compile, lockop and databranchutils package tests pass; seven selected real two-CN issue regressions pass; real service checks cover same-component exclusion, unrelated-component and cross-account progress, cancellation/rollback, KILL QUERY of a K waiter, and 1,000/2,000-table no-branch DROP smoke samples (5.46/15.01 seconds, rows zero). These single samples do not replace #29393's separate three-sample 25% performance gate.

The old-image protocol cannot safely mix online with this component protocol; deployment requires the approved full maintenance cutover. The prior #29393 performance review remains open and is not claimed resolved by this PR. A deliberately tiny lock budget can still expose an inherited mo_indexes range convoy for user tables with PK indexes; the component-specific low-budget witness uses no-PK tables to isolate its lock contract. Existing DDL INFO logs remain.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit-bound follow-up · 6b2818d5e69

Mergify merged current main into the draft branch after the reviewed issue commit 3983ea44ad1. I checked the added parent range: it changes CN bootstrap admission and fulltext planning/tests, with no edits to the #29400 protocol or its regression tests. On the actual new head, complete frontend, compile, lockop, databranchutils and cnservice package tests pass; the seven selected real two-CN issue regressions also pass. git diff --check is clean.

The RC/full-maintenance-cutover review verdict on 3983ea44ad1 remains unchanged: no confirmed blocker after closing the partition receipt and hidden-index widening findings. This is a COMMENT review by the author, not self approval. #29393 must include the #29400 fix before it merges, and its separate performance gate remains open; this draft PR is not an independent merge approval. New-head CI is still pending.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

CI update on head 6b2818d5e69: the earlier commit-bound no-blocker review is superseded by new required-check evidence. This draft is not ready.

  • Pessimistic multi-CN BVT and coverage UT expose a real branch-chain clone failure: a cloned source can retain DATA BRANCH CREATE as its original SQL, while RC FK-domain discovery expected a CREATE TABLE statement. The local correction uses normalized SHOW CREATE TABLE only for FK-bearing sources; both ordinary and FK-bearing second-generation branch clones now pass live SQL. BVT rerun is required.
  • Coverage UT also exposes TestIssue27040ConcurrentIfNotExistsDatabaseClone: ordinary CLONE still uses legacy terminal/global G-X admission while DATA BRANCH has moved to C/G-S plus scoped D/K. In an explicit first clone versus an autocommit second clone, the second holds G-X and waits target D; the first COMMIT fast-fails on G-X. This is a protocol integration blocker, not just an outdated lock-observation test. RC ordinary CLONE must join the component protocol; fix and discriminating rerun are in progress.
  • SCA found three dead legacy helpers and one preallocation issue; local cleanup is in progress. Coverage UT's TestCCPRGC also fails with lock table bind changed; main and fix(sql): reuse ordered cleanup for DROP DATABASE #29393 controls passed, so its attribution is under investigation.

The dependent #29393 performance acceptance remains separate and open. I will push a corrected commit and a new exact-head review only after these findings close.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit-bound review for ac9b8e6: PASS on the complete local diff against 6b2818d; independent Astra xhigh review found no unresolved concrete blocker. The previous CI failures were reproduced and fixed: FK-bearing second-generation branch cloning, ordinary RC CLONE lock protocol and IF NOT EXISTS target frontier, exact snapshot and target-table locks, valid lock-table bindings in the CCPR test fixture, and unused-helper SCA findings. Local selected two-CN issue tests (#27040 distinct-source target contention and missing-source no-op, #26113, #27055, #29400 FK branch), frontend/databranchutils/compile/lockop packages, and golangci-lint pass. Fresh exact-head CI is pending; this is not a CI-green claim. PR remains draft and depends on #29393 performance acceptance and the agreed maintenance cutover.

Pin catalog identity and TN-applied visibility before destructive DDL or local Snapshot/PITR publication. Recheck cross-database FK and publication scope after admission, retain commit conflict validation for branch lineage GC, and delay database branch reclaim until physical table cleanup has finished. Cover disjoint two-CN progress and stale-history failure paths.
Use nonwaiting global promotion and refresh relation identity for COPY ALTER and TRUNCATE. Defer complete multi-table DROP admission until the first live persistent member, retaining temporary-table order. Document the protocol and add two-CN and ordered DROP regressions.
Use the existing distributed deadlock detector after a wait edge is published, preserving normal waits for explicit transactions with prior DML locks. Cover both lifecycle gate modes, prompt submission, and paired snapshot fixtures.
@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Superseded by #29393 at c9451c221abc094f19354ebd4c5b97c3b84e600e. That PR includes all ten RC lifecycle commits from this draft, rebased after its latest parent repairs, plus the per-member branch-reclaim failure-boundary correction and an unrelated-component ALTER scan skip. Both source ranges were verified patch-equivalent before the follow-ups. Please review and merge #29393 as the single delivery path; this draft is closed to avoid duplicate review. New-head CI and deployment cutover validation are still pending, and #27575 remains open.

@XuPeng-SH XuPeng-SH closed this Sep 29, 2026
XuPeng-SH added a commit that referenced this pull request Sep 29, 2026
## Scope

Related to #27575 and #29400. Fixes #29395. Integrates the reviewed RC
lifecycle correction from #29457 into this PR.

- Keep `DROP DATABASE` cleanup in ordered per-table execution, including
temporary-table ownership, FK handling, failure boundaries, and
allocator deletion intent reconciliation after statement rollback.
- Use the RC lifecycle protocol with scoped
catalog/database/component/table admission, exact mutation rows,
applied-frontier identity revalidation, and transaction-owned locks. A
`DROP TABLE` in an unrelated database can finish while the target `DROP
DATABASE` waits for a slow table. RC multi-table `DROP TABLE` reclaims
branch state at each reached persistent member, preserving later
temporary-table failure boundaries. Unrelated ordinary components skip
repeated ALTER-lineage compaction scans. Retained shared-to-exclusive
lifecycle promotion fails promptly; ordinary prior DML cycles are
resolved by the distributed deadlock detector with whole-transaction
rollback and survivor progress.
- Preserve the View/deferred-FK correction, nil index-metadata error
handling, database-wide FK cleanup, bounded workspace point-read
optimization, and existing DDL/TN operation logs.

This does **not** establish the cause or resolution of #27575's
historical two-hour disconnect. ALTER-history cleanup still uses a broad
lifecycle gate. First activation of the RC protocol requires the
documented stop/drain/replace-all maintenance cutover; rolling old/new
writers are unsupported.

## Validation

- Current head `07bc41ffdb` retains base `main` at `d8152cb08d`; #29457
is integrated into this PR. The full branch retains the original parent
fixes and focused RC follow-ups.
- `make cgo`, full `pkg/sql/compile`, `pkg/sql/plan`, and
`pkg/incrservice` tests passed on the integrated code. On the current
cleanup revision, full `pkg/sql/compile` and `pkg/frontend` packages
pass with `-race`; focused compile/frontend tests and a real public SQL
RC database tail-reclaim fault test pass.
- Public SQL passed the retained-lock/deadlock-victim, disjoint database
progress, cancellation after table progress, statement rollback, branch
partition, and branch clone/FK cases. Added post-admission branch
mutation fault cases in both persistent/temporary orders, with statement
rollback followed by COMMIT, branch protection checks, and temporary
name reuse. The new three-actor check requires `DROP TABLE` in an
unrelated database to finish within 2 seconds while the target `DROP
DATABASE` remains blocked on a retained UPDATE table lock.
- Previous lockservice detector/race and snapshot SQL/result parser
checks remain applicable to unchanged code. The current public fault
test injects an RC `DROP DATABASE` reclaim failure after table cleanup.
It then commits prior statement work and verifies database tables,
branch metadata/snapshot, temporary alias, allocator usability, original
ISCP job identity and hidden table, and continued durable CDC tail
progress after a later INSERT. Before this correction, the same test
failed because a runtime ISCP fence survived statement-only rollback;
after statement-scoped fence cleanup, it passes in 42.24s. Full
`pkg/sql/compile -race`, focused local/remote fence tests including
5-run race checks, and changed-package `go vet` pass. Combined-head
multi-CN BVT and CI are not claimed as passed.

## Current integrated performance

The exact `c69187e0e3` base and integrated code before the branch-only
ordered-reclaim correction used the same Go 1.26.4/native inputs,
`GOAMD64=v3`, `GOEXPERIMENT=simd`, fresh one-CN clusters/data
directories, and alternating three-sample order at each scale. Setup was
excluded. Every sample checked the live table count, `SELECT 1` and
connection identity on one pinned connection, and zero
database/table/column/index catalog rows by saved database ID.

| Build | 1,000-table raw seconds | 2,000-table raw seconds | Median
1,000 / 2,000 |
| --- | --- | --- | --- |
| Exact base | 6.698, 6.713, 6.804 | 16.418, 16.497, 16.529 | 6.713 /
16.497 |
| Integrated head | 5.414, 5.360, 5.312 | 12.657, 12.665, 12.418 | 5.360
/ 12.657 |

Median improvement is **20.2% / 23.3%**, and the 2,000/1,000 growth
ratio improves from 2.458 to 2.361. This misses the original 25% target;
the revised delivery acceptance is measured improvement plus independent
progress when one target table is slow. A separate alternating
three-sample 1,000-table check found the integrated head 2.3% faster
than the parent-only revision. The later correction changes
branch-present `DROP TABLE` reclaim only; this plain-table `DROP
DATABASE` path is unchanged. These are controlled local results, not
production latency guarantees. Raw provenance and older nonpassing
rounds are in the [design
evidence](https://github.com/XuPeng-SH/matrixone/blob/codex/issue-27575-drop-database-serial/docs/design/20260926-drop-database-lifecycle.md).

## Review status

The latest #29393 external review's sole P1 prerequisite, integration of
#29457, is included in this branch. The latest parent View,
sparse-index, and redundant-FK-SQL comments remain fixed. This follow-up
removes test-only SI quota reading, impossible View errors, the
test-only single-table DROP wrapper, and its unreachable RC fallback.
Ordinary DML/SELECT no longer allocates temporary-DROP retry state.
Current RC protocol and archived design text are distinct. GPT-6 Astra
medium reviewed the follow-up cleanup and the new ISCP
statement-rollback correction with GO and no material blocker. New-head
CI, maintainer re-review, and deployment cutover validation are not
inferred from local tests.

The complete branch against its PR base changes 89 files, +8,008/−1,195
lines (net +6,813); production Go including generated code is
+3,620/−725 (net +2,895), Go tests +3,733/−431 (net +3,302), and docs
+380/−16 (net +364). The latest ISCP correction adds 128 and removes 28
lines (net +100): production net +14, focused tests net +84, and two
documentation lines. The existing public regression now checks durable
CDC consumer progress after rollback. This includes the parent
DROP/FK/allocator/read-path repairs and the full RC protocol, tests,
generated lock wire field, SQL fixtures, and design contracts. Exactly
ten child commits were imported without duplicating their inherited
parent history. ALTER-bearing members of one component can still require
fresh full-catalog scans; this path has not been separately benchmarked.

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/enhancement kind/test-ci size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Slow DROP DATABASE blocks unrelated database DDL on the global SNAPSHOT lifecycle gate

2 participants