Skip to content

fix: unblock 4.2 View metadata catalog upgrade - #27976

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
ck89119:issue-27967-main
Sep 1, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
ck89119:issue-27967-main

Conversation

@ck89119

@ck89119 ck89119 commented Sep 1, 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 #27967

What this PR does / why we need it:

The generic View metadata lifecycle hooks probed the lifecycle catalog before checking whether the mutated database was internal. During a 4.2-to-main bootstrap upgrade, creating mo_catalog.mo_view_dependencies and mo_catalog.mo_view_refresh could therefore access those tables before the catalog closure was available and abort CN startup.

This PR:

  • skips internal/system databases before every database-scoped View lifecycle probe or cleanup;
  • passes database identity into dropped-View/database helpers so the owner boundary enforces the same invariant;
  • adds focused coverage for every skipped database and same-shape mutation path while retaining a user-database control;
  • adds a real embedded-engine catalog upgrade test for neither/one/both lifecycle-table states plus failed-attempt rollback and retry convergence.

The main-to-4.2 HAKeeper rollback described in the issue remains unsupported and is not changed by this focused forward-upgrade fix.

Validation:

  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/sql/compile
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/bootstrap/versions/v4_0_6
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/tests/upgrade
  • go vet -mod=readonly ./pkg/sql/compile ./pkg/bootstrap/versions/v4_0_6 ./pkg/tests/upgrade

@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 on exact head 65c57a0a2fc60150837f626aade321bae35947d5.

Root cause and fix:

  • The forward 4.2 -> main upgrade creates mo_catalog.mo_view_dependencies / mo_view_refresh while DDL lifecycle hooks are active. Those hooks used to probe the same catalog tables before checking whether the target database is internal, so bootstrapping the tables could fail before the upgrade closed the dependency.
  • This change moves the internal-database guard ahead of availability probing, locking, and SQL for all six database-scoped lifecycle helpers. I traced CREATE/ALTER/DROP table/view, DROP DATABASE, and restore/recovery call sites; no database-scoped DDL path bypasses those guards.

Correctness / counterexamples checked:

  • Internal databases: every skipped database and every helper is covered; no lifecycle SQL is issued.
  • User databases: the control case still performs the availability probe, so this does not disable normal metadata maintenance.
  • Partial catalog states: neither table, either table alone, and both tables converge correctly.
  • Injected second-table creation failure rolls back the first table; retry creates both, avoiding a half-upgraded catalog.
  • Latest main has no overlapping file changes with this PR, so the exact-head evidence remains applicable although the branch is currently behind.

Unhappy path / lifecycle:

  • Q1: no new owned resources; upgrade transaction rollback/commit ownership remains explicit.
  • Q2: no new goroutine, channel, lock cycle, or wait path; early return happens before lifecycle locks.
  • Q3: no unbounded state or retry loop is introduced. The hot-path cost is one existing map lookup on DDL only, while internal DDL avoids catalog probe SQL.

Validation:

  • Exact-head required CI is green, including Ubuntu UT, arm64 SCA, coverage, PROXY BVT, and pessimistic multi-CN BVT.
  • Focused local tests passed: TestViewMetadataLifecycleSkipsInternalDatabasesBeforeCatalogProbe and TestV406UpgradeCreatesViewMetadataCatalogTables, including rollback-and-retry.

Scope note: this fixes the forward catalog-upgrade failure. The separately reported main -> 4.2 HAKeeper-command incompatibility is not fixed here, consistent with the PR scope; it does not invalidate this focused fix.

No blocking correctness, performance, or unhappy-path issue found.

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

mergify Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-01 21:47 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-01 22:04 UTC · at 47b1149182da496713e60ed15f0617336391e1c1

This pull request spent 16 minutes 24 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 #27976 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.

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 3f6856c into matrixorigin:main Sep 1, 2026
20 of 21 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 1, 2026
@ck89119
ck89119 deleted the issue-27967-main branch September 2, 2026 03:09
XuPeng-SH added a commit that referenced this pull request Sep 3, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue #27967

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

PR #27976 prevented internal catalog DDL from entering the generic View
metadata lifecycle hooks, but CN startup could still race the
asynchronous v4.0.6 same-version offset upgrade. Admission attempted to
fence the lifecycle catalog before `mo_view_dependencies` and
`mo_view_refresh` were committed, then startup teardown canceled the
upgrade owner and repeated the same failure on restart.

