ouroboros-consensus-0.26.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Storage.LedgerDB.V1.Lock

Synopsis

LedgerDB lock

data LedgerDBLock (m ∷ TypeType) Source #

A lock to prevent the LedgerDB (i.e. a DbChangelog) from getting out of sync with the BackingStore.

We rely on the capability of the BackingStores of providing BackingStoreValueHandles that can be used to hold a persistent view of the database as long as the handle is open. Assuming this functionality, the lock is used in three ways:

  • Read lock to acquire a value handle: we do this when acquiring a view of the LedgerDB (which lives in a StrictTVar at the ChainDB level) and of the BackingStore. We momentarily acquire a read lock, consult the transactional variable and also open a BackingStoreValueHandle. This is the case for ledger state queries and for the forging loop.
  • Read lock to ensure two operations are in sync: in the above situation, we relied on the BackingStoreValueHandle functionality, but sometimes we won't access the values through a value handle, and instead we might use the LMDB environment (as it is the case for lmdbCopy). In these cases, we acquire a read lock until we ended the copy, so that writers are blocked until this process is completed. This is the case when taking a snapshot.
  • Write lock when flushing differences.

data ReadLocked (m ∷ TypeType) a Source #

An action in m that has to hold the read lock. See withReadLock.

Instances

Instances details
Applicative m ⇒ Applicative (ReadLocked m) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.V1.Lock

Methods

pure ∷ a → ReadLocked m a #

(<*>)ReadLocked m (a → b) → ReadLocked m a → ReadLocked m b #

liftA2 ∷ (a → b → c) → ReadLocked m a → ReadLocked m b → ReadLocked m c #

(*>)ReadLocked m a → ReadLocked m b → ReadLocked m b #

(<*)ReadLocked m a → ReadLocked m b → ReadLocked m a #

Functor m ⇒ Functor (ReadLocked m) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.V1.Lock

Methods

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

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

Monad m ⇒ Monad (ReadLocked m) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.V1.Lock

Methods

(>>=)ReadLocked m a → (a → ReadLocked m b) → ReadLocked m b #

(>>)ReadLocked m a → ReadLocked m b → ReadLocked m b #

return ∷ a → ReadLocked m a #

data WriteLocked (m ∷ TypeType) a Source #

An action in m that has to hold the write lock. See withWriteLock.

Instances

Instances details
Applicative m ⇒ Applicative (WriteLocked m) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.V1.Lock

Methods

pure ∷ a → WriteLocked m a #

(<*>)WriteLocked m (a → b) → WriteLocked m a → WriteLocked m b #

liftA2 ∷ (a → b → c) → WriteLocked m a → WriteLocked m b → WriteLocked m c #

(*>)WriteLocked m a → WriteLocked m b → WriteLocked m b #

(<*)WriteLocked m a → WriteLocked m b → WriteLocked m a #

Functor m ⇒ Functor (WriteLocked m) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.V1.Lock

Methods

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

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

Monad m ⇒ Monad (WriteLocked m) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.V1.Lock

Methods

(>>=)WriteLocked m a → (a → WriteLocked m b) → WriteLocked m b #

(>>)WriteLocked m a → WriteLocked m b → WriteLocked m b #

return ∷ a → WriteLocked m a #

readLocked ∷ m a → ReadLocked m a Source #

Enforce that the action has to be run while holding the read lock.

unsafeIgnoreWriteLockWriteLocked m a → m a Source #

Used safely, for example, during initialization.

withReadLockIOLike m ⇒ LedgerDBLock m → ReadLocked m a → m a Source #

Acquire the ledger DB read lock and hold it while performing an action

withWriteLockIOLike m ⇒ LedgerDBLock m → WriteLocked m a → m a Source #

Acquire the ledger DB write lock and hold it while performing an action

writeLocked ∷ m a → WriteLocked m a Source #

Enforce that the action has to be run while holding the write lock.