Skip to content

fix(logservice): bound stalled RPCs and stale HAKeeper startup - #32147

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/logservice-32133-32135
Nov 5, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/logservice-32133-32135

Conversation

@jiangxinmeng1

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #32133
Fixes #32134
Fixes #32135

What this PR does / why we need it:

  • Bound LogService data RPC response inactivity with an 8-second MORPC read window. A blackholed established connection now fails before the WAL caller's one-minute attempt expires, so the next operation can select a reachable address. An Append that times out still has an unknown commit outcome; this change does not auto-replay it.
  • Replace the selected HAKeeper client generation when an attempted LogService heartbeat exhausts its caller deadline. A deadline before Send or an explicit cancellation leaves the shared generation intact. The next heartbeat performs normal endpoint discovery.
  • Include a bootstrap-configured initial HAKeeper replica ID in the bounded startup membership check even when L/Kill has already removed it from local metadata. Probe it before stored data shards, without persisting the synthetic candidate. A cold bootstrap without an authoritative membership reply still starts.

Validation

  • make -j4 cgo (matching native artifacts): passed.
  • Focused blackholed Append, heartbeat generation/failover, and warm/cold bootstrap tests: passed.
  • mo-cgo-test -count=1 -timeout=240s ./pkg/logservice: passed.
  • Adaptive focused race runs (1–100 repeats per exact test) and mo-cgo-test -race -count=1 -timeout=240s ./pkg/logservice: passed.
  • GOWORK=off go build and go vet for pkg/logservice and pkg/vm/engine/tae/logstore/driver/logservicedriver: passed.
  • mo-cgo-test -count=1 -timeout=120s ./pkg/vm/engine/tae/logstore/driver/logservicedriver: passed.

The extra work is limited to MORPC's existing read-window tracking on data connections and one startup membership candidate for bootstrap-configured stores. The startup check remains best effort when no peer gives an authoritative membership reply. HAKeeper reconnect still shuffles endpoints, so this change does not claim a strict 30-second worst-case recovery if each new attempt first selects an isolated address. The three-voter network-namespace chaos scenarios from the issues have not been rerun on this branch; CI is pending.

@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 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 67956b338b7639f1fd4edda6ed7781f5ccfac9b1

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 67956b338b7639f1fd4edda6ed7781f5ccfac9b1

Assessment: request_changes

The production fixes coherently reuse MORPC read windows, generation-scoped endpoint reset and bounded membership checks. The new proxy fixture has a teardown race that can hang its tests.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

  • P2 pkg/logservice/client_test.go:526: Cleanup runs after Accept returns but before the outbound DialTimeout finishes and registers its connections.
    Impact: The late sockets miss cleanup's close snapshot. Client EOF ends only the forwarding goroutine; serverConn.Read can remain blocked, so wg.Wait depends on the remote peer closing. The enclosing service cleanup runs after this callback returns. Seal connection registration during shutdown and close late dial results, or join the accept/dial producer before draining connections; add this interleaving to the fixture test.
    Evidence: Connections are registered at lines494-495 after DialTimeout, while cleanup drains the map before joining. A phase-controlled probe of the exact helper passes the already-tracked control and fails the pending-dial case; closing the missed target then releases teardown. See proxy-inputs.json and proxy-test-resume.log.

Validation:

  • Read the complete six-file delta, all discussion and linked issue context, and transport/WAL/heartbeat/bootstrap consumers. Both discussion keys are assessed.

  • Isolation preflight passed. Exact-helper probe: one passing control and one deterministic cleanup counterexample. All six changed Go files parse and pass gofmt.

  • Head-matched CI metadata reports successful UT/SCA/BVT/coverage; the author reports focused, owning-package, race and dependent-driver passes. Local receipts and retained logs are correlated in execution-ledger.json.

Limitations:

  • Local product tests did not compile: required Go1.27.1 bootstrap timed out, and native prerequisites are absent. No local product or race pass is claimed.

  • The reduced probe tests the proxy helper with injected phases, not a LogService cluster. Raw author/CI logs were unavailable; the three-voter chaos scenarios were not rerun.

@jiangxinmeng1

Copy link
Copy Markdown
Contributor Author