This PR keeps CN ingress closed while that catalog closure is
unavailable:

- verifies that the `mo_view_refresh` lifecycle gate row exists before
writing the revalidation marker, so
neither/only-dependencies/only-refresh states remain unadmitted;
- recognizes typed missing-table/database readiness through production
`errors.Join` rollback wrappers while mixed rollback failures remain
fail-closed;
- ties catalog admission to the automatic upgrade owner's 120-minute
context and propagates the actual terminal `BootstrapUpgrade` error
instead of masking it behind HAKeeper discovery timeout;
- retries child fence deadlines, `ErrTxnNeedRetry`, and
`ErrTxnNeedRetryWithDefChanged` only while that upgrade owner remains
live;
- classifies every joined error leaf, so a retryable primary error
combined with a permanent rollback error still fails closed;
- keeps the upgrade owner alive until the startup catalog dependency is
resolved, so a slower-than-discovery catalog DDL is not canceled by
`Start` teardown;
- retries with bounded exponential backoff and stable per-CN ±20%
jitter; heartbeat updates cannot bypass that backoff;
- retains the shorter HAKeeper discovery deadline when no automatic
upgrade owner exists;
- revalidates the authoritative generation/epoch after every successful
fence, preventing an older admitted snapshot from opening ingress after
heartbeat publishes a newer non-admitted epoch;
- linearizes authoritative snapshot publication with the final
post-listener ingress handoff; updates before the handoff must be
validated, while updates after it observe startup ownership released and
perform their own catalog fence;
- keeps the automatic upgrade owner alive through that final handoff, so
an epoch change while listeners start cannot fall back to the shorter
discovery deadline;
- serializes terminal upgrade-result publication with admission
acceptance, so an already-completed `BootstrapUpgrade` failure wins over
both catalog-ready success paths without waiting for a still-running
successful upgrade;
- adds deterministic Start-level convergence/failure tests, a blocked
stale-epoch handoff test, real embedded-engine fence/upgrade overlap,
and two-CN/partial-catalog/timeout/rollback-wrapper coverage.

The main-to-4.2 HAKeeper rollback remains unsupported and is not changed
by this forward-upgrade fix.

Validation on `0fb86760f8` after merging `mo/main @ 9f711e2`:

- buffered terminal-upgrade failure regression: normal and race
`-count=50`: PASS;
- combined terminal-failure, owner-deadline, and final-handoff
regressions: normal and race `-count=30`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/sql/compile`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/cnservice`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=20m
./pkg/cnservice`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/tests/upgrade`: PASS;
- `go vet -mod=readonly ./pkg/sql/compile ./pkg/cnservice
./pkg/tests/upgrade`: PASS;
- every touched production function has at least 75% focused coverage;
terminal-result polling is 100%, final snapshot acceptance is 86.4%,
admission wait is 83.3%, bootstrap is 92.7%, and `Start` is 77.5%.

---------

Co-authored-by: XuPeng-SH <[email protected]>
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
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#27967

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

The generic View metadata lifecycle hooks probed the lifecycle catalog
before checking whether the mutated database was internal. During a
4.2-to-main bootstrap upgrade, creating
`mo_catalog.mo_view_dependencies` and `mo_catalog.mo_view_refresh` could
therefore access those tables before the catalog closure was available
and abort CN startup.

This PR:

- skips internal/system databases before every database-scoped View
lifecycle probe or cleanup;
- passes database identity into dropped-View/database helpers so the
owner boundary enforces the same invariant;
- adds focused coverage for every skipped database and same-shape
mutation path while retaining a user-database control;
- adds a real embedded-engine catalog upgrade test for neither/one/both
lifecycle-table states plus failed-attempt rollback and retry
convergence.

