@@ -44,6 +44,7 @@ import Control.Monad.Except
44
44
import Control.Monad.State hiding (state )
45
45
import Control.ResourceRegistry
46
46
import Control.Tracer (Tracer (.. ))
47
+ import Data.Functor.Contravariant ((>$<) )
47
48
import qualified Data.List as L
48
49
import Data.Map.Strict (Map )
49
50
import qualified Data.Map.Strict as Map
@@ -63,11 +64,14 @@ import Ouroboros.Consensus.Storage.LedgerDB.V1 as V1
63
64
import Ouroboros.Consensus.Storage.LedgerDB.V1.Args hiding
64
65
( LedgerDbFlavorArgs
65
66
)
67
+ import Ouroboros.Consensus.Storage.LedgerDB.V1.Snapshots as V1
66
68
import Ouroboros.Consensus.Storage.LedgerDB.V2 as V2
67
69
import Ouroboros.Consensus.Storage.LedgerDB.V2.Args hiding
68
70
( LedgerDbFlavorArgs
69
71
)
70
72
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.Args as V2
73
+ import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory as InMemory
74
+ import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.LSM as LSM
71
75
import Ouroboros.Consensus.Util hiding (Some )
72
76
import Ouroboros.Consensus.Util.Args
73
77
import Ouroboros.Consensus.Util.IOLike
@@ -102,7 +106,9 @@ tests =
102
106
, testProperty " InMemV2" $
103
107
prop_sequential 100000 inMemV2TestArguments noFilePath simulatedFS
104
108
, testProperty " LMDB" $
105
- prop_sequential 1000 lmdbTestArguments realFilePath realFS
109
+ prop_sequential 1000 lmdbTestArguments (realFilePath " lmdb" ) realFS
110
+ , testProperty " LSM" $
111
+ prop_sequential 1000 lsmTestArguments (realFilePath " lsm" ) realFS
106
112
]
107
113
108
114
prop_sequential ::
@@ -156,9 +162,10 @@ data TestArguments m = TestArguments
156
162
noFilePath :: IO (FilePath , IO () )
157
163
noFilePath = pure (" Bogus" , pure () )
158
164
159
- realFilePath :: IO (FilePath , IO () )
160
- realFilePath = liftIO $ do
161
- tmpdir <- (FilePath. </> " test_lmdb" ) <$> Dir. getTemporaryDirectory
165
+ realFilePath :: String -> IO (FilePath , IO () )
166
+ realFilePath l = liftIO $ do
167
+ tmpdir <- (FilePath. </> (" test_" <> l)) <$> Dir. getTemporaryDirectory
168
+ Dir. createDirectoryIfMissing False tmpdir
162
169
pure
163
170
( tmpdir
164
171
, do
@@ -197,6 +204,17 @@ inMemV2TestArguments secParam _ =
197
204
, argLedgerDbCfg = extLedgerDbConfig secParam
198
205
}
199
206
207
+ lsmTestArguments ::
208
+ SecurityParam ->
209
+ FilePath ->
210
+ TestArguments IO
211
+ lsmTestArguments secParam fp =
212
+ TestArguments
213
+ { argFlavorArgs =
214
+ LedgerDbFlavorArgsV2 $ V2Args $ LSMHandleArgs $ LSMArgs fp LSM. stdGenSalt (LSM. stdMkBlockIOFS fp)
215
+ , argLedgerDbCfg = extLedgerDbConfig secParam
216
+ }
217
+
200
218
lmdbTestArguments ::
201
219
SecurityParam ->
202
220
FilePath ->
@@ -490,19 +508,40 @@ openLedgerDB flavArgs env cfg fs = do
490
508
Nothing
491
509
(ldb, _, od) <- case flavArgs of
492
510
LedgerDbFlavorArgsV1 bss ->
493
- let initDb =
511
+ let snapManager = V1. snapshotManager args
512
+ initDb =
494
513
V1. mkInitDb
495
514
args
496
515
bss
497
516
getBlock
498
- in openDBInternal args initDb stream replayGoal
499
- LedgerDbFlavorArgsV2 bss ->
517
+ snapManager
518
+ in openDBInternal args initDb snapManager stream replayGoal
519
+ LedgerDbFlavorArgsV2 bss -> do
520
+ (snapManager, bss') <- case bss of
521
+ V2. V2Args V2. InMemoryHandleArgs -> pure (InMemory. snapshotManager args, V2. InMemoryHandleEnv )
522
+ V2. V2Args (V2. LSMHandleArgs (V2. LSMArgs path genSalt mkFS)) -> do
523
+ (rk1, V2. SomeHasFSAndBlockIO fs' blockio) <- mkFS (lgrRegistry args)
524
+ session <-
525
+ allocate
526
+ (lgrRegistry args)
527
+ ( \ _ -> do
528
+ salt <- genSalt
529
+ LSM. openSession
530
+ (LedgerDBFlavorImplEvent . FlavorImplSpecificTraceV2 . V2. LSMTrace >$< lgrTracer args)
531
+ fs'
532
+ blockio
533
+ salt
534
+ (mkFsPath [path])
535
+ )
536
+ LSM. closeSession
537
+ pure (LSM. snapshotManager (snd session) args, V2. LSMHandleEnv session rk1)
500
538
let initDb =
501
539
V2. mkInitDb
502
540
args
503
- bss
541
+ bss'
504
542
getBlock
505
- in openDBInternal args initDb stream replayGoal
543
+ snapManager
544
+ openDBInternal args initDb snapManager stream replayGoal
506
545
withRegistry $ \ reg -> do
507
546
vr <- validateFork ldb reg (const $ pure () ) BlockCache. empty 0 (map getHeader volBlocks)
508
547
case vr of
@@ -617,6 +656,7 @@ mkTrackOpenHandles = do
617
656
atomically $ modifyTVar varOpen $ case ev of
618
657
V2. TraceLedgerTablesHandleCreate -> succ
619
658
V2. TraceLedgerTablesHandleClose -> pred
659
+ _ -> id
620
660
_ -> pure ()
621
661
pure (tracer, readTVarIO varOpen)
622
662
0 commit comments