Skip to content

fix(cnservice): gate startup on self-visible cluster inventory - #27166

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-27152-cn-self-inventory-readiness
Aug 14, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-27152-cn-self-inventory-readiness

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #27152

What this PR does / why we need it:

A replacement CN can publish a successful heartbeat and become visible to Proxy while its own local MOCluster still contains a pre-registration snapshot that does not include that CN. IVF entries scans require the current coordinator CN because only it can expose local appendable ranges. The pool-aware scheduler therefore rejects those requests with required-current-cn-outside-pool.

This PR adds a CN startup readiness gate before bootstrap and all query ingress:

  1. Wait for the first successful CN heartbeat.
  2. Synchronously refresh the local cluster snapshot through AuthoritativeRefresher.
  3. Require the snapshot to contain this CN's service ID, pipeline address, and build commit.
  4. Retry at the heartbeat cadence while bounded by the existing HAKeeper discovery timeout.
  5. Fail startup and use the existing rollback path if readiness cannot be established.

The change does not synthesize the current CN into a resolved pool and does not relax IVF's CurrentCNRequired rule, so tenant/label pool isolation and IVF local-range correctness are unchanged. It runs only during CN startup and adds no query or transaction hot-path work.

Regression tests cover:

  • stale CN generations with an old pipeline address or build commit;
  • cancellation before the first successful heartbeat;
  • authoritative refresh failure;
  • rejection of a cluster implementation without authoritative refresh;
  • proof that service.Start cannot enter bootstrap before the self-visible inventory gate opens.

Testing

  • go test -mod=readonly -count=1 -timeout 300s ./pkg/cnservice
  • go test -mod=readonly -race -count=10 -timeout 300s ./pkg/cnservice -run '^(TestClusterSelfReadiness.*|TestServiceStartDoesNotBootstrapBeforeClusterSelfReady)$'
  • go test -mod=readonly -race -count=1 -timeout 600s ./pkg/cnservice
  • go vet -mod=readonly ./pkg/cnservice

New production functions have 90.9%, 90.0%, 100%, and 100% statement coverage.

Wait for a successful CN heartbeat and an authoritative MOCluster refresh that contains the current CN generation before opening ingress. This prevents replacement CNs from serving IVF queries against a pre-registration local inventory.

Add deterministic startup ordering, stale generation, cancellation, refresh failure, and capability regression tests.
@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 →

@aptend aptend 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-reviewed the startup readiness invariant and the success, timeout, cancellation, refresh-failure, rollback, and concurrent-refresh paths. The gate is bounded, stays off query hot paths, preserves fail-closed pool semantics, and verifies the exact heartbeat identity fields needed for the replacement-CN race. Exact-head package build, vet, full cnservice tests, and focused race tests passed.

@mergify

mergify Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@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 f0d9a378ed0524ca36140bc9c129b535b51f4ef6.

No blocking findings. The startup gate closes the actual replacement-CN race at the ownership boundary: it waits for a successful current-generation heartbeat, performs a serialized authoritative refresh, and verifies the local inventory entry by service ID, pipeline address, and commit before bootstrap or ingress can open. It preserves fail-closed placement and IVF current-CN correctness instead of synthesizing pool membership.

I traced startup, heartbeat, authoritative refresh serialization, timeout/cancellation, partial-start rollback, concurrent background refresh, and shutdown dependencies. The wait is bounded by the existing HAKeeper discovery timeout, retries follow the heartbeat cadence, and there is no query-path cost. On this exact head, git diff --check, package list/build/vet, the full pkg/cnservice test suite, and the focused readiness tests under -race -count=20 all passed.

@mergify mergify Bot added the queued label Aug 14, 2026
@mergify

mergify Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-14 10:25 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-14 10:52 UTC · at c0e9a7c0d51c28dc34a66ec0f17f00849e38010b

This pull request spent 26 minutes 58 seconds in the queue, with no time running CI.

Reason

Pull request #27166 has been merged manually at 91dfe8c

Hint

You were too fast!

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 91dfe8c into matrixorigin:main Aug 14, 2026
23 of 25 checks passed
@mergify mergify Bot removed the queued label Aug 14, 2026
mergify Bot pushed a commit that referenced this pull request Aug 14, 2026
…27167)

Backports #27166 (`f0d9a378ed`) to `4.2-dev`.

A replacement CN can publish a successful heartbeat and become visible to Proxy while its own local `MOCluster` still contains a pre-registration snapshot that does not include that CN. IVF entries scans require the current coordinator CN because only it can expose local appendable ranges, so this ordering gap can reject valid requests with `required-current-cn-outside-pool`.

This change gates CN startup before bootstrap and all query ingress until:

1. the first CN heartbeat succeeds;
2. an authoritative local cluster refresh succeeds; and
3. the refreshed snapshot contains this CN's service ID, pipeline address, and build commit.

The retry is bounded by the existing HAKeeper discovery timeout. Failure uses the existing CN startup rollback path. The change does not relax tenant/label pool isolation or IVF's `CurrentCNRequired` rule, and it adds no query or transaction hot-path work.

The original regression tests are included unchanged.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…xorigin#27166)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#27152

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

A replacement CN can publish a successful heartbeat and become visible
to Proxy while its own local `MOCluster` still contains a
pre-registration snapshot that does not include that CN. IVF entries
scans require the current coordinator CN because only it can expose
local appendable ranges. The pool-aware scheduler therefore rejects
those requests with `required-current-cn-outside-pool`.

