Skip to main content

Module txn

Module txn 

Source
Expand description

SqliteTxn — the concrete transaction handle wrapping a rusqlite connection.

§Design (explicit transaction control)

rusqlite’s Transaction<'conn> is lifetime-bound to &mut Connection, which conflicts with the Txn: Send + 'static bound required by the port trait (§4) and spawn_blocking.

Resolution: SqliteTxn owns the Connection outright (moved out of the Arc<Mutex<…>> in begin_atomic). The SqlitePersistenceStore uses an Option<Arc<Mutex<Connection>>> internally; begin_atomic takes the connection out for the duration of the txn and returns it on commit/rollback. Because Connection: Send (rusqlite guarantees this), the owned SqliteTxn is Send + 'static.

A simpler, more robust alternative that avoids unsafe code: use a boxed Connection with an explicit BEGIN/COMMIT/ROLLBACK sequence rather than rusqlite’s Transaction type. This is the approach taken here.

§Single-writer per agent_id

v0.1 is single-process embedded. The AgentWriteLockMap in mempill-core coordinates writes per agent_id at the async boundary. The store itself assumes a single writer per connection file; no additional locking is needed inside SqliteTxn.

Structs§

SqliteTxn
An open, uncommitted SQLite transaction scoped to one agent_id.