Skip to content

Commit 6cad45a

Browse files
committed
ScheduledMerges: rename Op to Entry
This follows the naming from the real implementation, and it removes ambiguity with `Op`s from `quickcheck-lockstep`.
1 parent 5479581 commit 6cad45a

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src-prototypes/ScheduledMerges.hs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module ScheduledMerges (
3333
newWith,
3434
LookupResult (..),
3535
lookup, lookups,
36-
Op,
36+
Entry,
3737
Update (..),
3838
update, updates,
3939
insert, inserts,
@@ -192,7 +192,7 @@ class Show t => IsMergeType t where
192192
-- | Different types of merges created as part of a regular (non-union) level.
193193
--
194194
-- A last level merge behaves differently from a mid-level merge: last level
195-
-- merges can actually remove delete operations, whereas mid-level merges must
195+
-- merges can actually remove delete entries, whereas mid-level merges must
196196
-- preserve them. This is orthogonal to the 'MergePolicyForLevel'.
197197
data LevelMergeType = MergeMidLevel | MergeLastLevel
198198
deriving stock (Eq, Show)
@@ -275,8 +275,8 @@ pattern PendingMerge :: TreeMergeType
275275
-> PendingMerge s
276276
pattern PendingMerge mt prs ts <- (pendingContent -> (mt, prs, ts))
277277

278-
type Run = Map Key Op
279-
type Buffer = Map Key Op
278+
type Run = Map Key Entry
279+
type Buffer = Map Key Entry
280280

281281
bufferToRun :: Buffer -> Run
282282
bufferToRun = id
@@ -287,7 +287,7 @@ runSize = Map.size
287287
bufferSize :: Buffer -> Int
288288
bufferSize = Map.size
289289

290-
type Op = Update Value Blob
290+
type Entry = Update Value Blob
291291

292292
newtype Key = K Int
293293
deriving stock (Eq, Ord, Show)
@@ -897,7 +897,7 @@ mergek t =
897897
-- | Combines two entries that have been performed after another. Therefore, the
898898
-- newer one overwrites the old one (or modifies it for 'Mupsert'). Only take a
899899
-- blob from the left entry.
900-
combine :: Op -> Op -> Op
900+
combine :: Entry -> Entry -> Entry
901901
combine new_ old = case new_ of
902902
Insert{} -> new_
903903
Delete{} -> new_
@@ -912,7 +912,7 @@ combine new_ old = case new_ of
912912
-- from the left entry.
913913
--
914914
-- See 'MergeUnion'.
915-
combineUnion :: Op -> Op -> Op
915+
combineUnion :: Entry -> Entry -> Entry
916916
combineUnion Delete (Mupsert v) = Insert v Nothing
917917
combineUnion Delete old = old
918918
combineUnion (Mupsert u) Delete = Insert u Nothing
@@ -1005,17 +1005,17 @@ data Update v b =
10051005
| Delete
10061006
deriving stock (Eq, Show)
10071007

1008-
updates :: Tracer (ST s) Event -> LSM s -> [(Key, Op)] -> ST s ()
1008+
updates :: Tracer (ST s) Event -> LSM s -> [(Key, Entry)] -> ST s ()
10091009
updates tr lsm = mapM_ (uncurry (update tr lsm))
10101010

1011-
update :: Tracer (ST s) Event -> LSM s -> Key -> Op -> ST s ()
1012-
update tr (LSMHandle scr conf lsmr) k op = do
1011+
update :: Tracer (ST s) Event -> LSM s -> Key -> Entry -> ST s ()
1012+
update tr (LSMHandle scr conf lsmr) k entry = do
10131013
sc <- readSTRef scr
10141014
content@(LSMContent wb ls unionLevel) <- readSTRef lsmr
10151015
modifySTRef' scr (+1)
10161016
supplyCreditsLevels (NominalCredit 1) ls
10171017
invariant conf content
1018-
let wb' = Map.insertWith combine k op wb
1018+
let wb' = Map.insertWith combine k entry wb
10191019
if bufferSize wb' >= maxWriteBufferSize conf
10201020
then do
10211021
ls' <- increment tr sc conf (bufferToRun wb') ls unionLevel
@@ -1174,11 +1174,11 @@ checkedUnionDebt tree debtRef = do
11741174
-- Lookups
11751175
--
11761176

