Repository navigation
fix: unblock 4.2 View metadata catalog upgrade - #27976
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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_refreshwhile 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
mainhas 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:
TestViewMetadataLifecycleSkipsInternalDatabasesBeforeCatalogProbeandTestV406UpgradeCreatesViewMetadataCatalogTables, 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.
Merge Queue Status
This pull request spent 16 minutes 24 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull 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.
HintYou 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. Tick the box to put this pull request back in the merge queue (same as
|
## 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]>
## 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>
…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]>
## 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>
…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]>
## 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>
…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]>
What type of PR is this?
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_dependenciesandmo_catalog.mo_view_refreshcould therefore access those tables before the catalog closure was available and abort CN startup.This PR:
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/upgradego vet -mod=readonly ./pkg/sql/compile ./pkg/bootstrap/versions/v4_0_6 ./pkg/tests/upgrade