@@ -84,7 +84,7 @@ module Database.LSMTree.Normal (
8484 -- * Durability (snapshots)
8585 , SnapshotName
8686 , Common. mkSnapshotName
87- , Common. Labellable (.. )
87+ , Common. SnapshotLabel (.. )
8888 , createSnapshot
8989 , openSnapshot
9090 , Common. TableConfigOverride
@@ -115,7 +115,7 @@ import Control.Exception (throw)
115115import Control.Monad
116116import Data.Bifunctor (Bifunctor (.. ))
117117import Data.Kind (Type )
118- import Data.Typeable (Proxy ( .. ), eqT , type (:~: ) (Refl ))
118+ import Data.Typeable (eqT , type (:~: ) (Refl ))
119119import qualified Data.Vector as V
120120import Database.LSMTree.Common (BlobRef (BlobRef ), IOLike , Range (.. ),
121121 SerialiseKey , SerialiseValue , Session , SnapshotName ,
@@ -635,8 +635,8 @@ retrieveBlobs (Internal.Session' (sesh :: Internal.Session m h)) refs =
635635-------------------------------------------------------------------------------}
636636
637637{-# SPECIALISE createSnapshot ::
638- Common.Labellable (k, v, blob)
639- = > SnapshotName
638+ Common.SnapshotLabel
639+ - > SnapshotName
640640 -> Table IO k v blob
641641 -> IO () #-}
642642-- | Make the current value of a table durable on-disk by taking a snapshot and
@@ -647,6 +647,11 @@ retrieveBlobs (Internal.Session' (sesh :: Internal.Session m h)) refs =
647647-- via that name. Names are strings and the management of the names is up to
648648-- the user of the library.
649649--
650+ -- Snapshot labels are included in the snapshot metadata when a snapshot is
651+ -- created. Labels are text and the management of the labels is up to the user
652+ -- of the library. Labels assigns a dynamically checked "type" to a snapshot.
653+ -- See 'Common.SnapshotLabel' for more information.
654+ --
650655-- The names correspond to disk files, which imposes some constraints on length
651656-- and what characters can be used.
652657--
@@ -661,25 +666,26 @@ retrieveBlobs (Internal.Session' (sesh :: Internal.Session m h)) refs =
661666-- * It is safe to concurrently make snapshots from any table, provided that
662667-- the snapshot names are distinct (otherwise this would be a race).
663668createSnapshot :: forall m k v blob .
664- ( IOLike m
665- , Common. Labellable (k , v , blob )
666- )
667- => SnapshotName
669+ IOLike m
670+ => Common. SnapshotLabel
671+ -> SnapshotName
668672 -> Table m k v blob
669673 -> m ()
670- createSnapshot snap (Internal. NormalTable t) =
674+ createSnapshot label snap (Internal. NormalTable t) =
671675 Internal. createSnapshot const snap label Internal. SnapNormalTable t
672- where
673- label = Internal. SnapshotLabel $ Common. makeSnapshotLabel (Proxy @ (k , v , blob ))
674676
675677{-# SPECIALISE openSnapshot ::
676- Common.Labellable (k, v, blob)
677- => Session IO
678+ Session IO
678679 -> Common.TableConfigOverride
680+ -> Common.SnapshotLabel
679681 -> SnapshotName
680682 -> IO (Table IO k v blob ) #-}
681683-- | Open a table from a named snapshot, returning a new table.
682684--
685+ -- This function requires passing in an expected label that will be checked
686+ -- against the label that was included in the snapshot metadata. If there is a
687+ -- mismatch, an exception is thrown.
688+ --
683689-- NOTE: close tables using 'close' as soon as they are
684690-- unused.
685691--
@@ -697,14 +703,13 @@ createSnapshot snap (Internal.NormalTable t) =
697703-- 'openSnapshot' \@IO \@Bool \@Bool \@Bool session "intTable"
698704-- @
699705openSnapshot :: forall m k v blob .
700- ( IOLike m
701- , Common. Labellable (k , v , blob )
702- )
706+ IOLike m
703707 => Session m
704708 -> Common. TableConfigOverride -- ^ Optional config override
709+ -> Common. SnapshotLabel
705710 -> SnapshotName
706711 -> m (Table m k v blob )
707- openSnapshot (Internal. Session' sesh) override snap =
712+ openSnapshot (Internal. Session' sesh) override label snap =
708713 Internal. NormalTable <$!>
709714 Internal. openSnapshot
710715 sesh
@@ -713,8 +718,6 @@ openSnapshot (Internal.Session' sesh) override snap =
713718 override
714719 snap
715720 const
716- where
717- label = Internal. SnapshotLabel $ Common. makeSnapshotLabel (Proxy @ (k , v , blob ))
718721
719722{- ------------------------------------------------------------------------------
720723 Mutiple writable tables
0 commit comments