Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1847 - add logging to Rollbacks #1877

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading