Safe Haskell | None |
---|---|
Language | Haskell2010 |
Ouroboros.Consensus.Storage.LedgerDB.Snapshots
Description
Common logic and types for LedgerDB Snapshots.
Snapshots are saved copies of Ledger states in the chain which can be used to restart the node without having to replay the whole chain. Regardless of the actual LedgerDB implementation chosen, the general management of snapshots is common to all implementations.
Synopsis
- data CRCError
- data DiskSnapshot = DiskSnapshot {}
- data MetadataErr
- data NumOfDiskSnapshots
- data ReadSnapshotErr
- data SnapshotBackend
- data SnapshotFailure blk
- data SnapshotMetadata = SnapshotMetadata {}
- data SnapshotPolicyArgs = SnapshotPolicyArgs {}
- defaultSnapshotPolicyArgs ∷ SnapshotPolicyArgs
- readExtLedgerState ∷ ∀ (m ∷ Type → Type) blk. IOLike m ⇒ SomeHasFS m → (∀ s. Decoder s (ExtLedgerState blk EmptyMK)) → (∀ s. Decoder s (HeaderHash blk)) → FsPath → ExceptT ReadIncrementalErr m (ExtLedgerState blk EmptyMK, CRC)
- writeExtLedgerState ∷ MonadThrow m ⇒ SomeHasFS m → (ExtLedgerState blk EmptyMK → Encoding) → FsPath → ExtLedgerState blk EmptyMK → m CRC
- diskSnapshotIsTemporary ∷ DiskSnapshot → Bool
- snapshotFromPath ∷ String → Maybe DiskSnapshot
- snapshotToChecksumPath ∷ DiskSnapshot → FsPath
- snapshotToDirName ∷ DiskSnapshot → String
- snapshotToDirPath ∷ DiskSnapshot → FsPath
- snapshotToMetadataPath ∷ DiskSnapshot → FsPath
- deleteSnapshot ∷ (Monad m, HasCallStack) ⇒ SomeHasFS m → DiskSnapshot → m ()
- listSnapshots ∷ Monad m ⇒ SomeHasFS m → m [DiskSnapshot]
- loadSnapshotMetadata ∷ ∀ (m ∷ Type → Type). IOLike m ⇒ SomeHasFS m → DiskSnapshot → ExceptT MetadataErr m SnapshotMetadata
- trimSnapshots ∷ Monad m ⇒ Tracer m (TraceSnapshotEvent r) → SomeHasFS m → SnapshotPolicy → m [DiskSnapshot]
- writeSnapshotMetadata ∷ MonadThrow m ⇒ SomeHasFS m → DiskSnapshot → SnapshotMetadata → m ()
- data SnapshotInterval
- data SnapshotPolicy = SnapshotPolicy {}
- defaultSnapshotPolicy ∷ SecurityParam → SnapshotPolicyArgs → SnapshotPolicy
- pattern DoDiskSnapshotChecksum ∷ Flag "DoDiskSnapshotChecksum"
- pattern NoDoDiskSnapshotChecksum ∷ Flag "DoDiskSnapshotChecksum"
- data TraceSnapshotEvent blk
- newtype Flag (name ∷ Symbol) = Flag {}
- decodeLBackwardsCompatible ∷ ∀ l blk. Proxy blk → (∀ s. Decoder s l) → (∀ s. Decoder s (HeaderHash blk)) → ∀ s. Decoder s l
- destroySnapshots ∷ Monad m ⇒ SomeHasFS m → m ()
- encodeL ∷ (l → Encoding) → l → Encoding
- snapshotsMapM_ ∷ Monad m ⇒ SomeHasFS m → (FilePath → m a) → m ()
Snapshots
data DiskSnapshot Source #
Name of a disk snapshot.
The snapshot itself might not yet exist on disk.
Constructors
DiskSnapshot | |
Fields
|
Instances
data MetadataErr Source #
Constructors
MetadataFileDoesNotExist | The metadata file does not exist |
MetadataInvalid String | The metadata file is invalid and does not deserialize |
MetadataBackendMismatch | The metadata file has the incorrect backend |
Instances
Show MetadataErr Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods showsPrec ∷ Int → MetadataErr → ShowS # show ∷ MetadataErr → String # showList ∷ [MetadataErr] → ShowS # | |
Eq MetadataErr Source # | |
data NumOfDiskSnapshots Source #
Number of snapshots to be stored on disk. This is either the default value
as determined by the
, or it is provided by the user. See the
SnapshotPolicy
documentation for more information.SnapshotPolicy
Constructors
DefaultNumOfDiskSnapshots | |
RequestedNumOfDiskSnapshots Word |
Instances
Generic NumOfDiskSnapshots Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Associated Types
Methods | |||||
Show NumOfDiskSnapshots Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods showsPrec ∷ Int → NumOfDiskSnapshots → ShowS # show ∷ NumOfDiskSnapshots → String # showList ∷ [NumOfDiskSnapshots] → ShowS # | |||||
Eq NumOfDiskSnapshots Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods | |||||
type Rep NumOfDiskSnapshots Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots type Rep NumOfDiskSnapshots = D1 ('MetaData "NumOfDiskSnapshots" "Ouroboros.Consensus.Storage.LedgerDB.Snapshots" "ouroboros-consensus-0.26.0.0-inplace" 'False) (C1 ('MetaCons "DefaultNumOfDiskSnapshots" 'PrefixI 'False) (U1 ∷ Type → Type) :+: C1 ('MetaCons "RequestedNumOfDiskSnapshots" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word))) |
data ReadSnapshotErr Source #
Constructors
ReadSnapshotFailed ReadIncrementalErr | Error while de-serialising data |
ReadSnapshotDataCorruption | Checksum of read snapshot differs from the one tracked by its corresponding metadata file |
ReadMetadataError FsPath MetadataErr | An error occurred while reading the snapshot metadata file |
Instances
Show ReadSnapshotErr Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods showsPrec ∷ Int → ReadSnapshotErr → ShowS # show ∷ ReadSnapshotErr → String # showList ∷ [ReadSnapshotErr] → ShowS # | |
Eq ReadSnapshotErr Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods (==) ∷ ReadSnapshotErr → ReadSnapshotErr → Bool # (/=) ∷ ReadSnapshotErr → ReadSnapshotErr → Bool # |
data SnapshotBackend Source #
Constructors
UTxOHDMemSnapshot | |
UTxOHDLMDBSnapshot |
Instances
FromJSON SnapshotBackend Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods parseJSON ∷ Value → Parser SnapshotBackend Source # | |
ToJSON SnapshotBackend Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods toJSON ∷ SnapshotBackend → Value Source # toEncoding ∷ SnapshotBackend → Encoding Source # toJSONList ∷ [SnapshotBackend] → Value Source # | |
Show SnapshotBackend Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods showsPrec ∷ Int → SnapshotBackend → ShowS # show ∷ SnapshotBackend → String # showList ∷ [SnapshotBackend] → ShowS # | |
Eq SnapshotBackend Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods (==) ∷ SnapshotBackend → SnapshotBackend → Bool # (/=) ∷ SnapshotBackend → SnapshotBackend → Bool # |
data SnapshotFailure blk Source #
Constructors
InitFailureRead ReadSnapshotErr | We failed to deserialise the snapshot This can happen due to data corruption in the ledger DB or if the codecs changed. |
InitFailureTooRecent (RealPoint blk) | This snapshot is too recent (ahead of the tip of the immutable chain) |
InitFailureGenesis | This snapshot was of the ledger state at genesis, even though we never take snapshots at genesis, so this is unexpected. |
Instances
Generic (SnapshotFailure blk) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Associated Types
Methods from ∷ SnapshotFailure blk → Rep (SnapshotFailure blk) x # to ∷ Rep (SnapshotFailure blk) x → SnapshotFailure blk # | |||||
StandardHash blk ⇒ Show (SnapshotFailure blk) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods showsPrec ∷ Int → SnapshotFailure blk → ShowS # show ∷ SnapshotFailure blk → String # showList ∷ [SnapshotFailure blk] → ShowS # | |||||
StandardHash blk ⇒ Eq (SnapshotFailure blk) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods (==) ∷ SnapshotFailure blk → SnapshotFailure blk → Bool # (/=) ∷ SnapshotFailure blk → SnapshotFailure blk → Bool # | |||||
type Rep (SnapshotFailure blk) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots type Rep (SnapshotFailure blk) = D1 ('MetaData "SnapshotFailure" "Ouroboros.Consensus.Storage.LedgerDB.Snapshots" "ouroboros-consensus-0.26.0.0-inplace" 'False) (C1 ('MetaCons "InitFailureRead" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ReadSnapshotErr)) :+: (C1 ('MetaCons "InitFailureTooRecent" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (RealPoint blk))) :+: C1 ('MetaCons "InitFailureGenesis" 'PrefixI 'False) (U1 ∷ Type → Type))) |
data SnapshotMetadata Source #
Constructors
SnapshotMetadata | |
Fields |
Instances
FromJSON SnapshotMetadata Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods parseJSON ∷ Value → Parser SnapshotMetadata Source # | |
ToJSON SnapshotMetadata Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods toJSON ∷ SnapshotMetadata → Value Source # toEncoding ∷ SnapshotMetadata → Encoding Source # toJSONList ∷ [SnapshotMetadata] → Value Source # | |
Show SnapshotMetadata Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods showsPrec ∷ Int → SnapshotMetadata → ShowS # show ∷ SnapshotMetadata → String # showList ∷ [SnapshotMetadata] → ShowS # | |
Eq SnapshotMetadata Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods |
data SnapshotPolicyArgs Source #
Constructors
SnapshotPolicyArgs | |
Fields |
Codec
readExtLedgerState ∷ ∀ (m ∷ Type → Type) blk. IOLike m ⇒ SomeHasFS m → (∀ s. Decoder s (ExtLedgerState blk EmptyMK)) → (∀ s. Decoder s (HeaderHash blk)) → FsPath → ExceptT ReadIncrementalErr m (ExtLedgerState blk EmptyMK, CRC) Source #
Read an extended ledger state from disk
writeExtLedgerState ∷ MonadThrow m ⇒ SomeHasFS m → (ExtLedgerState blk EmptyMK → Encoding) → FsPath → ExtLedgerState blk EmptyMK → m CRC Source #
Write an extended ledger state to disk
Paths
diskSnapshotIsTemporary ∷ DiskSnapshot → Bool Source #
The snapshots that are periodically created are temporary, they will be deleted when trimming or if they fail to deserialize.
snapshotToDirPath ∷ DiskSnapshot → FsPath Source #
The path within the LedgerDB's filesystem to the snapshot's directory
Management
deleteSnapshot ∷ (Monad m, HasCallStack) ⇒ SomeHasFS m → DiskSnapshot → m () Source #
Delete snapshot from disk
listSnapshots ∷ Monad m ⇒ SomeHasFS m → m [DiskSnapshot] Source #
List on-disk snapshots, highest number first.
loadSnapshotMetadata ∷ ∀ (m ∷ Type → Type). IOLike m ⇒ SomeHasFS m → DiskSnapshot → ExceptT MetadataErr m SnapshotMetadata Source #
Load a snapshot metadata JSON file.
- Fails with
MetadataFileDoesNotExist
when the file doesn't exist; - Fails with
MetadataInvalid
when the contents of the file cannot be deserialised correctly
trimSnapshots ∷ Monad m ⇒ Tracer m (TraceSnapshotEvent r) → SomeHasFS m → SnapshotPolicy → m [DiskSnapshot] Source #
Trim the number of on disk snapshots so that at most onDiskNumSnapshots
snapshots are stored on disk. The oldest snapshots are deleted.
The deleted snapshots are returned.
writeSnapshotMetadata ∷ MonadThrow m ⇒ SomeHasFS m → DiskSnapshot → SnapshotMetadata → m () Source #
Write a snapshot metadata JSON file.
Policy
data SnapshotInterval Source #
Length of time that has to pass after which a snapshot is taken.
Instances
Generic SnapshotInterval Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Associated Types
Methods from ∷ SnapshotInterval → Rep SnapshotInterval x # to ∷ Rep SnapshotInterval x → SnapshotInterval # | |||||
Show SnapshotInterval Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods showsPrec ∷ Int → SnapshotInterval → ShowS # show ∷ SnapshotInterval → String # showList ∷ [SnapshotInterval] → ShowS # | |||||
Eq SnapshotInterval Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods | |||||
type Rep SnapshotInterval Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots type Rep SnapshotInterval = D1 ('MetaData "SnapshotInterval" "Ouroboros.Consensus.Storage.LedgerDB.Snapshots" "ouroboros-consensus-0.26.0.0-inplace" 'False) (C1 ('MetaCons "DefaultSnapshotInterval" 'PrefixI 'False) (U1 ∷ Type → Type) :+: (C1 ('MetaCons "RequestedSnapshotInterval" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DiffTime)) :+: C1 ('MetaCons "DisableSnapshots" 'PrefixI 'False) (U1 ∷ Type → Type))) |
data SnapshotPolicy Source #
Snapshots policy
We only write ledger states that are older than k
blocks to disk (that is,
snapshots that are guaranteed valid). The on-disk policy determines how often
we write to disk and how many checkpoints we keep.
Constructors
SnapshotPolicy | |
Fields
|
Instances
defaultSnapshotPolicy ∷ SecurityParam → SnapshotPolicyArgs → SnapshotPolicy Source #
Default on-disk policy suitable to use with cardano-node
pattern DoDiskSnapshotChecksum ∷ Flag "DoDiskSnapshotChecksum" Source #
Type-safe flag to regulate the checksum policy of the ledger state snapshots.
These patterns are exposed to cardano-node and will be passed as part of
.SnapshotPolicy
pattern NoDoDiskSnapshotChecksum ∷ Flag "DoDiskSnapshotChecksum" Source #
Type-safe flag to regulate the checksum policy of the ledger state snapshots.
These patterns are exposed to cardano-node and will be passed as part of
.SnapshotPolicy
Tracing
data TraceSnapshotEvent blk Source #
Constructors
InvalidSnapshot DiskSnapshot (SnapshotFailure blk) | An on disk snapshot was skipped because it was invalid. |
TookSnapshot DiskSnapshot (RealPoint blk) EnclosingTimed | A snapshot was written to disk. |
DeletedSnapshot DiskSnapshot | An old or invalid on-disk snapshot was deleted |
Instances
Generic (TraceSnapshotEvent blk) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Associated Types
Methods from ∷ TraceSnapshotEvent blk → Rep (TraceSnapshotEvent blk) x # to ∷ Rep (TraceSnapshotEvent blk) x → TraceSnapshotEvent blk # | |||||
StandardHash blk ⇒ Show (TraceSnapshotEvent blk) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods showsPrec ∷ Int → TraceSnapshotEvent blk → ShowS # show ∷ TraceSnapshotEvent blk → String # showList ∷ [TraceSnapshotEvent blk] → ShowS # | |||||
StandardHash blk ⇒ Eq (TraceSnapshotEvent blk) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots Methods (==) ∷ TraceSnapshotEvent blk → TraceSnapshotEvent blk → Bool # (/=) ∷ TraceSnapshotEvent blk → TraceSnapshotEvent blk → Bool # | |||||
type Rep (TraceSnapshotEvent blk) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots type Rep (TraceSnapshotEvent blk) = D1 ('MetaData "TraceSnapshotEvent" "Ouroboros.Consensus.Storage.LedgerDB.Snapshots" "ouroboros-consensus-0.26.0.0-inplace" 'False) (C1 ('MetaCons "InvalidSnapshot" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DiskSnapshot) :*: S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SnapshotFailure blk))) :+: (C1 ('MetaCons "TookSnapshot" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DiskSnapshot) :*: (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (RealPoint blk)) :*: S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EnclosingTimed))) :+: C1 ('MetaCons "DeletedSnapshot" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DiskSnapshot)))) |
Re-exports
newtype Flag (name ∷ Symbol) Source #
Type-safe boolean flags with type level tags
It is recommended to create pattern synonyms for the true and false values.
See DiskSnapshotChecksum
for an example.
Testing
decodeLBackwardsCompatible ∷ ∀ l blk. Proxy blk → (∀ s. Decoder s l) → (∀ s. Decoder s (HeaderHash blk)) → ∀ s. Decoder s l Source #
To remain backwards compatible with existing snapshots stored on disk, we must accept the old format as well as the new format.
The old format:
- The tip:
WithOrigin (RealPoint blk)
- The chain length:
Word64
- The ledger state:
l
The new format is described by snapshotEncodingVersion1
.
This decoder will accept and ignore them. The encoder (encodeSnapshot
) will
no longer encode them.
destroySnapshots ∷ Monad m ⇒ SomeHasFS m → m () Source #
Testing only! Destroy all snapshots in the DB.