Skip to content

Agent/fix 26299 hakeeper startup cleanup - #26316

Merged
mergify[bot] merged 10 commits into
matrixorigin:mainfrom
jiangxinmeng1:agent/fix-26299-hakeeper-startup-cleanup
Jul 30, 2026
Merged

mergify[bot] merged 10 commits into
matrixorigin:mainfrom
jiangxinmeng1:agent/fix-26299-hakeeper-startup-cleanup

Conversation

@jiangxinmeng1

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 #26299

What this PR does / why we need it:

Agent/fix 26299 hakeeper startup cleanup

Use a longer HAKeeper-running deadline only for embedded test clusters, and ensure the txn executor cluster is closed even when startup fails. Also propagate base-cluster startup failures.\n\nRefs matrixorigin#26299.
Close every started or partially initialized service after startup failure, continue cleanup past individual close errors, and make repeated cleanup safe. Roll back failed dynamic CN additions without stopping the running cluster.\n\nRefs matrixorigin#26299.
@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 →

@mergify mergify Bot added the kind/bug Something isn't working label Jul 28, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 28, 2026

@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-reviewed latest head eac719010d2ac6f79f0563aecf7991c6f0289a68 across initial startup, partial service construction, reverse-order close, repeated close, dynamic CN rollback, file-service cleanup, and the CI timeout change. The timeout is test-only and does not affect production or the successful startup path, but two real cleanup/state blockers remain.

P1 — Rollback still cannot close services whose Start/Bootstrap partially failed

The concrete service is assigned to op.reset.svc only after all startup work succeeds: LOG at pkg/embed/operator.go:226-245, TN at :260-273, and CN at :286-302. If s.Start() returns after starting an earlier component (CN starts query/frontend/RPC stages sequentially), or LOG BootstrapHAKeeper fails after the service is running, operator.Start returns with reset.svc == nil. cluster.Start then calls the new rollback, but operator.Close has no service handle and only stops the outer stopper/file service. The partially started service can retain goroutines/listeners and its own resources. Store ownership immediately after construction and make rollback close it on every later error. The new startFn test pre-populates reset.svc, so it cannot catch this production path.

P1 — A close error leaves a failed dynamic CN in the active cluster topology

rollbackNewServicesLocked truncates services, files, and restores options.cn only when every close returned nil (pkg/embed/cluster.go:260-267). CN Close legitimately aggregates RPC/query/gossip errors. On such an error, StartNewCNService returns failure but the cluster remains started while GetCNService/ForeachServices expose the failed, partly closed CN and subsequent additions use the inflated CN count/config sequence. Logical rollback must happen regardless of cleanup errors; retain any still-owned cleanup handles separately if retries are required. Add an unhappy-path test with a new CN whose Close returns an error.

The PR is also now genuinely conflicting with latest main: #26203 changed RunBaseClusterTests to take t, while this branch changes its old return-value form. Please rebase/merge and preserve the main-side startup-error propagation when resolving it.

…eeper-startup-cleanup

# Conflicts:
#	pkg/tests/txnexecutor/txn_executor_test.go
@mergify mergify Bot added dequeued and removed queued labels Jul 29, 2026
XuPeng-SH added a commit that referenced this pull request Jul 29, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to #26299 and #26316.

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

The Ubuntu/x86 race job for #26316 failed while `pkg/tests/shard` was
starting
its embedded cluster. The first test timed out in
`waitAnyShardReadyLocked`; a
later nil dereference was secondary because the shared fixture's
`sync.Once`
had already completed without publishing a cluster.

The runner had an 8-CPU scheduling limit but exposed 112 host CPUs
through
`runtime.NumCPU()`. Each embedded TN therefore created 896 transaction
RPC
workers (`8 * 112`). With the existing heavy-package parallelism of 3,
several
race-instrumented clusters created thousands of unnecessary workers and
starved HAKeeper startup.

This fixes the resource model rather than changing test scheduling:

- system initialization never raises a scheduler limit already
established by
  the Go runtime or `GOMAXPROCS`;
- the default MORPC server-worker count uses `runtime.GOMAXPROCS(0)`,
which is
the capacity available to Go scheduling, instead of host CPU visibility;
- the existing minimum of 100 workers and multiplier of 8 remain
unchanged;
- explicit `server-workers` configuration remains authoritative.

There is no package serialization, test-package allowlist, retry,
timeout
extension, assertion weakening, or reduction of `HEAVY_RACE_PARALLEL`.
Bare-metal defaults remain unchanged when `GOMAXPROCS ==
runtime.NumCPU()`.

## Validation

- `go build ./pkg/common/morpc ./pkg/common/system`
- `go vet ./pkg/common/morpc ./pkg/common/system`
- focused race stress, each separately with a 30-second budget:
- `TestAdjustConfig`: terminal duration below timer resolution,
`count=100`
- `TestDefaultServerWorkers`: terminal duration below timer resolution,
    `count=100`
  - `TestEffectiveGoMaxProcs`: terminal duration below timer resolution,
    `count=100`
- complete owning packages:
  - `mo-cgo-test -race -count=1 ./pkg/common/morpc`
  - `mo-cgo-test -race -count=1 ./pkg/common/system`
- controlled startup with `GOMAXPROCS=8` preserved 8 rather than raising
it to
  the 24 CPUs visible on the local host
- concurrently, with `GOMAXPROCS=8` and `-race`:
  - `TestPartitionBasedShardCanBeCreated` in `pkg/tests/shard`
  - `Test_TxnExecutorExec` in `pkg/tests/txnexecutor`
- `mo-cgo-test -race -count=1 ./pkg/txn/rpc`
- `git diff --check origin/main...HEAD`
@mergify

mergify Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-30 02:18 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-07-30 02:18 UTC · at 897484f185bcc2547a6312a9ed1f03a89d24f979 · squash

This pull request spent 26 seconds in the queue, including 2 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86

@mergify
mergify Bot merged commit 8b5f475 into matrixorigin:main Jul 30, 2026
25 of 26 checks passed
@mergify mergify Bot removed the queued label Jul 30, 2026

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.

3 participants