mvcc

GitHub

介绍实验性 MVCC 功能的使用指南,涵盖启用方式、与 WAL 的差异、架构设计及关键文件。说明快照隔离机制、检查点流程及当前限制(如缺乏垃圾回收和恢复),并提供相关测试运行方法。

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

触发场景

查询 MVCC 工作原理或配置 排查 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-06 21:37
浙ICP备14020137号-1 $访客地图$