Repository navigation
Description
Description
Under a controlled cross-process timing sequence, the TN LogService WAL driver replays incorrectly after driver.Truncate(acknowledged DSN - 20): an old, unacknowledged Append arrives late with the same DSN as a newer, acknowledged Append, and the physical truncate point falls between the two copies. A fresh driver then replays the old payload under the acknowledged DSN and fails with internal error: dsn <next> not found.
This was reproduced in three independent three-voter LogService clusters (3/3 when the controlled follower window was reached), including one run using the checked-in automated reproducer. No TN/CN process was started. The probe directly uses logservicedriver.NewLogServiceDriver, ReplayForWrite/Read, Append, Entry.WaitDone, and Truncate. This establishes a driver failure under the injected sequence; it does not establish that a real TN deployment can naturally reach the full sequence, especially the timing of new-instance writes and checkpoint-driven truncation while the old request remains delayed. LogService accepts the two requests under its leaseholder protocol; the issue concerns the driver's handling of their DSNs and truncation.
Environment
- MatrixOne LogService and TN WAL driver source baseline:
upstream/mainatd61a7206c16b30baa4efc525eb6067c4364035aa; test harness/report commit262dd14d88. - Test host
10.222.1.51; three isolated clusters with independent disks, UUIDs, and deployment IDs. Data shard 1 has three voting replicas; HAKeeper store timeout is the default 5 minutes. - Tested RPC sets:
127.0.0.1:57401/57411/57421,:57601/:57611/:57621, and:57801/:57811/:57821. - Probe uses three discovery addresses and overrides
-max-client 1to make the connected replica unambiguous. TN's defaultClientMaxCountis 100; the experiment has not reproduced the sequence with that default pool setting.
Stable reproduction
Use a fresh isolated three-node LogService test cluster and place the checked-in TN driver probe binary and chaos-client in its root. Then run the automated reproducer:
root=/home/mo/jxm/logservice-driver-repro2-20261105
python3 "$root/reproduce_orphan_truncate.py" \
--root "$root" \
--addresses 127.0.0.1:57801,127.0.0.1:57811,127.0.0.1:57821 \
--tag stable1The script retries its connection-selection precheck until the old driver is connected to a follower. For the fault attempt, it:
- Lets the old driver acknowledge 31 WAL entries, then pauses it before sending the next Append.
- Confirms its single TCP connection with
ss -tnp,SIGSTOPs that follower, releases the Append, observes no acknowledgement for 5 seconds, and kills only the old driver process. - Keeps the follower paused while a new driver replays and acknowledges 30 entries, then resumes the follower. The old request arrives late, making a second physical record with the same DSN but different payload. Before truncation, independent replay succeeds and logs
Wal-Replay-Duplicate-Entry. - Appends 10 more entries and requests one legal
driver.Truncate(latest acknowledged DSN - 20). It waits forWal-Truncate-Execute, then starts another fresh driver replay.
The script checks for the old payload being replayed under the new driver's acknowledged DSN and the subsequent dsn <next> not found error. Safety cleanup resumes any paused node even if a step fails.
| Independent cluster | Acknowledged copy / late copy | Truncate | Fresh replay |
|---|---|---|---|
| Original test cluster | DSN 1679 at PSN 1978 / 2008 | DSN 1698 → PSN 1997 | Replays old payload as DSN 1679; dsn 1680 not found, exit 2. |
| Fresh cluster 1 | DSN 155 at PSN 168 / 198 | DSN 174 → PSN 187 | Replays old payload as DSN 155; dsn 156 not found, exit 2. |
| Fresh cluster 2, automated script | DSN 63 at PSN 70 / 100 | DSN 82 → PSN 89 | Replays old payload as DSN 63; dsn 64 not found, exit 2. |
One separate control run paused the data leader before sending the old Append. After leader election, no late duplicate appeared and replay succeeded; this control is excluded from the 3/3 result. Connection-selection attempts that did not target a follower exited before fault injection.
Real TN reachability: verified links and remaining gap
- TN's TAE storage passes a LogService client factory into
wal.NewLogserviceHandle; that constructor creates thislogservicedriver(pkg/tnservice/factory.go,pkg/vm/engine/tae/db/open.go,pkg/vm/engine/tae/logstore/wal/store.go). The driver allocates DSNs and appends encoded WAL records; TAE replay promotes the driver toReplayForWritebefore accepting normal writes (db/db.go,db/replay.go). - A TN store reads its shard metadata from local storage on startup and starts the recorded shard, including its
ReplicaID(pkg/tnservice/store_metadata.go,store.go). For an in-place restart using that metadata, the LogService client is configured with the sameTNReplicaID(factory.go). LogService's state machine checks that ID on user updates (pkg/logservice/rsm.go); a new ID can fence an old request, but reusing the same ID is not a per-process generation fence. This makes the test's same-ID case relevant, but does not prove its timing in a real TN restart. - Normal TN truncation is derived from committed checkpoint metadata via
wal.StoreImpl.updateDSNCheckpointed, which then callsdriver.Truncate. The probe callsdriver.Truncatedirectly at an acknowledged DSN. It did not create a TAE checkpoint or prove that a restarted TN can checkpoint and issue the same cutoff before the delayed old request is processed. - A graceful TN shutdown drains handlers and
driver.Closewaits for accepted committers within a deadline. The probe instead kills its old process. An abrupt TN crash is the relevant candidate, but a real TN lifecycle experiment is still needed to establish end-to-end reachability and production impact.
Expected behavior
After legal truncation, a fresh TN WAL driver must either replay all retained acknowledged DSNs with the acknowledged payload or safely skip DSNs already covered by the durable truncate watermark. A delayed stale physical copy must not replace an acknowledged logical record, and replay must not fail because valid later records were truncated in physical order.
Code evidence and impact
logservicedriver/replayer.go removes a duplicate only while the first physical copy is still in the replay window. info.go selects a physical truncate PSN using its currently valid PSN→DSN map. In this sequence the chosen PSN is after the acknowledged copy but before the late copy. On restart, replay begins after the physical watermark; the acknowledged copy is no longer readable, while the late stale copy remains. This explains the wrong first replay payload followed by the missing-next-DSN failure. The test uses no future truncate watermark or malformed input.
The directly observed impact is failed standalone driver startup replay and an incorrect replay callback payload before that failure. We did not start a TN or execute SQL, so the experiment does not prove a TN outage or SQL-level corruption. This differs from #27410 (cross-batch DSN disorder) and #32133 (one-minute Append tail), although the latter can make ambiguous retries more likely.
Full test report and raw evidence retained on 51 under /home/mo/jxm/logservice-driver-chaos-20261104/driver-{prepaused-e,intermediate-cut}*, /home/mo/jxm/logservice-driver-repro-20261105/driver-{prepaused-fresh4,fresh-intermediate-cut}*, and /home/mo/jxm/logservice-driver-repro2-20261105/stable1*. All three fault states are preserved; no additional writes were made to those shards after replay failed.
Activity
jiangxinmeng1 commentedon Nov 5, 2026
补充持久性与实际写模式验证:在第三套复现集群中,保留原磁盘,将三个 LogService 进程全部
SIGKILL后从原目录重新启动。三进程和原三成员视图恢复,但全新 driver 的ReplayForRead仍先把旧 payloadstable1-attempt2-old/000031回放为 DSN 63,随后报internal error: dsn 64 not found,退出码 2。随后用测试探针的
-mode cycle -count 1进入真实ReplayForWrite路径;同样报dsn 64 not found并退出码 2,没有发出新 Append。所以该故障跨整个 LogService 集群冷重启保留,并阻断 WAL driver 写入初始化,不只是只读诊断回放失败。证据在 51 的
/home/mo/jxm/logservice-driver-repro2-20261105/bug-{cold-restart.timeline,after-cold.replay,write-mode.replay};测试报告已更新。[-][Bug]: TN WAL replay fails after legal truncate splits late duplicate from acknowledged copy[/-][+][Bug]: TN WAL driver replay fails under delayed same-ID Append and intervening truncate[/+]jiangxinmeng1 commentedon Nov 5, 2026
按后续复核结果关闭:先前的 3/3 复现只证明了受控、
ClientMaxCount=1的 driver 交错,不能证明真实 TN 生命周期会按此顺序发送请求。新增实验使用 TN TAE 实际的
wal.NewLogserviceHandle、StoreImpl.Replay(ReplayForWrite)、AppendEntry(GroupUserTxn)、RangeCheckpoint,保留默认ClientMaxCount=100,连接独立的三副本 LogService。刻意让两个同TNReplicaID的 WAL 进程同时存活时,可以让旧写入在新实例 checkpoint 后进入日志,并观察到回放 payload 错序;这仍是人为并存场景。更接近崩溃重启的路径中,旧进程的 Append 确实卡在暂停副本后即被
SIGKILL,新进程完成回放与写入,再恢复副本。共 13 次有效卡住窗口,其中 8 次脚本明确选择当时的普通副本;均未观察到旧请求迟到,后续回放成功。正常 TN 关闭还会先 drain 已接受的请求与 WAL。现有证据无法确定生产 TN 会出现此 issue 所需的完整请求顺序,也没有 TN/CN 端到端复现,因此按要求关闭;如以后找到真实同 ID TN 并存或崩溃后迟到请求的证据,可以重新评估。实验记录与探针:jiangxinmeng1@480fec956a