Skip to content

Fix LogService required LSN and WAL recovery across failover - #32330

Merged
mergify[bot] merged 20 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/issues-32320-32316-32304-32248-32246-32240
Nov 10, 2026
Merged

mergify[bot] merged 20 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/issues-32320-32316-32304-32248-32246-32240

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Nov 6, 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 #32320
Fixes #32316
Fixes #32304
Fixes #32248
Fixes #32246
Fixes #32329
Fixes #32322
Addresses #32240
Related to #32133

What this PR does / why we need it:

  • Fence DataSync required-LSN writes by replicated owner, revision, and applied Raft term. Verify cleanup before publishing the synced LSN. A consumer that loses ownership now restarts and reclaims the current term, including when the same replica is re-elected.
  • Restore legacy Required-LSN revisions deterministically from the persisted LSN, so replicas recovering from different snapshot indices agree on the next ownership claim.
  • Give the DataSync ownership leader-state RPC a deadline even when its caller only supports cancellation, preventing a MORPC panic during the first ownership claim.
  • Bound LogService LSN-query and required-LSN attempts on isolated established connections. Retry a WAL append with its logical DSN after a short quorum loss. Physical WAL truncation persists the checkpointed-DSN boundary so replay only skips authenticated gaps.
  • Cancel TN checkpoint truncation during shutdown, including client creation through the production TN → TAE → WAL factory path. Replay Read also stops when its caller context is canceled.
  • Reject TruncateWAL from read-only LogService clients before sending an RPC, preserving the durable PSN/DSN boundary.
  • Use the merged matrixorigin/dragonboat transport fix for forwarded proposals. No personal Dragonboat fork is used.

Validation

After merging upstream main at de2790be2094, the full test suites passed for pkg/logservice, pkg/datasync, pkg/tnservice, pkg/vm/engine/tae/db, pkg/vm/engine/tae/logstore/driver/logservicedriver, and pkg/vm/engine/tae/logstore/wal. Focused race tests passed for DataSync ownership reclaim and WAL driver in-flight client cancellation. The full pkg/datasync suite passed after the next main merge. The full pkg/logservice suite passed with the read-only fix; its real-client regression also passed after merging main at 0c8bd5e5f3. MatrixOne CI is running on head a1d12c6d86.

Remaining limit

An older WAL shard already physically truncated without a persisted checkpointed-DSN boundary has no authenticated proof for an interior gap. Replay keeps failing closed; repairing such old-format shards needs separate authenticated checkpoint metadata. This is why #32240 is linked as “Addresses” rather than auto-closed.

Recover LogService LSN operations from isolated established connections, bound WAL-only proposals, retry background truncation, and persist checkpointed DSN with physical WAL truncation.

Addresses matrixorigin#32320, matrixorigin#32316, matrixorigin#32304, matrixorigin#32248, matrixorigin#32246, and matrixorigin#32240.
@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 →

Preserve matrixorigin#32149 truncation bounds for the new WAL command and align WAL watermark retries with the upstream cancellation budget.
@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: c8d1bfffdc1c5151a31b3f930147a837303ac0fe

PR changed before dispatch

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

Reviewed exact head c8d1bfffdc1c5151a31b3f930147a837303ac0fe against main base de2790be20948f9d99cb833ddbbaa8a792b7a2ac.

Request changes for one confirmed process-crash regression:

  1. [P0] pkg/datasync/log_client.go:258 — Add a deadline before querying the ownership leader state. The production consumer runs through syncer.start → Stopper.RunNamedTask, whose context comes from context.WithCancel(context.Background()). Once shard 3 is led locally, consumer.Start passes that deadline-free context into claimRequiredLsn. This call to GetLeaderState forwards it unchanged through managedClient → client.request → MORPC. Future.init (pkg/common/morpc/future.go:76–77) unconditionally panics with context deadline not set for this ordinary unary request. The stopper goroutine does not recover, so enabling standby DataSync terminates the LogService process when the consumer first claims ownership. Wrap the leader-state query in the existing contextTimeout child context, as getLeaderID already does, and cover a cancel-only parent with the real client. The new consumer test mocks this RPC, while the real-client required-LSN test supplies an explicit deadline, so neither exercises this production input.

All three previous findings were checked against the current code and are addressed: legacy snapshot/replay revisions now agree, ownership conflicts restart the consumer without cleanup, and shutdown cancellation reaches the production TN → TAE → WAL client factory. The author explicitly replied to each: snapshot revision, ownership restart, factory cancellation. These resolved findings are not counted again.

Validation: inspected the complete 33-file diff and relevant callers; checked protobuf descriptor compatibility and ran the read-only PR artifact check successfully. Local package/cluster tests were not rerun: the new finding follows the explicit panic condition on the traced production path; existing exact-head CI evidence was reused. No runtime reproduction is claimed. Documentation checks are inapplicable because no documentation changed. Repairing old shards already truncated without an authenticated checkpoint boundary remains outside the recorded scope.

The supplied CI snapshot contains 37 checks: 21 success, 14 skipped, 2 neutral. None failed or remain pending, but they are not all successful. Exact-head workflow results.

Comment thread pkg/datasync/log_client.go Resolved
@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 97364e7e43a661012c5ea2c252e71af711be3c0c

Review discussion changed before publication; a fresh contextual review is queued.

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

