Skip to content

Commit c918bec

Browse files
committed
Remove BlobRef.readBlob and add BlobRef.readWeakBlobRef
The only uses of BlobRef.readBlob were in the context of withWeakBlobRef so we can go straight to a helper function that does just that. Also remove now-unused WriteBufferBlobs.readBlob
1 parent fd61a17 commit c918bec

File tree

4 files changed

+13
-30
lines changed

4 files changed

+13
-30
lines changed

src/Database/LSMTree/Internal/BlobRef.hs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Database.LSMTree.Internal.BlobRef (
1717
, removeReference
1818
, removeReferences
1919
, readRawBlobRef
20-
, readBlob
20+
, readWeakBlobRef
2121
, readBlobIOOp
2222
) where
2323

@@ -188,17 +188,16 @@ readRawBlobRef ::
188188
readRawBlobRef fs RawBlobRef {rawBlobRefFile, rawBlobRefSpan} =
189189
BlobFile.readBlobFile fs rawBlobRefFile rawBlobRefSpan
190190

191-
{-# SPECIALISE readBlob ::
192-
HasFS IO h
193-
-> StrongBlobRef IO h
194-
-> IO SerialisedBlob #-}
195-
readBlob ::
196-
(MonadThrow m, PrimMonad m)
191+
{-# SPECIALISE readWeakBlobRef :: HasFS IO h -> WeakBlobRef IO h -> IO SerialisedBlob #-}
192+
readWeakBlobRef ::
193+
(MonadMask m, PrimMonad m)
197194
=> HasFS m h
198-
-> StrongBlobRef m h
195+
-> WeakBlobRef m h
199196
-> m SerialisedBlob
200-
readBlob fs StrongBlobRef {strongBlobRefFile, strongBlobRefSpan} =
201-
BlobFile.readBlobFile fs strongBlobRefFile strongBlobRefSpan
197+
readWeakBlobRef fs wref =
198+
bracket (deRefWeakBlobRef wref) removeReference $
199+
\StrongBlobRef {strongBlobRefFile, strongBlobRefSpan} ->
200+
BlobFile.readBlobFile fs strongBlobRefFile strongBlobRefSpan
202201

203202
readBlobIOOp ::
204203
P.MutableByteArray s -> Int

src/Database/LSMTree/Internal/WriteBufferBlobs.hs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module Database.LSMTree.Internal.WriteBufferBlobs (
2727
addReference,
2828
removeReference,
2929
addBlob,
30-
readBlob,
3130
mkRawBlobRef,
3231
mkWeakBlobRef,
3332
-- * For tests
@@ -170,15 +169,6 @@ writeBlobAtOffset fs h (SerialisedBlob' (VP.Vector boff blen ba)) off = do
170169
(FS.AbsOffset off)
171170
return ()
172171

173-
{-# SPECIALISE readBlob :: HasFS IO h -> WriteBufferBlobs IO h -> BlobSpan -> IO SerialisedBlob #-}
174-
readBlob :: (PrimMonad m, MonadThrow m)
175-
=> HasFS m h
176-
-> WriteBufferBlobs m h
177-
-> BlobSpan
178-
-> m SerialisedBlob
179-
readBlob fs WriteBufferBlobs {blobFile} blobspan =
180-
readBlobFile fs blobFile blobspan
181-
182172
-- | Helper function to make a 'RawBlobRef' that points into a
183173
-- 'WriteBufferBlobs'.
184174
mkRawBlobRef :: WriteBufferBlobs m h

test/Test/Database/LSMTree/Internal.hs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ prop_interimOpenTable dat = ioProperty $
197197
fetchBlobs :: FS.HasFS IO h
198198
-> (V.Vector (Maybe (Entry v (WeakBlobRef IO h))))
199199
-> IO (V.Vector (Maybe (Entry v SerialisedBlob)))
200-
fetchBlobs hfs = traverse (traverse (traverse (fetchBlob hfs)))
200+
fetchBlobs hfs = traverse (traverse (traverse (readWeakBlobRef hfs)))
201201

202202
Test.InMemLookupData { runData, lookups = keysToLookup } = dat
203203
ks = V.map serialiseKey (V.fromList keysToLookup)
@@ -242,7 +242,7 @@ prop_roundtripCursor lb ub kops = ioProperty $
242242
fetchBlobs :: FS.HasFS IO h
243243
-> V.Vector (k, (v, Maybe (WeakBlobRef IO h)))
244244
-> IO (V.Vector (k, (v, Maybe SerialisedBlob)))
245-
fetchBlobs hfs = traverse (traverse (traverse (traverse (fetchBlob hfs))))
245+
fetchBlobs hfs = traverse (traverse (traverse (traverse (readWeakBlobRef hfs))))
246246

247247
toOffsetKey = maybe NoOffsetKey (OffsetKey . coerce)
248248

@@ -288,6 +288,3 @@ readCursorUntil resolve ub cursor = go V.empty
288288
appendSerialisedValue :: ResolveSerialisedValue
289289
appendSerialisedValue (SerialisedValue x) (SerialisedValue y) =
290290
SerialisedValue (x <> y)
291-
292-
fetchBlob :: FS.HasFS IO h -> WeakBlobRef IO h -> IO SerialisedBlob
293-
fetchBlob hfs bref = withWeakBlobRef bref (readBlob hfs)

test/Test/Database/LSMTree/Internal/Lookup.hs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ import Database.LSMTree.Extras.Generators
4444
import Database.LSMTree.Extras.RunData (RunData (..),
4545
liftArbitrary2Map, liftShrink2Map,
4646
unsafeFlushAsWriteBuffer)
47-
import Database.LSMTree.Internal.BlobRef (BlobSpan, WeakBlobRef,
48-
readBlob, withWeakBlobRef)
47+
import Database.LSMTree.Internal.BlobRef
4948
import Database.LSMTree.Internal.Entry as Entry
5049
import Database.LSMTree.Internal.IndexCompact as Index
5150
import Database.LSMTree.Internal.Lookup
@@ -325,9 +324,7 @@ prop_roundtripFromWriteBufferLookupIO (SmallList dats) =
325324
fetchBlobs :: FS.HasFS IO h
326325
-> (V.Vector (Maybe (Entry v (WeakBlobRef IO h))))
327326
-> IO (V.Vector (Maybe (Entry v SerialisedBlob)))
328-
fetchBlobs hfs = traverse (traverse (traverse fetchBlob))
329-
where
330-
fetchBlob bref = withWeakBlobRef bref (readBlob hfs)
327+
fetchBlobs hfs = traverse (traverse (traverse (readWeakBlobRef hfs)))
331328

332329
-- | Given a bunch of 'InMemLookupData', prepare the data into the form needed
333330
-- for 'lookupsIO': a write buffer (and blobs) and a vector of on-disk runs.

0 commit comments

Comments
 (0)