Skip to content

refactor(cold): require &mut self for ColdStorage write methods#42

Merged
prestwich merged 1 commit intomainfrom
prestwich/eng-1979-cold-storage-mut-writes
Mar 25, 2026
Merged

refactor(cold): require &mut self for ColdStorage write methods#42
prestwich merged 1 commit intomainfrom
prestwich/eng-1979-cold-storage-mut-writes

Conversation

@prestwich
Copy link
Member

@prestwich prestwich commented Mar 24, 2026

Summary

Split ColdStorage into three traits for compile-time read/write separation:

  • ColdStorageRead: Clone + Send + Sync, all &self read methods — cloneable, shareable across tasks
  • ColdStorageWrite: Send, &mut self write methods (append_block, append_blocks, truncate_above) — exclusively owned
  • ColdStorage: supertrait combining both, provides drain_above with default implementation

Eliminate RwLock from the task runner. The runner now holds:

  • An owned write backend (exclusive, for inline writes)
  • A cloned read backend (shared via Arc for spawned read tasks)

Read tasks literally cannot call write methods at the type level.

Also adds drain_above override to EitherCold to dispatch to inner backend's atomic implementation (was using the non-atomic default).

Closes ENG-1979

Test plan

  • cargo clippy clean on all 4 affected crates with both --all-features and --no-default-features
  • mem_backend_conformance passes
  • mdbx_backend_conformance passes
  • All unified storage integration tests pass (including drain_above_*)
  • ./scripts/test-postgres.sh (requires Postgres)

🤖 Generated with Claude Code

@prestwich prestwich requested a review from Fraser999 March 24, 2026 17:27
@prestwich prestwich force-pushed the prestwich/eng-1979-cold-storage-mut-writes branch 2 times, most recently from 593e0dd to 6151ead Compare March 25, 2026 12:25
@prestwich
Copy link
Member Author

[Claude Code]

Reworked based on your review feedback:

  1. Docs removeddocs/superpowers/ files dropped from the commit.
  2. EitherCold drain_above — now overrides to dispatch to inner backend's atomic impl.
  3. Trait splitColdStorage split into ColdStorageRead (Clone + Send + Sync, &self) + ColdStorageWrite (Send, &mut self) + ColdStorage supertrait (provides drain_above). RwLock eliminated from the task runner — read tasks get a cloned read backend via Arc, writes use an exclusively owned backend. Read tasks cannot call write methods at the type level.

Ready for another look.

…rite (ENG-1979)

Split the ColdStorage trait into three:
- ColdStorageRead: Clone + Send + Sync, all &self read methods
- ColdStorageWrite: Send, &mut self write methods (append_block,
  append_blocks, truncate_above)
- ColdStorage: supertrait combining both, provides drain_above
  with a default implementation

Eliminate RwLock from the task runner. The runner now holds an owned
write backend (exclusively for writes) and a cloned read backend
(shared via Arc for spawned read tasks). Read tasks cannot call
write methods at the type level.

Add drain_above override to EitherCold to dispatch to inner
backend's atomic implementation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@prestwich prestwich force-pushed the prestwich/eng-1979-cold-storage-mut-writes branch from 6151ead to 0c65a12 Compare March 25, 2026 12:28
@prestwich prestwich merged commit ae1c51b into main Mar 25, 2026
6 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