Skip to content

[Bug]: TN WAL replay fails after valid checkpoint truncation of concurrent writes #32240

Closed

Description

@jiangxinmeng1

Description

A normal TN WAL driver can acknowledge concurrent user writes, then successfully checkpoint and physically truncate them, but a fresh ReplayForWrite fails with internal error: dsn ... not found. This is reproducible with one WAL handle, the default 100-client pool, a real three-voter LogService shard, and a checkpoint target below the last acknowledged user LSN. It does not require a second TN/WAL process writing concurrently or a node fault.

The user entries above the checkpoint watermark remained physically readable in the observed runs, but the WAL driver could not finish replay or enter write mode. This is a WAL startup failure; this test did not launch a full TN/CN or SQL workload.

Environment

  • Baseline: upstream/main production code at d61a7206c16b30baa4efc525eb6067c4364035aa; reproducer/report commit b6a4e183b2.
  • Dedicated 3-voter LogService clusters on 10.222.1.51, data shard 1, default 5-minute store expiry, RPC 127.0.0.1:58201/58211/58221. Fresh empty disks for the no-fault reproduction.
  • The probe uses TN's wal.NewLogserviceHandle, StoreImpl.AppendEntry(GroupUserTxn), Entry.WaitDone, RangeCheckpoint(1,end,files...), and ReplayForWrite, with default ClientMaxCount=100.

Stable reproduction

  1. Start a fresh dedicated three-replica LogService shard with one TN leaseholder ID. Run concurrent_probe on one WAL handle with -workers 64 -per-worker 50 -delay 0s. Wait for summary acked=3200 expected=3200. A fresh wal_probe in -mode replay must succeed before truncation.
  2. Before checkpoint, run the read-only sequence_probe against the three addresses, save its record psn=... dsn=... lsn=... output, and run choose_checkpoint.py on that mapping. It selects a legal checkpoint LSN below the last ACK that leaves a lower DSN after physical prefix truncation but removes some following, already checkpointed DSNs. The exact cutoff varies with physical commit ordering.
  3. Run wal_probe -mode cycle -count 1 -checkpoint-every 1 -checkpoint-lag <printed checkpoint_lag> -checkpoint-files, wait for checkpoint_ack and Wal-Truncate-Execute success, then start a fresh wal_probe -mode replay.

No-fault fresh-cluster run: all 3200/3200 writes were ACKed, all 3200 replayed before checkpoint. A mapping-selected legal checkpoint at user LSN 3140 and physical Truncate(PSN 2915) succeeded. New replay applied DSN 3105–3110, then exited 2 with dsn 3111 not found. Direct physical scan found 60/60 uncheckpointed user records and matching payloads, plus 15 residual checkpointed records. The selector on this mapping also identifies other failing boundaries; cutoff 3140 was selected before its destructive truncation.

Two additional real runs produced the same failure class:

Run Workload / checkpoint New replay
Existing WAL shard, 32 concurrent appenders with one follower and then leader killed for 8s each, restoring between cuts 3360 ACKs matched full replay; checkpoint user LSN 4424; truncate PSN 10530 succeeded Applied residual DSN 4484, then dsn 4485 not found
Separate shard, 64 concurrent appenders after a completed follower/leader fault round Full pre-truncate read; mapping-selected checkpoint user LSN 5375; truncate PSN 5141 succeeded Applied residual DSN 5341, then dsn 5342 not found; 56/56 uncheckpointed records remained physically readable

One other fault round and one earlier no-fault round had successful post-checkpoint replay when their chosen boundaries did not form the problematic physical/logical ordering. This is a boundary-dependent defect, not every concurrent checkpoint.

Code path and expected behavior

logservicedriver/truncate.go:doTruncate advances a physical PSN prefix while each examined record has max DSN at or below the checkpoint DSN. Parallel clients can commit DSN ranges out of PSN order, leaving some older, checkpointed DSNs beyond the physical cutoff while deleting other checkpointed DSNs before it. replayer.go skips missing DSNs only before it has applied any LSN; once it applies a residual old DSN, a later checkpointed hole produces fatal dsn not found.

Replay must not fail on a hole made solely by valid checkpoint truncation. It should distinguish a missing checkpointed DSN from a missing uncheckpointed DSN and preserve the latter as an error. A fix must also keep the physical truncation boundary conservative enough that uncheckpointed entries are never deleted.

This differs from closed #27410 (disorder across read-batch boundaries) and #32220 (late Append from a second same-ID process). Here the original writes all completed before checkpoint, the failure is caused by a valid physical truncate, and the fresh no-fault run used only one writer instance at a time.

Full report. Raw logs and pre/post physical mappings are retained on 51 under /home/mo/jxm/logservice-concurrent-clean2-20261105/, /home/mo/jxm/logservice-concurrent-fault2-20261105/, and /home/mo/jxm/logservice-tnwal-lifecycle-20261105/.

