Skip to content

Commit c02b999

Browse files
authored
Emit a trace when the DB is not clean (#1198)
Closes #1195
2 parents 4dcefde + af3ec11 commit c02b999

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Non-Breaking
2+
3+
- Emit `ChainDB.TraceEvent(TraceLastShutdownUnclean)` when the `clean` marker is
4+
missing and the node will therefore revalidate all the data.

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ import Ouroboros.Consensus.Node.RethrowPolicy
9999
import Ouroboros.Consensus.Node.Run
100100
import Ouroboros.Consensus.Node.Tracers
101101
import Ouroboros.Consensus.NodeKernel
102-
import Ouroboros.Consensus.Storage.ChainDB (ChainDB, ChainDbArgs)
102+
import Ouroboros.Consensus.Storage.ChainDB (ChainDB, ChainDbArgs,
103+
TraceEvent)
103104
import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB
104105
import qualified Ouroboros.Consensus.Storage.ChainDB.Impl.Args as ChainDB
105106
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy
@@ -657,11 +658,12 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
657658
stdWithCheckedDB ::
658659
forall blk a. (StandardHash blk, Typeable blk)
659660
=> Proxy blk
661+
-> Tracer IO (TraceEvent blk)
660662
-> FilePath
661663
-> NetworkMagic
662664
-> (LastShutDownWasClean -> (ChainDB IO blk -> IO a -> IO a) -> IO a) -- ^ Body action with last shutdown was clean.
663665
-> IO a
664-
stdWithCheckedDB pb databasePath networkMagic body = do
666+
stdWithCheckedDB pb tracer databasePath networkMagic body = do
665667

666668
-- Check the DB marker first, before doing the lock file, since if the
667669
-- marker is not present, it expects an empty DB dir.
@@ -671,7 +673,7 @@ stdWithCheckedDB pb databasePath networkMagic body = do
671673
networkMagic
672674

673675
-- Then create the lock file.
674-
withLockDB mountPoint $ runWithCheckedDB pb hasFS body
676+
withLockDB mountPoint $ runWithCheckedDB pb tracer hasFS body
675677
where
676678
mountPoint = MountPoint databasePath
677679
hasFS = ioHasFS mountPoint
@@ -908,7 +910,7 @@ stdLowLevelRunNodeArgsIO RunNodeArgs{ rnProtocolInfo
908910
snd
909911
(supportedNodeToClientVersions (Proxy @blk))
910912
, llrnWithCheckedDB =
911-
stdWithCheckedDB (Proxy @blk) srnDatabasePath networkMagic
913+
stdWithCheckedDB (Proxy @blk) srnTraceChainDB srnDatabasePath networkMagic
912914
, llrnMaxCaughtUpAge = secondsToNominalDiffTime $ 20 * 60 -- 20 min
913915
, llrnMaxClockSkew =
914916
InFuture.defaultClockSkew

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node/Recovery.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Ouroboros.Consensus.Node.Recovery (
1010
) where
1111

1212
import Control.Monad (unless, when)
13+
import Control.Tracer (Tracer, traceWith)
1314
import Data.Proxy (Proxy)
1415
import Data.Typeable (Typeable)
1516
import Ouroboros.Consensus.Block (StandardHash)
@@ -88,18 +89,19 @@ exceptionRequiresRecovery pb e = case toExitReason pb e of
8889
runWithCheckedDB ::
8990
forall a m h blk. (IOLike m, StandardHash blk, Typeable blk)
9091
=> Proxy blk
92+
-> Tracer m (TraceEvent blk)
9193
-> HasFS m h
9294
-> (LastShutDownWasClean -> (ChainDB m blk -> m a -> m a) -> m a)
9395
-> m a
94-
runWithCheckedDB pb hasFS body = do
96+
runWithCheckedDB pb tracer hasFS body = do
9597
-- When we shut down cleanly, we create a marker file so that the next
9698
-- time we start, we know we don't have to validate the contents of the
9799
-- whole ChainDB. When we shut down with an exception indicating
98100
-- corruption or something going wrong with the file system, we don't
99101
-- create this marker file so that the next time we start, we do a full
100102
-- validation.
101103
wasClean <- hasCleanShutdownMarker hasFS
102-
104+
unless wasClean (traceWith tracer TraceLastShutdownUnclean)
103105
removeMarkerOnUncleanShutdown wasClean
104106
$ body
105107
(LastShutDownWasClean wasClean)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Breaking
2+
3+
- New `ChainDB.TraceEvent(TraceLastShutdownUnclean)` trace message to be emitted
4+
when the `clean` marker is missing and the node will therefore revalidate all
5+
the data.

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ data TraceEvent blk
544544
| TraceLedgerReplayEvent (LgrDB.TraceReplayEvent blk)
545545
| TraceImmutableDBEvent (ImmutableDB.TraceEvent blk)
546546
| TraceVolatileDBEvent (VolatileDB.TraceEvent blk)
547+
| TraceLastShutdownUnclean
547548
deriving (Generic)
548549

549550

ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/ChainDB/StateMachine.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,7 @@ traceEventName = \case
16311631
TraceLedgerReplayEvent ev -> "LedgerReplay." <> constrName ev
16321632
TraceImmutableDBEvent ev -> "ImmutableDB." <> constrName ev
16331633
TraceVolatileDBEvent ev -> "VolatileDB." <> constrName ev
1634+
TraceLastShutdownUnclean -> "LastShutdownUnclean"
16341635

16351636
mkArgs :: IOLike m
16361637
=> TopLevelConfig Blk

0 commit comments

Comments
 (0)