Skip to content

fix(cn): wait for admitted query inventory before SQL startup - #29526

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/29476-startup-admission
Sep 30, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/29476-startup-admission

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement
  • Test and CI

Which issue(s) this PR fixes:

Fixes #29476

What this PR does / why we need it:

CN startup checked raw self registration before bootstrap, then started SQL acceptance before the final ingress-ready heartbeat and admission-aware local inventory converged. SELECT 1 could succeed while a query requiring the current CN failed placement because the current incarnation was absent from the candidate pool.

Reuse the existing bounded self-readiness loop with explicit raw/query phases. Keep raw registration before bootstrap; start internal query/pipeline endpoints, perform the existing ingress admission handoff, wake the existing heartbeat worker, and require a successfully refreshed admission-aware snapshot containing the current UUID/address/commit/generation before starting SQL acceptance. Keep the bootstrap owner alive until this handoff completes and propagate its failure/cancellation during convergence. Existing admission and placement checks remain authoritative.

No new persistent readiness state, scheduling path, background worker, configuration or wire format. Cost is confined to startup: one additional authoritative refresh plus bounded retries while the ready heartbeat converges; query/DML paths have no added work. SQL sockets are already bound during initialization; accepting connections/handshakes waits for convergence. Startup failure follows existing rollback.

Reproduction and limits

A clean-base public regression starts two CNs, observes admission enabled through an independent HAKeeper client, then adds a CN with a one-hour periodic inventory refresh interval. Without refreshing its CN inventory through SHOW BACKEND SERVERS, SELECT 1, DDL, INSERT and IVF index creation succeed, but the first ordinary IVF query fails required-current-cn-outside-pool. The raw row is pending and the admitted pool contains only the original CNs. The same query returns IDs 1, 2 with this fix.

A synchronized Start regression also fails on the base: SQL startup completes before authoritative query-candidate convergence. With the fix, pipeline/ingress/heartbeat publication precedes convergence, while SQL acceptance stays closed; timeout and upgrade failure terminate the blocked refresh and clean up exactly once.

The exact historical clean two-CN / zero-eligible-worker incident was not reproduced. Two initial clean-start controls passed with a cached disabled admission policy. This PR demonstrates and closes the common startup readiness gap; it does not claim those controls reproduced the historical incident.

Validation

  • Full pkg/cnservice and pkg/clusterservice normal tests passed (8.442s / 0.467s).
  • Public startup IVF regression and existing single-CN/derived-view/CN-expansion lifecycle regression passed (24.75s / 21.35s; package 46.200s).
  • Actual disttae admission-aware candidate consumer regression passed.
  • Owning-package selection, build and vet passed; final incremental golangci-lint: 0 issues.
  • Race: snapshot and failure regressions 100 repetitions each, Start convergence/error/rollback regression 93 repetitions, shared raw readiness regression 100 repetitions; full CN package once under race passed (9.978s).
  • Independently designed QA Start barriers passed and were promoted into permanent regression coverage.
  • Actual GPT-6.1 Sol xhigh design and complete final review: PASS, no unresolved material blockers, reviewed commit 93a35261ed2daafaa2479202a6ebf9f613ad058a.

Production net +50 lines, tests net +356 lines, documentation 0. Tests cover separate public SQL, snapshot-policy/identity, and startup/rollback contracts using existing fixtures.

CI fixture correction

The first coverage run exposed a test ownership omission: the package retains its canonical single-CN fixture, so the specialized startup test's default exclusive cluster admission failed before SQL execution. The same-process shared-fixture + startup-test selection reproduced this exact error locally.

The specialized test now calls the existing CloseSingleCNBaseClusterTests() lifecycle boundary before starting its fresh inventory configuration. Exclusive admission and the public regression assertions/topology are preserved; the cached fixture remains reusable by later tests. This correction adds only three test lines and changes no production code.

The complete pkg/embed suite passed locally with CI's -short, matrixone_test, and set coverage mode: 155.377s, including the startup regression and later shared-fixture reinitialization/public SQL. Incremental SCA and owning-package vet passed. Actual GPT-6.1 Sol xhigh independently reviewed this delta and the fixture reuse evidence.

Local evidence is independent of CI; the new revision's CI results remain pending.

@XuPeng-SH
XuPeng-SH requested a review from aptend as a code owner September 30, 2026 08:08
@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 Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of exact head 2f1e033 against declared base/merge-base c628836. No blocking findings. This is a self-authored PR, so I am submitting COMMENT rather than presenting it as an independent GitHub approval.

