| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Database.LSMTree.Internal.Snapshot.Codec
Description
Encoders and decoders for snapshot metadata
Synopsis
- data SnapshotVersion
- prettySnapshotVersion :: SnapshotVersion -> String
- currentSnapshotVersion :: SnapshotVersion
- allCompatibleSnapshotVersions :: [SnapshotVersion]
- isCompatible :: SnapshotVersion -> Either SnapshotVersionIncompatibleError ()
- data SnapshotVersionUnknownError = ErrSnapshotVersionUnknown !Word !SnapshotVersion
- data SnapshotVersionIncompatibleError = ErrSnapshotVersionIncompatible !SnapshotVersion !SnapshotVersion
- writeFileSnapshotMetaData :: MonadThrow m => HasFS m h -> FsPath -> FsPath -> SnapshotMetaData -> m ()
- readFileSnapshotMetaData :: MonadThrow m => HasFS m h -> FsPath -> FsPath -> m SnapshotMetaData
- encodeSnapshotMetaData :: SnapshotMetaData -> ByteString
- class Encode a where
- class Decode a where
- decode :: Decoder s (Either DecodeError a)
- data DecodeError
- class DecodeVersioned a where
- decodeVersioned :: SnapshotVersion -> Decoder s a
- newtype Versioned a = Versioned {
- getVersioned :: a
Versioning
data SnapshotVersion Source #
The version of a snapshot.
A snapshot format version is a number. Version numbers are consecutive and increasing. A single release of the library may support several older snapshot format versions, and thereby provide backwards compatibility. Support for old versions is not guaranteed indefinitely, but backwards compatibility is guaranteed for at least the previous version, and preferably for more. Forwards compatibility is not provided at all: snapshots with a later version than the current version for the library release will always fail.
Instances
prettySnapshotVersion :: SnapshotVersion -> String Source #
Pretty-print a snapshot version
>>>prettySnapshotVersion currentSnapshotVersion"v2"
currentSnapshotVersion :: SnapshotVersion Source #
The current snapshot version
>>>currentSnapshotVersionV2
allCompatibleSnapshotVersions :: [SnapshotVersion] Source #
All snapshot versions that the current snapshot version is compatible with.
>>>allCompatibleSnapshotVersions[V0,V1,V2]
>>>last allCompatibleSnapshotVersions == currentSnapshotVersionTrue
isCompatible :: SnapshotVersion -> Either SnapshotVersionIncompatibleError () Source #
Check that a known version is compatible with currentSnapshotVersion.
Errors
data SnapshotVersionUnknownError Source #
The snapshot metadata declares a snapshot format version number that this version of the library does not know. Most likely the snapshot was written by a newer version of the library.
Constructors
| ErrSnapshotVersionUnknown | |
Fields
| |
Instances
data SnapshotVersionIncompatibleError Source #
The snapshot metadata declares a known snapshot format version that is no longer compatible with the current snapshot version of the library.
Constructors
| ErrSnapshotVersionIncompatible | |
Fields
| |
Instances
Writing and reading files
writeFileSnapshotMetaData Source #
Arguments
| :: MonadThrow m | |
| => HasFS m h | |
| -> FsPath | Target file for snapshot metadata |
| -> FsPath | Target file for checksum |
| -> SnapshotMetaData | |
| -> m () |
Encode SnapshotMetaData and write it to SnapshotMetaDataFile.
In the presence of exceptions, newly created files will not be removed. It is up to the user of this function to clean up the files.
readFileSnapshotMetaData Source #
Arguments
| :: MonadThrow m | |
| => HasFS m h | |
| -> FsPath | Source file for snapshot metadata |
| -> FsPath | Source file for checksum |
| -> m SnapshotMetaData |
Read from SnapshotMetaDataFile and attempt to decode it to
SnapshotMetaData.
Throws a SnapshotVersionUnknownError if the snapshot metadata declares a
snapshot format version that this version of the library does not know, or
a SnapshotVersionIncompatibleError if the version is known but no longer
supported.
Encoding and decoding
Instances
Decoder that is not parameterised by a SnapshotVersion.
Used only for SnapshotVersion and Versioned, which live outside the
SnapshotMetaData type hierarchy.
Instances
| Decode SnapshotVersion Source # | |
Defined in Database.LSMTree.Internal.Snapshot.Codec Methods decode :: Decoder s (Either DecodeError SnapshotVersion) Source # | |
| DecodeVersioned a => Decode (Versioned a) Source # | Decodes the version header, checks it for compatibility, and then passes
the version into the versioned decoder for |
Defined in Database.LSMTree.Internal.Snapshot.Codec | |
data DecodeError Source #
Constructors
| SnapshotVersionUnknownError SnapshotVersionUnknownError | |
| SnapshotVersionIncompatibleError SnapshotVersionIncompatibleError |
Instances
| Show DecodeError Source # | |
Defined in Database.LSMTree.Internal.Snapshot.Codec Methods showsPrec :: Int -> DecodeError -> ShowS # show :: DecodeError -> String # showList :: [DecodeError] -> ShowS # | |
| Eq DecodeError Source # | |
Defined in Database.LSMTree.Internal.Snapshot.Codec | |
class DecodeVersioned a where Source #
Decoder parameterised by a SnapshotVersion.
Used for every type in the SnapshotMetaData type hierarchy.
Methods
decodeVersioned :: SnapshotVersion -> Decoder s a Source #
Instances
Constructors
| Versioned | |
Fields
| |
Instances
| Show a => Show (Versioned a) Source # | |
| Eq a => Eq (Versioned a) Source # | |
| DecodeVersioned a => Decode (Versioned a) Source # | Decodes the version header, checks it for compatibility, and then passes
the version into the versioned decoder for |
Defined in Database.LSMTree.Internal.Snapshot.Codec | |
| Encode a => Encode (Versioned a) Source # | |