Skip to content

feat: make temporary DDL transaction-independent - #28332

Merged
XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
iamlinjunhong:m-28255
Sep 7, 2026
Merged

XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
iamlinjunhong:m-28255

Conversation

@iamlinjunhong

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 #28255

What this PR does / why we need it:

feat: make temporary DDL transaction-independent

@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 exact head dced74ad89b656d884161afa33200b30b24234d8, including the design and full production diff. No confirmed blocking issue found.

The ownership split is coherent: only top-level user temporary CREATE uses an independently committed schema transaction; CTAS population and subsequent DML retain the original transaction and snapshot. DROP removes logical visibility and retires a unique physical generation rather than deleting storage underneath pending parent writes. Reclamation follows transaction finalization and retains failed identities for reset/disconnect/retry. This addresses the transaction contract without committing unrelated user data or advancing the permanent-data snapshot.

I checked staging-session aliases, original plan/process restoration, callback panic/error handling, committed-but-unpublished cleanup ownership, failed CTAS, same-name recreation, journal invalidation, hidden-index naming/cleanup, admission bounds, and idle/reset/migration ownership. The catalog fallback is limited to missing ordinary visibility and a committed temporary marker plus physical identity and matching tenant; DML timestamps are unchanged. Exact frontend session ownership controls the metadata-lock exemption, including hidden-index references. The schema/data split is guarded by the capability, while internal shared-transaction DDL retains its original behavior.

The public SQL cases cover CREATE/DROP rollback independence, unrelated permanent DML atomicity, DROP with buffered writes followed by COMMIT, generations, CTAS parent-workspace reads and failure, prepared CREATE, indexes, and permanent SI-snapshot preservation. Focused tests cover failure/ambiguous commit/panic restoration, reset failure without alias resurrection, retirement capacity, and CN/TN visibility exclusions. Reported normal/race and repeated real-service validation are relevant evidence, not substituted by a changed expected result alone.

Non-zero costs and boundaries remain important: CREATE adds an independent commit/logtail barrier; cleanup can delay an idle boundary up to its bounded deadline; retained roots consume admission capacity; uncommitted database generations are rejected; rollout must update CN/TN before activation and drain sessions before downgrade. This approval does not claim ALTER/TRUNCATE or every extension now has the same transaction contract. When rebasing alongside other pending v55 users, reserve the next available capability rather than reusing another feature's version.

Evidence in this review: source/design/test inspection and git diff --check. I did not rerun native suites, race tests or a multi-node deployment; the design's execution reports remain author evidence. No production changes were made during review.

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

mergify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-07 12:01 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-07 12:14 UTC · at 7b31fa7a4d242742493284dedc59657111c34396

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

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

Reason

Pull request #28332 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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 cc205f5 into matrixorigin:main Sep 7, 2026
20 of 22 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 7, 2026
mergify Bot pushed a commit that referenced this pull request Sep 7, 2026
### 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@0b195e4`; `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 #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@fdc1e0c`, 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@0b195e4`; 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.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#28255

## What this PR does / why we need it:

feat: make temporary DDL transaction-independent

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…28325)

### 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 matrixorigin#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@0b195e4`; `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 matrixorigin#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 matrixorigin#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 matrixorigin#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 matrixorigin#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 matrixorigin#28313 shuffle-pool failure, while its pessimistic BVT job reproduced the then-unresolved matrixorigin#28352 temporary-table ALTER failure; the aggregate Coverage failure was a consequence of those failed producers.

After rebasing onto upstream matrixorigin#28343's remote-bind convergence change and matrixorigin#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 matrixorigin#26404 regression and the adjacent matrixorigin#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 matrixorigin#28356's executor-owned temporary ALTER COPY transaction fix, which resolved matrixorigin#28352. A second `range-diff` remained unchanged; the eight focused frontend tests and both two-CN regressions were rerun on `main@fdc1e0c`, 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 matrixorigin#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@0b195e4`; 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.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#28255

## What this PR does / why we need it:

feat: make temporary DDL transaction-independent

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…28325)

### 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 matrixorigin#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@0b195e4`; `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 matrixorigin#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 matrixorigin#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 matrixorigin#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 matrixorigin#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 matrixorigin#28313 shuffle-pool failure, while its pessimistic BVT job reproduced the then-unresolved matrixorigin#28352 temporary-table ALTER failure; the aggregate Coverage failure was a consequence of those failed producers.

After rebasing onto upstream matrixorigin#28343's remote-bind convergence change and matrixorigin#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 matrixorigin#26404 regression and the adjacent matrixorigin#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 matrixorigin#28356's executor-owned temporary ALTER COPY transaction fix, which resolved matrixorigin#28352. A second `range-diff` remained unchanged; the eight focused frontend tests and both two-CN regressions were rerun on `main@fdc1e0c`, 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 matrixorigin#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@0b195e4`; 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.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#28255

## What this PR does / why we need it:

feat: make temporary DDL transaction-independent

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…28325)

### 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 matrixorigin#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@0b195e4`; `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 matrixorigin#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 matrixorigin#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 matrixorigin#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 matrixorigin#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 matrixorigin#28313 shuffle-pool failure, while its pessimistic BVT job reproduced the then-unresolved matrixorigin#28352 temporary-table ALTER failure; the aggregate Coverage failure was a consequence of those failed producers.

After rebasing onto upstream matrixorigin#28343's remote-bind convergence change and matrixorigin#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 matrixorigin#26404 regression and the adjacent matrixorigin#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 matrixorigin#28356's executor-owned temporary ALTER COPY transaction fix, which resolved matrixorigin#28352. A second `range-diff` remained unchanged; the eight focused frontend tests and both two-CN regressions were rerun on `main@fdc1e0c`, 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 matrixorigin#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@0b195e4`; 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.

Approved by: @XuPeng-SH

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

size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants