Repository navigation
Description
Description
TN WAL ReplayForWrite can keep retrying a LogService Read for the driver's retry budget after the caller context has already expired. A short recovery/shutdown deadline is therefore not honored. In the default configuration that retry budget is 3 minutes, and the retry backoff uses an uncancellable time.Sleep.
This is a WAL driver cancellation defect in the Read phase, distinct from #32235's initial GetTruncatedLsn failover case and #32148's managed LogService Read attempt behavior.
Controlled 51 reproduction
- Binary built from PR fix(logservice): harden reads, proposals, snapshots, truncation, and HAKeeper restart #32149 commit
790bca99211ad431e9ea62429cc4c955956b9ef2withmatrixorigin/dragonboat. - Three LogService voters on
10.222.1.51; direct TN WAL entry pointwal.NewLogserviceHandleandReplay(ReplayForWrite)with the default 100-client pool. - Pause the probe after a successful
GetTruncatedLsnand immediately before the first replayRead. Disable all three dedicated host veth links, releaseRead, and restore all links after 9 seconds. The caller's replay context deadline is 5 seconds. - The truncate polling goroutine logged
context deadline exceededat14:37:23, but the replay process was still alive at14:38:14, 56 seconds after it started and long after both caller cancellation and link restoration. It was interrupted withSIGQUITto capture its stack. Goroutine 1 was sleeping inLogServiceDriver.readFromBackendatdriver.go:391, called byreplayer.readNextBatchandreplayer.Replay.
Fast independent reproduction
Using the same source and matrixorigin/dragonboat, a mock LogService client returns from Read when its context is canceled. The driver is configured with MaxTimeout=2s, one client, and a caller context timeout of 100ms. ReplayForWrite returns context deadline exceeded only after 3.102s:
14:40:10.660 Wal-Replay-Truncate-Loop: context deadline exceeded
14:40:13.662 Wal-Read-Backend: duration=3.102155826s, error=context deadline exceeded
replay_elapsed=3.102424208s context_err=context deadline exceeded replay_err=context deadline exceeded
Cause and expected behavior
In pkg/vm/engine/tae/logstore/driver/logservicedriver/driver.go, readFromBackend retries until d.config.MaxTimeout based on wall time, without checking ctx.Err() after a failed read. Each loop iteration creates a fresh attempt context from the original caller context. Once that caller context is canceled, subsequent attempts fail immediately, but the loop still retries until its wall-clock budget expires. The backoff is a plain time.Sleep, so cancellation cannot interrupt it. replayer.Replay checks caller cancellation before calling readNextBatch, but cannot regain control while readFromBackend is retrying.
When the caller context expires, replay should stop retries and return promptly. Attempt contexts should be derived from the original caller context, and backoff should be cancelable. Retrying transient errors while the caller is still live remains appropriate.
Evidence and limits
The remote probe/fault scripts and logs are under /home/mo/jxm/verify-wal-driver-20261106/ on the test host: cancel-replay-run.sh, cancel-replay-fault.sh, cancel-replay.log, and cancel-replay-fault.log. The fast mock probe source is /tmp/mo-replay-cancel/main.go on the build host. The 51 process was deliberately terminated with SIGQUIT at 56 seconds to capture the stack, so its eventual default-budget completion time was not measured. No TN process or SQL query was run; the test uses TN's WAL driver API directly.
Activity
Ariznawlll commentedon Nov 6, 2026
结论
补充同一问题在官方 main 上的独立复现,以及失败后的恢复边界;不是新增缺陷,也不是对某个修复 PR 的验收结论。
调用方的 100ms deadline 已到期,但 WAL 重放仍继续调用 Read,约 3.1 秒后才退出。取消后的新建 driver 能完整重放原来的已确认记录,本次没有观察到数据丢失或重复应用。
关键证据
b6c57d315c8d1df2aca40ab19dee72136e6f2f81,2026-11-06,macOS/arm64。使用真实本地 LogService RPC/Raft 与LogServiceDriver.Replay(ReplayForWrite);单副本、StrictMem,不是完整 TN/CN SQL 集群或真实磁盘恢复测试。ClientMaxCount=1、MaxTimeout=2s、调用方 deadline=100ms。三个独立 fixture 的日志:time.Sleep。因此本次补充与原 issue 的原因一致;2 秒配置也不是严格的返回上限,退避可使返回超过预算。待解决点
调用方已取消时应停止重试并及时释放重放调用;调用方仍有效时,瞬时错误重试及精确读回能力需要保留。本轮未测完整 TN 进程退出耗时,不能将上述 3.1 秒直接外推成 SQL 或生产恢复延迟。
Fix LogService required LSN and WAL recovery across failover (#32330)
XuPeng-SH commentedon Nov 10, 2026
QA 交接:修复 PR #32330 已于 2026-11-10 12:26:03 UTC 合入 main,merge SHA
39e470bad8262405906ada3b38d5da40647184f9(最终 headb837dd5d2d5ba8015b64aa037cde13b00621a7bf)。本项转交 QA,不代表验收通过。Replay Read 在池等待、每次尝试和退避期间响应原 caller cancellation;重点复测 100ms deadline 时及时退出、有效 caller 瞬时错误仍能重试、取消后新 driver 精确重放所有 ACK/二进制 payload 且无缺口或重复应用。
已核对本 issue 完整讨论及 PR 最终相关源码、全部 review/回复:旧快照 revision、ownership loss 重启、生产工厂取消、leader-state RPC deadline、read-only TruncateWAL 五项旧问题均已有修复及后续评审确认,没有当前适用的已验证反例或未完开发 follow-up 阻止本项转测。
实际证据与限制:作者报告 logservice、datasync、tnservice、TAE db、logservicedriver、wal owning suites 及定向 ownership/cancellation race 通过;远端合并队列记录 CI Required 成功。以上为作者/远端证据,本轮未本地执行、未读取测试主机原始日志,不能替代最终 merge SHA 的真实三 voter 故障、完整 TN/CN SQL 或长稳验收。请按本项原场景复测并记录版本、注入边界、时延及恢复结果。旧格式已物理截断且无认证 checkpoint 边界的 #32240 仍单独保留研发;不因本次转测自动要求 4.2 backport。
Ariznawlll commentedon Nov 11, 2026
测试版本
官方 main:
553e16f52b02d59e9ecc5e3c8862f2603e661f48。本地独立三进程、三副本 LogService,使用实际 TN WAL driver API;Linux CI 使用相同 main SHA。原问题验证
完成
GetTruncatedLsn后、首次回放 Read 前暂停三个 LogService,设置 5 秒调用方超时。最新 main 三次分别在 5.003、4.999、4.997 秒返回,不再等待完整驱动重试预算。Happy Path 覆盖
恢复节点后,使用新的 WAL driver 重放 30 条包含
00、ff、80的二进制记录,内容一致且无重复;调用方仍有效时的瞬时失败重试也通过。Unhappy Path 覆盖
三个副本同时暂停时验证回放 Read 的调用方取消及可中断等待,重复 3/3。这里测试的是 WAL driver API,没有将其描述为完整 TN SQL 业务故障演练。
白盒验证
TestReplayReadStopsOnCallerCancellation、TestReplayForWriteRetriesWALTruncateWithLiveContext等在最新 main 上以-race -count=3通过。回归测试
已加入 MOTR 回归 PR #1926,包含三副本回放取消和恢复后的数据校验;PR 尚未合入。
测试证据
Linux CI 三副本任务 使用相同 main SHA,记录
cancel_after_release=5.000s、binary_payloads=30、duplicate=0。测试结论
测试通过。