Skip to content

test(logservice): isolate WAL recovery service roles - #26659

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26652-be0bca4c
Aug 4, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26652-be0bca4c

Conversation

@gouhongshen

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

What this PR does / why we need it:

Root cause

NewService derives walRecovery.coordinator from the restore configuration before it starts the heartbeat worker, and that role is immutable for the service generation. TestServiceBootstrapRestoresHAKeeperAndWAL instead reused one live service for coordinator and non-coordinator restart scenarios by assigning that plain boolean after workers had started. The live heartbeat could read the field concurrently in addWALRecoveryStatus, producing the reported race.

Changes

  • Add local lifecycle helpers that fully close the active test service before constructing the next generation.
  • Construct coordinator and non-coordinator generations from their real restore configurations, so each generation derives its role before its heartbeat worker starts.
  • Assert configured, coordinator, and initial pending state for every generation before bootstrap.
  • Preserve the existing recovery-marker, ID-watermark, lease, replay-skip, and cancellation assertions.
  • Keep production synchronization and runtime behavior unchanged; the immutable-after-start role contract remains explicit.

Issue-to-test proof

  • The initial generation proves coordinator recovery and clears its pending status after bootstrap.
  • A separately constructed non-coordinator generation proves restart without a WAL artifact, including role derivation and pending-status completion.
  • A third coordinator generation proves the normal configured restart path while retaining the replicated marker, ID watermarks, and post-recovery lease.
  • The issue's focused race command passes 10 consecutive runs after the change, so no test write can overlap the heartbeat read.
  • BVT is not applicable because this is an internal LogService test/service-generation ownership defect with no SQL-visible behavior.

Validation

Passed on origin/main at 00aaf78e24:

  • .agents/skills/mo-dev/scripts/mo-cgo-test -race -run '^TestServiceBootstrapRestoresHAKeeperAndWAL$' -count=10 -timeout=600s ./pkg/logservice (320.899s)
  • Related WAL recovery/restore race suite covering status publication, coordinator waiting, recovery state, input validation, and replay (53.661s)
  • GOWORK=off go list -mod=readonly ./pkg/logservice
  • GOWORK=off go build -mod=readonly ./pkg/logservice with the repository CGo include/library environment
  • GOWORK=off go vet -mod=readonly ./pkg/logservice with the repository CGo include/library environment
  • git diff --check

Broader package verification was attempted but is not reported as passing:

  • Full ./pkg/logservice race testing is blocked by TestZombieRepro_WithFix failing to transfer leadership within 10 seconds; the identical focused failure reproduces on an isolated pristine origin/main worktree. Its failed cleanup then causes the fixed-port TestZombieRepro_WithoutFix to fail.
  • Full non-race testing also encountered unrelated HAKeeper cluster-test timeouts; serial execution excluding TestZombieRepro_* still failed only TestHAKeeperCanBootstrapAndRepairShards and TestRestoreIDWatermarksFromNonLeader. The changed target test passed, and the directly related race suite above passed.
  • The reported workflow was already on attempt 2 and was not rerun.

Residual risks

No production code, API, configuration, or runtime behavior changes. Each replacement service is created only after Close stops the previous generation's workers and releases its resources; the helper clears ownership before closing so an error path cannot close the same generation twice. The local full-package gaps above are outside this one-test change and are recorded explicitly.

@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-reviewed exact head 92484ae68c4f2a2afbcc82bce17c5963a2e95a26. No blocking findings.

The fix restores the real lifecycle contract instead of synchronizing a test-only mutation: coordinator role is derived from each generation's restore configuration before heartbeat startup, and every role transition is represented by a complete Service restart.

Audit Ownership / wait path Verdict
Q1 cleanup s owns one generation; restart transfers it to service, clears s, then calls Close; the deferred cleanup sees only the current generation Pass: one effective close owner, no double close
Q2 termination Service.Close stops the heartbeat stopper, HA client, RPC server, and store before NewService creates the next generation Pass: old workers and port/store ownership terminate before reuse
Q3 bound At most one Service generation is live; three sequential generations share only the intentionally persistent in-memory FileServices Pass: test-scoped and bounded

The original recovery assertions remain intact, while the added configured, coordinator, and initial pending assertions prove that each scenario is reached through configuration rather than mutable internal state.

Validation performed:

  • focused race test passed on the exact head (33.360s);
  • focused non-race test passed three consecutive full restart cycles (95.632s);
  • affected package go list, go build, and go vet passed;
  • git diff --check passed.

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

mergify Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-04 01:53 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-04 02:56 UTC · at 035eab58d81fa2a7e812e14beabc5f753c6dd577 · squash

This pull request spent 1 hour 2 minutes 44 seconds in the queue, including 1 hour 2 minutes 17 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 2190897 into matrixorigin:main Aug 4, 2026
24 of 25 checks passed
@mergify mergify Bot removed the queued label Aug 4, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

