ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Storage.LeiosDB.Impl.SQLite

Synopsis

Documentation

newLeiosDBSQLite ∷ ResourceRegistry IO → Tracer IO TraceLeiosDb → FilePath → FilePath → IO (LeiosDbHandle IO) Source #

Create a new Leios database using the SQLite implementation.

Each call to openReader on the returned handle creates new SQLite connection; readers are not thread-safe and should not be shared across threads. All writers submit to the one write connection created here, on its own worker thread.

The registry owns the background threads (writer, copier and a thread that samples the database's size): closeLeiosDbHandle stops them in order, and closing the registry cancels whatever is still running.

Creates both files with their schemas before returning, so call it only once their directories may be non-empty (after the ChainDB marker check).

newLeiosDBSQLiteWithGcBatchSize ∷ ResourceRegistry IO → Tracer IO TraceLeiosDb → FilePath → FilePath → Int64 → IO (LeiosDbHandle IO) Source #

newLeiosDBSQLite with an explicit GC sweep batch size: how many EBs the writer evicts per turn, between the jobs it serves.

Note that orphan transaction batch size is set by the gcOrphanTxBatchSize constant.

withLeiosDBSQLite ∷ Tracer IO TraceLeiosDb → FilePath → FilePath → (LeiosDbHandle IO → IO a) → IO a Source #

newLeiosDBSQLite bracketed with its closeLeiosDbHandle: on release every pending write has landed, the background threads are gone and the connections are closed, so e.g. the database files can be deleted.

Re-exported for internal tooling

truncateLeiosDbAfterSlot ∷ HasCallStack ⇒ FilePath → SlotNo → IO () Source #

Delete the EBs announced after the given slot.

For internal tooling.

Note: this function works for both the volatile and the immutable partition files. The immutable one has no ebsMissingTxs table (see sql_schema_imm), so the rows there are deleted only if the table exists.

deleteDanglingTxs ∷ HasCallStack ⇒ FilePath → IO () Source #

Delete the transactions that no EB references.

Used in tests.

vacuumLeiosDb ∷ HasCallStack ⇒ FilePath → IO () Source #

Shrink a LeiosDb file to the space its rows need.

A delete frees pages inside the file without returning them to the filesystem. This rewrites the file, so it needs free space of about the size of the file. For internal tooling.

SQL strings (re-exported for leios-schedule-gen)

sql_schema_vol ∷ String Source #

Schema of the volatile partition (leios.vol.db): sql_schema_imm with the columns and objects that track completeness and GC.

sql_schema_imm ∷ String Source #

Schema of the immutable partition (leios.imm.db): the subset of sql_schema_vol that the copier writes and the fallback reads use. The tables it keeps have the volatile columns, so the fallback reads reuse the volatile SQL verbatim and the copy is a server-side INSERT ... SELECT over ATTACH.

Left out, since EBs land here complete and are never collected: ebs.missingTxCount, ebs.status, ebsMissingTxs, the GC tables and indexes, and idx_ebTxs_txHashBytes. Files created before the split still have some of them; nothing reads them.