Reviewed exact head 97364e7e43a661012c5ea2c252e71af711be3c0c against main base 11d2e1ef7e1b3ed3a20e6d7f29f912e55118db5b.

Approve. No confirmed in-scope findings remain.

All four previous findings are addressed in the current code and have explicit author replies: legacy snapshot revisions, ownership-loss restart, production factory cancellation, and leader-state RPC deadline. The latest fix supplies a timeout before GetLeaderState; the real-client TestRequiredLsn now exercises ownership claiming with a cancel-only parent. The remaining ownership RPCs create bounded attempt contexts in the managed client.

Validation: inspected the complete 33-file diff, relevant production callers, regression tests, and the Dragonboat production dependency delta. Exact-SHA source comparisons, protobuf descriptor/schema compatibility checks, git diff --check, and the read-only PR artifact check passed. Local package, race, and cluster tests were not rerun; supplied CI results and the author's reported package/race validation were reviewed, without claiming an independent runtime reproduction.

The supplied CI snapshot has 37 checks: 21 success, 14 skipped, and 2 neutral. None failed or remain pending, but they are not all successful. Current-head workflow results.

Documentation-specific checks were skipped because no documentation changed. Repairing older WAL shards already truncated without an authenticated checkpoint boundary remains outside the recorded scope.

@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 97364e7e43a661012c5ea2c252e71af711be3c0c

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: 97364e7e43a661012c5ea2c252e71af711be3c0c

Assessment: request_changes

One P2 regression remains: read-only clients can invoke WAL truncation. The durable ownership/checkpoint state is justified within the existing RSM/WAL owners, and the four earlier findings are resolved. This new API-contract evidence changes the supplied same-head approval.

Model: gpt-6.1-sol / max

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

  • P2 pkg/logservice/client.go:871: Create a client with ClientConfig.ReadOnly=true and call TruncateWAL with an otherwise valid advancing PSN/checkpointed-DSN pair.
    Impact: The call can advance durable TruncatedLsn and CheckpointedDSN from a read-only handle instead of returning ErrInvalidInput, bypassing the restriction enforced by Truncate.
    Evidence: client.truncate checks readOnly() at client.go:808, but managedClient.TruncateWAL and client.truncateWAL send the new mutation without that guard. service.go:585 and store.go:987 forward it to rsm.go:317, which accepts a valid boundary. The unchanged TestReadOnlyClientRejectWriteRequests at client_test.go:978 covers only Append and Truncate. Add the same read-only guard before the RPC and extend that regression to verify rejection and unchanged truncation state. Source trace: readonly-truncate-trace.json.

Validation:

  • Completed source review, nine linked issues and all 21 discussion entries; discussion-assessment.json accounts for every key once.

  • Reused frozen exact-head CI: 21 successful, 14 skipped and 2 neutral checks, plus attributed author owning-package and focused race reports.

  • Dependency checksum audit and protobuf/source audit passed; released snapshot fields were preserved. Receipts: checks/1794296526023256034-3.json and checks/1794296833661897720-3.json.

  • git diff --check and gofmt -l on all 30 changed Go files passed. Receipts: checks/1794297247553356411-3.json and checks/1794297247809584168-3.json.

  • Final source, discussion and receipt/log reconciliation passed; checkout unchanged. Receipt: checks/1794297552664678627-3.json; retained validation-ledger.json.

Limitations:

  • No fresh local Go, race or live failover execution; raw author test logs were unavailable. The read-only finding is established by source tracing, without an integrated reproduction.

  • Already-stranded old-format WAL without checkpoint proof remains the explicitly accepted recovery limit.

@jiangxinmeng1

Copy link
Copy Markdown
Contributor Author

Addressed the latest read-only TruncateWAL change request in 010a4fd (current head a1d12c6). The client now returns ErrInvalidInput before the RPC. TestReadOnlyClientRejectWriteRequests uses a writable peer to create a valid advancing PSN, then verifies the read-only call is rejected and the durable PSN/DSN is unchanged. Full pkg/logservice tests passed, and the focused regression passed again after merging the latest main.

@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: a1d12c6d8661d02085aea6c53d0699fd485a6922

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: a1d12c6d8661d02085aea6c53d0699fd485a6922

Assessment: approve

All five prior findings are resolved, including read-only WAL truncation. The fencing and checkpoint metadata extend existing recovery owners with justified, bounded state. No actionable correctness or design issue remains.

Model: gpt-6.1-sol / max

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

Validation:

  • Reviewed all 33 changed files, affected consumers, nine linked issues and all 24 discussion entries; reconciliation retained in discussion-assessment.json.

  • Receipt-backed schema, codec-source, gofmt and diff checks passed. Source remains unchanged.

  • Reused frozen-head CI: 21 successful, 14 skipped and 2 neutral checks, including successful UT and multi-CN BVT. Verified unchanged inputs before reusing prior analysis.

Limitations:

  • No local Go/race/cluster tests rerun; author-reported package and race results lack supplied raw logs.

  • Legacy WAL already truncated without a checkpoint boundary remains fail-closed, consistent with the disclosed Addresses #32240 scope.

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 39e470b at 12:26 UTC

2 h 24 min in the queue, 1 h 10 min of it CI.

So far

  • ✅ Entered the queue Tue 10 Nov, 10:02 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 12:26 · 39e470b · 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 — b837dd5d Deployed Nov 10, 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/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

4 participants