From d68afd9b22f87af7a224216ecf81c86037a755e4 Mon Sep 17 00:00:00 2001 From: Duncan Coutts Date: Tue, 17 Sep 2024 14:08:25 +0100 Subject: [PATCH] Properly reference count the WriteBufferBlobs in cursors 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. --- src/Database/LSMTree/Internal.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Database/LSMTree/Internal.hs b/src/Database/LSMTree/Internal.hs index f72afee0b..352c48660 100644 --- a/src/Database/LSMTree/Internal.hs +++ b/src/Database/LSMTree/Internal.hs @@ -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'.