mvcc

GitHub

介绍实验性 MVCC 功能的指南,涵盖启用方式、快照隔离机制、与 WAL 的差异、架构设计及关键文件。指出当前非生产就绪状态,存在垃圾回收缺失、恢复未实现及检查点阻塞等限制。

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

Trigger Scenarios

询问关于数据库 MVCC 功能的配置或启用方法 需要了解 MVCC 与 WAL 的区别或架构细节 查询 MVCC 的已知限制或未实现功能

Install

npx skills add glommer/pgmicro --skill mvcc -g -y
More Options

Non-standard path

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

Use without installing

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

Version History

  • 3a97846 Current 2026-07-05 20:22

Same Skill Collection

.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

Metadata

Files
0
Version
3a97846
Hash
5abdeb34
Indexed
2026-07-05 20:22

Главная - Вики-сайт
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-09 04:22
浙ICP备14020137号-1 $Гость$