You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: TN WAL Close waits on checkpoint Truncate retries despite shutdown #32329
Closing the TN WAL driver can wait for an in-progress checkpoint Truncate retry loop even after shutdown cancellation. If LogService is unavailable or an RPC stalls, TN shutdown or a rolling restart can be delayed by repeated Truncate attempts.
Reproduction
Use the TN LogService WAL driver with a backend whose Truncate(ctx, ...) waits until ctx.Done() while the service is unavailable. Record a PSN/DSN, issue Truncate(1), wait until the backend call begins, and call LogServiceDriver.Close().
With MaxTimeout=100ms, a controlled test showed that Close() was still blocked after 350ms. Releasing the backend let it finish. Output:
Wal-Truncate-Prepare ... do-truncate=true
close still blocked 350ms after shutdown with MaxTimeout=100ms
Wal-Truncate-Execute ... duration=350.917806ms retry-times=3
The same path is used by TN checkpoints: wal.RangeCheckpoint queues the checkpoint intent, onCheckpointIntent calls updateDSNCheckpointed, and that calls driver.Truncate.
Expected
Driver shutdown should cancel or otherwise promptly finish background Truncate work. A remote Truncate attempt that is already in flight should not keep TN shutdown waiting through the full retry policy.
Cause
LogServiceDriver.Close() calls d.cancel() and then waits for truncateQueue.Stop(), but doTruncate() calls truncateFromRemote(context.Background(), psnIntent, 10). The RPC timeouts and all 11 retry attempts are therefore independent of the driver's shutdown context. The default MaxTimeout is 3 minutes per attempt, with retry backoff in between. GetOnFly() can also delay before the first attempt when client creation retries.
Real three-voter fault injection on [email protected] reproduced the shutdown delay with the default WAL configuration. A TN WAL probe acknowledged 20 appends and a checkpoint through user LSN 7034, then entered the first physical Truncate RPC (PSN 10268). I isolated the connection's LogService address before releasing that RPC. The foreground probe printed summary cycles=20 user_lsn=7044 at 15:33:25, but its process remained alive until the background Truncate finished at 15:43:20:
During the long isolation, the other two LogService processes also shut down; that overlaps with #32134, so this run does not establish a separate “healthy majority but Truncate stuck” claim. It does establish that TN WAL shutdown waited for the entire background Truncate retry sequence after foreground work finished. The network link was restored afterward.
Activity
jiangxinmeng1 commentedon Nov 6, 2026
Real three-voter fault injection on
[email protected]reproduced the shutdown delay with the default WAL configuration. A TN WAL probe acknowledged 20 appends and a checkpoint through user LSN 7034, then entered the first physical Truncate RPC (PSN 10268). I isolated the connection's LogService address before releasing that RPC. The foreground probe printedsummary cycles=20 user_lsn=7044at 15:33:25, but its process remained alive until the background Truncate finished at 15:43:20:During the long isolation, the other two LogService processes also shut down; that overlaps with #32134, so this run does not establish a separate “healthy majority but Truncate stuck” claim. It does establish that TN WAL shutdown waited for the entire background Truncate retry sequence after foreground work finished. The network link was restored afterward.
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,不代表验收通过。关闭时取消独立 truncate context,并贯通 TN→TAE→WAL 的生产 context-aware client factory、池等待/创建及截断重试;重点复测 Close 与在途 RPC、新 client 创建、池等待、后续定时重试的竞态和资源释放,不只覆盖直接注入 mock 工厂。
已核对本 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。本地 macOS/arm64:独立三 LogService 副本、真实 TN 和两个 CN;另有真实三进程 LogService 加 TN WAL driver 的受控 RPC 场景。Linux MOTR CI 使用相同 main SHA。原问题验证
在完整 TN→TAE→WAL 链路写入数据并强制 checkpoint,在确认后台截断开始且新 LogService 连接被阻塞后向 TN 发送 SIGTERM。三轮 TN 均正常退出,耗时分别 0.485、0.439、0.438 秒;每轮 TN 日志均确认
Wal-Truncate-Execute返回context canceled。为在小数据集稳定触发物理截断,本地隔离 TN 的reserved-WAL-entry-count从默认 5000 显式调整为 10;这些耗时不作为生产 SLA。Happy Path 覆盖
每轮均完成 640 笔双表事务,两个 CN 的双表结果一致;恢复 TN 并重启 TN 和两个 CN 后,640 行仍完全一致。每轮 SQL 确认数为 640,未出现未知或失败事务。
Unhappy Path 覆盖
TruncateWAL请求发出并丢弃响应,再关闭 WAL;本地 3/3,重放保留的 10 条记录无重复。Linux CI 观察到真实请求和被丢弃响应,close_inflight=4.855ms。白盒验证
最新 main 的连接池等待、连接创建取消、在途工厂取消和 checkpoint truncate 关闭等定向 Go 测试以
-race -count=3通过。TN 工厂经 TAE 配置传入 WAL 的路径已核对;单独 TN 工厂 race 构建因本机空间限制中止,未记为通过。回归测试
已加入 MOTR PR #1926:覆盖真实三副本上的新客户端创建失败、在途 TruncateWAL 响应丢失和关闭后重放。PR 尚未合入;完整 TN/双 CN、缩小 WAL 保留量的场景本轮为本地专项,不声称已在 MOTR 中覆盖。
测试证据
最新 Linux 三副本 CI 通过;本地完整服务三轮结果保存在
sql-tn-checkpoint-close-verified-553e-{1,2,3}.log及各隔离进程日志。测试结论
测试通过。