Addressed the requested proxy teardown fix in b55d6e0. Cleanup now seals connection registration under the same mutex used by the accept loop and closes already tracked sockets; a dial that returns after shutdown closes both of its sockets without starting a forwarding goroutine. A channel-controlled regression test covers that exact late-dial interleaving.

Validation passed: the focused regression test, race-mode focused tests including the blackholed Append case, and the complete pkg/logservice test suite. CI is running on the new commit.

@XuPeng-SH

XuPeng-SH commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: b55d6e0c743822b640b9a17b8e9d9caca4cdee6d

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: b55d6e0c743822b640b9a17b8e9d9caca4cdee6d

Assessment: approve

The prior proxy teardown hang is resolved by sealing registration and closing late sockets before joining. Production fixes coherently reuse existing read-window, generation-reset and membership-check owners; no actionable findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Completed the six-file and linked-issue/discussion review. The only delta from reviewed head 67956b3 is client_test.go; unchanged production/consumer coverage is reused. Closure reasoning is retained in closure-review.md.

  • The exact-helper/current-regression probe passed normally, once with race detection and through 100 race repetitions. T=0 at JSON timer resolution, B=30s, N=100. Receipts: checks/1793789692725889336-2.json, 1793789779562680191-2.json and 1793789850016565493-2.json; logs: proxy-normal.log, proxy-race-once.log and proxy-race-stress.log. proxy-inputs.json binds the extracted functions to the frozen source.

  • Read-only scope, patch, gofmt/parser, input/result and five-key discussion audit passed: checks/1793790100663564897-2.json; scope-audit.log.

  • Frozen exact-head CI reports 13 successful, 14 skipped and two neutral checks, including UT/SCA/coverage and compose successes. Current author-reported focused regression, blackholed-Append race and complete owning-package passes are reused within their stated scope.

Limitations:

  • The standalone fixture probe used Go1.26.6 and an equivalent require.NoError adapter; no full Go1.27.1 LogService or dependent-driver suite was independently rerun. Raw author/CI logs were unavailable.

  • The three-voter chaos scenarios were not rerun. Randomized endpoint rediscovery still provides no strict 30-second worst-case recovery guarantee, as disclosed in the PR.

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

mergify Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

❌ Left the queue · checks failed

1 h 30 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Wed 4 Nov, 11:05 · rule main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in place
  • 🚫 Left the queue 12:35 · 4db1f36

The failure is in this pull request. It failed tested alone on top of main.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

To get back in the queue

  • Push a fix: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

Requeue requested — the merge queue status continues in this comment ↓.

2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

@mergify

mergify Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

2 h 13 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Thu 5 Nov, 07:09 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 09:21 · 4c901ec

Reason

Pull request #32147 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

