@@ -1631,8 +1631,10 @@ remainingUnionDebt :: (MonadSTM m, MonadThrow m) => Table m h -> m UnionDebt
16311631remainingUnionDebt 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'.
16381640newtype 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"
0 commit comments