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 从公开仓库中收录这些内容。

举报或申请下架