Activity

  1. self-assigned this
    on Nov 5, 2026
  2. jiangxinmeng1 commented on Nov 5, 2026

    @jiangxinmeng1
    ContributorAuthor

    补充原盘冷重启验证:保留无节点故障复现的三个数据目录,停止全部 LogService 进程、确认旧进程退出后原盘启动三台。三地址恢复数据 shard 的 leader/三成员视图;新 TN WAL driver ReplayForWrite 仍在 同一个 dsn 3111 not found 处退出码 2。没有向故障 shard 发出新 WAL 写入,说明该失败状态跨三副本整组冷重启保留。

    第一次重启脚本仅等监听端口释放,撞到 node1 旧 PID 尚在退出而拒绝启动;该部分启动与等待多数派的探针没有计入结果。确认旧进程退出、三节点均正常运行后才执行上述验证。

    更新的报告:https://github.com/jiangxinmeng1/matrixone/blob/bd44928a54/docs/design/logservice_three_node_failure_test.md 。原始日志:51 上 /home/mo/jxm/logservice-concurrent-clean2-20261105/clean2-after-cold-retry.replay。测试节点现已收到停止信号。

  3. jiangxinmeng1 commented on Nov 5, 2026

    @jiangxinmeng1
    ContributorAuthor

    补充一条更接近 TN 持续运行的时间线:单个 wal.NewLogserviceHandle、默认 100 client,32 个协程并发 AppendEntry(GroupUserTxn);另一个协程根据连续已确认的 user LSN 前缀,每约 300 个 ACK 调用一次 RangeCheckpoint(1,end,files...),水位始终落后该前缀至少 100 条。期间在 ACK 276 时将当前 leader 和一个普通副本同时停 6 秒,再原盘恢复。没有第二个同 ID 写实例。

    最终 1920/1920 条写入获得 ACK,7 次 checkpoint intent 和对应的物理 Truncate 均成功;最后 checkpointed user LSN 10780、最新 user LSN 10880。全新 WAL 实例回放先读到残留的已 checkpoint user LSN 10773、10774,随后在 dsn 10833 not found 退出。只读物理扫描核对 checkpoint 之后 100/100 条确认记录仍在且 payload 一致;另残留 4 条旧 checkpoint 范围内记录。这与 issue 已述的旧 DSN 空洞阻断回放是同一机制。

    对照:三副本健康的并发 checkpoint 轮 3840/3840 ACK、10 次 checkpoint、回放成功;轮流只停一节点的轮次 2560/2560 ACK、7 次 checkpoint、回放成功;只黑洞 leader RPC 端口 12 秒的轮次 2560/2560 ACK、7 次 checkpoint、回放成功。各轮最大单条 ACK 延迟分别为 1.823、61.091、13.308 秒;两节点短停轮为 60.519 秒。后两种约一分钟尾延迟与已有连接故障问题有关,不是本 issue 的新根因。

    更新报告与探针。原始日志保留在 51 的 /home/mo/jxm/logservice-liveckp-20261105/:liveckp-two-down.{log,timeline,replay,mapping} 及三组对照。测试节点与网络规则均已清理。

  4. XuPeng-SH commented on Nov 10, 2026

    @XuPeng-SH
    Contributor

    合并范围补充:#32330 已于 2026-11-10 12:26:03 UTC 合入 main,merge SHA 39e470bad8262405906ada3b38d5da40647184f9(最终 head b837dd5d2d5ba8015b64aa037cde13b00621a7bf)。新 TruncateWAL 将物理 PSN 与 checkpointed DSN 边界一同持久化,重放只跳过有认证 checkpoint 边界的缺口,仍拒绝缺失的未 checkpoint 数据。

    本 issue 暂保留研发归属、保持 open:PR 明确只 Addresses 本项。已在旧格式下物理截断、未持久化 checkpointed-DSN 边界的存量 shard,仍缺少可认证的内部空洞证明;修复这类存量 shard 需要单独的可信 checkpoint 元数据,当前合并仍 fail closed。原盘冷重启后 dsn 3111 缺口及持续运行后 dsn 10833 缺口是旧版本证据,不写成此次合并后的实测反例;保留原因是明确未完成的存量恢复范围。

    已读 issue 全部两条评论、PR 完整讨论及最终相关实现。本轮未本地运行或审计测试主机原始日志。作者 owning/race 通过及远端 CI Required 成功不替代存量原盘恢复验收。后续应分别验证新格式的并发 checkpoint/乱序 DSN/缺失未 checkpoint 数据,以及存量 shard 的认证恢复路径;不据此关闭问题、改派 QA 或自动要求 4.2 backport。

  5. jiangxinmeng1 commented on Nov 17, 2026

    @jiangxinmeng1
    ContributorAuthor

    当前版本已由 #32330 修复这条路径:TruncateWAL 将物理 PSN 与 checkpointed DSN 边界作为同一条 Raft 状态变更持久化,replay 只跳过该边界内的缺口,并继续拒绝未 checkpoint 的缺口。按此范围关闭本 issue。旧格式已截断 shard 若缺少该边界,仍需依赖可信的存量 checkpoint 元数据进行单独恢复,不应猜测并跳过缺失记录;如有具体存量恢复需求,请另开 issue 跟踪。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions