Repository navigation
fix(kvdb): rebuild invalid sector headers during initialization - #446
Draft
brightness-810 wants to merge 1 commit into
Draft
brightness-810 wants to merge 1 commit into
brightness-810 wants to merge 1 commit into
Conversation
brightness-810
marked this pull request as draft
November 19, 2026 03:26
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
An interrupted sector erase or header write can leave one or more sector headers invalid while other sector headers remain valid. During initialization, the KVDB may then fail to traverse the sector layout reliably.
When
not_formatableis enabled, this change prechecks all sector headers before modifying flash. It aborts on a read error and preserves the flash if no valid sector header remains. If at least one valid header remains, it erases and reformats sectors whose headers are invalid, then recalculates the oldest sector address.This repairs headers only; it does not inspect the data area of a sector before erasing it. A sector with an invalid header may contain unique KV data, so recovery can lose that data. The warning is intentional: this is a destructive recovery policy, not proof that the sector contents are disposable.
Related issue
Closes #442
Test closure
tests/fdb_kvdb_tc.cortests/fdb_tsdb_tc.cUTEST_UNIT_RUN(...)list oftestcase()At the current PR head, the QEMU BSP build succeeds, but the KVDB UTEST fails for all six
FDB_WRITE_GRANvalues. TSDB passes. The available CI output does not include the failing assertion, so the failure has not yet been attributed to this commit specifically.Write granularity covered
FDB_WRITE_GRAN= 1 / 8 / 32 / 64 / 128 / 256Data layout and compatibility
inc/flashdb.hunchangedPower-loss semantics
fdb_xxx_deinit->fdb_xxx_initreboot simulation