transaction-correctness — скилл для Claude Code: WAL и ACID в Turso
Объясняет механику транзакций в Turso: как работает WAL, чекпоинты, восстановление после сбоя и правила конкурентного доступа.
npx skills add tursodatabase/turso --skill transaction-correctness -a claude-codeЧто делает transaction-correctness
Скилл разбирает, как Turso выполняет операции чтения и записи через WAL (Write-Ahead Logging): writer добавляет фреймы в .db-wal, reader видит консистентный снимок по read mark, checkpoint переносит изменения обратно в .db. Описаны четыре типа чекпоинта — PASSIVE, FULL, RESTART, TRUNCATE — и правила конкурентного доступа: один writer, читатели не блокируют запись.
Turso не использует файл .db-shm — вместо него in-memory структуры: hashmap frame_cache, атомарные read marks и блокировки. Скилл ссылается на wal.rs и pager.rs, показывает разницу между приватным состоянием соединения (Pager, WalFile) и общим (WalFileShared, DatabaseStorage). Это база для тех, кто правит транзакционный слой Turso или отлаживает race conditions.
Нужен репозиторий Turso — скилл опирается на конкретные файлы кодовой базы.
Какие задачи решает
- разобраться в WAL-механике Turso
- понять восстановление после сбоя
- изучить правила конкурентного доступа к базе
- отладить транзакционную логику
- разобраться в архитектуре Pager и WalFile
Примеры запросов агенту
- объясни, как работает чекпоинт в Turso
- покажи разницу между PASSIVE и FULL checkpoint
- как reader видит консистентный снимок данных
Как установить transaction-correctness
1Через Skills CLI (Vercel)
npx skills add tursodatabase/turso --skill transaction-correctness -a claude-code2Вручную: положить файлы
~/.claude/skills/transaction-correctness/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/transaction-correctness/
1Через Skills CLI (Vercel)
npx skills add tursodatabase/turso --skill transaction-correctness -a codex2Вручную: положить файлы
.agents/skills/transaction-correctness/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add tursodatabase/turso --skill transaction-correctness -a cursor2Вручную: положить файлы
.cursor/skills/transaction-correctness/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install tursodatabase/turso transaction-correctness2Вручную: положить файлы
.github/skills/transaction-correctness/SKILL.md1Через Skills CLI (Vercel)
npx skills add tursodatabase/turso --skill transaction-correctness -a gemini-cli2Командой платформы
gemini skills install https://github.com/tursodatabase/turso --path .claude/skills/transaction-correctnessВручную: положить файлы
.devin/skills/transaction-correctness/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add tursodatabase/turso --skill transaction-correctness -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
Из того же набора10
Весь набор →Похожие
Вопросы о transaction-correctness
Как установить transaction-correctness в Claude Code?
Выполни npx skills add tursodatabase/turso --skill transaction-correctness -a claude-code. Файл скилла появится в ~/.claude/skills/transaction-correctness/SKILL.md.
Что делает transaction-correctness?
Объясняет механику транзакций в Turso: как работает WAL, чекпоинты, восстановление после сбоя и конкурентный доступ к базе данных.
Чем Turso отличается от стандартного SQLite?
Turso не использует файл .db-shm — вместо него in-memory индекс WAL с hashmap frame_cache и атомарными read marks, потому что многопроцессный доступ не поддерживается.
Исходный текст
SKILL.md · MIT
--- name: transaction-correctness description: How WAL mechanics, checkpointing, concurrency rules, recovery work in tursodb --- # Transaction Correctness Guide Turso uses WAL (Write-Ahead Logging) mode exclusively. Files: `.db`, `.db-wal` (no `.db-shm` - Turso uses in-memory WAL index) ## WAL Mechanics ### Write Path 1. Writer appends frames (page data) to WAL file (sequential I/O) 2. COMMIT = frame with non-zero db_size in header (marks transaction end) 3. Original DB unchanged until checkpoint ### Read Path 1. Reader acquires read mark (mxFrame = last valid commit frame) 2. For each page: check WAL up to mxFrame, fall back to main DB 3. Reader sees consistent snapshot at its read mark ### Checkpointing Transfers WAL content back to main DB. ``` WAL grows → checkpoint triggered (default: 1000 pages) → pages copied to DB → WAL reused ``` Checkpoint types: - **PASSIVE**: Non-blocking, stops at pages needed by active readers - **FULL**: Waits for readers, checkpoints everything - **RESTART**: Like FULL, also resets WAL to beginning - **TRUNCATE**: Like RESTART, also truncates WAL file to zero length ### WAL-Index SQLite uses a shared memory file (`-shm`) for WAL index. **Turso does not** - it uses in-memory data structures (`frame_cache` hashmap, atomic read marks) since multi-process access is not supported. ## Concurrency Rules - One writer at a time - Readers don't block writer, writer doesn't block readers - Checkpoint must stop at pages needed by active readers ## Recovery On crash: 1. First connection acquires exclusive lock 2. Replays valid commits from WAL 3. Releases lock, normal operation resumes ## Turso Implementation Key files: - [WAL implementation](../../../core/storage/wal.rs) - WAL implementation - [Page management, transactions](../../../core/storage/pager.rs) ### Connection-Private vs Shared **Per-Connection (private):** - `Pager` - page cache, dirty pages, savepoints, commit state - `WalFile` - connection's snapshot view: - `max_frame` / `min_frame` - frame range for this connection's snapshot - `max_frame_read_lock_index` - which read lock slot this connection holds - `last_checksum` - rolling checksum state **Shared across connections:** - `WalFileShared` - global WAL state: - `frame_cache` - page-to-frame index (replaces `.shm` file) - `max_frame` / `nbackfills` - global WAL progress - `read_locks[5]` - read mark slots (TursoRwLock with embedded frame values) - `write_lock` - exclusive writer lock - `checkpoint_lock` - checkpoint serialization - `file` - WAL file handle - `DatabaseStorage` - main `.db` file - `BufferPool` - shared memory allocation ## Correctness Invariants 1. **Durability**: COMMIT record must be fsynced before returning success 2. **Atomicity**: Partial transactions never visible to readers 3. **Isolation**: Each reader sees consistent snapshot 4. **No lost updates**: Checkpoint can't overwrite uncommitted changes ## References - [SQLite WAL](https://sqlite.org/wal.html) - [WAL File Format](https://sqlite.org/walformat.html)
© tursodatabase · MIT · tursodatabase/turso