ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Storage.LeiosDB.API

Synopsis

Handle

data LeiosDbHandle (m ∷ Type → Type) Source #

The Leios database. Hands out readers, writers and subscriptions.

Constructors

LeiosDbHandle 

Fields

  • closeLeiosDbHandle ∷ m ()

    Close the database: flush what is in flight, stop whatever it runs behind the scenes, release its connections. Readers and writers handed out earlier are not usable afterwards.

  • openReader ∷ HasCallStack ⇒ m (LeiosDbReader m)

    Get a new reader. No interaction between readers or writers.

  • openWriter ∷ HasCallStack ⇒ m (LeiosDbWriter m)

    Get a new writer. All writes of all writers are serialised.

  • subscribeEbNotifications ∷ HasCallStack ⇒ m (StrictTChan m LeiosEbNotification)

    New EBs and EB closures as they are stored, from the moment of subscription. TODO: make return type more descriptive (e.g. Subscription { getNext :: STM m LeiosEbNotification })

  • garbageCollect ∷ HasCallStack ⇒ SlotNo → m ()

    Trigger garbage collection of the LeiosDB.

    This function does not do have to do the actual GC, but rather act as the MARK phase of GC and "create work" for a background SWEEP thread.

    See sqlGarbageCollect for the SQL backend implementation.

  • leiosDbPromoteToImmutable ∷ HasCallStack ⇒ [LeiosPoint] → m ()

    Promote the given EBs' bodies and tx closures from volatile into immutable LeiosDb. Takes a batch: the caller holds the ImmutableDB write lock and blocks on the shared writer queue, so this must be one round-trip per copyToImmutableDB pass, not one per certified EB.

  • leiosDbSampleStats ∷ HasCallStack ⇒ m LeiosDbStats

    Sample LeiosDbStats counters.

data LeiosDbStats Source #

In-memory LeiosDb counters: seeded from the database files once per handle, bumped by the write, copy and GC paths, never written back.

An EB that has been copied to the immutable partition but not yet evicted from the volatile one counts in both partitions -- that is the truth on disk during the window between copy and GC.

Constructors

LeiosDbStats 

Fields

Instances

Instances details
Show LeiosDbStats Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LeiosDB.Trace

data LeiosEbNotification Source #

What the DB tells its subscribers as it acquires EBs.

Each notification is sent at every LeiosPoint of the EB that is its election's focus and whose slot is not older than the ImmutableDB tip's, even one that becomes the focus after the EB was acquired. An election's focus is the first announcement in it that the node accepts, until a verified certificate names another, so every point that a block certifies is a focus. So a subscriber hears of the EB's youngest focus.

Constructors

AcquiredEb

The DB holds the EB's body.

Fields

AcquiredEbTxs

The DB holds the EB's body and every tx it lists.

Fields

Reading

data LeiosDbReader (m ∷ Type → Type) Source #

Query API into the LeiosDb. Do not use a reader in two concurrent threads.

Constructors

LeiosDbReader 

Fields

withReader ∷ MonadThrow m ⇒ LeiosDbHandle m → (LeiosDbReader m → m a) → m a Source #

Writing

data LeiosDbWriter (m ∷ Type → Type) Source #

Modifying API into the LeiosDb.

Asynchronous interface where each operation returns upon submission. The returned Promise can be used to await the write being performed. Any exceptions are thrown through await.

Constructors

LeiosDbWriter 

Fields

  • closeWriter ∷ m ()

    Close writer and flush all remaining writes.

  • writeEbPoint ∷ HasCallStack ⇒ LeiosPoint → BytesSize → m (Promise m ())

    Record an announced EB's point and expected size.

    TODO When this LeiosPoint is its election's focus and the DB already holds the EB's body, send AcquiredEb for it, and AcquiredEbTxs too if the DB holds every tx, as LeiosEbNotification requires. Nothing in the node calls writeEbPoint yet.

  • writeEbBody ∷ HasCallStack ⇒ LeiosPoint → EndorserBlock → m (Promise m CompletedEbs)

    Persist an EB body. Returns any EBs whose closure this completed.

    The returned EB is only used for tracing and too broad: it can actually only be this same EB which got completed.

    Its point must already have been written, by writeEbPoint.

  • writeTxs ∷ HasCallStack ⇒ LeiosPoint → [(TxOffset, ByteString)] → m (Promise m CompletedEbs)

    Persist tx bodies for the EB identified by LeiosPoint.

    No backend uses the point's slot: the tx bytes belong to the EB body, which every point with the same EB hash shares.

    Each transaction is given by its offset into the EB body and its bytes.

    ASSUMPTION: the EB body must already be written, otherwise the txs are dropped.

    ASSUMPTION: each transaction's bytes hash to the tx hash the EB body lists at its offset. The implementations do not check this.

    A transaction may be dropped by the implementation if: - is not in the body, - or it is already stored, - or its size is not the declared one.

newtype Promise (m ∷ Type → Type) a Source #

The result of a submitted write.

await rethrows whatever the write threw, in the awaiting thread, as a LeiosDbException naming the write and the site that submitted it. Awaiting twice is fine. Not awaiting does not discard a failure: a failed write is not survivable and stops the writer either way.

Constructors

Promise 

Fields

Instances

Instances details
Functor m ⇒ Functor (Promise m) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LeiosDB.API

Methods

fmap ∷ (a → b) → Promise m a → Promise m b #

(<$) ∷ a → Promise m b → Promise m a #

awaitAll ∷ (Foldable t, Applicative m) ⇒ t (Promise m ()) → m () Source #

Await every promise, in order.

withWriter ∷ MonadThrow m ⇒ LeiosDbHandle m → (LeiosDbWriter m → m a) → m a Source #

type CompletedEbs = [LeiosPoint] Source #

EBs whose tx closure became complete as a result of a write.

type TxOffset = Int Source #

The position of a transaction in its endorser block.