@@ -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'.
197197data LevelMergeType = MergeMidLevel | MergeLastLevel
198198 deriving stock (Eq , Show )
@@ -275,8 +275,8 @@ pattern PendingMerge :: TreeMergeType
275275 -> PendingMerge s
276276pattern 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
281281bufferToRun :: Buffer -> Run
282282bufferToRun = id
@@ -287,7 +287,7 @@ runSize = Map.size
287287bufferSize :: Buffer -> Int
288288bufferSize = Map. size
289289
290- type Op = Update Value Blob
290+ type Entry = Update Value Blob
291291
292292newtype 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
901901combine 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
916916combineUnion Delete (Mupsert v) = Insert v Nothing
917917combineUnion Delete old = old
918918combineUnion (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 ()
10091009updates 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
11801180updateAcc _ 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
11831183mergeAcc :: TreeMergeType -> [LookupAcc ] -> LookupAcc
11841184mergeAcc 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.
12201220lookupBatch :: LookupAcc -> Key -> [Run ] -> LookupAcc
12211221lookupBatch 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
12251225data 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--
12911291newtype 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
0 commit comments