Skip to content

Commit

Permalink
Revert "Don't take snapshot on epoch change"
Browse files Browse the repository at this point in the history
This reverts commit 5a0a96f.
  • Loading branch information
erikd committed Jan 18, 2022
1 parent 35ed0f6 commit b3d43a7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cardano-db-sync/src/Cardano/DbSync/Default.hs
Expand Up @@ -10,7 +10,7 @@ module Cardano.DbSync.Default

import Cardano.Prelude

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

import qualified Cardano.Db as DB

Expand Down Expand Up @@ -96,9 +96,21 @@ mkSnapshotMaybe
=> SyncEnv -> LedgerStateSnapshot -> BlockNo -> DB.SyncState
-> ExceptT SyncNodeError (ReaderT SqlBackend m) ()
mkSnapshotMaybe env snapshot blkNo syncState =
when (timeToSnapshot syncState blkNo) .
whenM (isEmptyEpochBulkOps $ envLedger env) .
liftIO $ saveCleanupState (envLedger env) (lssOldState snapshot) Nothing
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

where
timeToSnapshot :: DB.SyncState -> BlockNo -> Bool
timeToSnapshot syncSt bNo =
Expand Down

0 comments on commit b3d43a7

Please sign in to comment.