@@ -23,12 +23,10 @@ module Database.LSMTree.Internal.Run (
2323 , RunDataCaching (.. )
2424 -- * Snapshot
2525 , FileFormatError (.. )
26- , ChecksumError (.. )
2726 , openFromDisk
2827 ) where
2928
3029import Control.DeepSeq (NFData (.. ), rwhnf )
31- import Control.Monad (when )
3230import Control.Monad.Class.MonadST (MonadST )
3331import Control.Monad.Class.MonadSTM (MonadSTM (.. ))
3432import Control.Monad.Class.MonadThrow
@@ -236,10 +234,6 @@ fromWriteBuffer fs hbio caching alloc fsPaths buffer blobs = do
236234 Snapshot
237235-------------------------------------------------------------------------------}
238236
239- data ChecksumError = ChecksumError FS. FsPath CRC. CRC32C CRC. CRC32C
240- deriving stock Show
241- deriving anyclass Exception
242-
243237data FileFormatError = FileFormatError FS. FsPath String
244238 deriving stock Show
245239 deriving anyclass Exception
@@ -298,14 +292,8 @@ openFromDisk fs hbio runRunDataCaching runRunFsPaths = do
298292 -- Note: all file data for this path is evicted from the page cache /if/ the
299293 -- caching argument is 'NoCacheRunData'.
300294 checkCRC :: RunDataCaching -> CRC. CRC32C -> FS. FsPath -> m ()
301- checkCRC cache expected fp = FS. withFile fs fp FS. ReadMode $ \ h -> do
302- -- double the file readahead window (only applies to this file descriptor)
303- FS. hAdviseAll hbio h FS. AdviceSequential
304- ! checksum <- CRC. hGetAllCRC32C' fs h CRC. defaultChunkSize CRC. initialCRC32C
305- when (cache == NoCacheRunData ) $
306- -- drop the file from the OS page cache
307- FS. hDropCacheAll hbio h
308- expectChecksum fp expected checksum
295+ checkCRC cache expected fp =
296+ CRC. checkCRC fs hbio (cache == NoCacheRunData ) expected fp
309297
310298 -- Note: all file data for this path is evicted from the page cache
311299 readCRC :: CRC. CRC32C -> FS. FsPath -> m SBS. ShortByteString
@@ -316,12 +304,8 @@ openFromDisk fs hbio runRunDataCaching runRunFsPaths = do
316304 (sbs, ! checksum) <- CRC. hGetExactlyCRC32C_SBS fs h (fromIntegral n) CRC. initialCRC32C
317305 -- drop the file from the OS page cache
318306 FS. hAdviseAll hbio h FS. AdviceDontNeed
319- expectChecksum fp expected checksum
307+ CRC. expectChecksum fp expected checksum
320308 return sbs
321309
322- expectChecksum fp expected checksum =
323- when (expected /= checksum) $
324- throwIO $ ChecksumError fp expected checksum
325-
326310 expectValidFile _ (Right x) = pure x
327311 expectValidFile fp (Left err) = throwIO $ FileFormatError fp err
0 commit comments