MVCC and transaction model
Turso implements an MVCC layer (turso-src/core/mvcc/: clock.rs,
cursor.rs, portable_logical.rs, yield_hooks.rs, yield_points.rs) on
top of the storage/pager layer. Ahtola's managed engine mirrors the
observable transaction semantics (begin/commit/rollback, snapshot isolation,
savepoints) but adapts the implementation to managed idioms.
Where things live in Ahtola
- Transaction execution:
src/Ahtola.Core/Execution/VdbeTransaction.cs(BeginTransaction/CommitTransaction/RollbackTransactionopcodes). - Snapshot/adapter layer:
src/Ahtola.Core/ManagedLocalAdapters.cs—IManagedConnectionAdapter,ManagedSnapshotException,ManagedSnapshotFailure,CopySnapshotTo(...)between connections. - Rollback journal:
src/Ahtola.Core/Storage/SqliteRollbackJournal.cs. - WAL read-snapshot/checkpoint coordination:
SqliteWalReadSnapshotCoordinator.cs,SqliteWalWriterCheckpointCoordinator.cs. - Local/remote/replica provider dispatch:
Ahtola.Data(connection pooling, provider dispatch, Hrana remote client).
What must stay aligned
- Isolation semantics: a snapshot taken at begin-transaction must see a consistent database view for the transaction's lifetime. Do not weaken snapshot isolation to "read latest" to fix a test — fix the snapshot coordinator.
- Commit/rollback atomicity: commit must durably flush per the WAL
contract; rollback must restore the pre-transaction page state exactly.
Cross-check
SqliteRollbackJournal.csand the WAL checkpoint coordinator againstturso-src/core/mvcc/andturso-src/core/storage/wal.rs. - Schema version / user version / application id:
ApplySnapshotPragmaHeaderpropagates these on snapshot copy; do not drop them. - Snapshot copy invariants:
CopySnapshotTochecksCannotProveDistinctSnapshotFiles(...)and raises aManagedSnapshotExceptionwith aManagedSnapshotFailurereason. Preserve those failure reasons — callers branch on them.
Adaptation, not reimplementation
- Turso's MVCC uses cooperative yielding (
yield_hooks/yield_points) for scheduling. Ahtola usesasync/awaitor synchronous managed flow — the semantics (when a transaction yields, what a reader sees) must match, not the call style. See theasync-io-portskill. - The Turso MVCC clock (
clock.rs) assigns logical timestamps; mirror the ordering invariants in the managed layer even if the clock implementation differs. - Do not introduce a native MVCC or sync companion. Replica/sync behavior
references
Turso.Data.Syncby name and fails closed (seepure-managed-closure); that is a product decision.
When unsure
Consult turso-src/core/mvcc/ for the upstream semantics and
docs/wal-interoperability-contract.md for the WAL framing that the snapshot
coordinators depend on.