Skip to content

Commit c8df1f6

Browse files
wenkokkejorisdral
authored andcommitted
fix(upsert): rename mupsert to upsert in full API
1 parent 95d2eef commit c8df1f6

File tree

15 files changed

+88
-88
lines changed

15 files changed

+88
-88
lines changed

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ It has support for:
2424
- Range lookups, which efficiently retrieve the values for all keys in a
2525
given range.
2626

27-
- Monoidal upserts (or "mupserts") which combine the stored and new
28-
values.
27+
- Monoidal upserts which combine the stored and new values.
2928

3029
- BLOB storage which assocates a large auxiliary BLOB with a key.
3130

@@ -43,9 +42,8 @@ This package exports two modules:
4342
This module exports a simplified API which picks sensible defaults for
4443
a number of configuration parameters.
4544

46-
It does not support mupserts or BLOBs, due to their unintuitive
47-
interaction, see [Mupserts and
48-
BLOBs](#mupsertsandblobs "#mupsertsandblobs").
45+
It does not support upserts or BLOBs, due to their unintuitive
46+
interaction, see [Upsert and BLOB](#upsertandblob "#upsertandblob").
4947

5048
If you are looking at this package for the first time, it is strongly
5149
recommended that you start by reading this module.
@@ -54,13 +52,12 @@ This package exports two modules:
5452

5553
This module exports the full API.
5654

57-
### Mupserts and BLOBs <span id="mupsertsandblobs" class="anchor"></span>
55+
### Upsert and BLOB <span id="upsertandblob" class="anchor"></span>
5856

59-
The interaction between mupserts and BLOBs is unintuitive. A mupsert
60-
updates the value associated with the key by combining the old and new
61-
value with a user-specified function. However, this does not apply to
62-
any BLOB value associated with the key, which is simply overwritten by
63-
the new BLOB value.
57+
The interaction between upserts and BLOBs is unintuitive. A upsert
58+
updates the value associated with the key by combining the new and old
59+
values with a user-specified function. However, any BLOB associated with
60+
the key is simply deleted.
6461

6562
### Portability <span id="portability" class="anchor"></span>
6663

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,8 @@ updateToLookupResult :: LSM.Update v b -> LSM.LookupResult v ()
868868
updateToLookupResult (LSM.Insert v Nothing) = LSM.Found v
869869
updateToLookupResult (LSM.Insert v (Just _)) = LSM.FoundWithBlob v ()
870870
updateToLookupResult LSM.Delete = LSM.NotFound
871-
updateToLookupResult (LSM.Mupsert _) = error $
872-
"Unexpected mupsert encountered"
871+
updateToLookupResult (LSM.Upsert _) = error $
872+
"Unexpected upsert encountered"
873873

874874
-- | Return the adjacent batches where there is overlap between one batch's
875875
-- inserts and the next batch's lookups. Testing the pipelined version needs

bench/micro/Bench/Database/LSMTree.hs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ benchmarks = bgroup "Bench.Database.LSMTree" [
3333
benchLargeValueVsSmallValueBlob
3434
, benchCursorScanVsRangeLookupScan
3535
, benchInsertBatches
36-
, benchInsertsVsMupserts
37-
, benchLookupsInsertsVsMupserts
38-
, benchLookupInsertsVsLookupMupserts
36+
, benchInsertsVsUpserts
37+
, benchLookupsInsertsVsUpserts
38+
, benchLookupInsertsVsLookupUpserts
3939
]
4040

4141
{-------------------------------------------------------------------------------
@@ -275,22 +275,22 @@ benchInsertBatches =
275275
cleanupFiles (tmpDir, hfs, hbio)
276276

277277
{-------------------------------------------------------------------------------
278-
Inserts vs. Mupserts
278+
Inserts vs. Upserts
279279
-------------------------------------------------------------------------------}
280280

281-
-- | Compare inserts and mupserts. The logical contents of the resulting
281+
-- | Compare inserts and upserts. The logical contents of the resulting
282282
-- database are the same.
283-
benchInsertsVsMupserts :: Benchmark
284-
benchInsertsVsMupserts =
283+
benchInsertsVsUpserts :: Benchmark
284+
benchInsertsVsUpserts =
285285
env (pure $ snd $ randomEntriesGrouped 800_000 250) $ \ess ->
286286
env (pure $ V.map mkInserts ess) $ \inss ->
287-
bgroup "inserts-vs-mupserts" [
287+
bgroup "inserts-vs-upserts" [
288288
bench "inserts" $
289289
withEmptyTable $ \(_, _, _, _, t) ->
290290
V.mapM_ (inserts t) inss
291-
, bench "mupserts" $
291+
, bench "upserts" $
292292
withEmptyTable $ \(_, _, _, _, t) ->
293-
V.mapM_ (mupserts t) ess
293+
V.mapM_ (upserts t) ess
294294
]
295295
where
296296
withEmptyTable =
@@ -305,18 +305,18 @@ benchInsertsVsMupserts =
305305
)
306306

307307
{-------------------------------------------------------------------------------
308-
Lookups plus Inserts vs. Mupserts
308+
Lookups plus Inserts vs. Upserts
309309
-------------------------------------------------------------------------------}
310310

311-
-- | Compare lookups+inserts to mupserts. The former costs 2 LSMT operations,
312-
-- while Mupserts only cost 1 LSMT operation. The number of operations do not
311+
-- | Compare lookups+inserts to upserts. The former costs 2 LSMT operations,
312+
-- while Upserts only cost 1 LSMT operation. The number of operations do not
313313
-- directly translate to the number of I\/O operations, but one can assume that
314-
-- lookup+insert is roughly twice as costly as mupsert.
315-
benchLookupsInsertsVsMupserts :: Benchmark
316-
benchLookupsInsertsVsMupserts =
314+
-- lookup+insert is roughly twice as costly as upsert.
315+
benchLookupsInsertsVsUpserts :: Benchmark
316+
benchLookupsInsertsVsUpserts =
317317
env (pure $ snd $ randomEntriesGrouped 800_000 250) $ \ess ->
318318
env (pure $ V.map mkInserts ess) $ \inss ->
319-
bgroup "lookups-inserts-vs-mupserts" [
319+
bgroup "lookups-inserts-vs-upserts" [
320320
bench "lookups-inserts" $
321321
withTable inss $ \(_, _, _, _, t) ->
322322
-- Insert the same keys again, but we sum the existing values in
@@ -327,12 +327,12 @@ benchLookupsInsertsVsMupserts =
327327
lrs <- lookups t (V.map fst es)
328328
let ins' = V.zipWith f es lrs
329329
inserts t ins'
330-
, bench "mupserts" $
330+
, bench "upserts" $
331331
withTable inss $ \(_, _, _, _, t) ->
332332
-- Insert the same keys again, but we sum the existing values in
333333
-- the table with the values we are going to insert: submit
334-
-- mupserts with the insert values.
335-
V.forM_ ess $ \es -> mupserts t es
334+
-- upserts with the insert values.
335+
V.forM_ ess $ \es -> upserts t es
336336
]
337337
where
338338
f (k, v) = \case
@@ -353,20 +353,20 @@ benchLookupsInsertsVsMupserts =
353353
)
354354

355355
{-------------------------------------------------------------------------------
356-
Lookup Inserts vs. Lookup Mupserts
356+
Lookup Inserts vs. Lookup Upserts
357357
-------------------------------------------------------------------------------}
358358

359-
-- | Compare lookups after inserts against lookups after mupserts.
360-
benchLookupInsertsVsLookupMupserts :: Benchmark
361-
benchLookupInsertsVsLookupMupserts =
359+
-- | Compare lookups after inserts against lookups after upserts.
360+
benchLookupInsertsVsLookupUpserts :: Benchmark
361+
benchLookupInsertsVsLookupUpserts =
362362
env (pure $ snd $ randomEntriesGrouped 80_000 250) $ \ess ->
363363
env (pure $ V.map mkInserts ess) $ \inss ->
364-
bgroup "lookup-inserts-vs-lookup-mupserts" [
364+
bgroup "lookup-inserts-vs-lookup-upserts" [
365365
bench "lookup-inserts" $
366366
withInsertTable inss $ \(_, _, _, _, t) -> do
367367
V.forM_ ess $ \es -> lookups t (V.map fst es)
368-
, bench "lookup-mupserts" $
369-
withMupsertTable ess $ \(_, _, _, _, t) -> do
368+
, bench "lookup-upserts" $
369+
withUpsertTable ess $ \(_, _, _, _, t) -> do
370370
V.forM_ ess $ \es -> lookups t (V.map fst es)
371371
]
372372
where
@@ -387,14 +387,14 @@ benchLookupInsertsVsLookupMupserts =
387387
cleanupFiles (tmpDir, hfs, hbio)
388388
)
389389

390-
withMupsertTable ess =
390+
withUpsertTable ess =
391391
perRunEnvWithCleanup
392-
-- Mupsert the same key 10 times. The results in a logical database
392+
-- Upsert the same key 10 times. The results in a logical database
393393
-- containing the original keys with the original value *10.
394394
(do (tmpDir, hfs, hbio) <- mkFiles
395395
(s, t) <- mkTable hfs hbio benchConfig
396396
V.forM_ [1..10] $ \(_::Int) ->
397-
V.mapM_ (mupserts t) ess
397+
V.mapM_ (upserts t) ess
398398
pure (tmpDir, hfs, hbio, s, t)
399399
)
400400
(\(tmpDir, hfs, hbio, s, t) -> do

doc/format-page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Logically, a page consists of a value of type
2525
type Page = [(Key, Operation, Maybe BlobRef)]
2626
```
2727
where the operation can be insert (with a value), delete (with no value) or
28-
mupsert (with a value). The entries are sorted by key.
28+
upsert (with a value). The entries are sorted by key.
2929

3030
The file is structured in a page-oriented way to support efficient I/O using
3131
random page-sized reads. By page-oriented we mean that the information is

lsm-tree.cabal

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description:
99

1010
* Basic key–value operations, such as lookup, insert, and delete.
1111
* Range lookups, which efficiently retrieve the values for all keys in a given range.
12-
* Monoidal upserts (or \"mupserts\") which combine the stored and new values.
12+
* Monoidal upserts which combine the stored and new values.
1313
* BLOB storage which assocates a large auxiliary BLOB with a key.
1414
* Durable on-disk persistence and rollback via named snapshots.
1515
* Cheap table duplication where all duplicates can be independently accessed and modified.
@@ -21,19 +21,19 @@ description:
2121

2222
This module exports a simplified API which picks sensible defaults for a number of configuration parameters.
2323

24-
It does not support mupserts or BLOBs, due to their unintuitive interaction, see [Mupserts and BLOBs](#mupsertsandblobs).
24+
It does not support upserts or BLOBs, due to their unintuitive interaction, see [Upsert and BLOB](#upsertandblob).
2525

2626
If you are looking at this package for the first time, it is strongly recommended that you start by reading this module.
2727

2828
* "Database.LSMTree"
2929

3030
This module exports the full API.
3131

32-
== Mupserts and BLOBs #mupsertsandblobs#
32+
== Upsert and BLOB #upsertandblob#
3333

34-
The interaction between mupserts and BLOBs is unintuitive.
35-
A mupsert updates the value associated with the key by combining the old and new value with a user-specified function.
36-
However, this does not apply to any BLOB value associated with the key, which is simply overwritten by the new BLOB value.
34+
The interaction between upserts and BLOBs is unintuitive.
35+
A upsert updates the value associated with the key by combining the new and old values with a user-specified function.
36+
However, any BLOB associated with the key is simply deleted.
3737

3838
== Portability #portability#
3939

src-extras/Database/LSMTree/Extras/Generators.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ instance (Arbitrary v, Arbitrary b) => Arbitrary (Full.Update v b) where
8383
instance Arbitrary2 Full.Update where
8484
liftArbitrary2 genVal genBlob = frequency
8585
[ (10, Full.Insert <$> genVal <*> liftArbitrary genBlob)
86-
, (5, Full.Mupsert <$> genVal)
86+
, (5, Full.Upsert <$> genVal)
8787
, (1, pure Full.Delete)
8888
]
8989

@@ -92,7 +92,7 @@ instance Arbitrary2 Full.Update where
9292
Full.Delete
9393
: map (uncurry Full.Insert)
9494
(liftShrink2 shrinkVal (liftShrink shrinkBlob) (v, blob))
95-
Full.Mupsert v -> Full.Insert v Nothing : map Full.Mupsert (shrinkVal v)
95+
Full.Upsert v -> Full.Insert v Nothing : map Full.Upsert (shrinkVal v)
9696
Full.Delete -> []
9797

9898
instance (Arbitrary k, Ord k) => Arbitrary (Range k) where

src/Database/LSMTree.hs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ module Database.LSMTree (
4747
-- ** Table Updates #table_updates#
4848
insert,
4949
inserts,
50-
mupsert,
51-
mupserts,
50+
upsert,
51+
upserts,
5252
delete,
5353
deletes,
5454
Update (..),
@@ -1061,26 +1061,26 @@ upsert table k v = do
10611061
@
10621062
-}
10631063
{-# SPECIALISE
1064-
mupsert ::
1064+
upsert ::
10651065
(SerialiseKey k, ResolveValue v, SerialiseValue b) =>
10661066
Table IO k v b ->
10671067
k ->
10681068
v ->
10691069
IO ()
10701070
#-}
1071-
mupsert ::
1071+
upsert ::
10721072
forall m k v b.
10731073
(IOLike m) =>
10741074
(SerialiseKey k, ResolveValue v, SerialiseValue b) =>
10751075
Table m k v b ->
10761076
k ->
10771077
v ->
10781078
m ()
1079-
mupsert table k v =
1080-
mupserts table (V.singleton (k, v))
1079+
upsert table k v =
1080+
upserts table (V.singleton (k, v))
10811081

10821082
{- |
1083-
Variant of 'mupsert' for batch insertions.
1083+
Variant of 'upsert' for batch insertions.
10841084
10851085
The worst-case disk I\/O complexity of this operation depends on the merge policy of the table:
10861086
@@ -1091,24 +1091,24 @@ The variable \(b\) refers to the length of the input vector.
10911091
10921092
The following property holds in the absence of races:
10931093
1094-
prop> mupserts table entries = traverse_ (uncurry $ mupsert table) entries
1094+
prop> upserts table entries = traverse_ (uncurry $ upsert table) entries
10951095
-}
10961096
{-# SPECIALISE
1097-
mupserts ::
1097+
upserts ::
10981098
(SerialiseKey k, ResolveValue v, SerialiseValue b) =>
10991099
Table IO k v b ->
11001100
Vector (k, v) ->
11011101
IO ()
11021102
#-}
1103-
mupserts ::
1103+
upserts ::
11041104
forall m k v b.
11051105
(IOLike m) =>
11061106
(SerialiseKey k, ResolveValue v, SerialiseValue b) =>
11071107
Table m k v b ->
11081108
Vector (k, v) ->
11091109
m ()
1110-
mupserts table entries =
1111-
updates table (second Mupsert <$> entries)
1110+
upserts table entries =
1111+
updates table (second Upsert <$> entries)
11121112

11131113
{- |
11141114
Delete a key from the table.
@@ -1195,15 +1195,15 @@ type Update :: Type -> Type -> Type
11951195
data Update v b
11961196
= Insert !v !(Maybe b)
11971197
| Delete
1198-
| Mupsert !v
1198+
| Upsert !v
11991199
deriving stock (Show, Eq)
12001200

12011201
instance (NFData v, NFData b) => NFData (Update v b) where
12021202
rnf :: Update v b -> ()
12031203
rnf = \case
12041204
Insert v mb -> rnf v `seq` rnf mb
12051205
Delete -> ()
1206-
Mupsert v -> rnf v
1206+
Upsert v -> rnf v
12071207

12081208
{- |
12091209
Update generalises 'insert', 'delete', and 'upsert'.
@@ -1281,7 +1281,7 @@ updates (Table table :: Table m k v b) entries =
12811281
Insert v (Just b) -> Entry.InsertWithBlob (Internal.serialiseValue v) (Internal.serialiseBlob b)
12821282
Insert v Nothing -> Entry.Insert (Internal.serialiseValue v)
12831283
Delete -> Entry.Delete
1284-
Mupsert v -> Entry.Mupdate (Internal.serialiseValue v)
1284+
Upsert v -> Entry.Mupdate (Internal.serialiseValue v)
12851285

12861286
--------------------------------------------------------------------------------
12871287
-- Duplication

src/Database/LSMTree/Internal/Types.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# OPTIONS_HADDOCK not-home #-}
2+
13
module Database.LSMTree.Internal.Types (
24
Session (..),
35
Table (..),
@@ -109,7 +111,7 @@ instance NFData (Cursor m k v b) where
109111

110112
{- |
111113
An instance of @'ResolveValue' v@ specifies how to merge values when using
112-
monoidal upserts ('mupsert').
114+
monoidal upsert.
113115
114116
The class has two functions.
115117
The function 'resolve' acts on values, whereas the function 'resolveSerialised' acts on serialised values.
@@ -193,7 +195,7 @@ instance (SerialiseValue v, Semigroup v) => ResolveValue (ResolveViaSemigroup v)
193195
resolve (ResolveViaSemigroup v1) (ResolveViaSemigroup v2) = ResolveViaSemigroup (v1 <> v2)
194196

195197
{- |
196-
Wrapper that provides an instance of 'ResolveValue' such that 'mupsert' behaves as 'insert'.
198+
Wrapper that provides an instance of 'ResolveValue' such that 'Database.LSMTree.upsert' behaves as 'Database.LSMTree.insert'.
197199
198200
The name 'ResolveAsFirst' is in reference to the wrapper 'Data.Semigroup.First' from "Data.Semigroup".
199201

src/Database/LSMTree/Internal/Unsafe.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# OPTIONS_HADDOCK not-home #-}
23

34
-- | This module brings together the internal parts to provide an API in terms
45
-- of untyped serialised keys, values and blobs.
@@ -841,7 +842,7 @@ rangeLookup resolve range t fromEntry = do
841842
-> IO () #-}
842843
-- | See 'Database.LSMTree.updates'.
843844
--
844-
-- Does not enforce that mupsert and blobs should not occur in the same table.
845+
-- Does not enforce that upsert and BLOBs should not occur in the same table.
845846
updates ::
846847
(MonadMask m, MonadMVar m, MonadST m, MonadSTM m)
847848
=> ResolveSerialisedValue

test/Database/LSMTree/Class.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ instance IsTable R.Table where
278278
updates = R.updates
279279
inserts = R.inserts
280280
deletes = R.deletes
281-
mupserts = R.mupserts
281+
mupserts = R.upserts
282282

283283
rangeLookup = R.rangeLookup
284284
retrieveBlobs _ = R.retrieveBlobs

0 commit comments

Comments
 (0)