mvcc

GitHub

Turso数据库实验性MVCC功能的开发指南,涵盖启用方式、快照隔离原理、架构设计及与WAL的差异。包含关键文件路径、检查点机制及已知限制(如缺乏垃圾回收),并提供了针对该特性的测试运行方法。

.claude/skills/mvcc/SKILL.md glommer/pgmicro

触发场景

查询MVCC功能启用或配置 了解MVCC架构与数据一致性机制 排查MVCC相关Bug或性能问题 编写或运行MVCC单元测试

安装

npx skills add glommer/pgmicro --skill mvcc -g -y
更多选项

非标准路径

npx skills add https://github.com/glommer/pgmicro/tree/master/.claude/skills/mvcc -g -y

不安装直接使用

npx skills use glommer/pgmicro@mvcc

指定 Agent (Claude Code)

npx skills add glommer/pgmicro --skill mvcc -a claude-code -g -y

安装 repo 全部 skill

npx skills add glommer/pgmicro --all -g -y

预览 repo 内 skill

npx skills add glommer/pgmicro --list

SKILL.md

Frontmatter
{
    "name": "mvcc",
    "description": "Overview of Experimental MVCC feature - snapshot isolation, versioning, limitations"
}

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

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

Aspect WAL MVCC
Write granularity Every commit writes full pages Affected rows only
Readers/Writers Don't block each other Don't block each other
Persistence .db-wal .db-log (logical log)
Isolation Snapshot (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.

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

# Run MVCC-specific tests
cargo test mvcc

# TCL tests with MVCC
make test-mvcc

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

#[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

版本历史

  • 3a97846 当前 2026-07-05 20:22

同 Skill 集合

.claude/skills/async-io-model/SKILL.md
.claude/skills/cdc/SKILL.md
.claude/skills/code-quality/SKILL.md
.claude/skills/debugging/SKILL.md
.claude/skills/differential-fuzzer/SKILL.md
.claude/skills/index-knowledge/SKILL.md
.claude/skills/pr-workflow/SKILL.md
.claude/skills/storage-format/SKILL.md
.claude/skills/testing/SKILL.md
.claude/skills/transaction-correctness/SKILL.md
.claude/skills/memory-benchmark/SKILL.md

元信息

文件数
0
版本
3a97846
Hash
5abdeb34
收录时间
2026-07-05 20:22

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-10 01:06
浙ICP备14020137号-1 $访客地图$