Rewrite keyvalue item header with byte-aligned field layout#12
Merged
brayniac merged 3 commits intopelikan-io:mainfrom Apr 18, 2026
Merged
Conversation
Adopt crucible's BasicHeader design for ItemHeader: Old: [magic:4?][vlen|klen:4 (packed u32)][flags:1] = 5 bytes (9 with magic) New: [klen:1][flags:1][vlen:4][magic:4?] = 6 bytes (10 with magic) Each field is now directly byte-addressable — no cross-word bit manipulation for klen/vlen access. The flags byte packs is_numeric (1 bit) and olen (6 bits) without shift/mask across word boundaries. Also rewrites value.rs (Value/OwnedValue enums) with same API surface. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The magic sentinel is more useful at the start — if you hit garbage while scanning segment memory, you detect it before interpreting klen/flags/vlen as valid fields. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Rename the `magic` feature to `integrity` across all crates. When enabled (default in keyvalue), the item header includes: - 2-byte magic sentinel (0xCA, 0xFE) at the front - 4-byte CRC32 at the end, covering the full item Header layout: Without integrity: [klen:1][flags:1][vlen:4] = 6 bytes With integrity: [magic:2][klen:1][flags:1][vlen:4][crc32:4] = 12 bytes The CRC32 uses crc32fast which auto-detects SSE4.2 (x86_64) and ARM CRC instructions for hardware-accelerated computation. The checksum covers magic + klen + flags + vlen + optional + key + value, with the CRC field zeroed during calculation. CRC is recomputed after wrapping_add/saturating_sub mutations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
[klen:1][flags:1][vlen:4]= 6 bytes (12 with magic and checksum)integrityfeature which is on by default[vlen|klen:4][flags:1]layout that required cross-word bit manipulationklenis a single byte read,vlenis a direct u32value.rs(Value/OwnedValue) anditem/header.rswith clean codeitem/raw.rsto useis_numeric()instead of the oldvalue_type()enum