22-- from them. Tests and benchmarks should preferably use these utilities instead
33-- of (re-)defining their own.
44module Database.LSMTree.Extras.RunData (
5- -- * RunParams
6- defaultRunParams
75 -- * Create runs
8- , withRun
6+ withRun
97 , withRunAt
108 , withRuns
119 , unsafeCreateRun
@@ -50,16 +48,13 @@ import qualified Data.Vector as V
5048import Database.LSMTree.Extras (showPowersOf10 )
5149import Database.LSMTree.Extras.Generators ()
5250import Database.LSMTree.Internal.Entry
53- import Database.LSMTree.Internal.Index (IndexType (.. ))
5451import Database.LSMTree.Internal.Lookup (ResolveSerialisedValue )
5552import Database.LSMTree.Internal.MergeSchedule (addWriteBufferEntries )
5653import Database.LSMTree.Internal.Paths
5754import qualified Database.LSMTree.Internal.Paths as Paths
58- import Database.LSMTree.Internal.Run (Run , RunDataCaching (.. ),
59- RunParams (.. ))
55+ import Database.LSMTree.Internal.Run (Run , RunParams (.. ))
6056import qualified Database.LSMTree.Internal.Run as Run
61- import Database.LSMTree.Internal.RunAcc (RunBloomFilterAlloc (.. ),
62- entryWouldFitInPage )
57+ import Database.LSMTree.Internal.RunAcc (entryWouldFitInPage )
6358import Database.LSMTree.Internal.RunNumber
6459import Database.LSMTree.Internal.Serialise
6560import Database.LSMTree.Internal.UniqCounter
@@ -73,14 +68,6 @@ import System.FS.BlockIO.API (HasBlockIO)
7368import Test.QuickCheck
7469
7570
76- defaultRunParams :: RunParams
77- defaultRunParams =
78- RunParams {
79- runParamCaching = CacheRunData ,
80- runParamAlloc = RunAllocFixed 10 ,
81- runParamIndex = Compact
82- }
83-
8471{- ------------------------------------------------------------------------------
8572 Create runs
8673-------------------------------------------------------------------------------}
@@ -89,47 +76,47 @@ defaultRunParams =
8976withRun ::
9077 HasFS IO h
9178 -> HasBlockIO IO h
92- -> IndexType
79+ -> RunParams
9380 -> FS. FsPath
9481 -> UniqCounter IO
9582 -> SerialisedRunData
9683 -> (Ref (Run IO h ) -> IO a )
9784 -> IO a
98- withRun hfs hbio indexType path counter rd = do
85+ withRun hfs hbio runParams path counter rd = do
9986 bracket
100- (unsafeCreateRun hfs hbio indexType path counter rd)
87+ (unsafeCreateRun hfs hbio runParams path counter rd)
10188 releaseRef
10289
10390-- | Create a temporary 'Run' using 'unsafeCreateRunAt'.
10491withRunAt ::
10592 HasFS IO h
10693 -> HasBlockIO IO h
107- -> IndexType
94+ -> RunParams
10895 -> RunFsPaths
10996 -> SerialisedRunData
11097 -> (Ref (Run IO h ) -> IO a )
11198 -> IO a
112- withRunAt hfs hbio indexType path rd = do
99+ withRunAt hfs hbio runParams path rd = do
113100 bracket
114- (unsafeCreateRunAt hfs hbio indexType path rd)
101+ (unsafeCreateRunAt hfs hbio runParams path rd)
115102 releaseRef
116103
117104{-# INLINABLE withRuns #-}
118105-- | Create temporary 'Run's using 'unsafeCreateRun'.
119106withRuns ::
120107 HasFS IO h
121108 -> HasBlockIO IO h
122- -> IndexType
109+ -> RunParams
123110 -> FS. FsPath
124111 -> UniqCounter IO
125112 -> [SerialisedRunData ]
126113 -> ([Ref (Run IO h )] -> IO a )
127114 -> IO a
128- withRuns hfs hbio indexType path counter = go
115+ withRuns hfs hbio runParams path counter = go
129116 where
130117 go [] act = act []
131118 go (rd: rds) act =
132- withRun hfs hbio indexType path counter rd $ \ r ->
119+ withRun hfs hbio runParams path counter rd $ \ r ->
133120 go rds $ \ rs ->
134121 act (r: rs)
135122
@@ -138,15 +125,15 @@ withRuns hfs hbio indexType path counter = go
138125unsafeCreateRun ::
139126 HasFS IO h
140127 -> HasBlockIO IO h
141- -> IndexType
128+ -> RunParams
142129 -> FS. FsPath
143130 -> UniqCounter IO
144131 -> SerialisedRunData
145132 -> IO (Ref (Run IO h ))
146- unsafeCreateRun fs hbio indexType path counter rd = do
133+ unsafeCreateRun fs hbio runParams path counter rd = do
147134 n <- incrUniqCounter counter
148135 let fsPaths = RunFsPaths path (uniqueToRunNumber n)
149- unsafeCreateRunAt fs hbio indexType fsPaths rd
136+ unsafeCreateRunAt fs hbio runParams fsPaths rd
150137
151138-- | Flush serialised run data to disk as if it were a write buffer.
152139--
@@ -157,17 +144,15 @@ unsafeCreateRun fs hbio indexType path counter rd = do
157144unsafeCreateRunAt ::
158145 HasFS IO h
159146 -> HasBlockIO IO h
160- -> IndexType
147+ -> RunParams
161148 -> RunFsPaths
162149 -> SerialisedRunData
163150 -> IO (Ref (Run IO h ))
164- unsafeCreateRunAt fs hbio indexType fsPaths (RunData m) = do
151+ unsafeCreateRunAt fs hbio runParams fsPaths (RunData m) = do
165152 let blobpath = FS. addExtension (runBlobPath fsPaths) " .wb"
166153 bracket (WBB. new fs blobpath) releaseRef $ \ wbblobs -> do
167154 wb <- WB. fromMap <$> traverse (traverse (WBB. addBlob fs wbblobs)) m
168- Run. fromWriteBuffer fs hbio
169- defaultRunParams { runParamIndex = indexType }
170- fsPaths wb wbblobs
155+ Run. fromWriteBuffer fs hbio runParams fsPaths wb wbblobs
171156
172157-- | Create a 'RunFsPaths' using an empty 'FsPath'. The empty path corresponds
173158-- to the "root" or "mount point" of a 'HasFS' instance.
0 commit comments