### Root cause

`NewService` derives `walRecovery.coordinator` from the restore configuration before it starts the heartbeat worker, and that role is immutable for the service generation. `TestServiceBootstrapRestoresHAKeeperAndWAL` instead reused one live service for coordinator and non-coordinator restart scenarios by assigning that plain boolean after workers had started. The live heartbeat could read the field concurrently in `addWALRecoveryStatus`, producing the reported race.

### Changes

- Add local lifecycle helpers that fully close the active test service before constructing the next generation.
- Construct coordinator and non-coordinator generations from their real restore configurations, so each generation derives its role before its heartbeat worker starts.
- Assert `configured`, `coordinator`, and initial `pending` state for every generation before bootstrap.
- Preserve the existing recovery-marker, ID-watermark, lease, replay-skip, and cancellation assertions.
- Keep production synchronization and runtime behavior unchanged; the immutable-after-start role contract remains explicit.

### Issue-to-test proof

- The initial generation proves coordinator recovery and clears its pending status after bootstrap.
- A separately constructed non-coordinator generation proves restart without a WAL artifact, including role derivation and pending-status completion.
- A third coordinator generation proves the normal configured restart path while retaining the replicated marker, ID watermarks, and post-recovery lease.
- The issue's focused race command passes 10 consecutive runs after the change, so no test write can overlap the heartbeat read.
- BVT is not applicable because this is an internal LogService test/service-generation ownership defect with no SQL-visible behavior.

### Validation

Passed on `origin/main` at `00aaf78e24`:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -run '^TestServiceBootstrapRestoresHAKeeperAndWAL$' -count=10 -timeout=600s ./pkg/logservice` (`320.899s`)
- Related WAL recovery/restore race suite covering status publication, coordinator waiting, recovery state, input validation, and replay (`53.661s`)
- `GOWORK=off go list -mod=readonly ./pkg/logservice`
- `GOWORK=off go build -mod=readonly ./pkg/logservice` with the repository CGo include/library environment
- `GOWORK=off go vet -mod=readonly ./pkg/logservice` with the repository CGo include/library environment
- `git diff --check`

Broader package verification was attempted but is not reported as passing:

- Full `./pkg/logservice` race testing is blocked by `TestZombieRepro_WithFix` failing to transfer leadership within 10 seconds; the identical focused failure reproduces on an isolated pristine `origin/main` worktree. Its failed cleanup then causes the fixed-port `TestZombieRepro_WithoutFix` to fail.
- Full non-race testing also encountered unrelated HAKeeper cluster-test timeouts; serial execution excluding `TestZombieRepro_*` still failed only `TestHAKeeperCanBootstrapAndRepairShards` and `TestRestoreIDWatermarksFromNonLeader`. The changed target test passed, and the directly related race suite above passed.
- The reported workflow was already on attempt 2 and was not rerun.

### Residual risks

No production code, API, configuration, or runtime behavior changes. Each replacement service is created only after `Close` stops the previous generation's workers and releases its resources; the helper clears ownership before closing so an error path cannot close the same generation twice. The local full-package gaps above are outside this one-test change and are recorded explicitly.

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

### Root cause

`NewService` derives `walRecovery.coordinator` from the restore configuration before it starts the heartbeat worker, and that role is immutable for the service generation. `TestServiceBootstrapRestoresHAKeeperAndWAL` instead reused one live service for coordinator and non-coordinator restart scenarios by assigning that plain boolean after workers had started. The live heartbeat could read the field concurrently in `addWALRecoveryStatus`, producing the reported race.

### Changes

- Add local lifecycle helpers that fully close the active test service before constructing the next generation.
- Construct coordinator and non-coordinator generations from their real restore configurations, so each generation derives its role before its heartbeat worker starts.
- Assert `configured`, `coordinator`, and initial `pending` state for every generation before bootstrap.
- Preserve the existing recovery-marker, ID-watermark, lease, replay-skip, and cancellation assertions.
- Keep production synchronization and runtime behavior unchanged; the immutable-after-start role contract remains explicit.

### Issue-to-test proof

- The initial generation proves coordinator recovery and clears its pending status after bootstrap.
- A separately constructed non-coordinator generation proves restart without a WAL artifact, including role derivation and pending-status completion.
- A third coordinator generation proves the normal configured restart path while retaining the replicated marker, ID watermarks, and post-recovery lease.
- The issue's focused race command passes 10 consecutive runs after the change, so no test write can overlap the heartbeat read.
- BVT is not applicable because this is an internal LogService test/service-generation ownership defect with no SQL-visible behavior.

### Validation

Passed on `origin/main` at `00aaf78e24`:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -run '^TestServiceBootstrapRestoresHAKeeperAndWAL$' -count=10 -timeout=600s ./pkg/logservice` (`320.899s`)
- Related WAL recovery/restore race suite covering status publication, coordinator waiting, recovery state, input validation, and replay (`53.661s`)
- `GOWORK=off go list -mod=readonly ./pkg/logservice`
- `GOWORK=off go build -mod=readonly ./pkg/logservice` with the repository CGo include/library environment
- `GOWORK=off go vet -mod=readonly ./pkg/logservice` with the repository CGo include/library environment
- `git diff --check`

