Skip to content

fix: continue FlashDB recovery scanning after unfinished writes - #437

Closed
brightness-810 wants to merge 1 commit into
armink:masterfrom
brightness-810:fix/continue-recovery-after-interrupted-writes
Closed

brightness-810 wants to merge 1 commit into
armink:masterfrom
brightness-810:fix/continue-recovery-after-interrupted-writes

Conversation

@brightness-810

Copy link
Copy Markdown

What this changes

Fix an early exit in KVDB initialization recovery.

When check_and_recovery_kv_cb() encounters a PRE_WRITE record, it marks
the record as ERR_HDR. Previously, returning true then stopped the entire
KV traversal, rather than skipping only the unfinished record.

A valid PRE_DELETE old copy may appear later in traversal order. If no GC
request is pending, initialization does not retry the scan, so that old copy
can remain unrecovered and the corresponding key may be unavailable.

This change continues scanning after handling the unfinished record, allowing
later records to be processed by the existing recovery logic.

The change does not introduce a new recovery policy, restore DELETED
records, or modify GC behavior.

Related issue

Closes #436

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)
  • Bug fix: the case failed before the fix and passes after, and its name carries the issue number
  • No new case needed, reason: (pure comment / docs / formatting, or a behaviour-preserving refactor already covered)

Write granularity covered

  • CI passed for FDB_WRITE_GRAN = 1 / 8 / 32 / 64 / 128 / 256
  • Local manual verification only, granularities:128
  • Not verified, reason and risk:

Data layout and compatibility

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

Power-loss semantics

  • Not on a write path
  • On a write path, covered by the fdb_xxx_deinit -> fdb_xxx_init reboot simulation
  • On a write path, not coverable by utest, verification method:

@armink

armink commented Nov 16, 2026

Copy link
Copy Markdown
Owner

我按照 #438 方式合入了,这个先关闭了哈

@armink armink closed this Nov 16, 2026
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 掉电恢复] 遇到 PRE_WRITE 后提前结束遍历,可能遗漏后续 PRE_DELETE 旧记录

2 participants