@XuPeng-SH
XuPeng-SH merged commit d2dab99 into matrixorigin:main Nov 5, 2026
@mergify mergify Bot added dequeued and removed queued labels Nov 5, 2026
mergify Bot pushed a commit that referenced this pull request Nov 6, 2026
…HAKeeper restart (#32149)

## 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 #32148
Fixes #32144
Fixes #32159
Fixes #32151
Fixes #32161
Fixes #32235
Related to #32133

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

- Give each LogService `Read` attempt a seven-second child deadline. If an established data connection stops answering after the request is sent, reset that connection and retry the same LSN while the caller context remains live. Read can be repeated safely; writes retain their existing unknown-result behavior. Connection failures from MORPC also take this retry path, so this works alongside #32147's shared backend read window.
- Bound each `GetTruncatedLsn` attempt to seven seconds. A stalled read resets its LogService connection and retries while the caller is live; the WAL driver now keeps one overall replay deadline and cancels retry backoff promptly. This lets `ReplayForWrite` try another available replica when its first truncate-watermark read stalls. `Append` and `Truncate` write semantics are unchanged.
- During service restart, before starting each retained data replica, remove only canonical exported snapshot final directories that still contain Dragonboat's completion flag. A crash between final-directory rename and flag removal no longer leaves an untracked directory that blocks export at the same index. Valid exports and temporary directories remain available; filesystem cleanup errors fail startup visibly.
- When an exported snapshot finishes after its request times out, mark that replica for later disk reconciliation. Each truncation tick discovers complete final directories, includes them in import and quota decisions, and removes excess newest snapshots while keeping the oldest import candidate. Incomplete directories and I/O errors remain retryable; unaffected replicas do not scan.
- Reject a `Truncate` target at or beyond the Raft index of the truncate command when the state machine applies it. The persisted watermark cannot advance past entries already committed, so later acknowledged appends remain readable. The API keeps the `ErrInvalidTruncateLsn` error class.
- On ordinary HAKeeper cold restart, select the highest locally persisted replica ID that the peer membership check has not rejected. HAKeeper allocates replacement IDs monotonically; older local records are skipped so Dragonboat starts only one replica for shard 0. If a replacement is running, bootstrap does not replay the configured initial ID, even when its metadata record was removed.
- Add regressions for an established connection that stops answering, interrupted snapshot export, future truncate followed by append/read, a full three-voter cold restart with historical HAKeeper metadata, and an accepted snapshot request that times out before its final directory appears.

### Validation

- Native `make -j4 cgo`: passed on each original branch; native inputs are unchanged in the combined branch.
- Focused regressions for all four issues and complete `pkg/logservice` plus `pkg/common/moerr` packages: passed on the combined branch.
- Focused race repetitions and complete `pkg/logservice` race package for the original Read/snapshot changes: passed on the original #32149 head. The combined branch preserves those code paths.
- `go vet` for LogService and its WAL driver passed on the original #32149 head. The combined branch includes a separate `go vet` result for LogService and `moerr`.
- For #32161, the real Dragonboat post-admission timeout regression, late-completion/quota and scanner-error controls, complete `pkg/logservice` normal and race packages, focused race repetitions, and `go vet ./pkg/logservice` passed on that head.
- For #32235, a real LogService client with an established response-dropping connection recovered the expected truncate watermark through a healthy address. A short caller deadline stopped the blackholed request. `ReplayForWrite` retried a transient watermark error, and cancellation stopped the driver after one attempt. Complete `pkg/logservice` and WAL-driver packages passed in normal and race modes; focused race repetitions passed (client 3, replay 20, cancellation 20); `go vet` passed for both packages.
- Temporary overlay of #32147's shared eight-second MORPC backend read window, followed by the focused Read regression: passed on the original #32149 head; the overlay was removed afterward.
- On head `790bca9921`, upstream/main through `65b721e1b9` supplies #32147. The focused prior CI failures passed locally; the LIKE index case passed three consecutive runs after its deterministic test correction. Complete `pkg/logservice` and WAL-driver package tests, build, and vet passed against the MatrixOrigin Dragonboat dependency. The new MatrixOne CI is pending.

### Relationship and limits

The merged upstream/main includes #32147, which bounds the underlying data connection's read window for all operations. This PR adds `Read` and `GetTruncatedLsn` retry semantics without duplicating that patch. The child deadline is not a hard bound on every possible blocked send path inside MORPC; the reproduced failures stall after a small request is sent. A healthy `Read` or `GetTruncatedLsn` lasting more than seven seconds can be retried. Reconnect still uses existing randomized endpoint selection, so a single failed attempt does not guarantee a healthy endpoint on the next pick. The regressions use a single server behind a response-dropping proxy; the three-voter network-namespace chaos scenarios for `Read` and WAL replay have not been rerun on this branch. The pending-proposal transport fix for #32133 is in [matrixorigin/dragonboat#20](matrixorigin/dragonboat#20), which is still open and is not included in this PR. This PR uses the existing MatrixOrigin Dragonboat version. The three-voter network-namespace failure scenario has not been rerun, so #32133 is not claimed fully resolved. The WAL driver's `clientPool.Get()` remains context-unaware when the pool is empty, outside #32235's reproduced case with available pooled clients. Crash-marker cleanup remains a startup path; late valid exports are reconciled while the process runs on later truncation ticks. An affected replica continues to scan after an ambiguous request because the completion can arrive after any scan; disk quota can be exceeded transiently before the next tick.

When no peer can answer during HAKeeper cold restart, the choice among locally persisted replicas relies on monotonic replica IDs. The new three-voter regression verifies that this restores quorum with the issue's duplicate-metadata shape. The installed local `golangci-lint` was built with Go 1.26 and cannot lint this Go 1.27.1 repository; CI will run the configured lint check.




Approved-by: XuPeng-SH <[email protected]>

This branch was previously deployed

1 inactive deployment
ci — 4c901ec0 Deployed Nov 5, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/L Denotes a PR that changes [500,999] lines

Projects

None yet

3 participants