Skip to content

fix(cnservice): preserve bootstrap ownership through admission handoff - #29450

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
ck89119:issue-29396-admission-main
Sep 28, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
ck89119:issue-29396-admission-main

Conversation

@ck89119

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

Fixes #29396

What this PR does / why we need it:

After an interrupted upgrade, repairing the view metadata catalog does not necessarily complete CN admission. HAKeeper may still be draining the previous generation. The CN previously switched back to the shorter discovery deadline as soon as catalog fencing succeeded, even though its bootstrap owner was still waiting for the startup handoff. This could abort recovery after the catalog upgrade had completed, before SQL became ready.

This change:

  • Keeps the existing bounded bootstrap-owner context responsible for the entire admission handoff once authority has been discovered, including the interval after catalog repair.
  • Continues observing owner cancellation and rechecks the owner before accepting a snapshot under the admission mutex. An already-cancelled owner cannot publish ingress while its terminal result is still pending.
  • Preserves concrete upgrade errors, discovery bounds without an owner/authority, generation fencing, protocol checks, and catalog/admission gates. It does not increase default timeouts or bypass old-generation draining.

The new lightweight testing/synctest regressions cover catalog commit followed by delayed admission, preparing/enabled epochs, initialization/ingress/derived-definition callers, owner failure/cancellation/deadline/completion, superseded generations, and bounded discovery. They use virtual time and quiescence barriers rather than real-time sleeps to win scheduling races.

Validation

