@@ -15,9 +15,9 @@ import Cardano.Tools.DBAnalyser.HasAnalysis
15
15
import Cardano.Tools.DBAnalyser.Types
16
16
import Control.ResourceRegistry
17
17
import Control.Tracer (Tracer (.. ), nullTracer )
18
+ import Data.Functor.Contravariant ((>$<) )
18
19
import qualified Data.SOP.Dict as Dict
19
20
import Data.Singletons (Sing , SingI (.. ))
20
- import Data.Void
21
21
import qualified Debug.Trace as Debug
22
22
import Ouroboros.Consensus.Block
23
23
import Ouroboros.Consensus.Config
@@ -35,19 +35,24 @@ import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB
35
35
import qualified Ouroboros.Consensus.Storage.ChainDB.Impl.Args as ChainDB
36
36
import qualified Ouroboros.Consensus.Storage.ImmutableDB as ImmutableDB
37
37
import qualified Ouroboros.Consensus.Storage.ImmutableDB.Stream as ImmutableDB
38
+ import Ouroboros.Consensus.Storage.LedgerDB (TraceEvent (.. ))
38
39
import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB
39
40
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1 as LedgerDB.V1
40
41
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Args as LedgerDB.V1
41
42
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.LMDB as LMDB
42
- import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Snapshots as LedgerDB. V1
43
+ import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Snapshots as V1
43
44
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2 as LedgerDB.V2
44
45
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.Args as LedgerDB.V2
46
+ import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.Args as V2
45
47
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory as InMemory
48
+ import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.LSM as LSM
46
49
import Ouroboros.Consensus.Util.Args
47
50
import Ouroboros.Consensus.Util.IOLike
48
51
import Ouroboros.Consensus.Util.Orphans ()
49
52
import Ouroboros.Network.Block (genesisPoint )
53
+ import System.FS.API
50
54
import System.IO
55
+ import System.Random
51
56
import Text.Printf (printf )
52
57
53
58
{- ------------------------------------------------------------------------------
@@ -66,7 +71,7 @@ openLedgerDB ::
66
71
, LedgerDB. TestInternals' IO blk
67
72
)
68
73
openLedgerDB lgrDbArgs@ LedgerDB. LedgerDbArgs {LedgerDB. lgrFlavorArgs = LedgerDB. LedgerDbFlavorArgsV1 bss} = do
69
- let snapManager = LedgerDB. V1. snapshotManager lgrDbArgs
74
+ let snapManager = V1. snapshotManager lgrDbArgs
70
75
(ledgerDB, _, intLedgerDB) <-
71
76
LedgerDB. openDBInternal
72
77
lgrDbArgs
@@ -82,8 +87,27 @@ openLedgerDB
[email protected] {LedgerDB.lgrFlavorArgs = LedgerDB.L
82
87
pure (ledgerDB, intLedgerDB)
83
88
openLedgerDB lgrDbArgs@ LedgerDB. LedgerDbArgs {LedgerDB. lgrFlavorArgs = LedgerDB. LedgerDbFlavorArgsV2 args} = do
84
89
(snapManager, bss') <- case args of
85
- LedgerDB.V2. V2Args LedgerDB.V2. InMemoryHandleArgs -> pure (InMemory. snapshotManager lgrDbArgs, LedgerDB.V2. InMemoryHandleEnv )
86
- LedgerDB.V2. V2Args (LedgerDB.V2. LSMHandleArgs (LedgerDB.V2. LSMArgs x)) -> absurd x
90
+ V2. V2Args V2. InMemoryHandleArgs -> pure (InMemory. snapshotManager lgrDbArgs, V2. InMemoryHandleEnv )
91
+ V2. V2Args (V2. LSMHandleArgs (V2. LSMArgs path salt mkFS)) -> do
92
+ (rk1, V2. SomeHasFSAndBlockIO fs' blockio) <- mkFS (LedgerDB. lgrRegistry lgrDbArgs)
93
+ session <-
94
+ allocate
95
+ (LedgerDB. lgrRegistry lgrDbArgs)
96
+ ( \ _ ->
97
+ LSM. openSession
98
+ ( LedgerDBFlavorImplEvent . LedgerDB. FlavorImplSpecificTraceV2 . V2. LSMTrace
99
+ >$< LedgerDB. lgrTracer lgrDbArgs
100
+ )
101
+ fs'
102
+ blockio
103
+ salt
104
+ path
105
+ )
106
+ LSM. closeSession
107
+ pure
108
+ ( LSM. snapshotManager (snd session) lgrDbArgs
109
+ , V2. LSMHandleEnv (V2. LSMResources (fst session) (snd session) rk1)
110
+ )
87
111
(ledgerDB, _, intLedgerDB) <-
88
112
LedgerDB. openDBInternal
89
113
lgrDbArgs
@@ -126,6 +150,7 @@ analyse dbaConfig args =
126
150
lock <- newMVar ()
127
151
chainDBTracer <- mkTracer lock verbose
128
152
analysisTracer <- mkTracer lock True
153
+ lsmSalt <- fst . genWord64 <$> newStdGen
129
154
ProtocolInfo {pInfoInitLedger = genesisLedger, pInfoConfig = cfg} <-
130
155
mkProtocolInfo args
131
156
let shfs = Node. stdMkChainDbHasFS dbDir
@@ -150,6 +175,13 @@ analyse dbaConfig args =
150
175
V2InMem ->
151
176
LedgerDB. LedgerDbFlavorArgsV2
152
177
(LedgerDB.V2. V2Args LedgerDB.V2. InMemoryHandleArgs )
178
+ V2LSM ->
179
+ LedgerDB. LedgerDbFlavorArgsV2
180
+ ( LedgerDB.V2. V2Args
181
+ ( LedgerDB.V2. LSMHandleArgs
182
+ (LedgerDB.V2. LSMArgs (mkFsPath [" lsm" ]) lsmSalt (LSM. stdMkBlockIOFS dbDir))
183
+ )
184
+ )
153
185
args' =
154
186
ChainDB. completeChainDbArgs
155
187
registry
0 commit comments