Broader package verification was attempted but is not reported as passing:

- Full `./pkg/logservice` race testing is blocked by `TestZombieRepro_WithFix` failing to transfer leadership within 10 seconds; the identical focused failure reproduces on an isolated pristine `origin/main` worktree. Its failed cleanup then causes the fixed-port `TestZombieRepro_WithoutFix` to fail.
- Full non-race testing also encountered unrelated HAKeeper cluster-test timeouts; serial execution excluding `TestZombieRepro_*` still failed only `TestHAKeeperCanBootstrapAndRepairShards` and `TestRestoreIDWatermarksFromNonLeader`. The changed target test passed, and the directly related race suite above passed.
- The reported workflow was already on attempt 2 and was not rerun.

### Residual risks

No production code, API, configuration, or runtime behavior changes. Each replacement service is created only after `Close` stops the previous generation's workers and releases its resources; the helper clears ownership before closing so an error path cannot close the same generation twice. The local full-package gaps above are outside this one-test change and are recorded explicitly.

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

### Root cause

`NewService` derives `walRecovery.coordinator` from the restore configuration before it starts the heartbeat worker, and that role is immutable for the service generation. `TestServiceBootstrapRestoresHAKeeperAndWAL` instead reused one live service for coordinator and non-coordinator restart scenarios by assigning that plain boolean after workers had started. The live heartbeat could read the field concurrently in `addWALRecoveryStatus`, producing the reported race.

### Changes

- Add local lifecycle helpers that fully close the active test service before constructing the next generation.
- Construct coordinator and non-coordinator generations from their real restore configurations, so each generation derives its role before its heartbeat worker starts.
- Assert `configured`, `coordinator`, and initial `pending` state for every generation before bootstrap.
- Preserve the existing recovery-marker, ID-watermark, lease, replay-skip, and cancellation assertions.
- Keep production synchronization and runtime behavior unchanged; the immutable-after-start role contract remains explicit.

### Issue-to-test proof

- The initial generation proves coordinator recovery and clears its pending status after bootstrap.
- A separately constructed non-coordinator generation proves restart without a WAL artifact, including role derivation and pending-status completion.
- A third coordinator generation proves the normal configured restart path while retaining the replicated marker, ID watermarks, and post-recovery lease.
- The issue's focused race command passes 10 consecutive runs after the change, so no test write can overlap the heartbeat read.
- BVT is not applicable because this is an internal LogService test/service-generation ownership defect with no SQL-visible behavior.

### Validation

Passed on `origin/main` at `00aaf78e24`:

- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -run '^TestServiceBootstrapRestoresHAKeeperAndWAL$' -count=10 -timeout=600s ./pkg/logservice` (`320.899s`)
- Related WAL recovery/restore race suite covering status publication, coordinator waiting, recovery state, input validation, and replay (`53.661s`)
- `GOWORK=off go list -mod=readonly ./pkg/logservice`
- `GOWORK=off go build -mod=readonly ./pkg/logservice` with the repository CGo include/library environment
- `GOWORK=off go vet -mod=readonly ./pkg/logservice` with the repository CGo include/library environment
- `git diff --check`

Broader package verification was attempted but is not reported as passing:

- Full `./pkg/logservice` race testing is blocked by `TestZombieRepro_WithFix` failing to transfer leadership within 10 seconds; the identical focused failure reproduces on an isolated pristine `origin/main` worktree. Its failed cleanup then causes the fixed-port `TestZombieRepro_WithoutFix` to fail.
- Full non-race testing also encountered unrelated HAKeeper cluster-test timeouts; serial execution excluding `TestZombieRepro_*` still failed only `TestHAKeeperCanBootstrapAndRepairShards` and `TestRestoreIDWatermarksFromNonLeader`. The changed target test passed, and the directly related race suite above passed.
- The reported workflow was already on attempt 2 and was not rerun.

### Residual risks

No production code, API, configuration, or runtime behavior changes. Each replacement service is created only after `Close` stops the previous generation's workers and releases its resources; the helper clears ownership before closing so an error path cannot close the same generation twice. The local full-package gaps above are outside this one-test change and are recorded explicitly.

Approved by: @XuPeng-SH, @LeftHandCold

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/test-ci size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TestServiceBootstrapRestoresHAKeeperAndWAL races heartbeat status

4 participants