1177-
type LookupAcc = Maybe Op
1177+
type LookupAcc = Maybe Entry
11781178

1179-
updateAcc :: (Op -> Op -> Op) -> LookupAcc -> Op -> LookupAcc
1179+
updateAcc :: (Entry -> Entry -> Entry) -> LookupAcc -> Entry -> LookupAcc
11801180
updateAcc _ Nothing old = Just old
1181-
updateAcc f (Just new_) old = Just (f new_ old) -- acc has more recent Op
1181+
updateAcc f (Just new_) old = Just (f new_ old) -- acc has more recent Entry
11821182

11831183
mergeAcc :: TreeMergeType -> [LookupAcc] -> LookupAcc
11841184
mergeAcc mt = foldl (updateAcc com) Nothing . catMaybes
@@ -1219,8 +1219,8 @@ doLookup wb runs ul k = do
12191219
-- In a real implementation, this would take all keys at once and be in IO.
12201220
lookupBatch :: LookupAcc -> Key -> [Run] -> LookupAcc
12211221
lookupBatch acc k rs =
1222-
let ops = [op | r <- rs, Just op <- [Map.lookup k r]]
1223-
in foldl (updateAcc combine) acc ops
1222+
let entries = [entry | r <- rs, Just entry <- [Map.lookup k r]]
1223+
in foldl (updateAcc combine) acc entries
12241224

12251225
data LookupTree a = LookupBatch a
12261226
| LookupNode TreeMergeType [LookupTree a]
@@ -1277,22 +1277,22 @@ foldLookupTree = \case
12771277
--
12781278

12791279
-- | Nominal credit is the credit supplied to each level as we insert update
1280-
-- operations, one credit per update operation inserted.
1280+
-- entries, one credit per update entry inserted.
12811281
--
12821282
-- Nominal credit must be supplied up to the 'NominalDebt' to ensure the merge
12831283
-- is complete.
12841284
--
12851285
-- Nominal credits are a similar order of magnitude to physical credits (see
12861286
-- 'Credit') but not the same, and we have to scale linearly to convert between
12871287
-- them. Physical credits are the actual number of inputs to the merge, which
1288-
-- may be somewhat more or somewhat less than the number of update operations
1288+
-- may be somewhat more or somewhat less than the number of update entries
12891289
-- we will insert before we need the merge to be complete.
12901290
--
12911291
newtype NominalCredit = NominalCredit Credit
12921292
deriving stock Show
12931293

12941294
-- | The nominal debt for a merging run is the worst case (minimum) number of
1295-
-- update operations we expect to insert before we expect the merge to be
1295+
-- update entries we expect to insert before we expect the merge to be
12961296
-- complete.
12971297
--
12981298
-- We require that an equal amount of nominal credit is supplied before we can

test-prototypes/Test/ScheduledMerges.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ test_merge_again_with_incoming =
177177
--
178178

179179
-- | Supplying enough credits for the remaining debt completes the union merge.
180-
prop_union :: [[(LSM.Key, LSM.Op)]] -> Property
181-
prop_union kopss = length (filter (not . null) kopss) > 1 QC.==>
180+
prop_union :: [[(LSM.Key, LSM.Entry)]] -> Property
181+
prop_union kess = length (filter (not . null) kess) > 1 QC.==>
182182
QC.ioProperty $ runWithTracer $ \tr ->
183183
stToIO $ do
184-
ts <- traverse (mkTable tr) kopss
184+
ts <- traverse (mkTable tr) kess
185185
t <- LSM.unions ts
186186

187187
debt@(UnionDebt x) <- LSM.remainingUnionDebt t
@@ -199,7 +199,7 @@ prop_union kopss = length (filter (not . null) kopss) > 1 QC.==>
199199
MLeaf{} -> True
200200
MNode{} -> False
201201

202-
mkTable :: Tracer (ST s) Event -> [(LSM.Key, LSM.Op)] -> ST s (LSM s)
202+
mkTable :: Tracer (ST s) Event -> [(LSM.Key, LSM.Entry)] -> ST s (LSM s)
203203
mkTable tr ks = do
204204
t <- LSM.new
205205
LSM.updates tr t ks

0 commit comments

Comments
 (0)