| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Storage.LeiosDB.Impl.SQLite.Maintenance
Description
Maintenance of LeiosDB's volatile and immutable partitions.
- promotion: volatile EBs are copied to the immutable partition once they are old enough;
- garbage collection of the volatile partition;
- the in-memory
LeiosDbStats.
Synopsis
- sqlPromoteToImmutable ∷ WriteQueue → StrictTVar IO Bool → [LeiosPoint] → IO ()
- startCopier ∷ ResourceRegistry IO → Tracer IO TraceLeiosDb → StrictTVar IO LeiosDbStats → StrictTVar IO Bool → WriteQueue → FilePath → FilePath → IO (Thread IO ())
- sqlGarbageCollect ∷ WriteQueue → SlotNo → IO ()
- gcMark ∷ HasCallStack ⇒ Database → GcStmts → SlotNo → IO Int
- data SweeperConn = SweeperConn {
- swDb ∷ !Database
- swStmts ∷ !SweeperStmts
- sweepEbBatch ∷ SweeperConn → Int64 → IO Int
- defaultGcBatchSize ∷ Int64
- initialStats ∷ HasCallStack ⇒ FilePath → FilePath → IO LeiosDbStats
- startVolatileStatsSampler ∷ ResourceRegistry IO → Tracer IO TraceLeiosDb → StrictTVar IO LeiosDbStats → FilePath → IO (Thread IO ())
- bumpVolatileStats ∷ Conn → Int → IO ()
- bumpVolatileStatsVar ∷ StrictTVar IO LeiosDbStats → Int → IO ()
- bumpImmutableStats ∷ StrictTVar IO LeiosDbStats → Int → IO ()
Promotion to the immutable partition
sqlPromoteToImmutable ∷ WriteQueue → StrictTVar IO Bool → [LeiosPoint] → IO () Source #
Implements leiosDbPromoteToImmutable:
- synchronously pin the EB rows in the volatile partition for promotion (status 0 -> 1),
through the writer (PinEb);
- ring the copier's doorbell.
startCopier ∷ ResourceRegistry IO → Tracer IO TraceLeiosDb → StrictTVar IO LeiosDbStats → StrictTVar IO Bool → WriteQueue → FilePath → FilePath → IO (Thread IO ()) Source #
The copier: the only writer into the immutable partition.
Returns the copier's thread: cancelling it closes its connection.
GC mark
sqlGarbageCollect ∷ WriteQueue → SlotNo → IO () Source #
Implements garbageCollect: the MARK phase of GC mark-and-sweep,
as a GcMark job on the writer (see gcMark).
gcMark ∷ HasCallStack ⇒ Database → GcStmts → SlotNo → IO Int Source #
The MARK phase of GC mark-and-sweep: mark for GC (status = 3) every EB
hash all of whose announcements are older than the given slot and not
pinned (status = 1). Returns the number of ebs rows marked.
Runs on the writer. It does not do much work, but rather primes the state
for the writer's own sweep steps (see startWriter): the writer evicts the
marked EBs one batch per turn, so an insert waits for a batch at most.
GC sweep
data SweeperConn Source #
The sweeper's connection and its prepared statements.
Constructors
| SweeperConn | |
Fields
| |
sweepEbBatch ∷ SweeperConn → Int64 → IO Int Source #
One SweepEbBatch transaction: evict up to the given number of GC-marked
EBs, with their body and tx bytes -- three range deletes on the EBs' hashes.
Returns the number of evicted ebs rows. Runs on the writer.
GC batch sizes
defaultGcBatchSize ∷ Int64 Source #
How many EBs one sweep transaction takes, by default.
Stats
initialStats ∷ HasCallStack ⇒ FilePath → FilePath → IO LeiosDbStats Source #
Initialise LeiosDbStats by counting the EB rows of both partitions.
This will only run once per process.
startVolatileStatsSampler ∷ ResourceRegistry IO → Tracer IO TraceLeiosDb → StrictTVar IO LeiosDbStats → FilePath → IO (Thread IO ()) Source #
Fork a thread that traces TraceLeiosDbStats every 10 seconds. Samples
the volatile partition's file only.
bumpVolatileStats ∷ Conn → Int → IO () Source #
Fold a delta into the volatile EB count of the in-memory LeiosDbStats.
bumpVolatileStatsVar ∷ StrictTVar IO LeiosDbStats → Int → IO () Source #
bumpVolatileStats for the maintenance paths, which have no Conn.
bumpImmutableStats ∷ StrictTVar IO LeiosDbStats → Int → IO () Source #
Fold a delta into the immutable EB count of the in-memory LeiosDbStats.