transaction-correctness

2
0
Source

How WAL mechanics, checkpointing, concurrency rules, recovery work in tursodb

Install

mkdir -p .claude/skills/transaction-correctness && curl -L -o skill.zip "https://mcp.directory/api/skills/download/7245" && unzip -o skill.zip -d .claude/skills/transaction-correctness && rm skill.zip

Installs to .claude/skills/transaction-correctness

About this skill

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:

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

You might also like

flutter-development

aj-geddes

Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.

9521,094

drawio-diagrams-enhanced

jgtolentino

Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.

846846

ui-ux-pro-max

nextlevelbuilder

"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."

571699

godot

bfollington

This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.

548492

nano-banana-pro

garg-aayush

Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.

673466

fastapi-templates

wshobson

Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.

514280

Stay ahead of the MCP ecosystem

Get weekly updates on new skills and servers.