Safe Haskell | None |
---|---|
Language | Haskell2010 |
Ouroboros.Consensus.Storage.LedgerDB.V1.Lock
Contents
Synopsis
- data LedgerDBLock (m ∷ Type → Type)
- data ReadLocked (m ∷ Type → Type) a
- data WriteLocked (m ∷ Type → Type) a
- mkLedgerDBLock ∷ IOLike m ⇒ m (LedgerDBLock m)
- readLocked ∷ m a → ReadLocked m a
- unsafeIgnoreWriteLock ∷ WriteLocked m a → m a
- withReadLock ∷ IOLike m ⇒ LedgerDBLock m → ReadLocked m a → m a
- withWriteLock ∷ IOLike m ⇒ LedgerDBLock m → WriteLocked m a → m a
- writeLocked ∷ m a → WriteLocked m a
LedgerDB lock
data LedgerDBLock (m ∷ Type → Type) 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 BackingStore
s 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 aStrictTVar
at theChainDB
level) and of theBackingStore
. We momentarily acquire a read lock, consult the transactional variable and also open aBackingStoreValueHandle
. 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 forlmdbCopy
). 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.
Instances
NoThunks (RAWLock m ()) ⇒ NoThunks (LedgerDBLock m) Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.V1.Lock |
data ReadLocked (m ∷ Type → Type) a Source #
An action in m
that has to hold the read lock. See withReadLock
.
Instances
Applicative m ⇒ Applicative (ReadLocked m) Source # | |
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 # | |
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 # | |
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 ∷ Type → Type) a Source #
An action in m
that has to hold the write lock. See withWriteLock
.
Instances
Applicative m ⇒ Applicative (WriteLocked m) Source # | |
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 # | |
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 # | |
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 # |
mkLedgerDBLock ∷ IOLike m ⇒ m (LedgerDBLock m) Source #
readLocked ∷ m a → ReadLocked m a Source #
Enforce that the action has to be run while holding the read lock.
unsafeIgnoreWriteLock ∷ WriteLocked m a → m a Source #
Used safely, for example, during initialization.
withReadLock ∷ IOLike m ⇒ LedgerDBLock m → ReadLocked m a → m a Source #
Acquire the ledger DB read lock and hold it while performing an action
withWriteLock ∷ IOLike 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.