| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Storage.ImmutableDB.Impl.State
Contents
Synopsis
- data ImmutableDBEnv m blk = forall h.Eq h => ImmutableDBEnv {
- hasFS :: !(HasFS m h)
- varInternalState :: !(StrictMVar m (InternalState m blk h))
- checkIntegrity :: !(blk -> Bool)
- chunkInfo :: !ChunkInfo
- tracer :: !(Tracer m (TraceEvent blk))
- registry :: !(ResourceRegistry m)
- cacheConfig :: !CacheConfig
- codecConfig :: !(CodecConfig blk)
- data InternalState m blk h
- dbIsOpen :: InternalState m blk h -> Bool
- data OpenState m blk h = OpenState {
- currentChunk :: !ChunkNo
- currentChunkOffset :: !BlockOffset
- currentSecondaryOffset :: !SecondaryOffset
- currentChunkHandle :: !(Handle h)
- currentPrimaryHandle :: !(Handle h)
- currentSecondaryHandle :: !(Handle h)
- currentTip :: !(WithOrigin (Tip blk))
- currentIndex :: !(Index m blk h)
- mkOpenState :: forall m blk h. (HasCallStack, IOLike m, Eq h) => HasFS m h -> Index m blk h -> ChunkNo -> WithOrigin (Tip blk) -> AllowExisting -> WithTempRegistry (OpenState m blk h) m (OpenState m blk h)
- getOpenState :: (HasCallStack, IOLike m) => ImmutableDBEnv m blk -> STM m (SomePair (HasFS m) (OpenState m blk))
- type ModifyOpenState m blk h = StateT (OpenState m blk h) (WithTempRegistry (OpenState m blk h) m)
- modifyOpenState :: forall m blk a. (HasCallStack, IOLike m) => ImmutableDBEnv m blk -> (forall h. Eq h => HasFS m h -> ModifyOpenState m blk h a) -> m a
- withOpenState :: forall m blk r. (HasCallStack, IOLike m) => ImmutableDBEnv m blk -> (forall h. HasFS m h -> OpenState m blk h -> m r) -> m r
- closeOpenHandles :: Monad m => HasFS m h -> OpenState m blk h -> m ()
- cleanUp :: Monad m => HasFS m h -> OpenState m blk h -> m ()
State types
data ImmutableDBEnv m blk Source #
The environment used by the immutable database.
Constructors
| forall h.Eq h => ImmutableDBEnv | |
Fields
| |
data InternalState m blk h Source #
Instances
| Generic (InternalState m blk h) Source # | |
Defined in Ouroboros.Consensus.Storage.ImmutableDB.Impl.State Associated Types type Rep (InternalState m blk h) :: Type -> Type # Methods from :: InternalState m blk h -> Rep (InternalState m blk h) x # to :: Rep (InternalState m blk h) x -> InternalState m blk h # | |
| StandardHash blk => NoThunks (InternalState m blk h) Source # | |
| type Rep (InternalState m blk h) Source # | |
Defined in Ouroboros.Consensus.Storage.ImmutableDB.Impl.State type Rep (InternalState m blk h) = D1 ('MetaData "InternalState" "Ouroboros.Consensus.Storage.ImmutableDB.Impl.State" "ouroboros-consensus-0.1.0.0-GfJNvFcM6lj2s5utKAUPEp" 'False) (C1 ('MetaCons "DbClosed" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DbOpen" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (OpenState m blk h)))) | |
dbIsOpen :: InternalState m blk h -> Bool Source #
data OpenState m blk h Source #
Internal state when the database is open.
Constructors
| OpenState | |
Fields
| |
Instances
State helpers
mkOpenState :: forall m blk h. (HasCallStack, IOLike m, Eq h) => HasFS m h -> Index m blk h -> ChunkNo -> WithOrigin (Tip blk) -> AllowExisting -> WithTempRegistry (OpenState m blk h) m (OpenState m blk h) Source #
Create the internal open state for the given chunk.
getOpenState :: (HasCallStack, IOLike m) => ImmutableDBEnv m blk -> STM m (SomePair (HasFS m) (OpenState m blk)) Source #
Get the OpenState of the given database, throw a ClosedDBError in
case it is closed.
NOTE: Since the OpenState is parameterized over a type parameter h of
handles, which is not visible from the type of the ImmutableDBEnv,
we return a SomePair here that returns the open state along with a HasFS
instance for the same type parameter h. Note that it would be impossible
to use an existing HasFS instance already in scope otherwise, since the
h parameters would not be known to match.
type ModifyOpenState m blk h = StateT (OpenState m blk h) (WithTempRegistry (OpenState m blk h) m) Source #
Shorthand
modifyOpenState :: forall m blk a. (HasCallStack, IOLike m) => ImmutableDBEnv m blk -> (forall h. Eq h => HasFS m h -> ModifyOpenState m blk h a) -> m a Source #
Modify the internal state of an open database.
In case the database is closed, a ClosedDBError is thrown.
In case an UnexpectedFailure is thrown, the database is closed to prevent
further appending to a database in a potentially inconsistent state.
The action is run in the ModifyOpenState monad, which is a StateT
transformer (of the OpenState) over the WithTempRegistry monad. This
monad can be used to allocate resources in that will be transferred to the
returned OpenState that is safely stored in the ImmutableDBEnv. This
approach makes sure that no resources are leaked when an exception is
thrown while running the action modifying the state.
Note: This takes the TMVar, then runs the action (which might be
in IO), and then puts the TMVar back, just like
modifyMVar does. Consequently, it has the same
gotchas that modifyMVar does; the effects are observable and it is
susceptible to deadlock.
withOpenState :: forall m blk r. (HasCallStack, IOLike m) => ImmutableDBEnv m blk -> (forall h. HasFS m h -> OpenState m blk h -> m r) -> m r Source #
Perform an action that accesses the internal state of an open database.
In case the database is closed, a ClosedDBError is thrown.
In case an UnexpectedFailure is thrown while the action is being run, the
database is closed to prevent further appending to a database in a
potentially inconsistent state.