Repository navigation
fix(kvdb)/避免将空白 USING 扇区误标记为 ERR_HDR - #440
Draft
brightness-810 wants to merge 5 commits into
Draft
brightness-810 wants to merge 5 commits into
brightness-810 wants to merge 5 commits into
Conversation
掉电发生在扇区更新为 USING、首条 KV 尚未写入之间时, 可能留下扇区头有效但数据区全 FF 的状态。 恢复 PRE_DELETE 记录时,内部查找可能将已分配的空白目标 误判为损坏 KV 并写入 ERR_HDR。随后搬移仍在同一地址提交 WRITE,并将旧副本标记为 DELETED,导致该 key 无法正常查询。 在空间计算和内部 KV 遍历入口检查整个数据区: - 空间计算遇到全 FF 数据区时,保留首个空闲地址和完整容量 - 内部遍历跳过数据区全 FF 的 USING/FULL 扇区 - 非空数据区保持原有处理,不改变存储格式或增加擦除
An interrupted first KV write can leave the trailing-FF boundary inside its status table. Caching this boundary as free space allows recovery to allocate a replacement inside the incomplete header. A subsequent search can mark the residual header ERR_HDR at a byte that also belongs to the replacement's DELETED slot. Committing WRITE does not clear that marker, and deleting the source leaves no readable copy. Advance the initial cached free address past the complete first KV header when the FF boundary falls within its status-table interval. Keep the cache-hit condition, capacity calculation, and on-flash format unchanged, without adding flash reads or writes.
The KVDB QEMU UTEST fails for all tested FDB_WRITE_GRAN values, but the available CI output does not show the failing assertion. Revert only the startup invalid-sector-header recovery so the earlier KVDB fixes remain isolated while the failure is investigated.
Owner
|
CI 看着一个都没过 |
Author
|
我分别提交测试下哪笔commit有问题 |
brightness-810
marked this pull request as draft
November 19, 2026 03:32
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Fix three KVDB issues observed during power-loss recovery:
ERR_HDRinto fully erased data areas during USING-sector space calculation and internal USING/FULL-sector iteration. Preserve the correct free address and capacity.Recovery-policy change: invalid-header sectors are erased and reformatted even when automatic formatting is disabled. A sector with an invalid header may still contain unique data, so this recovery can lose data. Repairs completed before a later repair failure are not rolled back.
The blank-data guards and allocation-boundary adjustment reuse the existing FF-boundary helper and do not themselves add flash reads or writes. Existing
ERR_HDRorDELETEDrecords are not resurrected. The FF-boundary helper ignores underlying read errors, so these changes do not establish ECC/read-error safety or comprehensive GC safety.Related issue
Closes #439
Test closure
tests/fdb_kvdb_tc.cortests/fdb_tsdb_tc.cUTEST_UNIT_RUN(...)list oftestcase()Validation currently uses a standalone host RAM-flash harness. The cases have not been ported to the upstream UTEST files or registered with
UTEST_UNIT_RUN(...).Local evidence:
ERR_HDRduring actual space recalculation and advanced the free address by one KV header. This supports retaining the space-calculation guard.CI status at the current PR head:
FDB_WRITE_GRANvalues. TSDB passed.Remaining work:
tests/fdb_kvdb_tc.cand register them intestcase().Write granularity covered
FDB_WRITE_GRAN= 1 / 8 / 32 / 64 / 128 / 256Data layout and compatibility
inc/flashdb.hunchangedNo changes to persistent status encoding, public structures, APIs, or configuration macros. No data migration is required. The fix does not convert existing
ERR_HDRorDELETEDrecords back toWRITE.Power-loss semantics
fdb_kvdb_deinit()->fdb_kvdb_init()simulation for the blank-sector recovery casesThe guards affect allocation and startup recovery. Although the blank-data guards do not write flash themselves, they prevent
read_kv()from programmingERR_HDR. The invalid-header recovery path does erase and rewrite flash.The host reboot simulation does not establish safety for every interruption window, invalid-header recovery, or GC source erase. A post-fix hardware power-cut campaign remains outstanding.