44{-# LANGUAGE NoImplicitPrelude #-}
55
66module Cardano.DbSync.Database (
7- DbAction (.. ),
7+ DbEvent (.. ),
88 ThreadChannels ,
9- lengthDbActionQueue ,
9+ lengthDbEventQueue ,
1010 mkDbApply ,
1111 runDbThread ,
1212) where
1313
1414import Cardano.BM.Trace (logDebug , logError , logInfo )
1515import Cardano.DbSync.Api
1616import Cardano.DbSync.Api.Types (ConsistentLevel (.. ), LedgerEnv (.. ), SyncEnv (.. ))
17- import Cardano.DbSync.DbAction
17+ import Cardano.DbSync.DbEvent
1818import Cardano.DbSync.Default
1919import Cardano.DbSync.Error
2020import Cardano.DbSync.Ledger.State
@@ -53,7 +53,7 @@ runDbThread syncEnv metricsSetters queue = do
5353 -- Main loop to process the queue
5454 processQueue :: IO ()
5555 processQueue = do
56- actions <- blockingFlushDbActionQueue queue
56+ actions <- blockingFlushDbEventQueue queue
5757
5858 -- Log the number of blocks being processed if there are multiple
5959 when (length actions > 1 ) $ do
@@ -65,7 +65,7 @@ runDbThread syncEnv metricsSetters queue = do
6565 Nothing -> processActions actions
6666
6767 -- Process a list of actions
68- processActions :: [DbAction ] -> IO ()
68+ processActions :: [DbEvent ] -> IO ()
6969 processActions actions = do
7070 result <- runExceptT $ runActions syncEnv actions -- runActions is where we start inserting information we recieve from the node.
7171
@@ -108,7 +108,7 @@ runDbThread syncEnv metricsSetters queue = do
108108-- where
109109-- trce = getTrace syncEnv
110110-- loop = do
111- -- xs <- blockingFlushDbActionQueue queue
111+ -- xs <- blockingFlushDbEventQueue queue
112112
113113-- when (length xs > 1) $ do
114114-- logDebug trce $ "runDbThread: " <> textShow (length xs) <> " blocks"
@@ -136,19 +136,19 @@ runDbThread syncEnv metricsSetters queue = do
136136-- atomically $ putTMVar resultVar (latestPoints, currentTip)
137137-- loop
138138
139- -- | Run the list of 'DbAction 's. Block are applied in a single set (as a transaction)
139+ -- | Run the list of 'DbEvent 's. Block are applied in a single set (as a transaction)
140140-- and other operations are applied one-by-one.
141141runActions ::
142142 SyncEnv ->
143- [DbAction ] ->
143+ [DbEvent ] ->
144144 ExceptT SyncNodeError IO NextState
145145runActions syncEnv actions = do
146- dbAction Continue actions
146+ dbEvent Continue actions
147147 where
148- dbAction :: NextState -> [DbAction ] -> ExceptT SyncNodeError IO NextState
149- dbAction next [] = pure next
150- dbAction Done _ = pure Done
151- dbAction Continue xs =
148+ dbEvent :: NextState -> [DbEvent ] -> ExceptT SyncNodeError IO NextState
149+ dbEvent next [] = pure next
150+ dbEvent Done _ = pure Done
151+ dbEvent Continue xs =
152152 case spanDbApply xs of
153153 ([] , DbFinish : _) -> do
154154 pure Done
@@ -171,12 +171,12 @@ runActions syncEnv actions = do
171171 liftIO $ setConsistentLevel syncEnv DBAheadOfLedger
172172 blockNo <- lift $ getDbTipBlockNo syncEnv
173173 lift $ atomically $ putTMVar resultVar (points, blockNo)
174- dbAction Continue ys
174+ dbEvent Continue ys
175175 (ys, zs) -> do
176176 newExceptT $ insertListBlocks syncEnv ys
177177 if null zs
178178 then pure Continue
179- else dbAction Continue zs
179+ else dbEvent Continue zs
180180
181181rollbackLedger :: SyncEnv -> CardanoPoint -> IO (Maybe [CardanoPoint ])
182182rollbackLedger syncEnv point =
@@ -238,14 +238,14 @@ validateConsistentLevel syncEnv stPoint = do
238238 , show cLevel
239239 ]
240240
241- -- | Split the DbAction list into a prefix containing blocks to apply and a postfix.
242- spanDbApply :: [DbAction ] -> ([CardanoBlock ], [DbAction ])
241+ -- | Split the DbEvent list into a prefix containing blocks to apply and a postfix.
242+ spanDbApply :: [DbEvent ] -> ([CardanoBlock ], [DbEvent ])
243243spanDbApply lst =
244244 case lst of
245245 (DbApplyBlock bt : xs) -> let (ys, zs) = spanDbApply xs in (bt : ys, zs)
246246 xs -> ([] , xs)
247247
248- hasRestart :: [DbAction ] -> Maybe (StrictTMVar IO ([(CardanoPoint , Bool )], WithOrigin BlockNo ))
248+ hasRestart :: [DbEvent ] -> Maybe (StrictTMVar IO ([(CardanoPoint , Bool )], WithOrigin BlockNo ))
249249hasRestart = go
250250 where
251251 go [] = Nothing
0 commit comments