Skip to content

Commit

Permalink
add logging to Rollbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Cmdv committed Oct 10, 2024
1 parent e8a00e5 commit f761f3c
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 189 deletions.
6 changes: 3 additions & 3 deletions cardano-db-sync/app/cardano-db-sync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pRunDbSyncNode = do
<*> pHasInOut
<*> pure 500
<*> pure 10000
<*> optional pSlotNo
<*> optional pRollbackSlotNo

pConfigFile :: Parser ConfigFile
pConfigFile =
Expand Down Expand Up @@ -210,8 +210,8 @@ pSocketPath =
<> Opt.metavar "FILEPATH"
)

pSlotNo :: Parser SlotNo
pSlotNo =
pRollbackSlotNo :: Parser SlotNo
pRollbackSlotNo =
SlotNo
<$> Opt.option
Opt.auto
Expand Down
1 change: 1 addition & 0 deletions cardano-db-sync/src/Cardano/DbSync/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Cardano.DbSync.Api (
whenConsumeOrPruneTxOut,
whenPruneTxOut,
getTxOutTableType,
getPruneConsume,
getHasConsumedOrPruneTxOut,
getSkipTxIn,
getPrunes,
Expand Down
20 changes: 5 additions & 15 deletions cardano-db-sync/src/Cardano/DbSync/Rollback.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Cardano.DbSync.Rollback (
unsafeRollback,
) where

import Cardano.BM.Trace (Trace, logInfo)
import Cardano.BM.Trace (Trace, logInfo, logWarning)
import qualified Cardano.Db as DB
import Cardano.DbSync.Api
import Cardano.DbSync.Api.Types (SyncEnv (..))
Expand Down Expand Up @@ -48,17 +48,7 @@ rollbackFromBlockNo syncEnv blkNo = do
, textShow blkNo
]
lift $ do
(mTxId, deletedBlockCount) <- DB.deleteBlocksBlockId trce txOutTable blockId
whenConsumeOrPruneTxOut syncEnv $
DB.querySetNullTxOut trce txOutTable mTxId
DB.deleteEpochRows epochNo
DB.deleteDrepDistr epochNo
DB.deleteRewardRest epochNo
DB.deletePoolStat epochNo
DB.setNullEnacted epochNo
DB.setNullRatified epochNo
DB.setNullDropped epochNo
DB.setNullExpired epochNo
deletedBlockCount <- DB.deleteBlocksBlockId trce txOutTableType blockId epochNo (Just (DB.pcmConsumedTxOut $ getPruneConsume syncEnv))
when (deletedBlockCount > 0) $ do
-- We use custom constraints to improve input speeds when syncing.
-- If they don't already exists we add them here as once a rollback has happened
Expand All @@ -71,7 +61,7 @@ rollbackFromBlockNo syncEnv blkNo = do
where
trce = getTrace syncEnv
cache = envCache syncEnv
txOutTable = getTxOutTableType syncEnv
txOutTableType = getTxOutTableType syncEnv

prepareRollback :: SyncEnv -> CardanoPoint -> Tip CardanoBlock -> IO (Either SyncNodeError Bool)
prepareRollback syncEnv point serverTip =
Expand Down Expand Up @@ -120,5 +110,5 @@ prepareRollback syncEnv point serverTip =
-- For testing and debugging.
unsafeRollback :: Trace IO Text -> DB.TxOutTableType -> DB.PGConfig -> SlotNo -> IO (Either SyncNodeError ())
unsafeRollback trce txOutTableType config slotNo = do
logInfo trce $ "Forced rollback to slot " <> textShow (unSlotNo slotNo)
Right <$> DB.runDbNoLogging (DB.PGPassCached config) (void $ DB.deleteBlocksSlotNo trce txOutTableType slotNo)
logWarning trce $ "Starting a forced rollback to slot: " <> textShow (unSlotNo slotNo)
Right <$> DB.runDbNoLogging (DB.PGPassCached config) (void $ DB.deleteBlocksSlotNo trce txOutTableType slotNo Nothing)
Loading

0 comments on commit f761f3c

Please sign in to comment.