Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data DiskSnapshot = DiskSnapshot {}
- data ReadSnapshotErr
- data SnapshotFailure blk
- diskSnapshotIsTemporary ∷ DiskSnapshot → Bool
- listSnapshots ∷ Monad m ⇒ SomeHasFS m → m [DiskSnapshot]
- readSnapshot ∷ ∀ m blk. IOLike m ⇒ SomeHasFS m → (∀ s. Decoder s (ExtLedgerState blk)) → (∀ s. Decoder s (HeaderHash blk)) → Flag "DoDiskSnapshotChecksum" → DiskSnapshot → ExceptT ReadSnapshotErr m (ExtLedgerState blk)
- takeSnapshot ∷ ∀ m blk. (MonadThrow m, MonadMonotonicTime m, IsLedger (LedgerState blk)) ⇒ Tracer m (TraceSnapshotEvent blk) → SomeHasFS m → Flag "DoDiskSnapshotChecksum" → (ExtLedgerState blk → Encoding) → ExtLedgerState blk → m (Maybe (DiskSnapshot, RealPoint blk))
- trimSnapshots ∷ Monad m ⇒ Tracer m (TraceSnapshotEvent r) → SomeHasFS m → DiskPolicy → m [DiskSnapshot]
- writeSnapshot ∷ ∀ m blk. MonadThrow m ⇒ SomeHasFS m → Flag "DoDiskSnapshotChecksum" → (ExtLedgerState blk → Encoding) → DiskSnapshot → ExtLedgerState blk → m ()
- decodeSnapshotBackwardsCompatible ∷ ∀ l blk. Proxy blk → (∀ s. Decoder s l) → (∀ s. Decoder s (HeaderHash blk)) → ∀ s. Decoder s l
- deleteSnapshot ∷ Monad m ⇒ HasCallStack ⇒ SomeHasFS m → DiskSnapshot → m ()
- encodeSnapshot ∷ (l → Encoding) → l → Encoding
- snapshotToFileName ∷ DiskSnapshot → String
- snapshotToPath ∷ DiskSnapshot → FsPath
- data TraceSnapshotEvent blk
Documentation
data DiskSnapshot Source #
Name of a disk snapshot.
The snapshot itself might not yet exist on disk.
DiskSnapshot | |
|
Instances
Read from disk
data ReadSnapshotErr Source #
ReadSnapshotFailed ReadIncrementalErr | Error while de-serialising data |
ReadSnapshotDataCorruption | Checksum of read snapshot differs from the one tracked by the corresponding '.checksum' file |
ReadSnapshotNoChecksumFile FsPath | A '.checksum' file does not exist for a |
ReadSnapshotInvalidChecksumFile FsPath | A '.checksum' file exists for a |
Instances
Show ReadSnapshotErr Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots showsPrec ∷ Int → ReadSnapshotErr → ShowS # show ∷ ReadSnapshotErr → String # showList ∷ [ReadSnapshotErr] → ShowS # | |
Eq ReadSnapshotErr Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots (==) ∷ ReadSnapshotErr → ReadSnapshotErr → Bool # (/=) ∷ ReadSnapshotErr → ReadSnapshotErr → Bool # |
data SnapshotFailure blk Source #
InitFailureRead ReadSnapshotErr | We failed to deserialise the snapshot This can happen due to data corruption in the ledger DB. |
InitFailureTooRecent (RealPoint blk) | This snapshot is too recent (ahead of the tip of the chain) |
InitFailureGenesis | This snapshot was of the ledger state at genesis, even though we never take snapshots at genesis, so this is unexpected. |
Instances
diskSnapshotIsTemporary ∷ DiskSnapshot → Bool Source #
The snapshots that are periodically created are temporary, they will be deleted when trimming
listSnapshots ∷ Monad m ⇒ SomeHasFS m → m [DiskSnapshot] Source #
List on-disk snapshots, highest number first.
readSnapshot ∷ ∀ m blk. IOLike m ⇒ SomeHasFS m → (∀ s. Decoder s (ExtLedgerState blk)) → (∀ s. Decoder s (HeaderHash blk)) → Flag "DoDiskSnapshotChecksum" → DiskSnapshot → ExceptT ReadSnapshotErr m (ExtLedgerState blk) Source #
Read snapshot from disk.
Fail on data corruption, i.e. when the checksum of the read data differs
from the one tracked by
.DiskSnapshot
Write to disk
takeSnapshot ∷ ∀ m blk. (MonadThrow m, MonadMonotonicTime m, IsLedger (LedgerState blk)) ⇒ Tracer m (TraceSnapshotEvent blk) → SomeHasFS m → Flag "DoDiskSnapshotChecksum" → (ExtLedgerState blk → Encoding) → ExtLedgerState blk → m (Maybe (DiskSnapshot, RealPoint blk)) Source #
Take a snapshot of the oldest ledger state in the ledger DB
We write the oldest ledger state to disk because the intention is to only
write ledger states to disk that we know to be immutable. Primarily for
testing purposes, takeSnapshot
returns the block reference corresponding
to the snapshot that we wrote.
If a snapshot with the same number already exists on disk or if the tip is at genesis, no snapshot is taken.
Note that an EBB can have the same slot number and thus snapshot number as the block after it. This doesn't matter. The one block difference in the ledger state doesn't warrant an additional snapshot. The number in the name of the snapshot is only indicative, we don't rely on it being correct.
NOTE: This is a lower-level API that takes a snapshot independent from
whether this snapshot corresponds to a state that is more than k
back.
TODO: Should we delete the file if an error occurs during writing?
trimSnapshots ∷ Monad m ⇒ Tracer m (TraceSnapshotEvent r) → SomeHasFS m → DiskPolicy → 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.
writeSnapshot ∷ ∀ m blk. MonadThrow m ⇒ SomeHasFS m → Flag "DoDiskSnapshotChecksum" → (ExtLedgerState blk → Encoding) → DiskSnapshot → ExtLedgerState blk → m () Source #
Write a ledger state snapshot to disk
This function writes two files:
* the snapshot file itself, with the name generated by
* the checksum file, with the name generated by snapshotToPath
snapshotToChecksumPath
Low-level API (primarily exposed for testing)
decodeSnapshotBackwardsCompatible ∷ ∀ 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.
deleteSnapshot ∷ Monad m ⇒ HasCallStack ⇒ SomeHasFS m → DiskSnapshot → m () Source #
Delete snapshot from disk
encodeSnapshot ∷ (l → Encoding) → l → Encoding Source #
Encoder to be used in combination with decodeSnapshotBackwardsCompatible
.
Trace
data TraceSnapshotEvent blk Source #
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. |
SnapshotMissingChecksum DiskSnapshot | The checksum file for a snapshot was missing and was not checked |