Skip to content

Commit 581f28b

Browse files
committed
Manually invalidate blob references in the model
This is required for properly modelling the model's response to disk faults in `createSnapshot`. The current implementation for `createSnapshot` in the real system can invalidate blob references even if creating the snapshot failed, so the model will invalidate blob references as well. This change might become obsolete once #478 is merged.
1 parent ef1316c commit 581f28b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/Database/LSMTree/Model/Session.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ module Database.LSMTree.Model.Session (
6464
-- ** Blobs
6565
, BlobRef
6666
, retrieveBlobs
67+
, invalidateBlobRefs
6768
-- * Snapshots
6869
, SnapshotName
6970
, createSnapshot
@@ -481,6 +482,27 @@ liftBlobRefs ::
481482
-> g (f (BlobRef b))
482483
liftBlobRefs hid = fmap (fmap (BlobRef hid))
483484

485+
-- | Invalidate blob references that were created from the given table. This
486+
-- function assumes that it is called on an open table.
487+
--
488+
-- This is useful in tests where blob references should be invalidated for other
489+
-- reasons than normal operation of the model.
490+
--
491+
-- TODO: I (Joris) think this function will become obsolete once lsm-tree#478 is
492+
-- merged, because then createSnapshot won't flush the write buffer into the
493+
-- levels anymore.
494+
invalidateBlobRefs ::
495+
MonadState Model m
496+
=> Table k v b
497+
-> m ()
498+
invalidateBlobRefs Table{..} = do
499+
gets (Map.lookup tableID . tables) >>= \case
500+
Nothing -> error "invalidateBlobRefs: table is closed!"
501+
Just (updc, tbl) -> do
502+
modify (\m -> m {
503+
tables = Map.insert tableID (updc + 1, tbl) (tables m)
504+
})
505+
484506
{-------------------------------------------------------------------------------
485507
Snapshots
486508
-------------------------------------------------------------------------------}

0 commit comments

Comments
 (0)