ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Storage.LeiosDB.Impl.SQLite.Connection

Description

Opening, configuring and closing connections to the LeiosDB partition files, and Conn: a reader's (or the writer's) pair of connections with their prepared statements.

Synopsis

Partition files

initialiseLeiosDbFiles ∷ HasCallStack ⇒ FilePath → FilePath → IO () Source #

Create the volatile and immutable LeiosDB partition files if missing and apply their schemas.

openRawConnection ∷ HasCallStack ⇒ FilePath → IO Database Source #

Open a read-write connection to an existing partition file, whose schema initialiseLeiosDbFiles has already applied.

withReadOnlyConn ∷ HasCallStack ⇒ FilePath → (Database → IO a) → IO a Source #

Open a strictly read-only connection, for seeding DB statistics.

closeChecked ∷ HasCallStack ⇒ Database → IO () Source #

sqlite3_close refuses -- and would silently leak the connection -- if statements are still open; a caller that failed to finalize must hear it.

Connections with prepared statements

data Conn Source #

Constructors

Conn 

Fields

mkConn ∷ Tracer IO TraceLeiosDb → StrictTVar IO LeiosDbStats → Database → Database → IO Conn Source #

Build a Conn over two open partition connections, preparing every statement; closeConn undoes it. If preparing the immutable statements throws, the volatile ones are finalized first.

finalizeConnStmts ∷ Conn → IO () Source #

Finalize the statements of a Conn, leaving its connections open, for a caller that closes those itself.

closeConn ∷ Conn → IO () Source #

Finalize the statements of a Conn, then close both its connections.

dbWithWriteTransaction ∷ HasCallStack ⇒ Conn → IO a → IO a Source #

A writing transaction: BEGIN IMMEDIATE, taking the write lock up front.

A deferred transaction that reads before it writes has to upgrade its lock, and in WAL mode that upgrade fails with SQLITE_BUSY_SNAPSHOT whenever another connection committed in between. That status is not serviced by the busy handler and cannot be retried at the statement level, because the transaction's snapshot is stale for good: the only remedy is to roll back and start over. Taking the lock at BEGIN removes the upgrade, so contention surfaces here instead, where waiting actually resolves it.