Mvcc

tursodatabase/turso/.claude/skills/mvcc

作者 tursodatabaseff97ec42cdef無授權條款24K 個星標收錄於 2026年10月9日更新於 2026年10月8日儲存庫今天更新

Overview of Experimental MVCC feature - snapshot isolation, versioning, limitations

AI 產生的概覽

介紹實驗性 MVCC 儲存模式:如何啟用、架構、檢查點、限制與測試。

功能
此技能是一份關於資料庫引擎中實驗性多版本並行控制(MVCC)功能的參考指南。內容涵蓋如何透過 journal 模式 pragma 啟用 MVCC、資料列版本與快照隔離和 WAL 的差異、內部架構與關鍵原始碼檔案、檢查點行為及其 pragma、目前限制,以及如何執行 MVCC 專用測試。它產出的是說明性指引,而非程式碼或檔案。
適用情境
當你需要了解這個實驗性 MVCC 模式時使用,例如啟用它、理解其版本與檢查點模型,或尋找相關原始碼檔案與測試。在除錯前判斷某個缺陷是否與 MVCC 相關時也很有用。
執行需求
不需要指令碼或工具,僅為純說明性參考資料。測試章節提到宿主專案需要 Rust 工具鏈(cargo 與 make),但此技能本身除代理程式外無需其他相依項目。

MVCC Guide (Experimental)

Multi-Version Concurrency Control. Work in progress, not production-ready.

CRITICAL: Ignore MVCC when debugging unless the bug is MVCC-specific.

Enabling MVCC

sql
PRAGMA journal_mode = 'mvcc';

Runtime configuration, not a compile-time feature flag. Per-database setting.

How It Works

Standard WAL: single version per page, readers see snapshot at read mark time.

MVCC: multiple row versions, snapshot isolation. Each transaction sees consistent snapshot at begin time.

Key Differences from WAL

AspectWALMVCC
Write granularityEvery commit writes full pagesAffected rows only
Readers/WritersDon't block each otherDon't block each other
Persistence.db-wal.db-log (logical log)
IsolationSnapshot (page-level)Snapshot (row-level)

Versioning

Each row version tracks:

  • begin - timestamp when visible
  • end - timestamp when deleted/replaced
  • btree_resident - existed before MVCC enabled

Architecture

Database  └─ mv_store: MvStore      ├─ rows: SkipMap<RowID, Vec<RowVersion>>      ├─ txs: SkipMap<TxID, Transaction>      ├─ Storage (.db-log file)      └─ CheckpointStateMachine

Per-connection: mv_tx tracks current MVCC transaction.

Shared: MvStore with lock-free crossbeam_skiplist structures.

Key Files

  • core/mvcc/mod.rs - Module overview
  • core/mvcc/database/mod.rs - Main implementation (~3000 lines)
  • core/mvcc/cursor.rs - Merged MVCC + B-tree cursor
  • core/mvcc/persistent_storage/logical_log.rs - Disk format
  • core/mvcc/database/checkpoint_state_machine.rs - Checkpoint logic

Checkpointing

Flushes row versions to B-tree periodically.

sql
PRAGMA mvcc_checkpoint_threshold = <pages>;

Process: acquire lock → begin pager txn → write rows → commit → truncate log → fsync → release.

Current Limitations

Not implemented:

  • Garbage collection (old versions accumulate)
  • Recovery from logical log on restart

Known issues:

  • Checkpoint blocks other transactions, even reads!
  • No spilling to disk; memory use concerns

Testing

bash
# Run MVCC-specific testscargo test mvcc
# TCL tests with MVCCmake test-mvcc

Use #[turso_macros::test(mvcc)] attribute for MVCC-enabled tests.

rust
#[turso_macros::test(mvcc)]fn test_something() {    // runs with MVCC enabled}

References

  • core/mvcc/mod.rs documents data anomalies (dirty reads, lost updates, etc.)
  • Snapshot isolation vs serializability: MVCC provides the former, not the latter

來源與署名

來源:tursodatabase/turso位於.claude/skills/mvcc提交ff97ec4

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架