wasm_sqlite_db (wasm_sqlite v0.1.0)
View SourceThe process behind one open SQLite database.
Like wasm_redb_db: callers talk to this process, the guest runs in a
linked wasm_storage_guest, and this process holds BEAM-local ownership of
the database file, applies deadlines and replaces the guest after a failure.
After a replacement it reopens the guest at once, in the background
(start_open/1, opened/2): callers wait in the queue, each until its own
deadline, and a failed reopen answers them all {unavailable, R}.
Requests that cannot run now wait in one FIFO queue (enqueue/4,
drain/1): while another process owns the connection, or while the guest
reopens. A full queue (max_queue) first lets go of the callers whose
deadline has passed.
A request whose deadline has passed does not start, except one that ends
what its caller holds (late/3): a reset or a finalize runs under
cleanup_timeout, and a COMMIT, END or ROLLBACK of the caller's
transaction rolls it back, as a late commit aborts in redb.
SQLite has one connection here, and a transaction is a state of that
connection. When a request leaves the connection outside autocommit mode
(BEGIN, or a statement in one), the requesting process owns the connection
until a request of its own brings autocommit back (COMMIT, ROLLBACK).
A process that steps a write statement part way owns it too, until the
statement is done or reset: until then SQLite would not commit anybody
else's writes. Requests from other processes wait, in order. If the owner
exits, its statements are finalized and its transaction is rolled back. A
prepared statement belongs to the process that prepared it and is finalized
when that process exits.
When the guest is replaced while a process has a transaction open, the
transaction is gone, and that process's statements fail with
transaction_lost until it ends the transaction itself: they never run
outside it.
Use it through wasm_sqlite.