Skip to content

Commit afb675d

Browse files
committed
Semigroup and semantic tests for union and regular Entrys
We also update `combineUnion` to convert `Mupdate`s into `Insert`s unconditionally. This was already specified by the haddocks on `combineUnion`, but we were not doing this in cases where the left or right entry was a `Delete`.
1 parent 002f2ab commit afb675d

File tree

3 files changed

+344
-66
lines changed

3 files changed

+344
-66
lines changed

prototypes/ScheduledMerges.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,9 @@ combine new_ old = case new_ of
470470
--
471471
-- See 'MergeUnion'.
472472
combineUnion :: Op -> Op -> Op
473+
combineUnion Delete (Mupsert v) = Insert v Nothing
473474
combineUnion Delete old = old
475+
combineUnion (Mupsert u) Delete = Insert u Nothing
474476
combineUnion new_ Delete = new_
475477
combineUnion (Mupsert v') (Mupsert v ) = Insert (resolveValue v' v) Nothing
476478
combineUnion (Mupsert v') (Insert v _) = Insert (resolveValue v' v) Nothing

src/Database/LSMTree/Internal/Entry.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ unNumEntries (NumEntries x) = x
9292
Value resolution/merging
9393
-------------------------------------------------------------------------------}
9494

95-
-- | As long as values are a semigroup, an Entry is too
96-
instance Semigroup v => Semigroup (Entry v b) where
97-
e1 <> e2 = combine (<>) e1 e2
98-
9995
-- | Given a value-merge function, combine entries. Only take a blob from the
10096
-- left entry.
97+
--
98+
-- Note: 'Entry' is a semigroup with 'combine' if the @(v -> v -> v)@ argument
99+
-- is associative.
101100
combine :: (v -> v -> v) -> Entry v b -> Entry v b -> Entry v b
102101
combine _ e@Delete _ = e
103102
combine _ e@Insert {} _ = e
@@ -111,10 +110,15 @@ combine f (Mupdate u) (Mupdate v) = Mupdate (f u v)
111110
-- has a value, the result should have a value (represented by 'Insert'). If
112111
-- both have a value, these values get combined monoidally. Only take a blob
113112
-- from the left entry.
113+
--
114+
-- Note: 'Entry' is a semigroup with 'combineUnion' if the @(v -> v -> v)@
115+
-- argument is associative.
114116
combineUnion :: (v -> v -> v) -> Entry v b -> Entry v b -> Entry v b
115117
combineUnion f = go
116118
where
119+
go Delete (Mupdate v) = Insert v
117120
go Delete e = e
121+
go (Mupdate u) Delete = Insert u
118122
go e Delete = e
119123
go (Insert u) (Insert v) = Insert (f u v)
120124
go (Insert u) (InsertWithBlob v _) = Insert (f u v)

0 commit comments

Comments
 (0)