Rewrite segcache segments with atomic fields and mmap backing#11
Merged
brayniac merged 5 commits intopelikan-io:mainfrom Apr 18, 2026
Merged
Conversation
Replace the segment infrastructure with new code that uses atomic types for all mutable header fields and mmap-backed storage via memmap2. Key changes: - SegmentHeader fields are now AtomicI32/AtomicU32/AtomicU8/AtomicInstant, enabling shared-reference access (&self instead of &mut self) - Segment<'a> holds &'a SegmentHeader (shared ref) instead of &'a mut, simplifying get_mut_pair() since headers can alias freely - Segment data heap uses memmap2::MmapMut instead of Box<[u8]> - Boolean accessible/evictable flags replaced with SegmentState enum (Free, Filling, Active, Draining) stored in AtomicU8 - SegmentPool enum (Main, Admission) for S3-FIFO stored in AtomicU8 - fetch_add on write_offset for future concurrent appends - clocksource::coarse::AtomicInstant for create_at/merge_at timestamps Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Builder validation is now in build() instead of panicking setters - Added SegmentTooSmall and InvalidHeapSize error variants - Added Mmap variant wrapping std::io::Error for mmap failures - Removed Segments size assertion (MmapMut size is platform-dependent) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The third row is the last — padding is 26 bytes contiguous, not split across two rows. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
391d05a to
0422cf5
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
thinkingfish
approved these changes
Apr 18, 2026
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
segments/with atomic header fields and mmap-backed storageSegmentHeaderusesAtomicI32/AtomicU32/AtomicU8/AtomicInstantfor all mutable fieldsSegment<'a>now holds&'a SegmentHeader(shared ref) instead of&'a mut— all mutations via atomicsmemmap2::MmapMutinstead ofBox<[u8]>accessible/evictablebooleans replaced withSegmentStateenum (Free,Filling,Active,Draining)get_mut_pair()simplified — headers can alias freely, only data slices need splittingfetch_addon write_offset prepares for future concurrent appendsTest plan
cargo test -p segcache— 54 tests passcargo test -p segcache --features debug— 55 tests pass (magic feature)cargo test -p segcache --features loom -- loom— 8 loom tests passcargo clippy -p segcache --all-features --all-targets -- -D warnings— cleancargo fmt --all --check— clean🤖 Generated with Claude Code