765,846 Writes/Second Was a Lie: Building a Crash-Safe Key-Value Store With Only Rust's Standard Library
Описание и применение
StoneKV – это ключ‑значение, построенное на Rust без внешних зависимостей, которое гарантирует, что после возврата Ok(()) запись уже синхронизирована. В статье описывается, как устранить несовпадение проверок длины полей и как документировать известные ограничения формата.
Задача
Ensuring a key‑value store survives mid‑write crashes while keeping the implementation dependency‑free.
Результат
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.
Рабочий процесс
- 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.
Доказательства
After Store::set() or Store::delete() returns Ok(()), the write has been appended to the WAL and File::sync_all() has completed.
Boundary tests now assert both directions: exactly MAX_FIELD_LEN succeeds, one byte over fails at encode().
- Дата записи: 2026-09-08T08:45:14.703Z