@@ -68,6 +68,10 @@ module Database.LSMTree.Internal (
6868 , duplicate
6969 -- * Table union
7070 , unions
71+ , UnionDebt (.. )
72+ , remainingUnionDebt
73+ , UnionCredits (.. )
74+ , supplyUnionCredits
7175 ) where
7276
7377import Codec.CBOR.Read
@@ -275,6 +279,9 @@ data TableTrace =
275279 | TraceSnapshot SnapshotName
276280 -- Duplicate
277281 | TraceDuplicate
282+ -- Unions
283+ | TraceRemainingUnionDebt
284+ | TraceSupplyUnionCredits UnionCredits
278285 deriving stock Show
279286
280287data CursorTrace =
@@ -1535,3 +1542,34 @@ matchSessions = \(t :| ts) ->
15351542 else pure (Left i)
15361543
15371544 withSessionRoot t k = withOpenSession (tableSession t) $ k . sessionRoot
1545+
1546+ {- ------------------------------------------------------------------------------
1547+ Table union: debt and credit
1548+ -------------------------------------------------------------------------------}
1549+
1550+ -- | See 'Database.LSMTree.Normal.UnionDebt'.
1551+ newtype UnionDebt = UnionDebt Int
1552+ deriving newtype (Show , Eq )
1553+
1554+ {-# SPECIALISE remainingUnionDebt :: Table IO h -> IO UnionDebt #-}
1555+ -- | See 'Database.LSMTree.Normal.remainingUnionDebt'.
1556+ remainingUnionDebt :: (MonadSTM m , MonadThrow m ) => Table m h -> m UnionDebt
1557+ remainingUnionDebt t = do
1558+ traceWith (tableTracer t) TraceRemainingUnionDebt
1559+ withOpenTable t $ \ tEnv -> do
1560+ RW. withReadAccess (tableContent tEnv) $ \ _tableContent -> do
1561+ error " remainingUnionDebt: not yet implemented"
1562+
1563+ -- | See 'Database.LSMTree.Normal.UnionCredits'.
1564+ newtype UnionCredits = UnionCredits Int
1565+ deriving newtype (Show , Eq )
1566+
1567+ {-# SPECIALISE supplyUnionCredits :: Table IO h -> UnionCredits -> IO UnionCredits #-}
1568+ -- | See 'Database.LSMTree.Normal.supplyUnionCredits'.
1569+ supplyUnionCredits :: (MonadSTM m , MonadCatch m ) => Table m h -> UnionCredits -> m UnionCredits
1570+ supplyUnionCredits t credits = do
1571+ traceWith (tableTracer t) $ TraceSupplyUnionCredits credits
1572+ withOpenTable t $ \ tEnv -> do
1573+ -- TODO: should this be acquiring read or write access?
1574+ RW. withWriteAccess (tableContent tEnv) $ \ _tableContent -> do
1575+ error " supplyUnionCredits: not yet implemented"
0 commit comments