The delivered patch is the same two-file change validated on main 239fe81c82ae07a8c316576cac8555c445c92212, using Go 1.26.4 and matching Linux/arm64 native artifacts:

  • Regression red/green: eight post-catalog-commit cases failed on the unmodified implementation; the final suite passes.
  • pkg/cnservice: whole-package normal/coverage and race runs passed through .agents/skills/mo-dev/scripts/mo-cgo-test (GOMEMLIMIT=off for the existing memory-limit test's initial-state assumption).
  • Eight individually selected admission/owner concurrency tests passed -race -count=100 each, selected using measured durations; no repeated whole-package stress.
  • HAKeeper controls passed: TestViewMetadataAdmissionReplacementKeepsOldGenerationUntilTimeout, TestViewMetadataAdmissionCleanRestartSkipsOldGenerationTimeout, and TestViewMetadataAdmissionPreparingWaitsForReplacedGenerationTimeout.
  • Incremental vet, golangci-lint 2.6.2 built with Go 1.26.4 (using the complete delivery patch, including the new test), gofmt, and diff checks passed.
  • Changed-production-line-intersecting coverage blocks: 22/22 statements hit. Whole CN package coverage: 66.3%; these are distinct measurements.

Actual interrupted-upgrade validation

Old binary: 4.2-dev 1a44f3db3056e32975fde86ca0ab69a094996a3f.
Main baseline: 239fe81c82ae07a8c316576cac8555c445c92212 (final catalog 4.0.9 / offset 1 / state 2).

The old binary naturally created a 4.0.6/offset-5 catalog, a user table with two sentinel rows, and a view. GDB killed the actual single LOG/TN/CN launch process at the v4.0.8 cluster-upgrade entry, before its repair DDL. No upgrade records were manually seeded. Each recovery run started from a separate copy of the same never-recovered interrupted data.

Scenario Unmodified baseline Patched binary
Default configuration: normal upgrade and subsequent restart Pass Pass
Default configuration: first recovery after interruption and another restart Pass in this run Pass
Deterministic delayed-generation control: CN store timeout 45s, discovery unchanged at 30s Admission timeout; SQL never ready First recovery SQL-ready at 49.169s after process launch; subsequent restart passes

The 45s value is a valid test-instance HAKeeper configuration, identical for both binaries, not a product-default change or an increased CN discovery timeout. The baseline also failed under a diagnostic GDB run: its local and authoritative catalog-fenced epochs were already 1, while generation 101 was still preparing and not admitted after capturing the previous ready generation 1.

Passing scenarios checked MySQL readiness, both catalog tables, the user table/view rows, completed non-duplicate upgrade steps, and stable catalog table IDs across the next restart. The patched binary SHA256 is 62bb3df8c2d171b1704e7aa807334d91d4137220bc1e576a816310fadb4fd6da.

Validation after merging the latest target branch

The PR branch now merges mo/main at d99187d7b3bfda8744088b3ae8cf16739b690aa0 (remote merge commit 9ea665b7a0a24785b770e3858bfdd1185d38a21d). Validation used an independently produced local merge commit 19f7ace0de7a9366da96aa2a3e2c3ff0c66a246d; both commits have the exact same Git tree 112c154d7351b38789282aa7203d9479186f7d63 (no source/config/test difference). The current binary, built with Go 1.26.4 on Linux/arm64, has SHA256 996c8e3b18ff5b42ed960f1287115db010d8a80886c9697d0553d78d947bdd4c. The target catalog is now 4.0.10 / offset 1 / state 2, including protocol 100 and the new system-view upgrade.

  • On this merged revision, the entire pkg/cnservice package passed normal/coverage (66.3%) and race runs via the repository CGo wrapper, -count=1 in both modes. GOMEMLIMIT=off preserves the initial-state assumption of an existing memory-limit test.
  • Actual 4.2-dev → merged-main normal upgrade and subsequent restart passed (first SQL-ready after 25.805s).
  • Starting with 4.2-dev's naturally generated 4.0.6/offset-5 data, GDB terminated the merged-main binary at its v4.0.8 cluster-upgrade entry before DDL. The resulting interrupted catalog has a 4.0.10 final target. Separate, never-recovered copies of that same checkpoint both reached SQL-ready on the first recovery, under default configuration (33.432s) and with HAKeeper CN-store timeout set to 45s while CN discovery stayed at its 30s default (49.269s). Each subsequently restarted successfully.
  • All passing runs checked both mo_view_* catalog tables, stable IDs over restart, the two original user table/view rows, final catalog state, and exactly four complete, nonduplicate upgrade steps through 4.0.10. The 45s runtime reports CNStoreTimeout=45000000000 in its log; product defaults are unchanged.

Separate failure boundary: Reusing the older checkpoint generated while the previous main was targeting 4.0.9 does not pass when upgraded directly to 4.0.10: the framework intentionally rejects a different version still marked upgrading (cannot upgrade to version 4.0.10, because version 4.0.9 is in upgrading). We retained that failing evidence and did not bypass the guard or claim support for cross-target interrupted upgrades. The passing interruption above was performed by the current merged binary itself. Original QA data and multi-CN topology remain untested; no CI result is claimed.

@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 of 9ea665b7a0a24785b770e3858bfdd1185d38a21d against merge-base d99187d7b3bfda8744088b3ae8cf16739b690aa0. APPROVE: no blocking findings in this change. Reviewed directly; no subagents.

Design and correctness

The fix addresses a real ownership gap: committing the catalog fence does not complete startup admission. HAKeeper can still legitimately be draining the previous generation. Falling back to the shorter discovery deadline at that point abandons a still-active bootstrap operation.

Keeping the existing bootstrap owner responsible until the final handoff is coherent. This is an ordinary corrective change, not a new state machine requiring a separate feature design. It adds no protocol/configuration, alternate admission path, or timeout increase. The 120-minute owner bound already exists; absent authority/no active owner retain the discovery bound.

I traced Start -> bootstrap context/result publication -> local admission/system-view initialization -> final ingress acceptance -> startup-ready notification, plus heartbeat/HAKeeper replacement-generation handling. Successful bootstrap result publication waits for startup-ready, so normal owner completion cannot prematurely remove ownership between these startup phases. Old-generation draining, epoch fencing and persisted-expression protocol checks remain in force.

Cancellation is checked both at loop entry and under the admission mutex before acceptance. An already-buffered concrete failure takes precedence over cancellation. Error rollback still belongs to Start/closeService; stopper cancellation, result-channel capacity, epoch-fence close, scoped catalog transaction timeout and retry-timer cleanup remain bounded. No new goroutine, unbounded queue, retry fan-out or background resource owner is introduced.

Independent QA and evidence

Locally on Darwin/arm64, Go 1.26.4, with verified matching native inputs:

  • Eight focused tests passed under race detection: the three new regression groups, final-ingress linearization, both real Start bootstrap-error tests, system-views-before-ingress, and an independent reviewer probe.
  • Each of the three new regression groups separately passed -race -count=100: TestCNViewMetadataAdmissionOwnerAfterCatalogCommit, TestCNViewMetadataAdmissionDiscoveryRemainsBounded, and TestCNViewMetadataAdmissionCancelledOwnerCannotPublishIngress.
  • Independent TestReviewerAdmissionOwnerAtLockedAcceptance separately passed -race -count=100. It queues acceptance behind the admission mutex, cancels the owner while acceptance is blocked, then releases the mutex. Oracle: no ingress publication and cancellation returned; with a buffered concrete upgrade failure, that error wins. The otherwise-identical live-owner control accepts. This tests a later cancellation boundary than cancel-before-entry. The probe is review-only, not a production/PR modification.

Exact-head CI run 36411062934 passed. I checked the UT checkpoint artifact: the successful light race stage explicitly selects cnservice and HAKeeper, rather than inferring package coverage from the rollup alone. Reused the author's reported Linux package/upgrade evidence after verifying the reported final validation tree matches this head's tree 112c154d7351b38789282aa7203d9479186f7d63; those upgrade experiments were not independently rerun here.

Performance, engineering and limits

Production changes are small (+27/-11): startup-only context/result checks, with no SQL execution hot-path change. Existing retry backoff and notification coalescing are retained. Longer startup during legitimate generation draining is the intended correctness behavior, not a claimed query-performance improvement. The new lightweight synctest cases cover distinct ownership/timeout/generation boundaries without introducing an embedded-cluster fixture.

There were no previous human reviews or inline review comments to resolve; the only existing PR comment is the review-bot subscription notice.

Approval is for this bounded admission-handoff fix, not proof that every interrupted-upgrade history is recoverable. Upgrade CI jobs were skipped, not passed. Original issue #29396's retained QA data and actual multi-CN interrupted-upgrade recovery remain unverified. The author also explicitly reports that an already-in-progress upgrade targeting 4.0.9 cannot simply be resumed by a 4.0.10-target binary due to the existing framework guard; this patch does not change that contract. Preserve these limits when declaring the original incident fully resolved.

@mergify mergify Bot added the queued label Sep 28, 2026
@XuPeng-SH
XuPeng-SH merged commit 3fe37b3 into matrixorigin:main Sep 28, 2026
46 of 54 checks passed
@mergify

mergify Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-28 11:58 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-09-28 11:58 UTC · at 9ea665b7a0a24785b770e3858bfdd1185d38a21d

This pull request spent 28 seconds in the queue, with no time running CI.

Reason

Pull request #29450 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

@mergify mergify Bot added dequeued and removed queued labels Sep 28, 2026
@ck89119
ck89119 deleted the issue-29396-admission-main branch September 28, 2026 12:02
mergify Bot pushed a commit that referenced this pull request Sep 29, 2026
Complete the S1 implementation-gating design against the current on-demand implementation already merged in #29139, rather than rebuilding the superseded durable-refresh architecture.

- Map 17 consumer boundaries and classify all current `Type`, `ColDef`, and `mo_columns` fields as authoritative definition state, derived output, or physical compatibility data. Include the `SELECT * FROM view LIMIT 0` catalog shortcut, column-count SHOW, prepared/cached/cursor paths, subscriptions, and the actual unsupported boundaries of COM_FIELD_LIST and View DUMP TABLE.
- Specify one read-only inference/provenance contract, statement-local ownership and memoization, snapshot/own-DDL behavior, frozen stars, legacy definitions, authorization, invalid-view errors, and historical system-template adaptation.
- Make the raw-catalog choice explicit: direct `mo_columns` reads retain physical/MVCC compatibility semantics and are not a current View-schema interface. Record the required reconciliation with #26227's earlier persistence-oriented acceptance criteria.
- Define numeric resource/performance budgets, benchmark cases, mixed-version activation and rollback restrictions, and the shared admission/protocol/snapshot protections that must survive refresh retirement.
- Map remaining work and evidence to S2–S9; cross-request caching remains conditional and separately reviewed. No older issue is edited or closed by this change.

### Exact design revision and approval

- Commit: `371e3c1761dab22dff95d0e830caab31aa46eeeb`.
- [Reviewed design: v2.0-draft.1](https://github.com/ck89119/matrixone/blob/371e3c1761dab22dff95d0e830caab31aa46eeeb/docs/design/CLAUDE_20260922-view-metadata-on-demand.md).
- Design SHA-256: `f8cd0a71d59c37d14bb6dc964e968d4c68b0d95b01cb6a371f597c1eb6ea0120`.
- [Approval and self-review record](https://github.com/ck89119/matrixone/blob/371e3c1761dab22dff95d0e830caab31aa46eeeb/docs/design/CLAUDE_20260928-view-metadata-s1-review.md).

The requester approved this exact revision after the design and the four material choices (raw-catalog compatibility, legacy rejection, rollback restrictions, and numeric budgets) were presented. The approved design bytes are frozen; its pre-approval wording is intentionally retained, with the subsequent APPROVED status recorded separately. This is a task-session approval record, not a claimed GitHub review vote or production rollout approval.

### Validation and delivery scope

- Documentation only: two Markdown files; no production, test, generated-code, or configuration changes.
- `git diff --check` and staged-diff checks passed.
- Lightweight document checks passed: 35 local file links, 21 consistent Markdown tables, balanced code fences, numbered sections, 17 consumer entries, and 10 decisions.
- Field-inventory checks cover 9 `Type`, 22 `ColDef`, and 27 `mo_columns` fields; the approved design checksum matches the approval record.
- Updated the branch to `mo/main` at `3fe37b311df718eb7b369513cd6d615b10b04092` and reviewed the complete #29450 increment. Its bootstrap-owner/admission fix preserves the shared protections required by this design; no design-contract change was needed.
- Go tests, BVT, race, mixed-binary/restore tests, and benchmarks were not run for this documentation-only change. Their required evidence remains assigned to the implementation phases; historical #29139 results are not relabeled as fresh validation.

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

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.

[Bug]: retrying interrupted 4.2→main upgrade stalls on missing mo_view_refresh

3 participants