Skip to content

Rewrite segcache segments with atomic fields and mmap backing#11

Merged
brayniac merged 5 commits intopelikan-io:mainfrom
brayniac:brayniac/rewrite-segcache-segments
Apr 18, 2026
Merged

Rewrite segcache segments with atomic fields and mmap backing#11
brayniac merged 5 commits intopelikan-io:mainfrom
brayniac:brayniac/rewrite-segcache-segments

Conversation

@brayniac
Copy link
Copy Markdown
Contributor

Summary

  • Rewrite all 6 files in segments/ with atomic header fields and mmap-backed storage
  • SegmentHeader uses AtomicI32/AtomicU32/AtomicU8/AtomicInstant for all mutable fields
  • Segment<'a> now holds &'a SegmentHeader (shared ref) instead of &'a mut — all mutations via atomics
  • Data heap uses memmap2::MmapMut instead of Box<[u8]>
  • accessible/evictable booleans replaced with SegmentState enum (Free, Filling, Active, Draining)
  • get_mut_pair() simplified — headers can alias freely, only data slices need splitting
  • fetch_add on write_offset prepares for future concurrent appends

Test plan

  • cargo test -p segcache — 54 tests pass
  • cargo test -p segcache --features debug — 55 tests pass (magic feature)
  • cargo test -p segcache --features loom -- loom — 8 loom tests pass
  • cargo clippy -p segcache --all-features --all-targets -- -D warnings — clean
  • cargo fmt --all --check — clean

🤖 Generated with Claude Code

brayniac and others added 4 commits April 16, 2026 14:48
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>
@brayniac brayniac force-pushed the brayniac/rewrite-segcache-segments branch from 391d05a to 0422cf5 Compare April 16, 2026 23:35
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brayniac brayniac merged commit 1f99362 into pelikan-io:main Apr 18, 2026
4 checks passed
@brayniac brayniac deleted the brayniac/rewrite-segcache-segments branch April 18, 2026 15:18
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