@@ -19,6 +19,7 @@ module Ouroboros.Consensus.Storage.LedgerDB.V1.Forker
1919 , implForkerReadTables
2020 ) where
2121
22+ import qualified Control.Monad as Monad
2223import Control.ResourceRegistry
2324import Control.Tracer
2425import qualified Data.Map.Strict as Map
@@ -55,7 +56,7 @@ data ForkerEnv m l blk = ForkerEnv
5556 m
5657 ( Either
5758 (LedgerDBLock m , LedgerBackingStore m l , ResourceRegistry m )
58- (LedgerBackingStoreValueHandle m l )
59+ (ResourceKey m , LedgerBackingStoreValueHandle m l )
5960 )
6061 )
6162 -- ^ Either the ingredients to create a value handle or a value handle, i.e. a
@@ -91,7 +92,7 @@ deriving instance
9192
9293closeForkerEnv :: IOLike m => ForkerEnv m l blk -> m ()
9394closeForkerEnv ForkerEnv {foeBackingStoreValueHandle} = do
94- either (\ (l, _, _) -> atomically . unsafeReleaseReadAccess $ l) bsvhClose
95+ either (\ (l, _, _) -> atomically . unsafeReleaseReadAccess $ l) ( Monad. void . release . fst )
9596 =<< takeMVar foeBackingStoreValueHandle
9697
9798{- ------------------------------------------------------------------------------
@@ -103,18 +104,16 @@ closeForkerEnv ForkerEnv{foeBackingStoreValueHandle} = do
103104getValueHandle :: (GetTip l , IOLike m ) => ForkerEnv m l blk -> m (LedgerBackingStoreValueHandle m l )
104105getValueHandle ForkerEnv {foeBackingStoreValueHandle, foeChangelog} =
105106 modifyMVar foeBackingStoreValueHandle $ \ case
106- r@ (Right bsvh) -> pure (r, bsvh)
107+ r@ (Right (_, bsvh) ) -> pure (r, bsvh)
107108 Left (l, bs, rr) -> do
108- -- bsvhClose is idempotent, so we let the resource call it even if the value
109- -- handle might have been closed somewhere else
110- (_, bsvh) <- allocate rr (\ _ -> bsValueHandle bs) bsvhClose
109+ (k, bsvh) <- allocate rr (\ _ -> bsValueHandle bs) bsvhClose
111110 dblogSlot <- getTipSlot . changelogLastFlushedState <$> readTVarIO foeChangelog
112111 if bsvhAtSlot bsvh == dblogSlot
113112 then do
114113 atomically $ unsafeReleaseReadAccess l
115- pure (Right bsvh, bsvh)
114+ pure (Right (k, bsvh) , bsvh)
116115 else
117- bsvhClose bsvh
116+ release k
118117 >> error
119118 ( " Critical error: Value handles are created at "
120119 <> show (bsvhAtSlot bsvh)
0 commit comments