Skip to content

Commit 55d84c3

Browse files
committed
LedgerDB.V2: add trace events for opening/closing of handles
For tracking whether we are leaking any handles, in a test to be added in a follow-up commit
1 parent 986e0fe commit 55d84c3

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

ouroboros-consensus-cardano/app/snapshot-converter.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ load config@Config{inpath = pathToDiskSnapshot -> Just (fs@(SomeHasFS hasFS), pa
198198
pure (forgetLedgerTables st, projectLedgerTables st)
199199
Mem -> do
200200
checkSnapshotFileStructure Mem path fs
201-
(ls, _) <- withExceptT SnapshotError $ V2.loadSnapshot rr ccfg fs ds
201+
(ls, _) <- withExceptT SnapshotError $ V2.loadSnapshot nullTracer rr ccfg fs ds
202202
let h = V2.currentHandle ls
203203
(V2.state h,) <$> Trans.lift (V2.readAll (V2.tables h))
204204
LMDB -> do
@@ -237,7 +237,7 @@ store config@Config{outpath = pathToDiskSnapshot -> Just (fs@(SomeHasFS hasFS),
237237
withFile hasFS (path <.> "checksum") (WriteMode MustBeNew) $ \h ->
238238
Monad.void $ hPutAll hasFS h . BS.toLazyByteString . BS.word32HexFixed $ getCRC crc
239239
Mem -> do
240-
lseq <- V2.empty state tbs $ V2.newInMemoryLedgerTablesHandle fs
240+
lseq <- V2.empty state tbs $ V2.newInMemoryLedgerTablesHandle nullTracer fs
241241
let h = V2.currentHandle lseq
242242
Monad.void $ V2.takeSnapshot ccfg nullTracer fs suffix h
243243
LMDB -> do
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Breaking
2+
3+
- LedgerDB: added new trace events (enabling new tests).

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V2.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,15 @@ mkInitDb args flavArgs getBlock =
128128

129129
bss = case flavArgs of V2Args bss0 -> bss0
130130

131+
v2Tracer :: Tracer m V2.FlavorImplSpecificTrace
132+
v2Tracer = LedgerDBFlavorImplEvent . FlavorImplSpecificTraceV2 >$< lgrTracer
133+
131134
emptyF ::
132135
ExtLedgerState blk ValuesMK ->
133136
m (LedgerSeq' m blk)
134137
emptyF st =
135138
empty' st $ case bss of
136-
InMemoryHandleArgs -> InMemory.newInMemoryLedgerTablesHandle lgrHasFS
139+
InMemoryHandleArgs -> InMemory.newInMemoryLedgerTablesHandle v2Tracer lgrHasFS
137140
LSMHandleArgs x -> absurd x
138141

139142
loadSnapshot ::
@@ -142,7 +145,7 @@ mkInitDb args flavArgs getBlock =
142145
DiskSnapshot ->
143146
m (Either (SnapshotFailure blk) (LedgerSeq' m blk, RealPoint blk))
144147
loadSnapshot ccfg fs ds = case bss of
145-
InMemoryHandleArgs -> runExceptT $ InMemory.loadSnapshot lgrRegistry ccfg fs ds
148+
InMemoryHandleArgs -> runExceptT $ InMemory.loadSnapshot v2Tracer lgrRegistry ccfg fs ds
146149
LSMHandleArgs x -> absurd x
147150

148151
implMkLedgerDb ::

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V2/Args.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ data HandleArgs
2626
deriving (Generic, NoThunks)
2727

2828
data FlavorImplSpecificTrace
29-
= FlavorImplSpecificTraceInMemory
30-
| FlavorImplSpecificTraceOnDisk
29+
= -- | Created a new 'LedgerTablesHandle', potentially by duplicating an
30+
-- existing one.
31+
TraceLedgerTablesHandleCreate
32+
| -- | Closed a 'LedgerTablesHandle'.
33+
TraceLedgerTablesHandleClose
3134
deriving (Show, Eq)

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V2/InMemory.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import Ouroboros.Consensus.Ledger.SupportsProtocol
5151
import qualified Ouroboros.Consensus.Ledger.Tables.Diff as Diff
5252
import Ouroboros.Consensus.Storage.LedgerDB.API
5353
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
54+
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.Args as V2
5455
import Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq
5556
import Ouroboros.Consensus.Util.CBOR (readIncremental)
5657
import Ouroboros.Consensus.Util.CRC
@@ -85,18 +86,21 @@ newInMemoryLedgerTablesHandle ::
8586
, CanUpgradeLedgerTables l
8687
, SerializeTablesWithHint l
8788
) =>
89+
Tracer m V2.FlavorImplSpecificTrace ->
8890
SomeHasFS m ->
8991
LedgerTables l ValuesMK ->
9092
m (LedgerTablesHandle m l)
91-
newInMemoryLedgerTablesHandle someFS@(SomeHasFS hasFS) l = do
93+
newInMemoryLedgerTablesHandle tracer someFS@(SomeHasFS hasFS) l = do
9294
!tv <- newTVarIO (LedgerTablesHandleOpen l)
95+
traceWith tracer V2.TraceLedgerTablesHandleCreate
9396
pure
9497
LedgerTablesHandle
95-
{ close =
98+
{ close = do
9699
atomically $ writeTVar tv LedgerTablesHandleClosed
100+
traceWith tracer V2.TraceLedgerTablesHandleClose
97101
, duplicate = do
98102
hs <- readTVarIO tv
99-
!x <- guardClosed hs $ newInMemoryLedgerTablesHandle someFS
103+
!x <- guardClosed hs $ newInMemoryLedgerTablesHandle tracer someFS
100104
pure x
101105
, read = \keys -> do
102106
hs <- readTVarIO tv
@@ -208,12 +212,13 @@ loadSnapshot ::
208212
, IOLike m
209213
, LedgerSupportsInMemoryLedgerDB blk
210214
) =>
215+
Tracer m V2.FlavorImplSpecificTrace ->
211216
ResourceRegistry m ->
212217
CodecConfig blk ->
213218
SomeHasFS m ->
214219
DiskSnapshot ->
215220
ExceptT (SnapshotFailure blk) m (LedgerSeq' m blk, RealPoint blk)
216-
loadSnapshot _rr ccfg fs ds = do
221+
loadSnapshot tracer _rr ccfg fs ds = do
217222
snapshotMeta <-
218223
withExceptT (InitFailureRead . ReadMetadataError (snapshotToMetadataPath ds)) $
219224
loadSnapshotMetadata fs ds
@@ -242,4 +247,4 @@ loadSnapshot _rr ccfg fs ds = do
242247
throwE $
243248
InitFailureRead $
244249
ReadSnapshotDataCorruption
245-
(,pt) <$> lift (empty extLedgerSt values (newInMemoryLedgerTablesHandle fs))
250+
(,pt) <$> lift (empty extLedgerSt values (newInMemoryLedgerTablesHandle tracer fs))

0 commit comments

Comments
 (0)