@@ -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.
12781280newPendingLevelMerge :: [IncomingRun s ]
12791281 -> Maybe (MergingTree s )
12801282 -> ST s (Maybe (MergingTree s ))
12811283newPendingLevelMerge [] t = return t
12821284newPendingLevelMerge [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"
12881291newPendingLevelMerge irs tree = do
12891292 let prs = map incomingToPreExistingRun irs
12901293 st = PendingTreeMerge (PendingLevelMerge prs tree)
0 commit comments