Repository navigation
test(logservice): isolate WAL recovery service roles - #26659
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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, andgo vetpassed; git diff --checkpassed.
Merge Queue Status
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
|
) ### 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
) ### 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
) ### 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
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #26652
What this PR does / why we need it:
Root cause
NewServicederiveswalRecovery.coordinatorfrom the restore configuration before it starts the heartbeat worker, and that role is immutable for the service generation.TestServiceBootstrapRestoresHAKeeperAndWALinstead 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 inaddWALRecoveryStatus, producing the reported race.Changes
configured,coordinator, and initialpendingstate for every generation before bootstrap.Issue-to-test proof
Validation
Passed on
origin/mainat00aaf78e24:.agents/skills/mo-dev/scripts/mo-cgo-test -race -run '^TestServiceBootstrapRestoresHAKeeperAndWAL$' -count=10 -timeout=600s ./pkg/logservice(320.899s)53.661s)GOWORK=off go list -mod=readonly ./pkg/logserviceGOWORK=off go build -mod=readonly ./pkg/logservicewith the repository CGo include/library environmentGOWORK=off go vet -mod=readonly ./pkg/logservicewith the repository CGo include/library environmentgit diff --checkBroader package verification was attempted but is not reported as passing:
./pkg/logservicerace testing is blocked byTestZombieRepro_WithFixfailing to transfer leadership within 10 seconds; the identical focused failure reproduces on an isolated pristineorigin/mainworktree. Its failed cleanup then causes the fixed-portTestZombieRepro_WithoutFixto fail.TestZombieRepro_*still failed onlyTestHAKeeperCanBootstrapAndRepairShardsandTestRestoreIDWatermarksFromNonLeader. The changed target test passed, and the directly related race suite above passed.Residual risks
No production code, API, configuration, or runtime behavior changes. Each replacement service is created only after
Closestops 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.