@@ -41,16 +41,19 @@ import Data.Text (Text)
4141import Data.Traversable (for )
4242import qualified Data.Vector as V
4343import Database.LSMTree.Internal.Config
44+ import Database.LSMTree.Internal.CRC32C (checkCRC )
45+ import qualified Database.LSMTree.Internal.CRC32C as CRC
4446import Database.LSMTree.Internal.Entry
4547import Database.LSMTree.Internal.Lookup (ResolveSerialisedValue )
4648import Database.LSMTree.Internal.Merge (MergeType (.. ))
4749import qualified Database.LSMTree.Internal.Merge as Merge
4850import Database.LSMTree.Internal.MergeSchedule
4951import Database.LSMTree.Internal.MergingRun (NumRuns (.. ))
5052import qualified Database.LSMTree.Internal.MergingRun as MR
51- import Database.LSMTree.Internal.Paths (ActiveDir (.. ), ForKOps (.. ),
52- NamedSnapshotDir (.. ), RunFsPaths (.. ),
53- WriteBufferFsPaths (.. ), pathsForRunFiles ,
53+ import Database.LSMTree.Internal.Paths (ActiveDir (.. ), ForBlob (.. ),
54+ ForKOps (.. ), NamedSnapshotDir (.. ), RunFsPaths (.. ),
55+ WriteBufferFsPaths (.. ),
56+ fromChecksumsFileForWriteBufferFiles , pathsForRunFiles ,
5457 runChecksumsPath , writeBufferBlobPath ,
5558 writeBufferChecksumsPath , writeBufferKOpsPath )
5659import Database.LSMTree.Internal.Run (Run )
@@ -301,6 +304,14 @@ openWriteBuffer ::
301304 -> WriteBufferFsPaths
302305 -> m (WriteBuffer , Ref (WriteBufferBlobs m h ))
303306openWriteBuffer reg resolve hfs hbio uc activeDir snapWriteBufferPaths = do
307+ -- Check the checksums
308+ -- TODO: This reads the blobfile twice: once to check the CRC and once more
309+ -- to copy it from the snapshot directory to the active directory.
310+ (expectedChecksumForKOps, expectedChecksumForBlob) <-
311+ CRC. expectValidFile (writeBufferChecksumsPath snapWriteBufferPaths) . fromChecksumsFileForWriteBufferFiles
312+ =<< CRC. readChecksumsFile hfs (writeBufferChecksumsPath snapWriteBufferPaths)
313+ checkCRC hfs hbio False (unForKOps expectedChecksumForKOps) (writeBufferKOpsPath snapWriteBufferPaths)
314+ checkCRC hfs hbio False (unForBlob expectedChecksumForBlob) (writeBufferBlobPath snapWriteBufferPaths)
304315 -- Copy the write buffer blobs file to the active directory and open it.
305316 activeWriteBufferNumber <- uniqueToInt <$> incrUniqCounter uc
306317 let activeWriteBufferBlobPath =
0 commit comments