This PR adds a CN startup readiness gate before bootstrap and all query
ingress:

1. Wait for the first successful CN heartbeat.
2. Synchronously refresh the local cluster snapshot through
`AuthoritativeRefresher`.
3. Require the snapshot to contain this CN's service ID, pipeline
address, and build commit.
4. Retry at the heartbeat cadence while bounded by the existing HAKeeper
discovery timeout.
5. Fail startup and use the existing rollback path if readiness cannot
be established.

The change does not synthesize the current CN into a resolved pool and
does not relax IVF's `CurrentCNRequired` rule, so tenant/label pool
isolation and IVF local-range correctness are unchanged. It runs only
during CN startup and adds no query or transaction hot-path work.

Regression tests cover:

- stale CN generations with an old pipeline address or build commit;
- cancellation before the first successful heartbeat;
- authoritative refresh failure;
- rejection of a cluster implementation without authoritative refresh;
- proof that `service.Start` cannot enter bootstrap before the
self-visible inventory gate opens.

## Testing

- `go test -mod=readonly -count=1 -timeout 300s ./pkg/cnservice`
- `go test -mod=readonly -race -count=10 -timeout 300s ./pkg/cnservice
-run
'^(TestClusterSelfReadiness.*|TestServiceStartDoesNotBootstrapBeforeClusterSelfReady)$'`
- `go test -mod=readonly -race -count=1 -timeout 600s ./pkg/cnservice`
- `go vet -mod=readonly ./pkg/cnservice`

New production functions have 90.9%, 90.0%, 100%, and 100% statement
coverage.

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
…xorigin#27166)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#27152

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

A replacement CN can publish a successful heartbeat and become visible
to Proxy while its own local `MOCluster` still contains a
pre-registration snapshot that does not include that CN. IVF entries
scans require the current coordinator CN because only it can expose
local appendable ranges. The pool-aware scheduler therefore rejects
those requests with `required-current-cn-outside-pool`.

This PR adds a CN startup readiness gate before bootstrap and all query
ingress:

1. Wait for the first successful CN heartbeat.
2. Synchronously refresh the local cluster snapshot through
`AuthoritativeRefresher`.
3. Require the snapshot to contain this CN's service ID, pipeline
address, and build commit.
4. Retry at the heartbeat cadence while bounded by the existing HAKeeper
discovery timeout.
5. Fail startup and use the existing rollback path if readiness cannot
be established.

The change does not synthesize the current CN into a resolved pool and
does not relax IVF's `CurrentCNRequired` rule, so tenant/label pool
isolation and IVF local-range correctness are unchanged. It runs only
during CN startup and adds no query or transaction hot-path work.

Regression tests cover:

- stale CN generations with an old pipeline address or build commit;
- cancellation before the first successful heartbeat;
- authoritative refresh failure;
- rejection of a cluster implementation without authoritative refresh;
- proof that `service.Start` cannot enter bootstrap before the
self-visible inventory gate opens.

## Testing

- `go test -mod=readonly -count=1 -timeout 300s ./pkg/cnservice`
- `go test -mod=readonly -race -count=10 -timeout 300s ./pkg/cnservice
-run
'^(TestClusterSelfReadiness.*|TestServiceStartDoesNotBootstrapBeforeClusterSelfReady)$'`
- `go test -mod=readonly -race -count=1 -timeout 600s ./pkg/cnservice`
- `go vet -mod=readonly ./pkg/cnservice`

New production functions have 90.9%, 90.0%, 100%, and 100% statement
coverage.

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
…xorigin#27166)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#27152

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

A replacement CN can publish a successful heartbeat and become visible
to Proxy while its own local `MOCluster` still contains a
pre-registration snapshot that does not include that CN. IVF entries
scans require the current coordinator CN because only it can expose
local appendable ranges. The pool-aware scheduler therefore rejects
those requests with `required-current-cn-outside-pool`.

This PR adds a CN startup readiness gate before bootstrap and all query
ingress:

1. Wait for the first successful CN heartbeat.
2. Synchronously refresh the local cluster snapshot through
`AuthoritativeRefresher`.
3. Require the snapshot to contain this CN's service ID, pipeline
address, and build commit.
4. Retry at the heartbeat cadence while bounded by the existing HAKeeper
discovery timeout.
5. Fail startup and use the existing rollback path if readiness cannot
be established.

The change does not synthesize the current CN into a resolved pool and
does not relax IVF's `CurrentCNRequired` rule, so tenant/label pool
isolation and IVF local-range correctness are unchanged. It runs only
during CN startup and adds no query or transaction hot-path work.

Regression tests cover:

- stale CN generations with an old pipeline address or build commit;
- cancellation before the first successful heartbeat;
- authoritative refresh failure;
- rejection of a cluster implementation without authoritative refresh;
- proof that `service.Start` cannot enter bootstrap before the
self-visible inventory gate opens.

## Testing

- `go test -mod=readonly -count=1 -timeout 300s ./pkg/cnservice`
- `go test -mod=readonly -race -count=10 -timeout 300s ./pkg/cnservice
-run
'^(TestClusterSelfReadiness.*|TestServiceStartDoesNotBootstrapBeforeClusterSelfReady)$'`
- `go test -mod=readonly -race -count=1 -timeout 600s ./pkg/cnservice`
- `go vet -mod=readonly ./pkg/cnservice`

New production functions have 90.9%, 90.0%, 100%, and 100% statement
coverage.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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]: IVF vector queries fail with required-current-cn-outside-pool after CN kill despite eligible CNs

4 participants