Skip to content

[Bug]: TN cannot restart when WAL DSN disorder crosses replay read-batch boundaries #27410

Closed

Description

@aptend

Is there an existing issue for the same bug?

Branch Name

v4.1.2 / 4.1-dev. The relevant replayer implementation is also unchanged in tag v4.1.4.

Commit ID

ce99d32

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:

  1. the missing next DSN is found, or
  2. 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:

  1. Build user records whose PSNs increase while DSNs are logically ordered as 1, 3, 2.
  2. Set safeDSN/checkpoint handling so replay can advance the scheduling watermark after reading 1, 3.
  3. Use a read size that ends the first batch after DSN 3 and returns DSN 2 in the second batch.
  4. Start replay.
  5. Observe that the second batch reaches the dsn-1 < dsnScheduled && schedulePSNCount != 0 branch and panics with logic error.

Regression coverage should include:

  • 1, 3, 2 inside one batch: apply 1, 2, 3
  • 1, 3 in batch 1 and 2 in batch 2: apply 1, 2, 3 without 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:

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-end completed 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

  1. added
    kind/bug
    on Aug 20, 2026
  2. self-assigned this
    on Aug 20, 2026
  3. added
    severity/s0
    on Aug 20, 2026
  4. added a commit that references this issue on Aug 26, 2026
    3c8b4d0
  5. added 3 commits that reference this issue on Sep 17, 2026
    435b166
    b48688f
    adb6486
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions