| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Storage.ImmutableDB.Impl.Util
Contents
Synopsis
- data Two a = Two a a
- renderFile :: Text -> ChunkNo -> FsPath
- fsPathChunkFile :: ChunkNo -> FsPath
- fsPathPrimaryIndexFile :: ChunkNo -> FsPath
- fsPathSecondaryIndexFile :: ChunkNo -> FsPath
- wrapFsError :: MonadCatch m => m a -> m a
- tryImmutableDB :: MonadCatch m => m a -> m (Either ImmutableDBError a)
- parseDBFile :: String -> Maybe (String, ChunkNo)
- dbFilesOnDisk :: Set String -> (Set ChunkNo, Set ChunkNo, Set ChunkNo)
- removeFilesStartingFrom :: (HasCallStack, Monad m) => HasFS m h -> ChunkNo -> m ()
- runGet :: (HasCallStack, MonadThrow m) => FsPath -> Get a -> ByteString -> m a
- runGetWithUnconsumed :: (HasCallStack, MonadThrow m) => FsPath -> Get a -> ByteString -> m (ByteString, a)
- checkChecksum :: (HasCallStack, HasHeader blk, MonadThrow m) => FsPath -> RealPoint blk -> CRC -> CRC -> m ()
Utilities
Useful when you have exactly two values of some type and want to
traverse over both of them (which is not possible with a tuple).
Constructors
| Two a a |
Instances
| Functor Two Source # | |
| Foldable Two Source # | |
Defined in Ouroboros.Consensus.Storage.ImmutableDB.Impl.Util Methods fold :: Monoid m => Two m -> m # foldMap :: Monoid m => (a -> m) -> Two a -> m # foldMap' :: Monoid m => (a -> m) -> Two a -> m # foldr :: (a -> b -> b) -> b -> Two a -> b # foldr' :: (a -> b -> b) -> b -> Two a -> b # foldl :: (b -> a -> b) -> b -> Two a -> b # foldl' :: (b -> a -> b) -> b -> Two a -> b # foldr1 :: (a -> a -> a) -> Two a -> a # foldl1 :: (a -> a -> a) -> Two a -> a # elem :: Eq a => a -> Two a -> Bool # maximum :: Ord a => Two a -> a # | |
| Traversable Two Source # | |
renderFile :: Text -> ChunkNo -> FsPath Source #
Opposite of parseDBFile.
fsPathChunkFile :: ChunkNo -> FsPath Source #
wrapFsError :: MonadCatch m => m a -> m a Source #
Rewrap FsError in a ImmutableDBError.
tryImmutableDB :: MonadCatch m => m a -> m (Either ImmutableDBError a) Source #
Execute an action and catch the ImmutableDBError and FsError that can
be thrown by it, and wrap the FsError in an ImmutableDBError using the
FileSystemError constructor.
This should be used whenever you want to run an action on the ImmutableDB
and catch the ImmutableDBError and the FsError (wrapped in the former)
it may thrown.
parseDBFile :: String -> Maybe (String, ChunkNo) Source #
Parse the prefix and chunk number from the filename of an index or chunk file.
parseDBFile "00001.chunk"
Just ("chunk", 1) > parseDBFile "00012.primary" Just ("primary", 12)
dbFilesOnDisk :: Set String -> (Set ChunkNo, Set ChunkNo, Set ChunkNo) Source #
Go through all files, making three sets: the set of chunk files, primary index files, and secondary index files, discarding all others.
removeFilesStartingFrom :: (HasCallStack, Monad m) => HasFS m h -> ChunkNo -> m () Source #
Remove all chunk and index starting from the given chunk (included).
runGet :: (HasCallStack, MonadThrow m) => FsPath -> Get a -> ByteString -> m a Source #
Wrapper around runGetOrFail that throws an InvalidFileError when
it failed or when there was unconsumed input.
runGetWithUnconsumed :: (HasCallStack, MonadThrow m) => FsPath -> Get a -> ByteString -> m (ByteString, a) Source #
Same as runGet, but allows unconsumed input and returns it.
Arguments
| :: (HasCallStack, HasHeader blk, MonadThrow m) | |
| => FsPath | |
| -> RealPoint blk | |
| -> CRC | Expected checksum |
| -> CRC | Actual checksum |
| -> m () |
Check whether the given checksums match. If not, throw a
ChecksumMismatchError.