The main-to-4.2 HAKeeper rollback described in the issue remains
unsupported and is not changed by this focused forward-upgrade fix.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/sql/compile`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/bootstrap/versions/v4_0_6`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/tests/upgrade`
- `go vet -mod=readonly ./pkg/sql/compile
./pkg/bootstrap/versions/v4_0_6 ./pkg/tests/upgrade`

---------

Co-authored-by: XuPeng-SH <[email protected]>
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
…ixorigin#28020)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#27967

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

PR matrixorigin#27976 prevented internal catalog DDL from entering the generic View
metadata lifecycle hooks, but CN startup could still race the
asynchronous v4.0.6 same-version offset upgrade. Admission attempted to
fence the lifecycle catalog before `mo_view_dependencies` and
`mo_view_refresh` were committed, then startup teardown canceled the
upgrade owner and repeated the same failure on restart.

This PR keeps CN ingress closed while that catalog closure is
unavailable:

- verifies that the `mo_view_refresh` lifecycle gate row exists before
writing the revalidation marker, so
neither/only-dependencies/only-refresh states remain unadmitted;
- recognizes typed missing-table/database readiness through production
`errors.Join` rollback wrappers while mixed rollback failures remain
fail-closed;
- ties catalog admission to the automatic upgrade owner's 120-minute
context and propagates the actual terminal `BootstrapUpgrade` error
instead of masking it behind HAKeeper discovery timeout;
- retries child fence deadlines, `ErrTxnNeedRetry`, and
`ErrTxnNeedRetryWithDefChanged` only while that upgrade owner remains
live;
- classifies every joined error leaf, so a retryable primary error
combined with a permanent rollback error still fails closed;
- keeps the upgrade owner alive until the startup catalog dependency is
resolved, so a slower-than-discovery catalog DDL is not canceled by
`Start` teardown;
- retries with bounded exponential backoff and stable per-CN ±20%
jitter; heartbeat updates cannot bypass that backoff;
- retains the shorter HAKeeper discovery deadline when no automatic
upgrade owner exists;
- revalidates the authoritative generation/epoch after every successful
fence, preventing an older admitted snapshot from opening ingress after
heartbeat publishes a newer non-admitted epoch;
- linearizes authoritative snapshot publication with the final
post-listener ingress handoff; updates before the handoff must be
validated, while updates after it observe startup ownership released and
perform their own catalog fence;
- keeps the automatic upgrade owner alive through that final handoff, so
an epoch change while listeners start cannot fall back to the shorter
discovery deadline;
- serializes terminal upgrade-result publication with admission
acceptance, so an already-completed `BootstrapUpgrade` failure wins over
both catalog-ready success paths without waiting for a still-running
successful upgrade;
- adds deterministic Start-level convergence/failure tests, a blocked
stale-epoch handoff test, real embedded-engine fence/upgrade overlap,
and two-CN/partial-catalog/timeout/rollback-wrapper coverage.

The main-to-4.2 HAKeeper rollback remains unsupported and is not changed
by this forward-upgrade fix.

Validation on `0fb86760f8` after merging `mo/main @ 9f711e2`:

- buffered terminal-upgrade failure regression: normal and race
`-count=50`: PASS;
- combined terminal-failure, owner-deadline, and final-handoff
regressions: normal and race `-count=30`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/sql/compile`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/cnservice`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=20m
./pkg/cnservice`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/tests/upgrade`: PASS;
- `go vet -mod=readonly ./pkg/sql/compile ./pkg/cnservice
./pkg/tests/upgrade`: PASS;
- every touched production function has at least 75% focused coverage;
terminal-result polling is 100%, final snapshot acceptance is 86.4%,
admission wait is 83.3%, bootstrap is 92.7%, and `Start` is 77.5%.

---------

Co-authored-by: XuPeng-SH <[email protected]>
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
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#27967

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

The generic View metadata lifecycle hooks probed the lifecycle catalog
before checking whether the mutated database was internal. During a
4.2-to-main bootstrap upgrade, creating
`mo_catalog.mo_view_dependencies` and `mo_catalog.mo_view_refresh` could
therefore access those tables before the catalog closure was available
and abort CN startup.

This PR:

- skips internal/system databases before every database-scoped View
lifecycle probe or cleanup;
- passes database identity into dropped-View/database helpers so the
owner boundary enforces the same invariant;
- adds focused coverage for every skipped database and same-shape
mutation path while retaining a user-database control;
- adds a real embedded-engine catalog upgrade test for neither/one/both
lifecycle-table states plus failed-attempt rollback and retry
convergence.

The main-to-4.2 HAKeeper rollback described in the issue remains
unsupported and is not changed by this focused forward-upgrade fix.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/sql/compile`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/bootstrap/versions/v4_0_6`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/tests/upgrade`
- `go vet -mod=readonly ./pkg/sql/compile
./pkg/bootstrap/versions/v4_0_6 ./pkg/tests/upgrade`