Design: a focused readiness-contract correction, not a new feature. The actual query candidate consumer uses admission-aware inventory; a raw self-registration check does not prove the current CN can be scheduled. The fix reuses the existing authoritative refresh owner and self-readiness loop with two explicit phases. Raw registration stays before bootstrap. Internal query/pipeline endpoints start before ingress publication; the existing heartbeat worker is awakened; a fresh admitted snapshot must contain the same UUID, address, commit and incarnation generation before SQL acceptance starts. Placement/admission checks are not weakened.

I read all four changed files and followed the unchanged bootstrap, heartbeat, HAKeeper, clusterservice, frontend and candidate-consumer boundaries. No startup dependency cycle was found: bootstrap/upgrade protocols use internal endpoints and the internal SQL executor, not external MySQL acceptance. Frontend initialization already binds listeners, while Start owns accepting/handshaking. The added convergence phase keeps the existing bootstrap owner alive and uses its cancellation context; failure follows Start's original closeService rollback. Generation revocation still owns fail-closed publication and serialized frontend teardown.

Independent adjacent QA challenges the real clusterservice refresh gate, not just a pre-populated inventory predicate: after the initial snapshot, a background refresh holds the gate/RPC. Query startup enters authoritative refresh, then its bootstrap owner is cancelled. The query phase must terminate without opening that gate, issuing another RPC or inheriting the blocked background work. The raw-bootstrap control intentionally ignores this later owner and instead terminates at its own discovery deadline behind the same gate. Normal execution passes (0.16s), along with the permanent snapshot, failure, startup-order/rollback and raw-registration controls; focused package invocation passed in 3.759s. Full owning-package normal tests also passed: cnservice 11.714s and clusterservice 2.262s. The strengthened probe separates cancellation from the discovery timeout: the query phase has a one-second discovery budget but must return within 200ms after owner cancellation; the raw control then uses its own 150ms deadline. This final probe passes normally (package 3.143s) and on all 20 race-enabled repetitions (package 5.541s).

Closure Ownership / termination / bounds
Readiness Existing authoritative refresher, atomic inventory and heartbeat owner reused; no new readiness cache or background worker.
Waits Refresh-gate acquisition, HAKeeper RPC/retry and readiness timer retain cancellation/deadline paths; owner failure/revocation is checked around refresh.
Rollback Existing Start deferred rollback and closeOnce retain cleanup ownership; SQL is not started on convergence failure; internal endpoints/owner are stopped through existing teardown.
Test fixture CloseSingleCNBaseClusterTests releases the canonical fixture through its lifecycle owner before specialized exclusive admission; no bypass of admission, weaker assertions or duplicate fixture implementation.

Evidence reuse: the recorded clean-base public IVF regression and synchronized Start regression fail before the production fix. At the fixed production revision, the public query returns IDs 1,2 without SHOW BACKEND SERVERS or query retry; failure/cancellation tests close exactly once. The final three-line fixture correction changes no production code. I reused the complete post-correction embed run with CI's short/matrixone_test/coverage mode (155.377s), including later shared-fixture reinitialization and public SQL. I did not start another expensive cluster to duplicate this qualifying evidence. Exact-head full CI run 36693526092 is now successful; its coverage producer exited zero and recorded no failed package/test events, and normal light/heavy UT stages completed successfully.

Scope/quality: production net +50, tests net +356, docs 0 were assessed separately. Policy/identity units, synchronized Start failure tests and public IVF behavior test different contracts; shared scaffolding uses existing owners. The obsolete early frontend Start is removed, and both phases share one loop instead of maintaining parallel readiness paths. No persisted data, configuration or wire changes are introduced. Additional work is confined to startup (one authoritative refresh plus bounded retries); no query/DML hot-path work is added, and no end-to-end throughput improvement is claimed.

Important limit: the exact historical clean two-CN/zero-eligible-worker observation in #29476 was not reproduced. This PR demonstrates and fixes a common startup readiness gap with a clean-base added-CN reproducer; it does not prove that every historical startup placement failure has the same cause. There are no outstanding actionable review comments on this PR. No production changes or subagents were used during this review.

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 kind/enhancement kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: First ordinary IVF query can fail during clean 2-CN startup despite SQL readiness

2 participants