Skip to content

fix(frontend): order composite lineage lifecycle locks - #28325

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26404-de1d2434
Sep 7, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26404-de1d2434

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Sep 7, 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:

Related to #26404

What this PR does / why we need it:

Root cause

Mixed DATA BRANCH and CLONE workflows used inconsistent lock order. DIFF, PICK, MERGE, and ordinary CLONE could first acquire catalog/view/object locks and only later enter nested scratch/restore/drop paths that acquire the existing lineage-owner lifecycle row lock. Concurrent DROP, SNAPSHOT, and branch operations acquire the lineage lock first and then catalog/view/object locks. Across CNs these two orders can form a distributed wait cycle even when the business database names are independent.

The previous revision of this PR tried to merge the view and lineage gates. That changed the restore catalog contract and caused both unit and broad BVT regressions when mo_feature_registry was unavailable in tenant/PITR restore contexts. This revision restores the two existing gates and corrects only composite-operation admission order.

Changes

  • Add one shared mutation-admission helper that acquires the existing lineage-owner lifecycle lock before composite autocommit work starts.
  • Admit table/database CLONE and DATA BRANCH DIFF/PICK/MERGE before endpoint/catalog resolution.
  • Reacquire the lineage lifecycle lock when database-clone target-lock retry restarts its owned transaction.
  • Preserve existing explicit user-transaction validation and ownership semantics.
  • Add deterministic two-CN regression coverage plus focused admission/retry failure-path unit tests.
  • Update the existing concurrent IF NOT EXISTS clone regression to observe the new leading lineage lifecycle gate while preserving its transaction-order and result assertions.

Issue-to-test proof

TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock runs authenticated SQL through a real two-CN cluster. It uses lock-service waiter barriers rather than timing sleeps and covers:

  • database CLONE with table data, full-text index, and view metadata while an unrelated database DROP runs;
  • DIFF while an unrelated database DROP runs;
  • PICK and MERGE with a destination-row conflict while an unrelated database DROP waits on the lineage gate;
  • completion, result correctness, and unrelated-drop visibility after every interleaving.

The exact external regression set from #26404 was also run for 20 rounds at concurrency 9: 200/200 cases and 4,840/4,840 statements passed, with no deadlock or 20701 in runner/server logs.

Validation

  • rebased cleanly onto main@0b195e4f5a; git range-diff confirms both issue commits are unchanged
  • focused frontend admission and retry tests, including rollback/begin/gate error propagation
  • TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock: -count=3
  • TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock: -race -count=1
  • TestIssue27040ConcurrentIfNotExistsDatabaseClone: -count=3
  • TestIssue27040ConcurrentIfNotExistsDatabaseClone: focused frontend coverage mode and -race -count=1
  • full ./pkg/catalog ./pkg/frontend/databranchutils ./pkg/sql/compile ./pkg/frontend after the shared SNAPSHOT/View-gate change landed
  • full ./pkg/frontend
  • full ./pkg/tests/issues
  • exact adjacent regressions: TestIssue26087ConcurrentDataBranchQuota, TestIssue26640AccountPITRUsesCatalogRestoreHandlers, and TestIssue28317ViewSnapshotGateOrderSQL
  • go vet ./pkg/frontend ./pkg/tests/issues with the repository CGo environment
  • make build
  • exact ten-case MOTR command from [Bug]: concurrent mixed DATA BRANCH workflows deadlock across independent databases #26404 with --repeat 20 -j 9
  • temporary_table_clone BVT after the temporary-DDL transaction change: 166/166 statements passed with JDBC metadata ignored
  • git diff --check

After upstream #28322 unified SNAPSHOT -> View locking, the shared lock packages, frontend/compile packages, the real two-CN issue test, all three adjacent regressions, and the race case were rerun successfully. After upstream #28332 made temporary DDL transaction-independent, focused/full frontend and compile tests, the real two-CN issue test, make build, and the existing 166-statement temporary-clone BVT were rerun. The local machine has JDK 17 rather than the tester-required JDK 8: normal BVT comparison reported 12 JDBC display-width-only differences, each inspected against the SQL and expected data/DDL/error semantics; -n then proved all 166 semantic results. No result file was regenerated or changed.

The old-head Ubuntu UT, UT coverage, and pessimistic multi-CN BVT failures in workflow run 34098109436 all traced to the discarded shared-gate revision; local exact regression tests pass with this revision. They are not unrelated CI blockers.

Workflow run 34125753066 exposed one stale assertion in the existing #27040 regression: it still expected the second clone to wait at the target mo_database key, but this PR intentionally admits clone at the lineage lifecycle gate first. Commit d71f4dbd updates only that observation point; the original early-return, commit-order, uniqueness, and payload assertions remain intact. The same job also reproduced the unrelated #28313 shuffle-pool failure, while its pessimistic BVT job reproduced the then-unresolved #28352 temporary-table ALTER failure; the aggregate Coverage failure was a consequence of those failed producers.

