Skip to content

fix: wait for View metadata catalog upgrade before CN admission - #28020

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

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

Conversation

@ck89119

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

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 @ 9f711e2134:

  • 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%.

@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 re-review on exact head 85a04f940e471c9e0e53681f74d928b6de06072b. The previous deadline-owner, transient-retry, stale-epoch, and final handoff TOCTOU blockers are closed. The publication/handoff mutex gives a real linearization point, mixed rollback failures remain fail-closed, and retry state/backoff are bounded.

[P1][startup correctness] Do not accept catalog admission after the automatic upgrade has already failed.

Both success paths in waitForViewMetadataAdmissionHandoff return directly from acceptViewMetadataAdmissionSnapshot (lines 347-350 and 423-425) without first observing bootstrapUpgradeResult. The result channel is only read in the later error/select paths. Therefore an already-buffered terminal BootstrapUpgrade error is lost whenever the View catalog is usable and the admission snapshot is valid.

I reproduced this deterministically on this exact head with a review-only Start-level test: BootstrapUpgrade returns a sentinel error; the lifecycle-gate executor waits until len(bootstrapUpgradeResult)==1, then returns a valid gate row. The upgrade failure is logged, but Start() returns nil and ingress becomes ready. It fails 20/20. This is reachable if the View catalog transaction committed and a later automatic-upgrade step failed, or if the catalog was already present while upgrade failed elsewhere.

Please make every successful admission/handoff transition reject an already-completed upgrade error (without unnecessarily turning the intentionally asynchronous successful upgrade into a synchronous startup dependency), and add this ordering as a deterministic regression. The existing failure test only keeps the catalog fence incomplete, so it necessarily reaches the select and misses this path.

No additional blocking lock-order, cancellation, retry-growth, catalog-presence, or performance issue was found. Exact-head CI is green; the review-only test was removed with its temporary worktree.

@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 re-review completed on exact head 0fb86760f8c49c3ed56734b0ad53d86a0d570858 against merge base 9f711e21346ff52aa082ccf86999c4cfb4f84943. I read every changed hunk and traced the complete BootstrapUpgrade owner -> catalog fence/retry -> authoritative snapshot publication -> final ingress handoff -> shutdown closure, including the delta since my prior CHANGES_REQUESTED review.

The previous P1 is closed. Terminal upgrade-result publication and admission acceptance now share the same linearization lock, and both the disabled and admitted success paths poll an already-published terminal error before acceptance. The deterministic Start-level regression proves that a failure buffered after the catalog becomes usable is returned instead of publishing ingress readiness; a still-running successful upgrade remains asynchronous.

No additional blocker was found:

  • correctness: partial-catalog states remain fail-closed, joined rollback failures are not retried, stale epochs/generations cannot open ingress, and the final listener handoff is linearized with heartbeat publication;
  • liveness/resources: the upgrade task, timer, and channels have terminal owners; stopper cancellation and the 120-minute owner context terminate waits; retries retain constant state;
  • performance/operations: heartbeat publication adds only a short constant-time mutex section, catalog retries use capped per-CN jittered backoff (max below 5s), and same-epoch heartbeats cannot bypass it. This reduces rather than amplifies the previous retry/log pressure.

Evidence: exact-head substantive CI is green, including Linux UT/SCA and standalone/compose BVT; author-provided exact-head focused normal/race and owning-package runs are semantically applicable; git diff --check passes. The isolated macOS worktree correctly refused to reuse a mismatched cgo/libmo.dylib, so that local prerequisite failure was not counted as test evidence. Current main has advanced only through unrelated clone files, so the reviewed dependency closure is unchanged.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants