Skip to content

Commit be14346

Browse files
committed
prototype: clarify that there are no merges on level 1
1 parent 7fbfac7 commit be14346

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

prototypes/ScheduledMerges.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,9 @@ invariant (LSMContent _ levels ul) = do
326326
Single r ->
327327
return (CompletedMerge r)
328328
Merging mp _ _ (MergingRun mt _ ref) -> do
329+
assertST $ ln > 1 -- no merges on level 1
329330
assertST $ mp == mergePolicyForLevel ln ls ul
330-
&& mt == mergeTypeForLevel ls ul
331+
assertST $ mt == mergeTypeForLevel ls ul
331332
readSTRef ref
332333

333334
assertST $ length rs <= 3
@@ -1274,17 +1275,19 @@ levellingLevelIsFull ln _incoming resident = levellingRunSizeToLevel resident >
12741275
-- first merge each input table into a single run, as there is no practical
12751276
-- distributive property between level and union merges.
12761277

1277-
-- | Ensures that the merge contains more than one input.
1278+
-- | Ensures that the merge contains more than one input, avoiding creating a
1279+
-- pending merge where possible.
12781280
newPendingLevelMerge :: [IncomingRun s]
12791281
-> Maybe (MergingTree s)
12801282
-> ST s (Maybe (MergingTree s))
12811283
newPendingLevelMerge [] t = return t
12821284
newPendingLevelMerge [Single r] Nothing =
1283-
-- If there is only a 'Merging' run, we could in principle also directly
1284-
-- turn that into 'OngoingTreeMerge`, but the type parameters don't match,
1285-
-- since it could be a midlevel merge. For simplicity, we don't handle that
1286-
-- case here, which means that there can be unary pending level merges.
12871285
Just . MergingTree <$> newSTRef (CompletedTreeMerge r)
1286+
newPendingLevelMerge [Merging{}] Nothing =
1287+
-- This case should never occur. If there is a single entry in the list,
1288+
-- there can only be one level in the input table. At level 1 there are no
1289+
-- merging runs, so it must be a PreExistingRun.
1290+
error "newPendingLevelMerge: singleton Merging run"
12881291
newPendingLevelMerge irs tree = do
12891292
let prs = map incomingToPreExistingRun irs
12901293
st = PendingTreeMerge (PendingLevelMerge prs tree)

src/Database/LSMTree/Internal/MergingTree.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,14 @@ newPendingLevelMerge prs mmt = do
128128
-- are masked then there can be no async exceptions here at all.
129129
mergeTreeState <- case (prs, mmt) of
130130
([PreExistingRun r], Nothing) ->
131-
-- If there is just a single PreExistingMergingRun, we could in theory
132-
-- also directly turn that into a MergingTree, but it's not necessary
133-
-- and a little complicated because of the LevelMergeType/TreeMergeType
134-
-- mismatch.
131+
-- No need to create a pending merge here.
132+
--
133+
-- We could do something similar for PreExistingMergingRun, but it's:
134+
-- * complicated, because of the LevelMergeType/TreeMergeType mismatch.
135+
-- * unneeded, since that case should never occur. If there is only a
136+
-- single entry in the list, there can only be one level in the input
137+
-- table. At level 1 there are no merging runs, so it must be a
138+
-- PreExistingRun.
135139
CompletedTreeMerge <$> dupRef r
136140

137141
_ -> PendingTreeMerge <$>

0 commit comments

Comments
 (0)