[Important] 尾部截断后缺少持久化步骤 #12

Closed
opened 2026-06-09 13:08:50 +08:00 by dailz · 0 comments
Owner

来源

Oracle 审核 docs/design.md Section 3.2 WAL

位置

Section 3.2 "Physical Record 解析规则" 尾部损坏处理(~line 495)

问题描述

Recovery 允许截断最后一个 segment 的尾部损坏。但截断操作本身(ftruncate + 删除后续空 segment)需要 fsync 才能在再次崩溃时保持一致性。设计文档未说明截断后的持久化步骤。

如果在截断后、fsync 前再次崩溃,recovery 会再次看到未截断的尾部损坏,可能重复截断或产生其他不一致。

建议修复

在 "恢复完成状态" 之后或 "Recovery 扫描流程" 末尾添加截断持久化步骤:

  1. ftruncate active segment 到 lastCompleteBatchEnd
  2. fsync truncated segment
  3. 删除 startSequence == expectedSequence 但无 complete batch 的后续空 segment
  4. fsync WAL directory
  5. 更新 MANIFEST 记录恢复终点
  6. fsync metadata directory

以上完成后,引擎才能开始接受新写入。

## 来源 Oracle 审核 `docs/design.md` Section 3.2 WAL ## 位置 Section 3.2 "Physical Record 解析规则" 尾部损坏处理(~line 495) ## 问题描述 Recovery 允许截断最后一个 segment 的尾部损坏。但截断操作本身(`ftruncate` + 删除后续空 segment)需要 fsync 才能在再次崩溃时保持一致性。设计文档未说明截断后的持久化步骤。 如果在截断后、fsync 前再次崩溃,recovery 会再次看到未截断的尾部损坏,可能重复截断或产生其他不一致。 ## 建议修复 在 "恢复完成状态" 之后或 "Recovery 扫描流程" 末尾添加截断持久化步骤: 1. `ftruncate` active segment 到 `lastCompleteBatchEnd` 2. `fsync` truncated segment 3. 删除 `startSequence == expectedSequence` 但无 complete batch 的后续空 segment 4. `fsync` WAL directory 5. 更新 MANIFEST 记录恢复终点 6. `fsync` metadata directory 以上完成后,引擎才能开始接受新写入。
dailz closed this issue 2026-06-11 20:17:59 +08:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dailz/go-kv#12