Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

765,846 Writes/Second Was a Lie: Building a Crash-Safe Key-Value Store With Only Rust's Standard Library

Description and use

StoneKV is a Rust‑only key‑value store that guarantees durability after Ok(()) by syncing the WAL. The article explains how to fix asymmetric length checks and document format limits.

Problem

Ensuring a key‑value store survives mid‑write crashes while keeping the implementation dependency‑free.

Outcome

StoneKV now guarantees that any acknowledged write is durable, with symmetric size checks preventing silent corruption. Known format limits are documented, and the crash‑safety contract is explicit.

Workflow

  • 1. Append record to WAL and sync with File::sync_all().
  • 2. Update memtable after sync succeeds.
  • 3. Flush memtable to disk when threshold reached.
  • 4. On restart, detect incomplete WAL record, replay valid prefix, truncate invalid tail.
  • 5. Enforce MAX_FIELD_LEN in both encode() and decode() to prevent asymmetric corruption.
  • 6. Add tests for boundary conditions and document unresolved limitations.

Evidence

After Store::set() or Store::delete() returns Ok(()), the write has been appended to the WAL and File::sync_all() has completed.

Source

Boundary tests now assert both directions: exactly MAX_FIELD_LEN succeeds, one byte over fails at encode().

Source

  • Record date: 2026-09-08T08:45:14.703Z