Skip to content

Commit 68c24d3

Browse files
authored
Expose hidden entities and small tweaks for integrating LSM-trees into the node (#1715)
# Description Expose some constructors for the sake of integration into `cardano-node`.
2 parents 68ea5a2 + 980a6d9 commit 68c24d3

File tree

9 files changed

+65
-11
lines changed

9 files changed

+65
-11
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Patch
10+
11+
- A bullet item for the Patch category.
12+
13+
-->
14+
<!--
15+
### Non-Breaking
16+
17+
- A bullet item for the Non-Breaking category.
18+
19+
-->
20+
21+
### Breaking
22+
23+
- `srnLedgerDbBackendArgs` now receives and returns a `StdGen` argument.

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ module Ouroboros.Consensus.Node
4343
, LowLevelRunNodeArgs (..)
4444
, MempoolCapacityBytesOverride (..)
4545
, NodeDatabasePaths (..)
46+
, immutableDbPath
47+
, nonImmutableDbPath
4648
, NodeKernel (..)
4749
, NodeKernelArgs (..)
4850
, ProtocolInfo (..)
@@ -376,7 +378,10 @@ data
376378
, -- Ad hoc values to replace default ChainDB configurations
377379
srnSnapshotPolicyArgs :: SnapshotPolicyArgs
378380
, srnQueryBatchSize :: QueryBatchSize
379-
, srnLedgerDbBackendArgs :: LedgerDbBackendArgs m blk
381+
, srnLedgerDbBackendArgs :: (StdGen -> (LedgerDbBackendArgs m blk, StdGen))
382+
-- ^ The 'StdGen' will be used to initialize the salt for the LSM backend. It
383+
-- is expected that it is the same 'StdGen' that is passed elsewhere in
384+
-- Consensus, i.e. 'llrnRng'.
380385
}
381386

382387
{-------------------------------------------------------------------------------
@@ -1005,7 +1010,7 @@ stdLowLevelRunNodeArgsIO
10051010
}
10061011
$(SafeWildCards.fields 'StdRunNodeArgs) = do
10071012
llrnBfcSalt <- stdBfcSaltIO
1008-
llrnRng <- newStdGen
1013+
(ldbBackendArgs, llrnRng) <- srnLedgerDbBackendArgs <$> newStdGen
10091014
pure
10101015
LowLevelRunNodeArgs
10111016
{ llrnBfcSalt
@@ -1050,7 +1055,7 @@ stdLowLevelRunNodeArgsIO
10501055
InFutureCheck.defaultClockSkew
10511056
, llrnPublicPeerSelectionStateVar =
10521057
Diffusion.dcPublicPeerSelectionVar srnDiffusionConfiguration
1053-
, llrnLdbFlavorArgs = srnLedgerDbBackendArgs
1058+
, llrnLdbFlavorArgs = ldbBackendArgs
10541059
}
10551060
where
10561061
networkMagic :: NetworkMagic
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
### Patch
9+
10+
- LSM-trees database directory is now created on startup.
11+
12+
### Non-Breaking
13+
14+
- Expose `Ouroboros.Consensus.Storage.LedgerDB.(V1.BackingStore|V2).Backend(Trace)` constructors.
15+
16+
### Breaking
17+
18+
- `Ouroboros.Consensus.Storage.LedgerDB.(V1.BackingStore|V2).Backend(Trace)` no longer depends on the running monad `m`.

ouroboros-consensus/src/ouroboros-consensus-lmdb/Ouroboros/Consensus/Storage/LedgerDB/V1/BackingStore/Impl/LMDB.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.LMDB
2222
LMDB
2323
, Backend (..)
2424
, Args (LMDBBackingStoreArgs)
25+
, Trace (OnDiskBackingStoreInitialise, OnDiskBackingStoreTrace)
2526
, LMDBLimits (LMDBLimits, lmdbMapSize, lmdbMaxDatabases, lmdbMaxReaders)
2627
, mkLMDBArgs
2728

@@ -832,7 +833,7 @@ instance
832833
where
833834
data Args m LMDB
834835
= LMDBBackingStoreArgs FilePath LMDBLimits (Dict.Dict MonadIOPrim m)
835-
data Trace m LMDB
836+
data Trace LMDB
836837
= OnDiskBackingStoreInitialise LMDB.Limits
837838
| OnDiskBackingStoreTrace BackingStoreTrace
838839
deriving (Eq, Show)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ module Ouroboros.Consensus.Storage.LedgerDB.V2.LSM
2525
LSM
2626
, Backend (..)
2727
, Args (LSMArgs)
28+
, Trace (LSMTreeTrace)
29+
, LSM.LSMTreeTrace (..)
2830
, mkLSMArgs
2931
, stdMkBlockIOFS
3032

@@ -571,12 +573,13 @@ instance
571573
}
572574
deriving Generic
573575

