Skip to content

fix(kvdb): reject sector headers with unused status (#443) - #444

Open
tthjjg wants to merge 1 commit into
armink:masterfrom
tthjjg:fix/kvdb-sector-status-validation
Open

tthjjg wants to merge 1 commit into
armink:masterfrom
tthjjg:fix/kvdb-sector-status-validation

Conversation

@tthjjg

@tthjjg tthjjg commented Nov 16, 2026

Copy link
Copy Markdown

What this changes

修复 #443:当扇区 magic、combined 合法,但 store 或 dirty 为 UNUSED 时,将其判为异常扇区头。

正常初始化先写状态表,再写 magic,因此这种状态组合不应被接受。新增检查沿用现有异常处理流程,不改变 API、存储格式或状态编码。

Related issue

Closes #443

Test closure

  • Added or updated cases in tests/fdb_kvdb_tc.c or tests/fdb_tsdb_tc.c
  • New cases are registered in the UTEST_UNIT_RUN(...) list of testcase()
  • Cases cover boundaries (sector full / GC triggered / blob crossing write granularity / init check failure)
    • 覆盖三种 UNUSED 状态组合、初始化拒绝、禁止格式化时现场不变、允许格式化时修复及有效数据保留。
  • Bug fix: the case failed before the fix and passes after, and its name carries the issue number
    • 用例名为 test_fdb_github_issue_443_sector_status,上游执行结果待 CI。
    • 本地板上对照:无修复时报 INVALID_HEADER_NOT_REJECTED;加入修复后三个场景全部通过。
  • No new case needed, reason: N/A,已新增回归用例。

Write granularity covered

  • CI passed for FDB_WRITE_GRAN = 1 / 8 / 32 / 64 / 128 / 256
  • Local manual verification only, granularities: 32
    • GD32F303VCT6 本地移植工程,片内 Flash,2 KB 擦除页。
  • Not verified, reason and risk: 上游 BSP/QEMU 的六种写入粒度待 CI 验证。

Data layout and compatibility

  • KV/TSL node format unchanged
  • Node format changed: version bumped, old data migrates by: N/A
  • Public struct or API in inc/flashdb.h changed, compatibility impact: N/A
  • API or config macro changed, and docs/ plus docs/zh-cn/ are updated: N/A

Power-loss semantics

  • Not on a write path: N/A,影响初始化时的异常扇区格式化判断。
  • On a write path, covered by the fdb_xxx_deinit -> fdb_xxx_init reboot simulation
    • 已加入该重启模拟用例,待 CI 执行。
  • On a write path, not coverable by utest, verification method: N/A

板上测试在 GC 搬迁完成后构造异常镜像,通过软件复位验证恢复。
测试不假设页内物理擦除顺序。

@armink

armink commented Nov 16, 2026

Copy link
Copy Markdown
Owner

有冲突哈

@tthjjg
tthjjg force-pushed the fix/kvdb-sector-status-validation branch from 73876ba to 7b07706 Compare November 16, 2026 15:45
@tthjjg

tthjjg commented Nov 16, 2026

Copy link
Copy Markdown
Author

龙哥,已 rebase 到最新 master。这次与新合入的 #438(6c722f1)在测试文件的新增用例位置产生了冲突,现已保留两组用例并解决,更新后的提交是 7b07706。目前 CI 等待批准运行,麻烦再看一下,谢谢!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kvdb:GC 擦除中断恢复时未检查 UNUSED 扇区状态

3 participants