After rebasing onto upstream #28343's remote-bind convergence change and #28096's frontend MEMBER OF support, the eight focused frontend admission/retry/error-path tests and the full pkg/frontend package passed. The real two-CN #26404 regression and the adjacent #27040 clone regression each passed three normal runs and one race run, validating the current lockservice dependency rather than reusing the older topology evidence. Main then advanced with #28356's executor-owned temporary ALTER COPY transaction fix, which resolved #28352. A second range-diff remained unchanged; the eight focused frontend tests and both two-CN regressions were rerun on main@fdc1e0ca8f, with three normal runs per regression and a combined race run passing.

Pre-rebase workflow run 34150466865 passed Linux UT, coverage UT, SCA, Proxy and pessimistic multi-CN BVT, and aggregate Coverage; the remaining completed jobs were successful, neutral, or intentionally skipped. Main then added only #28355's correlated scalar-aggregate planner optimization. A third range-diff remained unchanged, and the eight focused frontend tests plus both real two-CN regressions passed on main@0b195e4f5a; the existing race evidence remains valid because neither the PR's synchronization code nor its lockservice dependency changed.

Residual risk

The corrected order intentionally serializes these composite autocommit workflows at the existing global lineage lifecycle boundary for their owned transaction. The 20-round exact workload completed without stalls. Explicit user-transaction behavior is unchanged and is outside the reported autocommit workload.

@mergify mergify Bot added the kind/bug Something isn't working label Sep 7, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 7, 2026
@gouhongshen
gouhongshen force-pushed the agent/issue-26404-de1d2434 branch from 5259954 to e63439a Compare September 7, 2026 10:30
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Sep 7, 2026
@gouhongshen gouhongshen changed the title fix(catalog): unify metadata lifecycle gate fix(frontend): order composite lineage lifecycle locks Sep 7, 2026
@gouhongshen
gouhongshen force-pushed the agent/issue-26404-de1d2434 branch from e63439a to 4177b2b Compare September 7, 2026 11:15
@gouhongshen
gouhongshen force-pushed the agent/issue-26404-de1d2434 branch from 4177b2b to 4acf574 Compare September 7, 2026 13:08
@gouhongshen
gouhongshen force-pushed the agent/issue-26404-de1d2434 branch from 9abab31 to 2d82020 Compare September 7, 2026 17:54
@gouhongshen
gouhongshen force-pushed the agent/issue-26404-de1d2434 branch from 2d82020 to c7c66bb Compare September 7, 2026 18:09
@gouhongshen
gouhongshen marked this pull request as ready for review September 7, 2026 19:05
@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.

Deep review completed for d71f4db against 0b195e4. No blocking issue found.

Read all six changed files and traced public/nested CLONE and DIFF/PICK/MERGE admission, background/shared transaction ownership, target-lock retry, and final commit/rollback. This is a lock-order bug fix reusing existing catalog gates, not a new persistent/protocol design.

The leading lineage gate is taken before endpoint/catalog resolution in owned transactions. A replacement transaction reacquires it before retrying the target key; the retry remains bounded to one and excludes shared/data-branch-owned transactions. Admission errors finish/close the owned executor; explicit CLONE preserves its original transaction authority, while explicit DATA BRANCH retains commit-time validation.

Audit closure Result
Q1 executor/transaction ownership Factory failure closes locally; admission failure invokes finalizer; success transfers one finalizer to caller.
Q2 lock order / retry Owned composite work follows lineage -> view/catalog/object; retry re-enters the leading gate. Shared transactions are not rolled back by the new retry helper.
Q3 retained work No new queue/cache/background worker; one bounded retry. Tests have bounded contexts and operation joins.

The tests retain result/uniqueness/commit-order assertions while changing the #27040 waiter observation to the new leading gate. The new real two-CN scenarios exercise clone/view/fulltext, DIFF, and destination conflicts for PICK/MERGE against unrelated DROP. Reused the author's current-base normal tests, semantically current race/topology evidence, full-package runs and exact 20-round external workload rather than claiming a new run. The documented JDBC metadata-only limitation is not represented as a strict BVT pass.

The broader serialization at the existing global gate is an explicit correctness tradeoff, supported by the concurrent workload evidence; it is not a claim of unchanged peak clone throughput. A future finer-grained optimization should preserve the same lock-order proof. Approval is for this exact head.

@mergify

mergify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-07 22:15 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-07 22:15 UTC · at 62770aedaa0cf3b5613bb7a42371bb08ef14ed5c · squash

This pull request spent 15 seconds in the queue, including 1 second running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

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 size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: temporary-table ALTER loses auto-increment metadata in Compose+Proxy BVT

3 participants