---------

Co-authored-by: XuPeng-SH <[email protected]>
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
…ixorigin#28020)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#27967

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

PR matrixorigin#27976 prevented internal catalog DDL from entering the generic View
metadata lifecycle hooks, but CN startup could still race the
asynchronous v4.0.6 same-version offset upgrade. Admission attempted to
fence the lifecycle catalog before `mo_view_dependencies` and
`mo_view_refresh` were committed, then startup teardown canceled the
upgrade owner and repeated the same failure on restart.

This PR keeps CN ingress closed while that catalog closure is
unavailable:

- verifies that the `mo_view_refresh` lifecycle gate row exists before
writing the revalidation marker, so
neither/only-dependencies/only-refresh states remain unadmitted;
- recognizes typed missing-table/database readiness through production
`errors.Join` rollback wrappers while mixed rollback failures remain
fail-closed;
- ties catalog admission to the automatic upgrade owner's 120-minute
context and propagates the actual terminal `BootstrapUpgrade` error
instead of masking it behind HAKeeper discovery timeout;
- retries child fence deadlines, `ErrTxnNeedRetry`, and
`ErrTxnNeedRetryWithDefChanged` only while that upgrade owner remains
live;
- classifies every joined error leaf, so a retryable primary error
combined with a permanent rollback error still fails closed;
- keeps the upgrade owner alive until the startup catalog dependency is
resolved, so a slower-than-discovery catalog DDL is not canceled by
`Start` teardown;
- retries with bounded exponential backoff and stable per-CN ±20%
jitter; heartbeat updates cannot bypass that backoff;
- retains the shorter HAKeeper discovery deadline when no automatic
upgrade owner exists;
- revalidates the authoritative generation/epoch after every successful
fence, preventing an older admitted snapshot from opening ingress after
heartbeat publishes a newer non-admitted epoch;
- linearizes authoritative snapshot publication with the final
post-listener ingress handoff; updates before the handoff must be
validated, while updates after it observe startup ownership released and
perform their own catalog fence;
- keeps the automatic upgrade owner alive through that final handoff, so
an epoch change while listeners start cannot fall back to the shorter
discovery deadline;
- serializes terminal upgrade-result publication with admission
acceptance, so an already-completed `BootstrapUpgrade` failure wins over
both catalog-ready success paths without waiting for a still-running
successful upgrade;
- adds deterministic Start-level convergence/failure tests, a blocked
stale-epoch handoff test, real embedded-engine fence/upgrade overlap,
and two-CN/partial-catalog/timeout/rollback-wrapper coverage.

The main-to-4.2 HAKeeper rollback remains unsupported and is not changed
by this forward-upgrade fix.

Validation on `0fb86760f8` after merging `mo/main @ 9f711e2`:

- buffered terminal-upgrade failure regression: normal and race
`-count=50`: PASS;
- combined terminal-failure, owner-deadline, and final-handoff
regressions: normal and race `-count=30`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/sql/compile`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/cnservice`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=20m
./pkg/cnservice`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/tests/upgrade`: PASS;
- `go vet -mod=readonly ./pkg/sql/compile ./pkg/cnservice
./pkg/tests/upgrade`: PASS;
- every touched production function has at least 75% focused coverage;
terminal-result polling is 100%, final snapshot acceptance is 86.4%,
admission wait is 83.3%, bootstrap is 92.7%, and `Start` is 77.5%.

---------

Co-authored-by: XuPeng-SH <[email protected]>
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
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#27967

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

The generic View metadata lifecycle hooks probed the lifecycle catalog
before checking whether the mutated database was internal. During a
4.2-to-main bootstrap upgrade, creating
`mo_catalog.mo_view_dependencies` and `mo_catalog.mo_view_refresh` could
therefore access those tables before the catalog closure was available
and abort CN startup.

This PR:

