Skip to content

Commit

Permalink
Don't take snapshot on epoch change
Browse files Browse the repository at this point in the history
Cross-epoch snapshot path can trigger flush of bulk queue if a rollback
to previous epoch is triggered right after, causing long delays
until normal operation is resumed.

Closes: #991
  • Loading branch information
sorki authored and erikd committed Jan 11, 2022
1 parent 22f92e4 commit 5a0a96f
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions cardano-db-sync/src/Cardano/DbSync/Default.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Cardano.DbSync.Default

import Cardano.Prelude

import Cardano.BM.Trace (Trace, logDebug, logInfo)
import Cardano.BM.Trace (Trace, logInfo)

import qualified Cardano.Db as DB

Expand Down Expand Up @@ -96,21 +96,9 @@ mkSnapshotMaybe
=> SyncEnv -> LedgerStateSnapshot -> BlockNo -> DB.SyncState
-> ExceptT SyncNodeError (ReaderT SqlBackend m) ()
mkSnapshotMaybe env snapshot blkNo syncState =
case maybeFromStrict (lssNewEpoch snapshot) of
Just newEpoch -> do
liftIO $ logDebug (leTrace $ envLedger env) "Preparing for a snapshot"
let newEpochNo = Generic.neEpoch newEpoch
-- flush all volatile data
finalizeEpochBulkOps (envLedger env)
liftIO $ logDebug (leTrace $ envLedger env) "Taking a ledger a snapshot"
-- finally take a ledger snapshot
-- TODO: Instead of newEpochNo - 1, is there any way to get the epochNo from 'lssOldState'?
liftIO $ saveCleanupState (envLedger env) (lssOldState snapshot) (Just $ newEpochNo - 1)
Nothing ->
when (timeToSnapshot syncState blkNo) .
whenM (isEmptyEpochBulkOps $ envLedger env) .
liftIO $ saveCleanupState (envLedger env) (lssOldState snapshot) Nothing

when (timeToSnapshot syncState blkNo) .
whenM (isEmptyEpochBulkOps $ envLedger env) .
liftIO $ saveCleanupState (envLedger env) (lssOldState snapshot) Nothing
where
timeToSnapshot :: DB.SyncState -> BlockNo -> Bool
timeToSnapshot syncSt bNo =
Expand Down

0 comments on commit 5a0a96f

Please sign in to comment.