@@ -80,8 +80,7 @@ import Ouroboros.Network.Point (WithOrigin (..))
80
80
import Ouroboros.Consensus.Block (GetHeader (.. ), IsEBB (.. ))
81
81
import Ouroboros.Consensus.Util.IOLike
82
82
import Ouroboros.Consensus.Util.Orphans ()
83
- import Ouroboros.Consensus.Util.ResourceRegistry (ResourceRegistry ,
84
- allocateEither , unsafeRelease )
83
+ import Ouroboros.Consensus.Util.ResourceRegistry (ResourceRegistry )
85
84
86
85
import Ouroboros.Storage.ChainDB.API (ChainDB )
87
86
import Ouroboros.Storage.ChainDB.API hiding (ChainDB (.. ),
@@ -417,14 +416,10 @@ appendBlock db@ImmDB{..} b = withDB db $ \imm -> case isEBB (getHeader b) of
417
416
Streaming
418
417
-------------------------------------------------------------------------------}
419
418
420
- -- | Wrapper around 'ImmDB.stream' that 'allocate's the iterator in the
421
- -- 'ResourceRegistry' so that 'ImmDB.iteratorClose' is registered as the
422
- -- clean-up action. Translates the requested 'BlockComponent' into the
423
- -- 'ImmDB.BlockComponent' the ImmutableDB understands.
424
- --
425
- -- When the returned iterator is closed, it will be 'release'd from the
426
- -- 'ResourceRegistry'.
427
- registeredStream
419
+ -- | Wrapper around 'ImmDB.stream' that translates the requested
420
+ -- 'BlockComponent' into the 'ImmDB.BlockComponent' the ImmutableDB
421
+ -- understands.
422
+ openIterator
428
423
:: forall m blk b . (IOLike m , HasHeader blk )
429
424
=> ImmDB m blk
430
425
-> ResourceRegistry m
@@ -433,20 +428,8 @@ registeredStream
433
428
-> Maybe (SlotNo , HeaderHash blk )
434
429
-> m (Either (ImmDB. WrongBoundError (HeaderHash blk ))
435
430
(ImmDB. Iterator (HeaderHash blk ) m b ))
436
- registeredStream db registry blockComponent start end = do
437
- errOrKeyAndIt <- allocateEither registry
438
- (\ _key -> withDB db $ \ imm ->
439
- ImmDB. stream imm blockComponent' start end)
440
- (iteratorClose db)
441
- return $ case errOrKeyAndIt of
442
- Left e -> Left e
443
- -- The iterator will be used by a thread that is unknown to the registry
444
- -- (which, after all, is entirely internal to the chain DB). This means
445
- -- that the registry cannot guarantee that the iterator will be live for
446
- -- the duration of that thread, and indeed, it may not be: the chain DB
447
- -- might be closed before that thread terminates. We will deal with this
448
- -- in the chain DB itself (throw ClosedDBError exception).
449
- Right (key, it) -> Right it { ImmDB. iteratorClose = unsafeRelease key }
431
+ openIterator db registry blockComponent start end =
432
+ withDB db $ \ imm -> ImmDB. stream imm registry blockComponent' start end
450
433
where
451
434
blockComponent' = translateToRawDB (parse db) (addHdrEnv db) blockComponent
452
435
@@ -489,29 +472,29 @@ stream db registry blockComponent from to = runExceptT $ do
489
472
case from of
490
473
StreamFromExclusive pt@ BlockPoint { atSlot = slot, withHash = hash } -> do
491
474
when (pointSlot pt > slotNoAtTip) $ throwError $ MissingBlock pt
492
- it <- openRegisteredStream (Just (slot, hash)) end
475
+ it <- openStream (Just (slot, hash)) end
493
476
-- Skip the first block, as the bound is exclusive
494
477
void $ lift $ iteratorNext db it
495
478
return it
496
479
StreamFromExclusive GenesisPoint ->
497
- openRegisteredStream Nothing end
480
+ openStream Nothing end
498
481
StreamFromInclusive pt@ BlockPoint { atSlot = slot, withHash = hash } -> do
499
482
when (pointSlot pt > slotNoAtTip) $ throwError $ MissingBlock pt
500
- openRegisteredStream (Just (slot, hash)) end
483
+ openStream (Just (slot, hash)) end
501
484
StreamFromInclusive GenesisPoint ->
502
485
throwM NoGenesisBlock
503
486
where
504
- openRegisteredStream
487
+ openStream
505
488
:: Maybe (SlotNo , HeaderHash blk )
506
489
-> Maybe (SlotNo , HeaderHash blk )
507
490
-> ExceptT (UnknownRange blk )
508
491
m
509
492
(ImmDB. Iterator (HeaderHash blk ) m b )
510
- openRegisteredStream start end = ExceptT $
493
+ openStream start end = ExceptT $
511
494
bimap toUnknownRange (fmap snd . stopAt to) <$>
512
495
-- 'stopAt' needs to know the hash of each streamed block, so we \"Get\"
513
496
-- it in addition to @b@, but we drop it afterwards.
514
- registeredStream db registry ((,) <$> GetHash <*> blockComponent) start end
497
+ openIterator db registry ((,) <$> GetHash <*> blockComponent) start end
515
498
where
516
499
toUnknownRange :: ImmDB. WrongBoundError (HeaderHash blk ) -> UnknownRange blk
517
500
toUnknownRange e
@@ -570,7 +553,7 @@ streamAfter
570
553
(ImmDB. WrongBoundError (HeaderHash blk ))
571
554
(ImmDB. Iterator (HeaderHash blk ) m b ))
572
555
streamAfter db registry blockComponent low =
573
- registeredStream db registry blockComponent low' Nothing >>= \ case
556
+ openIterator db registry blockComponent low' Nothing >>= \ case
574
557
Left err -> return $ Left err
575
558
Right itr -> do
576
559
case low of
0 commit comments