Description
Is there an existing issue for the same bug?
- I have checked the existing issues. [Bug]: dn can not restarted successfully by replay failed after restarted for several times #20575, [Bug]: TestCkpLeak panics with ExpectedEOB during WAL replay #26364, and [Bug]: 4.2-dev TN panics in WAL replay on unsupported IOEntry[3004,2] after DN network chaos #27140 involve different WAL/checkpoint failure signatures and are not duplicates.
Branch Name
v4.1.2 / 4.1-dev. The relevant replayer implementation is also unchanged in tag v4.1.4.
Commit ID
Other Environment Information
- Distributed deployment with one TN and three Log Service replicas
- Restore/restart path with about 18 GiB of WAL backlog
- Default WAL replay read size: 64 MiB
- Customer-site identifiers and endpoints are intentionally omitted
Actual Behavior
After a restore, the TN repeatedly failed to restart and never completed open-tae. WAL replay panicked after about 303.8 seconds:
safe: 254297098, dsn: 254297102, psn: 242057393, scheduled: 254297680
panic: logic error
The panic is raised in pkg/vm/engine/tae/logstore/driver/logservicedriver/replayer.go when a lower DSN is read at a later PSN after a larger DSN has already been scheduled.
Observed replay details before the panic:
- Start PSN: 241204046 (truncated PSN: 241204045)
- Checkpoint LSN: 253309370
- First replayed entry: DSN 253351005 / PSN 241204046
- Physical records read: 853,348
- Network bytes received: about 15,586,341,102 bytes (14.52 GiB), equivalent to about 232 full 64 MiB windows
- The failure happened after scanning roughly 80% of the available WAL
- Impact: the TN could not complete startup, so the cluster remained unavailable. No data corruption was observed.
This is not arbitrary disorder inside one loaded batch: the scheduler applies cached entries in DSN order and can handle that case. The failure occurs when the disorder crosses a read-batch boundary. Replay schedules after each batch; a later batch can then expose a lower DSN after dsnScheduled has already advanced.
Expected Behavior
WAL replay should preserve logical DSN order independently of physical PSN order and independently of replay read-batch boundaries. A valid late lower DSN must not panic the TN or make restart depend on choosing a sufficiently large fixed read window.
Replay should remain memory-bounded while reading ahead until either:
- the missing next DSN is found, or
- physical EOF/truncation proves it cannot arrive and the existing skip/truncation rules can be applied.
Steps to Reproduce
The production WAL is not attached, but the failure shape can be reproduced with a replayer test that deliberately places a lower DSN in the next physical read batch:
- Build user records whose PSNs increase while DSNs are logically ordered as
1, 3, 2. - Set
safeDSN/checkpoint handling so replay can advance the scheduling watermark after reading1, 3. - Use a read size that ends the first batch after DSN 3 and returns DSN 2 in the second batch.
- Start replay.
- Observe that the second batch reaches the
dsn-1 < dsnScheduled && schedulePSNCount != 0branch and panics withlogic error.
Regression coverage should include:
1, 3, 2inside one batch: apply1, 2, 31, 3in batch 1 and2in batch 2: apply1, 2, 3without panic- A true missing/truncated DSN at EOF: preserve the intended skip/truncation behavior
- Both startup replay and continuous replay paths
Additional information
Code references in v4.1.2:
- The implementation explicitly documents that DSN is monotonic while PSN may be non-monotonic: https://github.com/matrixorigin/matrixone/blob/v4.1.2/pkg/vm/engine/tae/logstore/driver/logservicedriver/replayer.go#L205-L212
- The panic assumes a smaller DSN with a larger PSN "should not happen": https://github.com/matrixorigin/matrixone/blob/v4.1.2/pkg/vm/engine/tae/logstore/driver/logservicedriver/replayer.go#L828-L850
A temporary recovery hotfix made the replay read size configurable under [dn.logservice] replay-read-size. With a 272 MiB window (ReplayReadSize: 285212672), this incident recovered successfully:
open-tae-endcompleted after 6m16.676s- Replay read 1,007,475 PSNs and 1,124,521 DSNs
- Replay applied 1,119,465 LSNs; last applied DSN/LSN: 254475471 / 254428835
- The first incremental checkpoint completed in 5.189s after the flush backlog drained
- Subsequent incremental/global checkpoints completed normally and WAL truncation advanced
Hotfix reference: 1e7047f
Increasing the fixed window is therefore a useful emergency workaround, but it only changes the probability that the disorder is contained in one batch. It is not a correctness fix. The durable fix should provide memory-bounded dynamic read-ahead/reordering and log the unresolved DSN gap, look-ahead bytes/records, PSN range, safeDSN, and scheduling watermark before failing or applying truncation logic.
Activity
fix(logservice): tolerate duplicate WAL records during replay (#27552)
fix(logservice): tolerate duplicate WAL records during replay (matrix…
fix(logservice): tolerate duplicate WAL records during replay (matrix…
fix(logservice): tolerate duplicate WAL records during replay (matrix…