Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data DiskSnapshot = DiskSnapshot {}
- 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)) → DiskSnapshot → ExceptT ReadIncrementalErr m (ExtLedgerState blk)
- takeSnapshot ∷ ∀ m blk. (MonadThrow m, MonadMonotonicTime m, IsLedger (LedgerState blk)) ⇒ Tracer m (TraceSnapshotEvent blk) → SomeHasFS m → (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 → (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 ∷ HasCallStack ⇒ SomeHasFS m → DiskSnapshot → m ()
- encodeSnapshot ∷ (l → Encoding) → l → Encoding
- snapshotToFileName ∷ DiskSnapshot → String
- snapshotToPath ∷ DiskSnapshot → FsPath
- data TraceSnapshotEvent blk
Documentation
data DiskSnapshot Source #
DiskSnapshot | |
|
Instances
Read from disk
data SnapshotFailure blk Source #
InitFailureRead ReadIncrementalErr | 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)) → DiskSnapshot → ExceptT ReadIncrementalErr m (ExtLedgerState blk) Source #
Read snapshot from disk
Write to disk
takeSnapshot ∷ ∀ m blk. (MonadThrow m, MonadMonotonicTime m, IsLedger (LedgerState blk)) ⇒ Tracer m (TraceSnapshotEvent blk) → SomeHasFS m → (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 → (ExtLedgerState blk → Encoding) → DiskSnapshot → ExtLedgerState blk → m () Source #
Write snapshot to disk
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 ∷ 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 |