Skip to content

[Bug]: LogService future Truncate compacts later acknowledged appends #32159

Closed

Description

@jiangxinmeng1

Description

LogService accepts Truncate(target) when target is beyond the current latest LSN. Later Append calls can succeed and return LSNs at or below that future watermark. Once exported snapshots are imported and Raft logs compacted, those acknowledged records become unreadable on all three replicas (invalid log range). The direct-client experiment reproduced this physical loss in 3/3 rounds.

This is a deliberately invalid direct LogService API call in an isolated test cluster. No TN/CN ran in the experiment; it does not establish that the normal TN path sends future truncation watermarks.

Environment

  • Isolated three-voter LogService cluster on 10.222.1.51, test bundle logservice-chaos-20261103-d61a7206, data shard 1, RPC addresses 127.0.0.1:56411, :56421, :56431.
  • Same local directories and running cluster as the earlier LogService chaos tests. All three nodes were online during this experiment.
  • Source review: pkg/logservice/store.go:883 (truncateLog) and pkg/logservice/rsm.go:250 (handleTruncateLsn). The latter only checks that the requested watermark exceeds the previous watermark; it does not bound it by the current applied log index.

Stable reproduction

On the dedicated test cluster, use the checked-in reproducer:

root=/home/mo/jxm/logservice-chaos-20261103-d61a7206
python3 "$root/reproduce_future_truncate.py" "$root" --rounds 2 --prefix future-repeat-20261104

The script requires three reachable addresses, reads GetLatestLsn(), submits Truncate(latest + 18), checks that it succeeds and becomes the watermark, then issues paced distinct Appends across the watermark. It waits for the first acknowledged LSN below the watermark to become unreadable on each single-address client, and checks that the acknowledged record above the watermark remains readable on each address. It restricts execution to this dedicated test directory.

Round Latest before → accepted target Acknowledged LSN subsequently unreadable on all three Acknowledged LSN still readable above target
Manual paced round 10245 → 10263 10249 10265, 10268
Automated round 1 10276 → 10294 10281 10297
Automated round 2 10313 → 10331 10318 10333

Each automated round acknowledged nine Append calls. In the manual round, the initial read of LSN 10249 succeeded before snapshot import. After imports, a read from that LSN returned invalid log range on all three addresses. The automated rounds independently reached the same result. The three-address cluster remained responsive after the tests.

Expected behavior

Reject a truncation watermark beyond the log position already committed when the truncate command is applied. A future watermark must never authorize compaction of subsequently acknowledged Append entries. Validate this in the replicated state machine so a client-side GetLatestLsn check is not the sole protection against races.

Impact and evidence

An erroneous caller can make LogService acknowledge new WAL records and then physically remove them. The interface contract says Truncate removes records through the specified LSN; it does not specify that a future LSN should reserve permission to discard later writes. The normal TN call path and whether it can generate this input need separate evaluation.

Report and reproducer: test report, Python reproducer. Raw evidence on 51: $root/future-truncate-paced-20261104.*, $root/future-repeat-20261104.log, $root/future-repeat-20261104/round-*.{truncate,append,old-node-*,new-node-*,summary.json}, and node-{1,2,3}/stdout.log showing snapshot imports. Scope is the direct LogService API; no ordinary MO SQL workload was tested for this issue.

Activity

  1. added
    kind/bug
    on Nov 4, 2026
  2. self-assigned this
    on Nov 4, 2026
  3. added a commit that references this issue on Nov 6, 2026
    ee5e93b
  4. XuPeng-SH commented on Nov 6, 2026

    @XuPeng-SH
    Contributor

    QA 交接:#32149 于 2026-11-06 07:40:26 UTC 合入 main,merge ee5e93bcefd4f04bcda6b8e5002eef96038396d3,最终 head f83150eb8ffb17a3d91a3fbf6865e5a0d0b9ec2e。转交 @Ariznawlll 验证,不表示验收通过。

    修复范围:在 replicated state machine 应用 Truncate 时,拒绝目标 LSN 大于或等于该 Truncate 命令自己的 Raft index,保持原截断水位,不让 future watermark 覆盖随后已确认的 Append。保留 ErrInvalidTruncateLsn 错误类别,文案使用 boundary。此保护不是仅靠客户端查询最新 LSN。

    已读完整 issue 正文,当前无评论,最终 diff 和 PR 讨论已核对。正文 3/3 物理丢失复现属于修复前专用 direct API 实验,并非当前合并版本反例,也未证明普通 TN 会发送非法未来水位。作者报告组合分支定向回归、完整 logservice/moerr 测试及 vet 通过;最新本地验证与 approved review 绑定旧 head 790bca9921。Mergify 报告合并门禁 CI Required 成功;最终 diff 包含 current/future index 拒绝及后续 Append 可读测试,本轮未执行测试。

    QA 建议:在专用隔离集群分别覆盖 current-index、future、合法单调和旧水位边界;拒绝后确认水位未前移,并在后续 append、snapshot import/compaction 后从三地址逐条读回已确认 LSN/payload,保留合法截断对照。建议核对正常 TN checkpoint 调用的兼容性,但不把尚未评估的 TN 输入生成路径写成已证实生产丢数。本改动不会恢复过去已丢失记录,也不覆盖 #32329 的 Truncate 关机取消链。

  5. Ariznawlll commented on Nov 11, 2026

    @Ariznawlll
    Collaborator

    测试版本

    原问题验证

    对超过当前 latest LSN 的未来截断请求,验证返回 invalid truncate lsn、原截断水位不变;随后每轮追加 30 条已确认日志,从三个副本逐条核对 LSN 和 payload。本地完整场景 3/3 通过,每次包含 3 轮未来截断。

    Happy Path 覆盖

    合法单调截断后,确认三个副本均实际导入快照;导入后保留的 20 条已确认日志从三个地址逐条读回,无缺失或重复。本地完整场景 3/3 通过。

    Unhappy Path 覆盖

    未来截断被明确拒绝,拒绝后水位不前移。现有状态机测试另外覆盖当前应用索引和未来索引边界,以及拒绝后的后续追加可读。

    白盒验证

    核对状态机和 LogService 测试断言;相关定向测试普通及 race 各重复 3 次通过。本场景没有覆盖业务 TN SQL 恢复。

    回归测试

    已新增 mo-nightly-regression #1926 独立回归,合入后每日运行;该 PR 仍开放,后续由你合入。

    测试证据

    Linux 三副本 CI 使用相同 main SHA,3 轮未来截断、三个副本快照导入及保留数据校验均通过。

    测试结论

    测试通过。

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