@@ -66,7 +66,9 @@ import Data.BloomFilter (Bloom)
6666import qualified Data.ByteString.Short as SBS
6767import Data.Foldable (for_ )
6868import Data.Word (Word64 )
69- import Database.LSMTree.Internal.BlobRef (BlobRef (.. ), BlobSpan (.. ))
69+ import Database.LSMTree.Internal.BlobFile hiding (removeReference )
70+ import qualified Database.LSMTree.Internal.BlobFile as BlobFile
71+ import Database.LSMTree.Internal.BlobRef hiding (removeReference )
7072import Database.LSMTree.Internal.BloomFilter (bloomFilterFromSBS )
7173import qualified Database.LSMTree.Internal.CRC32C as CRC
7274import Database.LSMTree.Internal.Entry (NumEntries (.. ))
@@ -111,7 +113,7 @@ data Run m h = Run {
111113 -- | The file handle for the BLOBs file. This file is opened
112114 -- read-only and is accessed in a normal style using buffered
113115 -- I\/O, reading arbitrary file offset and length spans.
114- , runBlobFile :: ! (FS. Handle h )
116+ , runBlobFile :: ! (BlobFile m h )
115117 , runRunDataCaching :: ! RunDataCaching
116118 , runHasFS :: ! (HasFS m h )
117119 , runHasBlockIO :: ! (HasBlockIO m h )
@@ -143,10 +145,10 @@ removeReferenceN r = RC.removeReferenceN (runRefCounter r)
143145
144146-- | Helper function to make a 'BlobRef' that points into a 'Run'.
145147mkBlobRefForRun :: Run m h -> BlobSpan -> BlobRef m (FS. Handle h )
146- mkBlobRefForRun Run {runBlobFile, runRefCounter } blobRefSpan =
148+ mkBlobRefForRun Run {runBlobFile} blobRefSpan =
147149 BlobRef {
148- blobRefFile = runBlobFile,
149- blobRefCount = runRefCounter ,
150+ blobRefFile = blobFileHandle runBlobFile,
151+ blobRefCount = blobFileRefCounter runBlobFile ,
150152 blobRefSpan
151153 }
152154
@@ -158,18 +160,18 @@ mkBlobRefForRun Run{runBlobFile, runRefCounter} blobRefSpan =
158160--
159161-- TODO: Once snapshots are implemented, files should get removed, but for now
160162-- we want to be able to re-open closed runs from disk.
161- close :: (MonadSTM m , MonadThrow m ) => Run m h -> m ()
163+ close :: (MonadSTM m , MonadMask m , PrimMonad m ) => Run m h -> m ()
162164close Run {.. } = do
163165 -- TODO: removing files should drop them from the page cache, but until we
164166 -- have proper snapshotting we are keeping the files around. Because of
165167 -- this, we instruct the OS to drop all run-related files from the page
166168 -- cache
167169 FS. hDropCacheAll runHasBlockIO runKOpsFile
168- FS. hDropCacheAll runHasBlockIO runBlobFile
170+ FS. hDropCacheAll runHasBlockIO (blobFileHandle runBlobFile)
169171
170172 FS. hClose runHasFS runKOpsFile
171173 `finally`
172- FS. hClose runHasFS runBlobFile
174+ BlobFile. removeReference runBlobFile
173175
174176-- | Should this run cache key\/ops data in memory?
175177data RunDataCaching = CacheRunData | NoCacheRunData
@@ -205,7 +207,7 @@ setRunDataCaching hbio runKOpsFile NoCacheRunData = do
205207 -> RunBuilder IO h
206208 -> IO (Run IO h) #-}
207209fromMutable ::
208- (MonadFix m , MonadST m , MonadSTM m , MonadThrow m )
210+ (MonadFix m , MonadST m , MonadSTM m , MonadMask m )
209211 => RunDataCaching
210212 -> RefCount
211213 -> RunBuilder m h
@@ -214,7 +216,8 @@ fromMutable runRunDataCaching refCount builder = do
214216 (runHasFS, runHasBlockIO, runRunFsPaths, runFilter, runIndex, runNumEntries) <-
215217 Builder. unsafeFinalise (runRunDataCaching == NoCacheRunData ) builder
216218 runKOpsFile <- FS. hOpen runHasFS (runKOpsPath runRunFsPaths) FS. ReadMode
217- runBlobFile <- FS. hOpen runHasFS (runBlobPath runRunFsPaths) FS. ReadMode
219+ runBlobFile <- newBlobFile runHasFS
220+ =<< FS. hOpen runHasFS (runBlobPath runRunFsPaths) FS. ReadMode
218221 setRunDataCaching runHasBlockIO runKOpsFile runRunDataCaching
219222 rec runRefCounter <- RC. unsafeMkRefCounterN refCount (Just $ close r)
220223 let ! r = Run { .. }
@@ -236,7 +239,7 @@ fromMutable runRunDataCaching refCount builder = do
236239-- immediately when they are added to the write buffer, avoiding the need to do
237240-- it here.
238241fromWriteBuffer ::
239- (MonadFix m , MonadST m , MonadSTM m , MonadThrow m )
242+ (MonadFix m , MonadST m , MonadSTM m , MonadMask m )
240243 => HasFS m h
241244 -> HasBlockIO m h
242245 -> RunDataCaching
@@ -274,7 +277,7 @@ data FileFormatError = FileFormatError FS.FsPath String
274277-- checksum ('ChecksumError') or can't be parsed ('FileFormatError').
275278openFromDisk ::
276279 forall m h .
277- (MonadFix m , MonadSTM m , MonadThrow m , PrimMonad m )
280+ (MonadFix m , MonadSTM m , MonadMask m , PrimMonad m )
278281 => HasFS m h
279282 -> HasBlockIO m h
280283 -> RunDataCaching
@@ -299,7 +302,8 @@ openFromDisk fs hbio runRunDataCaching runRunFsPaths = do
299302 =<< readCRC (forRunIndex expectedChecksums) (forRunIndex paths)
300303
301304 runKOpsFile <- FS. hOpen fs (runKOpsPath runRunFsPaths) FS. ReadMode
302- runBlobFile <- FS. hOpen fs (runBlobPath runRunFsPaths) FS. ReadMode
305+ runBlobFile <- newBlobFile fs
306+ =<< FS. hOpen fs (runBlobPath runRunFsPaths) FS. ReadMode
303307 setRunDataCaching hbio runKOpsFile runRunDataCaching
304308 rec runRefCounter <- RC. unsafeMkRefCounterN (RefCount 1 ) (Just $ close r)
305309 let ! r = Run
0 commit comments