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

Ouroboros.Consensus.Storage.ImmutableDB.Impl.Index.Cache

Synopsis

Environment

data CacheEnv m blk h Source #

Environment used by functions operating on the cached index.

newEnv Source #

Arguments

:: (HasCallStack, IOLike m, ConvertRawHash blk, StandardHash blk) 
=> HasFS m h 
-> ResourceRegistry m 
-> Tracer m TraceCacheEvent 
-> CacheConfig 
-> ChunkInfo 
-> ChunkNo

Current chunk

-> m (CacheEnv m blk h) 

Creates a new CacheEnv and launches a background thread that expires unused past chunks (expireUnusedChunks).

PRECONDITION: $sel:pastChunksToCache:CacheConfig (in CacheConfig) > 0

data CacheConfig Source #

Constructors

CacheConfig 

Fields

checkInvariants Source #

Arguments

:: Word32

Maximum number of past chunks to cache

-> Cached blk 
-> Maybe String 

Background thread

expireUnusedChunks :: (HasCallStack, IOLike m) => CacheEnv m blk h -> m Void Source #

Intended to run as a background thread.

Will expire past chunks that haven't been used for $sel:expireUnusedAfter:CacheConfig from the cache.

Operations

close :: IOLike m => CacheEnv m blk h -> m () Source #

Stops the background expiration thread.

This operation is idempotent.

restart Source #

Arguments

:: (ConvertRawHash blk, IOLike m) 
=> CacheEnv m blk h 
-> ChunkNo

The new current chunk

-> m () 

Restarts the background expiration thread, drops all previously cached information, loads the given chunk.

PRECONDITION: the background thread expiring unused past chunks must have been terminated.

On the primary index

openPrimaryIndex :: (HasCallStack, ConvertRawHash blk, IOLike m) => CacheEnv m blk h -> ChunkNo -> AllowExisting -> m (Handle h) Source #

This is called when a new chunk is started, which means we need to update Cached to reflect this.

On the secondary index

readEntries :: forall m blk h t. (HasCallStack, ConvertRawHash blk, Traversable t, IOLike m) => CacheEnv m blk h -> ChunkNo -> t (IsEBB, SecondaryOffset) -> m (t (Entry blk, BlockSize)) Source #

readAllEntries :: forall m blk h. (HasCallStack, ConvertRawHash blk, IOLike m) => CacheEnv m blk h -> SecondaryOffset -> ChunkNo -> (Entry blk -> Bool) -> Word64 -> IsEBB -> m [WithBlockSize (Entry blk)] Source #

appendEntry :: forall m blk h. (HasCallStack, ConvertRawHash blk, IOLike m) => CacheEnv m blk h -> ChunkNo -> Handle h -> Entry blk -> m Word64 Source #