Skip to content

Commit 6221551

Browse files
committed
Add documentation for LedgerDB snapshots
1 parent 04c14d5 commit 6221551

File tree

2 files changed

+45
-5
lines changed
  • ouroboros-consensus/src
    • ouroboros-consensus-lsm/Ouroboros/Consensus/Storage/LedgerDB/V2
    • ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB

2 files changed

+45
-5
lines changed

ouroboros-consensus/src/ouroboros-consensus-lsm/Ouroboros/Consensus/Storage/LedgerDB/V2/LSM.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,24 @@ implTakeHandleSnapshot t _ snapshotName = do
322322
SnapshotManager
323323
-------------------------------------------------------------------------------}
324324

325+
-- | Snapshots in LSM trees are split in two parts for now:
326+
--
327+
-- - The @state@ and @meta@ files in the usual location (@./ledger/<slotno>@ in
328+
-- the ChainDB).
329+
--
330+
-- - The ledger tables, which are stored in the LSM-trees session directory.
331+
--
332+
-- Note that the name of the folder in which the @state@ file is and the name of
333+
-- the snapshot in the LSM-trees directory have to match. This means that if the
334+
-- user adds a suffix to the snapshot renaming the directory
335+
-- @./ledger/<slotno>@, they will also have to rename the directory
336+
-- @./lsm/snapshots/<slotno>@. Otherwise the initialization logic will exit with
337+
-- failure saying that the snapshot was not found.
338+
--
339+
-- There is [an issue open in
340+
-- LSM-trees](https://github.com/IntersectMBO/lsm-tree/issues/272) such that the
341+
-- ledger tables part of the snapshot could also be stored in the
342+
-- @./ledger/<slotno>@ directory, but it is not implemented yet.
325343
snapshotManager ::
326344
( IOLike m
327345
, LedgerDbSerialiseConstraints blk

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/Snapshots.hs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,34 @@
1111
{-# LANGUAGE ScopedTypeVariables #-}
1212
{-# LANGUAGE TypeApplications #-}
1313

14-
-- | Common logic and types for LedgerDB Snapshots.
14+
-- | Snapshots
1515
--
16-
-- Snapshots are saved copies of Ledger states in the chain which can be used to
17-
-- restart the node without having to replay the whole chain. Regardless of the
18-
-- actual LedgerDB implementation chosen, the general management of snapshots is
19-
-- common to all implementations.
16+
-- Snapshotting a ledger state means saving a copy of the state to disk, so that
17+
-- a later start of a cardano-node can use such a snapshot as a starting point
18+
-- instead of having to replay from Genesis.
19+
--
20+
-- A snapshot is identified by the slot number of the ledger state it contains
21+
-- and possibly has a suffix in the name. The consensus logic will not delete a
22+
-- snapshot if it has a suffix. This can be used to store important
23+
-- snapshots. The suffix can be manually added to the snapshot by renaming the
24+
-- folder (see the caveats in 'snapshotManager' for the LSM backend). It will
25+
-- also be added automatically by some tools such as db-analyser.
26+
--
27+
-- In general snapshots will be stored in the @./ledger@ directory inside the
28+
-- ChainDB directory, but each LedgerDB backend is free to store it somewhere
29+
-- else. Management of snapshots is done through the 'SnapshotManager'
30+
-- record (see the 'snapshotManager' functions on each backend).
31+
--
32+
-- Snapshots cosists of two parts:
33+
--
34+
-- - the ledger state tables: location and format differs among backends,
35+
--
36+
-- - the rest of the ledger state: a CBOR serialization of an @ExtLedgerState
37+
-- blk EmptyMK@, stored in the @./state@ file in the snapshot directory.
38+
--
39+
-- V2 backends will provide means of loading a snapshot via the method
40+
-- 'newHandleFromSnapshot'. V1 backends load the snapshot directly in
41+
-- 'initFromSnapshot'.
2042
module Ouroboros.Consensus.Storage.LedgerDB.Snapshots
2143
( -- * Snapshots
2244
CRCError (..)

0 commit comments

Comments
 (0)