574-
data Trace m LSM
576+
data Trace LSM
575577
= LSMTreeTrace !LSM.LSMTreeTrace
576578
deriving Show
577579

578580
mkResources _ trcr (LSMArgs path salt mkFS) reg _ = do
579581
(rk1, SomeHasFSAndBlockIO fs blockio) <- mkFS reg
582+
createDirectoryIfMissing fs True path
580583
session <-
581584
allocate
582585
reg

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V1/BackingStore.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore
3232
import Cardano.Slotting.Slot
3333
import Control.Tracer
3434
import Data.Proxy
35+
import Data.Typeable
3536
import Ouroboros.Consensus.Ledger.Basics
3637
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
3738
import Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.API
@@ -67,15 +68,15 @@ data SomeBackendArgs m l where
6768
SomeBackendArgs :: Backend m backend l => Args m backend -> SomeBackendArgs m l
6869

6970
data SomeBackendTrace where
70-
SomeBackendTrace :: Show (Trace m backend) => Trace m backend -> SomeBackendTrace
71+
SomeBackendTrace :: (Show (Trace backend), Typeable backend) => Trace backend -> SomeBackendTrace
7172

7273
instance Show SomeBackendTrace where
7374
show (SomeBackendTrace tr) = show tr
7475

7576
class Backend m backend l where
7677
data Args m backend
7778

78-
data Trace m backend
79+
data Trace backend
7980

8081
isRightBackendForSnapshot ::
8182
Proxy l ->

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V1/BackingStore/Impl/InMemory.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ instance
360360
Backend m Mem l
361361
where
362362
data Args m Mem = InMemArgs
363-
data Trace m Mem
363+
data Trace Mem
364364
= InMemoryBackingStoreInitialise
365365
| InMemoryBackingStoreTrace BackingStoreTrace
366366
deriving (Eq, Show)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Control.Monad.Except
2323
import Control.ResourceRegistry
2424
import Control.Tracer
2525
import Data.Proxy
26+
import Data.Typeable
2627
import NoThunks.Class
2728
import Ouroboros.Consensus.Block
2829
import Ouroboros.Consensus.Ledger.Abstract
@@ -41,7 +42,7 @@ class NoThunks (Resources m backend) => Backend m backend blk where
4142
data Resources m backend
4243

4344
-- | A trace dependent on the particular backend.
44-
data Trace m backend
45+
data Trace backend
4546

4647
-- | Transform 'Args' into 'Resources', with some context made up of
4748
-- 'LedgerDbArgs'.
@@ -89,7 +90,8 @@ class NoThunks (Resources m backend) => Backend m backend blk where
8990
-------------------------------------------------------------------------------}
9091

9192
data SomeBackendTrace where
92-
SomeBackendTrace :: Show (Trace m backend) => Trace m backend -> SomeBackendTrace
93+
SomeBackendTrace ::
94+
(Show (Trace backend), Typeable backend) => Trace backend -> SomeBackendTrace
9395

9496
instance Show SomeBackendTrace where
9597
show (SomeBackendTrace tr) = show tr

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
module Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory
1919
( Backend (..)
2020
, Args (InMemArgs)
21+
, Trace (NoTrace)
2122
, Mem
2223
, YieldArgs (YieldInMemory)
2324
, SinkArgs (SinkInMemory)
@@ -363,7 +364,7 @@ instance
363364
data Args m Mem = InMemArgs
364365
newtype Resources m Mem = Resources (SomeHasFS m)
365366
deriving newtype NoThunks
366-
newtype Trace m Mem = NoTrace Void
367+
newtype Trace Mem = NoTrace Void
367368
deriving newtype Show
368369

369370
mkResources _ _ _ _ = pure . Resources

0 commit comments

Comments
 (0)