Skip to content

Rewrite keyvalue item header with byte-aligned field layout#12

Merged
brayniac merged 3 commits intopelikan-io:mainfrom
brayniac:brayniac/rewrite-keyvalue-item-format
Apr 18, 2026
Merged

Rewrite keyvalue item header with byte-aligned field layout#12
brayniac merged 3 commits intopelikan-io:mainfrom
brayniac:brayniac/rewrite-keyvalue-item-format

Conversation

@brayniac
Copy link
Copy Markdown
Contributor

@brayniac brayniac commented Apr 18, 2026

Summary

  • Adopt crucible's BasicHeader design: [klen:1][flags:1][vlen:4] = 6 bytes (12 with magic and checksum)
  • Magic and checksum are enabled with the integrity feature which is on by default
  • Replaces the old packed [vlen|klen:4][flags:1] layout that required cross-word bit manipulation
  • Each field is directly byte-addressable — klen is a single byte read, vlen is a direct u32
  • Rewrites value.rs (Value/OwnedValue) and item/header.rs with clean code
  • Updates item/raw.rs to use is_numeric() instead of the old value_type() enum
  • Header size changes: 5→6 bytes (without integrity), 9→12 bytes (with magic)

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>
@brayniac brayniac requested a review from thinkingfish April 18, 2026 16:28
Comment thread crates/keyvalue/src/item/header.rs Outdated
brayniac and others added 2 commits April 18, 2026 09:51
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>
@brayniac brayniac merged commit ed913a7 into pelikan-io:main Apr 18, 2026
4 checks passed
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.

2 participants