Skip to content

fix(logservice): harden reads, proposals, snapshots, truncation, and HAKeeper restart - #32149

Merged
mergify[bot] merged 15 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/logservice-32144-32148
Nov 6, 2026
Merged

mergify[bot] merged 15 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/logservice-32144-32148

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Nov 4, 2026 •

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 #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 fix(logservice): bound stalled RPCs and stale HAKeeper startup #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

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

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

@jiangxinmeng1
jiangxinmeng1 requested a review from aptend as a code owner November 4, 2026 09:23
@jiangxinmeng1 jiangxinmeng1 changed the title fix(logservice): retry stalled reads and recover interrupted exports fix(logservice): harden reads, snapshots, truncation, and HAKeeper restart Nov 4, 2026
@XuPeng-SH

XuPeng-SH commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 790bca99211ad431e9ea62429cc4c955956b9ef2

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: 790bca99211ad431e9ea62429cc4c955956b9ef2

Assessment: approve

The fixes reuse existing retry, snapshot/truncation and restart owners. Per-replica uncertainty tracking is justified by late export completion, while unaffected replicas avoid disk scans. No actionable correctness or design findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed all 18 changed files, affected consumers, and linked issue bodies/comments; all three discussion keys are covered.

  • Local isolation preflight and source/provenance/whitespace checks passed. Receipts and retained logs are reconciled in validation-ledger.json.

  • Frozen-head CI passed shared build, UT, SCA, coverage and PROXY/PESSIMISTIC BVT checks. Reused matching author-reported normal/race regressions and recovery tests.

Limitations:

  • No fresh local Go or cluster tests executed; author raw logs were not supplied.

  • Read/WAL three-voter network-chaos scenarios were not rerun. The seven-second child deadline does not bound blocked sends or empty-pool acquisition; healthy longer requests may retry.

  • Uncertain replicas continue scanning, with possible transient quota excess. The separate Dragonboat proposal-transport fix remains outside this PR.

@mergify

mergify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as ee5e93b at 07:40 UTC

3 h 3 min in the queue, 1 h 16 min of it CI.

So far

  • ✅ Entered the queue Fri 6 Nov, 04:37 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 07:40 · ee5e93b · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
ci — f83150eb Deployed Nov 6, 2026 by mergify[bot]
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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

4 participants