Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Database/LSMTree/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,8 +1630,10 @@ remainingUnionDebt :: (MonadSTM m, MonadThrow m) => Table m h -> m UnionDebt
remainingUnionDebt t = do
traceWith (tableTracer t) TraceRemainingUnionDebt
withOpenTable t $ \tEnv -> do
RW.withReadAccess (tableContent tEnv) $ \_tableContent -> do
error "remainingUnionDebt: not yet implemented"
RW.withReadAccess (tableContent tEnv) $ \tableContent ->
case tableUnionLevel tableContent of
NoUnion -> pure (UnionDebt 0)
Union{} -> error "remainingUnionDebt: not yet implemented"

-- | See 'Database.LSMTree.Normal.UnionCredits'.
newtype UnionCredits = UnionCredits Int
Expand All @@ -1644,5 +1646,12 @@ supplyUnionCredits t credits = do
traceWith (tableTracer t) $ TraceSupplyUnionCredits credits
withOpenTable t $ \tEnv -> do
-- TODO: should this be acquiring read or write access?
RW.withWriteAccess (tableContent tEnv) $ \_tableContent -> do
error "supplyUnionCredits: not yet implemented"
RW.withWriteAccess (tableContent tEnv) $ \tableContent ->
case tableUnionLevel tableContent of
NoUnion -> pure (tableContent, credits) -- all leftovers
Union{}
| credits <= UnionCredits 0 -> pure (tableContent, UnionCredits 0)
--TODO: remove this 0 special case once the general case covers it.
-- We do not need to optimise the 0 case. It is just here to
-- simplify test coverage.
| otherwise -> error "supplyUnionCredits: not yet implemented"
Comment on lines +1654 to +1657
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured we would more reliably notice this TODO and resolve it when we implement the general case, rather than notice a TODO on an out-of-the-way unit test to say to enable it once supplyUnionCredits was implemented. So better to have the unit test running, and temporarily implement the special case in the real impl.

5 changes: 1 addition & 4 deletions src/Database/LSMTree/Internal/MergeSchedule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,7 @@ iforLevelM_ lvls k = V.iforM_ lvls $ \i lvl -> k (LevelNo (i + 1)) lvl
-- of multiple runs, but a nested tree of merges.
--
-- TODO: So far, this is
-- * never created
-- * not stored in snapshots
-- * not loaded from snapshots
-- * ignored in lookups
-- * not considered when creating cursors (also used for range lookups)
-- * never made merge progress on (by supplying credits to it)
-- * never merged into the regular levels
data UnionLevel m h =
Expand Down
4 changes: 3 additions & 1 deletion test/Database/LSMTree/Model/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,9 @@ supplyUnionCredits ::
-> UnionCredits
-> m UnionCredits
supplyUnionCredits t@Table{..} c@(UnionCredits credits)
| credits <= 0 = pure c
| credits <= 0 = do
_ <- guardTableIsOpen t
pure (UnionCredits 0) -- always 0, not negative
| otherwise = do
(updc, table) <- guardTableIsOpen t
when (isUnionDescendant == IsUnionDescendant) $
Expand Down
Loading