Skip to content

refactor(db): write-actor + read-pool SQLite connection model (Phase 6 prep) #67

Open

Description

@utof

Per docs/research/architecture_audit.md §3.7 and §4.4.

Problem

Current connection model has three parallel issues:

  1. Three separate eager Mutex<Connection> instances (metadata, tag, search — each opened at startup in crates/desktop/src/lib.rs).
  2. Per-command open_and_migrate in file_repo.rs and volume_repo.rs — re-negotiates WAL shm files + re-applies pragmas on every call.
  3. Mutex<Connection> serializes reads unnecessarily.

Target shape

Write-actor + read-pool hybrid:

  • Writer: one std::thread::spawn owning the rusqlite::Connection, consuming flume::Receiver<WriteCmd>. Migrations applied once at startup via rusqlite_migration 2.4.1. Domain events published onto the bus ONLY after COMMIT from inside this actor — free ordering guarantee.
  • Readers: deadpool-sqlite = "0.13" (Feb 2026; tracks rusqlite 0.38) with max_size = 4, post_create hook applying PRAGMA busy_timeout=5000; temp_store=MEMORY; query_only=1; mmap_size=268435456;. SQLITE_OPEN_READ_ONLY makes write separation a hard invariant.
  • Kill per-command open_and_migrate in file/volume repos.

Reference

silvermine/tauri-plugin-sqlite ships exactly this architecture (using sqlx) for Tauri apps — strongest 2026 precedent.

Label: needs-research

Verify before implementing:

  • deadpool-sqlite current version (was 0.13 in Feb 2026).
  • rusqlite_migration compat with rusqlite 0.38 (bundled feature).
  • flume vs crossbeam::channel trade-off.

Rejected alternatives

From architecture_audit.md §4.4:

Constraint

Move to write-actor NOW, not mid-Phase-6. The refactor is ~300 LOC, removes more code than it adds. Doing it inside the axum work means every new HTTP handler gets written against the wrong shape.

Source

docs/research/architecture_audit.md §3.7, §4.4.

Execution hint

Brainstorm → plan cycle. Block Phase 6 (issue #59) on this.

Activity

  1. added
    type/chore
    status/needs-research
    on Apr 19, 2026
  2. utof commented on Apr 19, 2026

    @utof
    OwnerAuthor

    Correction: The body's parenthetical "Phase 6 (issue #59)" is wrong — GH issue #59 is a different FTS refactor. "Phase 6" here refers to the internal task-tracker epic (Local HTTP API: axum + keychain + OpenAPI); there is no matching GH issue yet. This issue is a blocker/prep for that epic whenever it starts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/needs-researchtype/chore

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions