Skip to content

feat(engine): Phase 11.1 multi-connection foundation (SQLR-22)#122

Merged
joaoh82 merged 1 commit intomainfrom
worktree-phase-10-1-multi-conn
May 10, 2026
Merged

feat(engine): Phase 11.1 multi-connection foundation (SQLR-22)#122
joaoh82 merged 1 commit intomainfrom
worktree-phase-10-1-multi-conn

Conversation

@joaoh82
Copy link
Copy Markdown
Owner

@joaoh82 joaoh82 commented May 10, 2026

Summary

First slice of Phase 11 — concurrent writes via MVCC + BEGIN CONCURRENT (SQLR-22). Refactors Connection from owning Database by value to holding Arc<Mutex<Database>>, so multiple Connection handles can address the same engine state from inside one process.

  • New Connection::connect() mints a sibling handle that shares the backing Database. Connection: Send + Sync.
  • Connection::database() / database_mut() (already #[doc(hidden)]) now return MutexGuard<'_, Database>. Internal call sites in src/ask/, the seven sqlrite-mcp tools that read the database, and the Python / Node / WASM SDK shims bind the guard to a local first.
  • Six new tests in src/connection.rs: in-memory + file-backed sibling sharing, handle counting, 8-thread × 25-INSERT contention, per-handle prep cache, compile-time Send + Sync check.
  • Docs: roadmap Phase 11 wrapper, design-decisions entry 12a, embedding.md "Sharing one database across threads" section, _index.md project-state line.

Scope honesty

Phase 11.1 is capability, not throughput. Every commit still serializes through the per-database Mutex and the existing pager flock. True multi-writer throughput on disjoint rows lands with BEGIN CONCURRENT in 11.4 — see the plan doc for the sequenced rest of Phase 11.

The plan doc internally numbers sub-phases as "Phase 10.x" — that's its working title from before Phase 10 (benchmarks) shipped. Roadmap entries say Phase 11.x; code comments and tests track the plan-doc numbering for continuity.

Test plan

  • cargo build --workspace --exclude sqlrite-desktop --exclude sqlrite-python --exclude sqlrite-nodejs --exclude sqlrite-benchmarks --all-targets — clean
  • cargo test --workspace --exclude sqlrite-desktop --exclude sqlrite-python --exclude sqlrite-nodejs --exclude sqlrite-benchmarks — 579/579 pass (32/32 connection tests, including 6 new)
  • cargo clippy --workspace --exclude sqlrite-desktop --exclude sqlrite-python --exclude sqlrite-nodejs --exclude sqlrite-benchmarks --all-targets — no new warnings
  • cargo fmt --all -- --check — clean
  • cargo doc --workspace --exclude sqlrite-desktop --exclude sqlrite-python --exclude sqlrite-nodejs --exclude sqlrite-benchmarks --no-deps — no new warnings on changed files
  • No file-format change; .sqlrite files written before this PR open identically

Followups (next sub-phases, separate PRs)

  • 11.2 — MvccClock + ActiveTxRegistry; persist clock high-water in WAL header (v1 → v2)
  • 11.3 — MvStore skeleton + PRAGMA journal_mode = mvcc snapshot-isolated reads
  • 11.4 — BEGIN CONCURRENT writes + commit-time validation (the meat)
  • 11.5 — Checkpoint integration + crash recovery
  • 11.6 — GC (per-commit + background)
  • 11.7 — Indexes under MVCC (deferred-by-design — separate slice)
  • 11.8 — SDK + REPL propagation of Busy / BusySnapshot; new bench workload
  • 11.9 — Docs sweep — promote plan to docs/concurrent-writes.md

🤖 Generated with Claude Code

First slice of Phase 11 (concurrent writes via MVCC + BEGIN CONCURRENT).
Refactors Connection from owning Database by value to holding
Arc<Mutex<Database>>, so multiple Connection handles can address the
same engine state from inside one process.

Connection::connect() mints a sibling handle that shares the backing
Database. Connection is now Send + Sync and can be moved across
threads without an outer Mutex<Connection>. The pager's existing
process-level flock and per-database mutex still serialize commits;
true multi-writer throughput on disjoint rows lands with
BEGIN CONCURRENT in 11.4.

Connection::database() / database_mut() return MutexGuard<'_, Database>;
internal call sites in src/ask, sqlrite-mcp tools, and the
Python/Node/WASM SDK shims bind the guard to a local first.

Six new tests in src/connection.rs:
- connect_shares_underlying_database
- connect_shares_file_backed_database
- handle_count_reflects_live_handles
- threaded_writers_serialize_cleanly (8 threads × 25 INSERTs)
- prep_cache_is_per_handle
- connection_is_send_and_sync (compile-time Send+Sync check)

Docs sweep: roadmap gets a Phase 11 section linking to
concurrent-writes-plan.md (the plan-doc internally numbers
sub-phases as "Phase 10.x" — that's its working title from before
Phase 10 = benchmarks shipped). New design-decisions entry 12a.
embedding.md gains a "Sharing one database across threads" section.

No file-format change. 579/579 workspace tests pass. No new clippy
warnings. fmt clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
rust-sqlite Ready Ready Preview, Comment May 10, 2026 10:29am

Request Review

@joaoh82 joaoh82 merged commit c2ad854 into main May 10, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant