Skip to content

Commit 7903d6c

Browse files
committed
rename snapshot operations
1 parent 6be2863 commit 7903d6c

File tree

14 files changed

+152
-149
lines changed

14 files changed

+152
-149
lines changed

bench/macro/lsm-tree-bench-wp8.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ doSetup' gopts opts = do
418418
| i <- NE.toList batch
419419
]
420420

421-
LSM.snapshot name tbl
421+
LSM.createSnapshot name tbl
422422

423423
-------------------------------------------------------------------------------
424424
-- dry-run
@@ -577,7 +577,7 @@ doRun gopts opts = do
577577
-- necessary for testing to load the whole snapshot).
578578
tbl <- if check opts
579579
then LSM.new @IO @K @V @B session (mkTableConfigRun gopts LSM.defaultTableConfig)
580-
else LSM.open @IO @K @V @B session (mkTableConfigOverride gopts) name
580+
else LSM.openSnapshot @IO @K @V @B session (mkTableConfigOverride gopts) name
581581

582582
-- In checking mode, compare each output against a pure reference.
583583
checkvar <- newIORef $ pureReference

src/Database/LSMTree/Internal.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ module Database.LSMTree.Internal (
5858
, readCursorWhile
5959
-- * Snapshots
6060
, SnapshotLabel
61-
, snapshot
62-
, open
61+
, createSnapshot
62+
, openSnapshot
6363
, deleteSnapshot
6464
, listSnapshots
6565
-- * Mutiple writable tables
@@ -297,8 +297,8 @@ data SessionEnv m h = SessionEnv {
297297
--
298298
-- Tables are assigned unique identifiers using 'sessionUniqCounter' to
299299
-- ensure that modifications to the set of known tables are independent.
300-
-- Each identifier is added only once in 'new', 'open' or 'duplicate', and
301-
-- is deleted only once in 'close' or 'closeSession'.
300+
-- Each identifier is added only once in 'new', 'openSnapshot' or
301+
-- 'duplicate', and is deleted only once in 'close' or 'closeSession'.
302302
--
303303
-- * A new table may only insert its own identifier when it has acquired the
304304
-- 'sessionState' read-lock. This is to prevent races with 'closeSession'.
@@ -1056,23 +1056,23 @@ readCursorWhile resolve keyIsWanted n Cursor {..} fromEntry = do
10561056
Snapshots
10571057
-------------------------------------------------------------------------------}
10581058

1059-
{-# SPECIALISE snapshot ::
1059+
{-# SPECIALISE createSnapshot ::
10601060
ResolveSerialisedValue
10611061
-> SnapshotName
10621062
-> SnapshotLabel
10631063
-> SnapshotTableType
10641064
-> Table IO h
10651065
-> IO Int #-}
1066-
-- | See 'Database.LSMTree.Normal.snapshot''.
1067-
snapshot ::
1066+
-- | See 'Database.LSMTree.Normal.createSnapshot''.
1067+
createSnapshot ::
10681068
(MonadFix m, MonadMask m, MonadMVar m, MonadST m, MonadSTM m)
10691069
=> ResolveSerialisedValue
10701070
-> SnapshotName
10711071
-> SnapshotLabel
10721072
-> SnapshotTableType
10731073
-> Table m h
10741074
-> m Int
1075-
snapshot resolve snap label tableType t = do
1075+
createSnapshot resolve snap label tableType t = do
10761076
traceWith (tableTracer t) $ TraceSnapshot snap
10771077
let conf = tableConfig t
10781078
withOpenTable t $ \thEnv -> do
@@ -1120,16 +1120,16 @@ snapshot resolve snap label tableType t = do
11201120

11211121
pure $! numSnapRuns snappedLevels
11221122

1123-
{-# SPECIALISE open ::
1123+
{-# SPECIALISE openSnapshot ::
11241124
Session IO h
11251125
-> SnapshotLabel
11261126
-> SnapshotTableType
11271127
-> TableConfigOverride
11281128
-> SnapshotName
11291129
-> ResolveSerialisedValue
11301130
-> IO (Table IO h) #-}
1131-
-- | See 'Database.LSMTree.Normal.open'.
1132-
open ::
1131+
-- | See 'Database.LSMTree.Normal.openSnapshot'.
1132+
openSnapshot ::
11331133
(MonadFix m, MonadMask m, MonadMVar m, MonadST m, MonadSTM m)
11341134
=> Session m h
11351135
-> SnapshotLabel -- ^ Expected label
@@ -1138,7 +1138,7 @@ open ::
11381138
-> SnapshotName
11391139
-> ResolveSerialisedValue
11401140
-> m (Table m h)
1141-
open sesh label tableType override snap resolve = do
1141+
openSnapshot sesh label tableType override snap resolve = do
11421142
traceWith (sessionTracer sesh) $ TraceOpenSnapshot snap override
11431143
withOpenSession sesh $ \seshEnv -> do
11441144
withTempRegistry $ \reg -> do

src/Database/LSMTree/Monoidal.hs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ module Database.LSMTree.Monoidal (
8989
, SnapshotName
9090
, Common.mkSnapshotName
9191
, Common.Labellable (..)
92-
, snapshot
93-
, open
92+
, createSnapshot
93+
, openSnapshot
9494
, Common.TableConfigOverride
9595
, Common.configNoOverride
9696
, Common.configOverrideDiskCachePolicy
@@ -521,7 +521,7 @@ mupserts t = updates t . fmap (second Mupsert)
521521
Snapshots
522522
-------------------------------------------------------------------------------}
523523

524-
{-# SPECIALISE snapshot ::
524+
{-# SPECIALISE createSnapshot ::
525525
(SerialiseKey k, SerialiseValue v, ResolveValue v, Common.Labellable (k, v))
526526
=> SnapshotName
527527
-> Table IO k v
@@ -530,9 +530,9 @@ mupserts t = updates t . fmap (second Mupsert)
530530
-- giving the snapshot a name. This is the __only__ mechanism to make a table
531531
-- durable -- ordinary insert\/delete operations are otherwise not preserved.
532532
--
533-
-- Snapshots have names and the table may be opened later using 'open' via that
534-
-- name. Names are strings and the management of the names is up to the user of
535-
-- the library.
533+
-- Snapshots have names and the table may be opened later using 'openSnapshot'
534+
-- via that name. Names are strings and the management of the names is up to the
535+
-- user of the library.
536536
--
537537
-- The names correspond to disk files, which imposes some constraints on length
538538
-- and what characters can be used.
@@ -548,7 +548,7 @@ mupserts t = updates t . fmap (second Mupsert)
548548
-- * It is safe to concurrently make snapshots from any table, provided that
549549
-- the snapshot names are distinct (otherwise this would be a race).
550550
--
551-
snapshot :: forall m k v.
551+
createSnapshot :: forall m k v.
552552
( IOLike m
553553
, SerialiseKey k
554554
, SerialiseValue v
@@ -558,12 +558,12 @@ snapshot :: forall m k v.
558558
=> SnapshotName
559559
-> Table m k v
560560
-> m ()
561-
snapshot snap (Internal.MonoidalTable t) =
562-
void $ Internal.snapshot (resolve @v Proxy) snap label Internal.SnapMonoidalTable t
561+
createSnapshot snap (Internal.MonoidalTable t) =
562+
void $ Internal.createSnapshot (resolve @v Proxy) snap label Internal.SnapMonoidalTable t
563563
where
564564
label = Internal.SnapshotLabel $ Common.makeSnapshotLabel (Proxy @(k, v))
565565

566-
{-# SPECIALISE open ::
566+
{-# SPECIALISE openSnapshot ::
567567
(SerialiseKey k, SerialiseValue v, ResolveValue v, Common.Labellable (k, v))
568568
=> Session IO
569569
-> Common.TableConfigOverride
@@ -584,14 +584,10 @@ snapshot snap (Internal.MonoidalTable t) =
584584
-- @
585585
-- example session = do
586586
-- t <- 'new' \@IO \@Int \@Int \@Int session _
587-
-- 'snapshot' "intTable" t
588-
-- 'open' \@IO \@Bool \@Bool \@Bool session "intTable"
587+
-- 'createSnapshot' "intTable" t
588+
-- 'openSnapshot' \@IO \@Bool \@Bool \@Bool session "intTable"
589589
-- @
590-
--
591-
-- TOREMOVE: before snapshots are implemented, the snapshot name should be ignored.
592-
-- Instead, this function should open a table from files that exist in
593-
-- the session's directory.
594-
open :: forall m k v.
590+
openSnapshot :: forall m k v.
595591
( IOLike m
596592
, SerialiseKey k
597593
, SerialiseValue v
@@ -602,9 +598,9 @@ open :: forall m k v.
602598
-> Common.TableConfigOverride -- ^ Optional config override
603599
-> SnapshotName
604600
-> m (Table m k v)
605-
open (Internal.Session' sesh) override snap =
601+
openSnapshot (Internal.Session' sesh) override snap =
606602
Internal.MonoidalTable <$>
607-
Internal.open
603+
Internal.openSnapshot
608604
sesh
609605
label
610606
Internal.SnapMonoidalTable

src/Database/LSMTree/Normal.hs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ module Database.LSMTree.Normal (
9090
, SnapshotName
9191
, Common.mkSnapshotName
9292
, Common.Labellable (..)
93-
, snapshot
94-
, open
93+
, createSnapshot
94+
, openSnapshot
9595
, Common.TableConfigOverride
9696
, Common.configNoOverride
9797
, Common.configOverrideDiskCachePolicy
@@ -150,7 +150,7 @@ import qualified Database.LSMTree.Internal.Vector as V
150150
--
151151
-- * 'openSession'
152152
-- * 'new'
153-
-- * 'open'
153+
-- * 'openSnapshot'
154154
-- * 'duplicate'
155155
-- * 'newCursor'
156156
--
@@ -171,7 +171,7 @@ import qualified Database.LSMTree.Internal.Vector as V
171171
--
172172
-- * 'openSession', paired with 'closeSession'
173173
-- * 'new', paired with 'close'
174-
-- * 'open', paired with 'close'
174+
-- * 'openSnapshot', paired with 'close'
175175
-- * 'duplicate', paired with 'close'
176176
-- * 'newCursor', paired with 'closeCursor'
177177
--
@@ -201,7 +201,7 @@ import qualified Database.LSMTree.Internal.Vector as V
201201
-- * 'lookups'
202202
-- * 'rangeLookup'
203203
-- * 'retrieveBlobs'
204-
-- * 'snapshot'
204+
-- * 'createSnapshot'
205205
-- * 'duplicate'
206206
--
207207
-- The write operations are:
@@ -639,7 +639,7 @@ retrieveBlobs (Internal.Session' (sesh :: Internal.Session m h)) refs =
639639
Snapshots
640640
-------------------------------------------------------------------------------}
641641

642-
{-# SPECIALISE snapshot ::
642+
{-# SPECIALISE createSnapshot ::
643643
( SerialiseKey k
644644
, SerialiseValue v
645645
, SerialiseValue blob
@@ -652,9 +652,9 @@ retrieveBlobs (Internal.Session' (sesh :: Internal.Session m h)) refs =
652652
-- giving the snapshot a name. This is the __only__ mechanism to make a table
653653
-- durable -- ordinary insert\/delete operations are otherwise not preserved.
654654
--
655-
-- Snapshots have names and the table may be opened later using 'open' via that
656-
-- name. Names are strings and the management of the names is up to the user of
657-
-- the library.
655+
-- Snapshots have names and the table may be opened later using 'openSnapshot'
656+
-- via that name. Names are strings and the management of the names is up to
657+
-- the user of the library.
658658
--
659659
-- The names correspond to disk files, which imposes some constraints on length
660660
-- and what characters can be used.
@@ -677,7 +677,7 @@ retrieveBlobs (Internal.Session' (sesh :: Internal.Session m h)) refs =
677677
-- as part of the snapshot because run files aren't (yet) deleted when runs are
678678
-- closed. The write buffer is also persisted to disk as part of the snapshot,
679679
-- but the original table remains unchanged.
680-
snapshot :: forall m k v blob.
680+
createSnapshot :: forall m k v blob.
681681
( IOLike m
682682
, SerialiseKey k
683683
, SerialiseValue v
@@ -687,12 +687,12 @@ snapshot :: forall m k v blob.
687687
=> SnapshotName
688688
-> Table m k v blob
689689
-> m ()
690-
snapshot snap (Internal.NormalTable t) =
691-
void $ Internal.snapshot const snap label Internal.SnapNormalTable t
690+
createSnapshot snap (Internal.NormalTable t) =
691+
void $ Internal.createSnapshot const snap label Internal.SnapNormalTable t
692692
where
693693
label = Internal.SnapshotLabel $ Common.makeSnapshotLabel (Proxy @(k, v, blob))
694694

695-
{-# SPECIALISE open ::
695+
{-# SPECIALISE openSnapshot ::
696696
( SerialiseKey k
697697
, SerialiseValue v
698698
, SerialiseValue blob
@@ -717,13 +717,13 @@ snapshot snap (Internal.NormalTable t) =
717717
-- @
718718
-- example session = do
719719
-- t <- 'new' \@IO \@Int \@Int \@Int session _
720-
-- 'snapshot' "intTable" t
721-
-- 'open' \@IO \@Bool \@Bool \@Bool session "intTable"
720+
-- 'createSnapshot' "intTable" t
721+
-- 'openSnapshot' \@IO \@Bool \@Bool \@Bool session "intTable"
722722
-- @
723723
--
724724
-- TODO: this function currently has a temporary implementation until we have
725-
-- proper snapshots. See 'snapshot'.
726-
open :: forall m k v blob.
725+
-- proper snapshots. See 'createSnapshot'.
726+
openSnapshot :: forall m k v blob.
727727
( IOLike m
728728
, SerialiseKey k
729729
, SerialiseValue v
@@ -734,8 +734,15 @@ open :: forall m k v blob.
734734
-> Common.TableConfigOverride -- ^ Optional config override
735735
-> SnapshotName
736736
-> m (Table m k v blob)
737-
open (Internal.Session' sesh) override snap =
738-
Internal.NormalTable <$!> Internal.open sesh label Internal.SnapNormalTable override snap const
737+
openSnapshot (Internal.Session' sesh) override snap =
738+
Internal.NormalTable <$!>
739+
Internal.openSnapshot
740+
sesh
741+
label
742+
Internal.SnapNormalTable
743+
override
744+
snap
745+
const
739746
where
740747
label = Internal.SnapshotLabel $ Common.makeSnapshotLabel (Proxy @(k, v, blob))
741748

test/Database/LSMTree/Class/Monoidal.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Database.LSMTree.Class.Monoidal (
1010
, withSession
1111
, IsTable (..)
1212
, withTableNew
13-
, withTableOpen
13+
, withTableFromSnapshot
1414
, withTableDuplicate
1515
, withTableUnion
1616
, withCursor
@@ -152,7 +152,7 @@ class (IsSession (Session h)) => IsTable h where
152152
-> V.Vector (k, v)
153153
-> m ()
154154

155-
snapshot ::
155+
createSnapshot ::
156156
( IOLike m
157157
, Labellable (k, v)
158158
, ResolveValue v
@@ -164,7 +164,7 @@ class (IsSession (Session h)) => IsTable h where
164164
-> h m k v
165165
-> m ()
166166

167-
open ::
167+
openSnapshot ::
168168
( IOLike m
169169
, Labellable (k, v)
170170
, ResolveValue v
@@ -204,7 +204,7 @@ withTableNew :: forall h m k v a.
204204
-> m a
205205
withTableNew sesh conf = bracket (new sesh conf) close
206206

207-
withTableOpen :: forall h m k v a.
207+
withTableFromSnapshot :: forall h m k v a.
208208
( IOLike m
209209
, IsTable h
210210
, ResolveValue v
@@ -217,7 +217,7 @@ withTableOpen :: forall h m k v a.
217217
-> SnapshotName
218218
-> (h m k v -> m a)
219219
-> m a
220-
withTableOpen sesh snap = bracket (open sesh snap) close
220+
withTableFromSnapshot sesh snap = bracket (openSnapshot sesh snap) close
221221

222222
withTableDuplicate :: forall h m k v a.
223223
( IOLike m
@@ -277,8 +277,8 @@ instance IsTable R.Table where
277277
closeCursor _ = R.closeCursor
278278
readCursor _ = R.readCursor
279279

280-
snapshot = R.snapshot
281-
open sesh snap = R.open sesh R.configNoOverride snap
280+
createSnapshot = R.createSnapshot
281+
openSnapshot sesh snap = R.openSnapshot sesh R.configNoOverride snap
282282

283283
duplicate = R.duplicate
284284
union = R.union

0 commit comments

Comments
 (0)