- skips internal/system databases before every database-scoped View
lifecycle probe or cleanup;
- passes database identity into dropped-View/database helpers so the
owner boundary enforces the same invariant;
- adds focused coverage for every skipped database and same-shape
mutation path while retaining a user-database control;
- adds a real embedded-engine catalog upgrade test for neither/one/both
lifecycle-table states plus failed-attempt rollback and retry
convergence.

The main-to-4.2 HAKeeper rollback described in the issue remains
unsupported and is not changed by this focused forward-upgrade fix.

Validation:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/sql/compile`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/bootstrap/versions/v4_0_6`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/tests/upgrade`
- `go vet -mod=readonly ./pkg/sql/compile
./pkg/bootstrap/versions/v4_0_6 ./pkg/tests/upgrade`

---------

Co-authored-by: XuPeng-SH <[email protected]>
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
…ixorigin#28020)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#27967

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

PR matrixorigin#27976 prevented internal catalog DDL from entering the generic View
metadata lifecycle hooks, but CN startup could still race the
asynchronous v4.0.6 same-version offset upgrade. Admission attempted to
fence the lifecycle catalog before `mo_view_dependencies` and
`mo_view_refresh` were committed, then startup teardown canceled the
upgrade owner and repeated the same failure on restart.

This PR keeps CN ingress closed while that catalog closure is
unavailable:

- verifies that the `mo_view_refresh` lifecycle gate row exists before
writing the revalidation marker, so
neither/only-dependencies/only-refresh states remain unadmitted;
- recognizes typed missing-table/database readiness through production
`errors.Join` rollback wrappers while mixed rollback failures remain
fail-closed;
- ties catalog admission to the automatic upgrade owner's 120-minute
context and propagates the actual terminal `BootstrapUpgrade` error
instead of masking it behind HAKeeper discovery timeout;
- retries child fence deadlines, `ErrTxnNeedRetry`, and
`ErrTxnNeedRetryWithDefChanged` only while that upgrade owner remains
live;
- classifies every joined error leaf, so a retryable primary error
combined with a permanent rollback error still fails closed;
- keeps the upgrade owner alive until the startup catalog dependency is
resolved, so a slower-than-discovery catalog DDL is not canceled by
`Start` teardown;
- retries with bounded exponential backoff and stable per-CN ±20%
jitter; heartbeat updates cannot bypass that backoff;
- retains the shorter HAKeeper discovery deadline when no automatic
upgrade owner exists;
- revalidates the authoritative generation/epoch after every successful
fence, preventing an older admitted snapshot from opening ingress after
heartbeat publishes a newer non-admitted epoch;
- linearizes authoritative snapshot publication with the final
post-listener ingress handoff; updates before the handoff must be
validated, while updates after it observe startup ownership released and
perform their own catalog fence;
- keeps the automatic upgrade owner alive through that final handoff, so
an epoch change while listeners start cannot fall back to the shorter
discovery deadline;
- serializes terminal upgrade-result publication with admission
acceptance, so an already-completed `BootstrapUpgrade` failure wins over
both catalog-ready success paths without waiting for a still-running
successful upgrade;
- adds deterministic Start-level convergence/failure tests, a blocked
stale-epoch handoff test, real embedded-engine fence/upgrade overlap,
and two-CN/partial-catalog/timeout/rollback-wrapper coverage.

The main-to-4.2 HAKeeper rollback remains unsupported and is not changed
by this forward-upgrade fix.

Validation on `0fb86760f8` after merging `mo/main @ 9f711e2`:

- buffered terminal-upgrade failure regression: normal and race
`-count=50`: PASS;
- combined terminal-failure, owner-deadline, and final-handoff
regressions: normal and race `-count=30`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/sql/compile`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/cnservice`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=20m
./pkg/cnservice`: PASS;
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m
./pkg/tests/upgrade`: PASS;
- `go vet -mod=readonly ./pkg/sql/compile ./pkg/cnservice
./pkg/tests/upgrade`: PASS;
- every touched production function has at least 75% focused coverage;
terminal-result polling is 100%, final snapshot acceptance is 86.4%,
admission wait is 83.3%, bootstrap is 92.7%, and `Start` is 77.5%.

---------

Co-authored-by: XuPeng-SH <[email protected]>

This branch was previously deployed

1 inactive deployment
ci — 47b11491 Deployed Sep 1, 2026 by mergify[bot] via Matrixone Utils CI / Coverage #49980
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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants