Repository navigation
fix(logservice): tolerate duplicate WAL records during replay - #27552
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 81d7817eeee1bab5faea3291f5a652429304a07d against the replay state machine, physical/logical ordering model, skip records, batch boundaries, continuous replay, and failure cleanup. One recovery-correctness blocker remains:
[P1] Reject overlaps against all pending ranges, not only the scheduled watermark or an identical start DSN. In readNextBatch, the new checks cover (a) a range overlapping dsnScheduled, and (b) a pending entry with the same start DSN. Two pending ranges with different starts are not compared. This makes correctness depend on whether scheduling occurs between the two reads.
Deterministic counterexample on this head, using the existing mock replayer:
PSN 1: DSN range [1,3]
PSN 2: DSN range [3,5]
readBatchSize = 30
Both records enter dsn2PSNMap before either is scheduled. Replay schedules [1,3], advances dsnScheduled to 3, then looks for start DSN 4; the remaining [3,5] entry is now unreachable under key 3. The exact result is err=nil, applied DSNs [1,2,3], pending map map[3:2]—DSNs 4 and 5 are silently omitted while recovery reports success. With readBatchSize=1, the existing scheduled-overlap check rejects the same logical corruption, so the outcome is explicitly batch-size dependent.
Please maintain/check a non-overlapping interval invariant for every pending record (including different-start partial and contained overlaps) before accepting it; exact retry duplicates may still be coalesced under the intended identity rule. Add same-batch and cross-batch tests for partial overlaps in both directions and containment, asserting fail-closed behavior and no successful incomplete replay. The check also needs to remain sub-quadratic for the million-record/18-GiB recovery shape in #27410.
Validation: the new PR tests pass as a package and under focused -race -count=5; the counterexample above fails before any test-only assumptions are introduced. Q1–Q3 audit found no new resource leak, double cleanup, wait cycle, or unbounded duplicate retention beyond this logical-range ownership hole.
|
Addressed the P1 blocker in
The new matrix covers both read batch sizes 1 and 30 for Local validation on the final diff:
|
jiangxinmeng1
left a comment
There was a problem hiding this comment.
Re-reviewed the updated head 4f8c230. The previous P1 blocker is resolved.
The new B-tree-based pending-range index correctly detects overlaps through predecessor/successor checks, covering
partial overlaps and containment in both directions with O(log n) operations. Exact duplicate ranges retain the
first physical copy, while scheduling and skip processing consistently remove records from both the pending index
and read cache. The WAL and skip-command formats remain unchanged.
I also checked the scheduling, duplicate, skip/reuse, EOF, and continuous-replay paths. No new correctness,
resource-lifecycle, wait-cycle, or unbounded-growth blockers were found.
Code review LGTM. The latest build, UT, coverage, and SCA checks were still running at the time of this review.
|
Fixed the remaining legacy-skip P1 in 28d6cef. Legacy commands now accept a pending DSN only when its current PSN is present in the command PSN set, preserving compatibility with historically permuted pairs while rejecting delayed duplicates after DSN reuse. Added a serialized legacy regression for readBatchSize=1 and 30; before the fix it reproduced applied DSNs [1,2], and after the fix it applies [1,2,3]. Validation passed: owning-package normal and full race, focused race count=100, controlled CGo build/vet, and make static-check (0 issues). |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review of exact head e77a07ee7705405fd2c45ec08c30992a1562798a completed. The ordered B-tree now enforces disjoint pending DSN ranges in O(log n), exact duplicate ranges keep the first physical owner, and scheduled duplicates are retired from cache without changing logical order. Skip replay is now idempotent and identity-safe in both formats: v1 uses exact DSN/PSN pairs, while legacy v0 uses the preserved PSN set to tolerate historical pair permutation without deleting a later record that reused the DSN. Static serialized legacy fixtures cover compatibility and delayed duplicates across batch sizes. Non-sentinel scheduling/append errors terminate once instead of looping/logging, and Replay owns apply-channel closure on normal, error, and panic unwind paths. The original same/cross-batch, continuous replay, range overlap/containment, skip/reuse, EOF, and failure cases are all represented. I found no remaining scoped recovery-correctness, asymptotic-performance, lifecycle, or log-storm blocker; exact-head CI is green.
Merge Queue Status
This pull request spent 10 minutes 12 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #27552 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.
Failing checks:
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27410
What this PR does / why we need it:
WAL replay uses PSN as physical order and DSN as logical order. A record may appear again at a later PSN, for example when an append is committed but times out and the caller retries it. If that record's complete DSN range has already been scheduled, the later physical copy contains no new logical work; the previous code treated it as an impossible ordering and panicked, preventing TN restart.
This PR:
Wal-Replay-Duplicate-Entryand invalid overlaps asWal-Replay-DSN-Overlap.A genuinely missing next DSN is not discarded: the scheduling watermark cannot advance past it, so normal out-of-order records continue to be cached and replayed in DSN order. The behavior is therefore independent of replay read-batch boundaries without reading or spilling the complete WAL.
Regression tests cover same-batch and cross-batch duplicates, continuous replay after EOF, multi-entry DSN ranges, partial and pending range conflicts, and DSN reuse after a skip command.