Skip to content

Commit 6c219ca

Browse files
authored
Merge pull request #614 from IntersectMBO/mheinzel/qls-enable-unions
Enable unions in lockstep tests
2 parents a69b8a9 + 0acc119 commit 6c219ca

File tree

5 files changed

+212
-161
lines changed

5 files changed

+212
-161
lines changed

src/Database/LSMTree/Internal.hs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,8 +1631,10 @@ remainingUnionDebt :: (MonadSTM m, MonadThrow m) => Table m h -> m UnionDebt
16311631
remainingUnionDebt t = do
16321632
traceWith (tableTracer t) TraceRemainingUnionDebt
16331633
withOpenTable t $ \tEnv -> do
1634-
RW.withReadAccess (tableContent tEnv) $ \_tableContent -> do
1635-
error "remainingUnionDebt: not yet implemented"
1634+
RW.withReadAccess (tableContent tEnv) $ \tableContent ->
1635+
case tableUnionLevel tableContent of
1636+
NoUnion -> pure (UnionDebt 0)
1637+
Union{} -> error "remainingUnionDebt: not yet implemented"
16361638

16371639
-- | See 'Database.LSMTree.Normal.UnionCredits'.
16381640
newtype UnionCredits = UnionCredits Int
@@ -1645,5 +1647,12 @@ supplyUnionCredits t credits = do
16451647
traceWith (tableTracer t) $ TraceSupplyUnionCredits credits
16461648
withOpenTable t $ \tEnv -> do
16471649
-- TODO: should this be acquiring read or write access?
1648-
RW.withWriteAccess (tableContent tEnv) $ \_tableContent -> do
1649-
error "supplyUnionCredits: not yet implemented"
1650+
RW.withWriteAccess (tableContent tEnv) $ \tableContent ->
1651+
case tableUnionLevel tableContent of
1652+
NoUnion -> pure (tableContent, credits) -- all leftovers
1653+
Union{}
1654+
| credits <= UnionCredits 0 -> pure (tableContent, UnionCredits 0)
1655+
--TODO: remove this 0 special case once the general case covers it.
1656+
-- We do not need to optimise the 0 case. It is just here to
1657+
-- simplify test coverage.
1658+
| otherwise -> error "supplyUnionCredits: not yet implemented"

src/Database/LSMTree/Internal/MergeSchedule.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,7 @@ iforLevelM_ lvls k = V.iforM_ lvls $ \i lvl -> k (LevelNo (i + 1)) lvl
352352
-- of multiple runs, but a nested tree of merges.
353353
--
354354
-- TODO: So far, this is
355-
-- * never created
356-
-- * not stored in snapshots
357-
-- * not loaded from snapshots
358-
-- * ignored in lookups
355+
-- * not considered when creating cursors (also used for range lookups)
359356
-- * never made merge progress on (by supplying credits to it)
360357
-- * never merged into the regular levels
361358
data UnionLevel m h =

test/Database/LSMTree/Model/Session.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,9 @@ supplyUnionCredits ::
844844
-> UnionCredits
845845
-> m UnionCredits
846846
supplyUnionCredits t@Table{..} c@(UnionCredits credits)
847-
| credits <= 0 = pure c
847+
| credits <= 0 = do
848+
_ <- guardTableIsOpen t
849+
pure (UnionCredits 0) -- always 0, not negative
848850
| otherwise = do
849851
(updc, table) <- guardTableIsOpen t
850852
when (isUnionDescendant == IsUnionDescendant) $

0 commit comments

Comments
 (0)