Skip to content

Commit

Permalink
Properly reference count the WriteBufferBlobs in cursors
Browse files Browse the repository at this point in the history
Cursors, being like read-only tables, need to do the same reference
counting for the WriteBufferBlobs as tables do. In particular they need
to take a reference on the blob store when the cursor is created (in
case the original table is modified or closed), and release the
reference when the cursor itself is closed.
  • Loading branch information
dcoutts committed Sep 18, 2024
1 parent dedeaca commit d68afd9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Database/LSMTree/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -881,12 +881,17 @@ newCursor !offsetKey th = withOpenTable th $ \thEnv -> do
-- references to each run, so it is safe.
allocTableContent reg contentVar = do
RW.withReadAccess contentVar $ \content -> do
let wb = tableWriteBuffer content
wbblobs = tableWriteBufferBlobs content
allocateTemp reg
(WBB.addReference wbblobs)
(\_ -> WBB.removeReference wbblobs)
let runs = cachedRuns (tableCache content)
V.forM_ runs $ \r -> do
allocateTemp reg
(Run.addReference r)
(\_ -> Run.removeReference r)
pure (tableWriteBuffer content, runs)
pure (wb, runs)

{-# SPECIALISE closeCursor :: Cursor IO h -> IO () #-}
-- | See 'Database.LSMTree.Normal.closeCursor'.
Expand Down

0 comments on commit d68afd9

Please sign in to comment.