Repository navigation
fix(kvdb): skip a status-only first KV header when caching free space - #445
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
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.
brightness-810
marked this pull request as draft
November 19, 2026 03:06
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 first KV write can leave the trailing-FF boundary inside its status table. Caching this boundary as free space can let recovery allocate a replacement inside the incomplete header.
A subsequent search may mark the residual header
ERR_HDRat a byte that also belongs to the replacement KV'sDELETEDstatus slot. Committing the replacement asWRITEdoes not clear that marker; deleting the source can then leave no readable copy.When the initial cached FF boundary falls within the first KV header's status-table interval, advance the allocation address past the complete header. This keeps the cache-hit condition, remaining-capacity calculation, and on-flash format unchanged, and adds no flash reads or writes.
What this changes
During initial free-space caching, skip the first KV header only when the trailing-FF boundary falls inside its status-table interval. A fully blank data area is unchanged.
This changes only the in-memory allocation address. It does not modify persistent status encoding, the on-flash format, public structures, or APIs.
Related issue
Closes #441
Test closure
tests/fdb_kvdb_tc.cortests/fdb_tsdb_tc.cUTEST_UNIT_RUN(...)list oftestcase()Local host RAM-NOR tests covered the reconstructed case with caches disabled and enabled, including a deinit/init reopen. A controlled STM32 debug replay also verified the adjusted allocation address and a subsequent reboot. These tests have not been ported to the upstream UTEST suite.
The PR's QEMU KVDB UTEST failed for all six
FDB_WRITE_GRANvalues. The available log does not include the failing assertion, so this change is not yet validated by CI.Write granularity covered
FDB_WRITE_GRAN= 1 / 8 / 32 / 64 / 128 / 256Data layout and compatibility
inc/flashdb.hchanged, compatibility impact: N/Adocs/plusdocs/zh-cn/are updated: N/APower-loss semantics
fdb_kvdb_deinit->fdb_kvdb_initreboot simulation; also exercised in a controlled STM32 debug replay