| 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 ⇒ StrictTVar IO Bool → Database → GcStmts → SlotNo → IO ()
- data SweeperConn = SweeperConn {
- swDb ∷ !Database
- swStmts ∷ !SweeperStmts
- data SweepState
- sweepEbBatch ∷ SweeperConn → Int64 → IO Int
- sweepOrphanBatch ∷ SweeperConn → Int64 → IO (Maybe Int)
- gcReinit ∷ SweeperConn → IO ()
- defaultGcBatchSize ∷ Int64
- gcOrphanTxBatchSize ∷ 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 #
gcMark ∷ HasCallStack ⇒ StrictTVar IO Bool → Database → GcStmts → SlotNo → IO () 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);
- stage its txs as GC candidates;
- ask for a sweep.
Runs on the writer. It does not do much work, but rather primes the state
for the writer's own sweep steps (see startWriter).
GC sweep
data SweeperConn Source #
The sweeper's connection and its prepared statements.
Constructors
| SweeperConn | |
Fields
| |
data SweepState Source #
How far a sweep pass has got. The writer advances it one batch per turn rather than running a pass to completion, so an insert waits for a batch at most.
Constructors
| SweepIdle | |
| SweepEbs | Evicting GC-marked EBs. |
Fields
| |
| SweepOrphans | Evicting the txs they orphaned. |
Instances
sweepEbBatch ∷ SweeperConn → Int64 → IO Int Source #
One SweepEbBatch transaction: evict up to the given number of GC-marked
EBs. Runs on the writer.
sweepOrphanBatch ∷ SweeperConn → Int64 → IO (Maybe Int) Source #
One SweepOrphanBatch transaction: evict up to the given number of
orphaned txs, or Nothing if there was nothing to do. Runs on the writer.
gcReinit ∷ SweeperConn → IO () Source #
Stage every unstaged GC candidate, one page per transaction.
The sweeper only ever reads gcTxCandidates, which the mark phase fills
(sql_gc_stage_marked). A tx orphaned by anything else -- a
truncateLeiosDbAfterSlot that dropped its EB's rows, a database written
before the table existed -- is referenced by nothing and staged nowhere,
and would never be collected.
Only such out-of-band edits can leave that behind, and only before the writer started, so this runs once per process, on the writer.
GC batch sizes
defaultGcBatchSize ∷ Int64 Source #
How many EBs one sweep transaction takes, by default.
gcOrphanTxBatchSize ∷ Int64 Source #
How many orphaned txs to GC in one sweep.
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.