{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ViewPatterns #-}
module Ouroboros.Consensus.Storage.ChainDB.Impl.Iterator (
closeAllIterators
, stream
, IteratorEnv (..)
, newIterator
) where
import Control.Monad (unless, when)
import Control.Monad.Except (ExceptT (..), catchError, runExceptT,
throwError, withExceptT)
import Control.Monad.Trans.Class (lift)
import Control.ResourceRegistry (ResourceRegistry)
import Control.Tracer
import Data.Functor (($>))
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NE
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (isJust)
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import GHC.Stack (HasCallStack)
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Storage.ChainDB.API (BlockComponent (..),
ChainDbError (..), Iterator (..), IteratorResult (..),
StreamFrom (..), StreamTo (..), UnknownRange (..),
getPoint, validBounds)
import Ouroboros.Consensus.Storage.ChainDB.Impl.Paths (Path (..),
computePath)
import Ouroboros.Consensus.Storage.ChainDB.Impl.Types
import Ouroboros.Consensus.Storage.ImmutableDB (ImmutableDB)
import qualified Ouroboros.Consensus.Storage.ImmutableDB as ImmutableDB
import Ouroboros.Consensus.Storage.VolatileDB (VolatileDB)
import qualified Ouroboros.Consensus.Storage.VolatileDB as VolatileDB
import Ouroboros.Consensus.Util.IOLike
stream ::
forall m blk b.
( IOLike m
, HasHeader blk
, HasCallStack
)
=> ChainDbHandle m blk
-> ResourceRegistry m
-> BlockComponent blk b
-> StreamFrom blk
-> StreamTo blk
-> m (Either (UnknownRange blk) (Iterator m blk b))
stream :: forall (m :: * -> *) blk b.
(IOLike m, HasHeader blk, HasCallStack) =>
ChainDbHandle m blk
-> ResourceRegistry m
-> BlockComponent blk b
-> StreamFrom blk
-> StreamTo blk
-> m (Either (UnknownRange blk) (Iterator m blk b))
stream ChainDbHandle m blk
h ResourceRegistry m
registry BlockComponent blk b
blockComponent StreamFrom blk
from StreamTo blk
to = ChainDbHandle m blk
-> (ChainDbEnv m blk
-> m (Either (UnknownRange blk) (Iterator m blk b)))
-> m (Either (UnknownRange blk) (Iterator m blk b))
forall (m :: * -> *) blk r.
(IOLike m, HasCallStack, HasHeader blk) =>
ChainDbHandle m blk -> (ChainDbEnv m blk -> m r) -> m r
getEnv ChainDbHandle m blk
h ((ChainDbEnv m blk
-> m (Either (UnknownRange blk) (Iterator m blk b)))
-> m (Either (UnknownRange blk) (Iterator m blk b)))
-> (ChainDbEnv m blk
-> m (Either (UnknownRange blk) (Iterator m blk b)))
-> m (Either (UnknownRange blk) (Iterator m blk b))
forall a b. (a -> b) -> a -> b
$ \ChainDbEnv m blk
cdb ->
IteratorEnv m blk
-> (forall r. (IteratorEnv m blk -> m r) -> m r)
-> ResourceRegistry m
-> BlockComponent blk b
-> StreamFrom blk
-> StreamTo blk
-> m (Either (UnknownRange blk) (Iterator m blk b))
forall (m :: * -> *) blk b.
(IOLike m, HasHeader blk, HasCallStack) =>
IteratorEnv m blk
-> (forall r. (IteratorEnv m blk -> m r) -> m r)
-> ResourceRegistry m
-> BlockComponent blk b
-> StreamFrom blk
-> StreamTo blk
-> m (Either (UnknownRange blk) (Iterator m blk b))
newIterator (ChainDbEnv m blk -> IteratorEnv m blk
forall (m :: * -> *) blk. ChainDbEnv m blk -> IteratorEnv m blk
fromChainDbEnv ChainDbEnv m blk
cdb) (IteratorEnv m blk -> m r) -> m r
forall r. (IteratorEnv m blk -> m r) -> m r
getItEnv ResourceRegistry m
registry BlockComponent blk b
blockComponent StreamFrom blk
from StreamTo blk
to
where
getItEnv :: forall r. (IteratorEnv m blk -> m r) -> m r
getItEnv :: forall r. (IteratorEnv m blk -> m r) -> m r
getItEnv IteratorEnv m blk -> m r
f = ChainDbHandle m blk -> (ChainDbEnv m blk -> m r) -> m r
forall (m :: * -> *) blk r.
(IOLike m, HasCallStack, HasHeader blk) =>
ChainDbHandle m blk -> (ChainDbEnv m blk -> m r) -> m r
getEnv ChainDbHandle m blk
h (IteratorEnv m blk -> m r
f (IteratorEnv m blk -> m r)
-> (ChainDbEnv m blk -> IteratorEnv m blk)
-> ChainDbEnv m blk
-> m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ChainDbEnv m blk -> IteratorEnv m blk
forall (m :: * -> *) blk. ChainDbEnv m blk -> IteratorEnv m blk
fromChainDbEnv)
data IteratorEnv m blk = IteratorEnv {
forall (m :: * -> *) blk. IteratorEnv m blk -> ImmutableDB m blk
itImmutableDB :: ImmutableDB m blk
, forall (m :: * -> *) blk. IteratorEnv m blk -> VolatileDB m blk
itVolatileDB :: VolatileDB m blk
, forall (m :: * -> *) blk.
IteratorEnv m blk -> StrictTVar m (Map IteratorKey (m ()))
itIterators :: StrictTVar m (Map IteratorKey (m ()))
, forall (m :: * -> *) blk.
IteratorEnv m blk -> StrictTVar m IteratorKey
itNextIteratorKey :: StrictTVar m IteratorKey
, forall (m :: * -> *) blk.
IteratorEnv m blk -> Tracer m (TraceIteratorEvent blk)
itTracer :: Tracer m (TraceIteratorEvent blk)
}
fromChainDbEnv :: ChainDbEnv m blk -> IteratorEnv m blk
fromChainDbEnv :: forall (m :: * -> *) blk. ChainDbEnv m blk -> IteratorEnv m blk
fromChainDbEnv CDB{m (LoE (AnchoredFragment (Header blk)))
Tracer m (TraceEvent blk)
DiffTime
ResourceRegistry m
StrictTVar m (m ())
StrictTVar m (Map FollowerKey (FollowerHandle m blk))
StrictTVar m (Map IteratorKey (m ()))
StrictTVar m (StrictMaybe (Header blk))
StrictTVar m (AnchoredFragment (Header blk))
StrictTVar m (TentativeHeaderState blk)
StrictTVar m (WithFingerprint (InvalidBlocks blk))
StrictTVar m FollowerKey
StrictTVar m IteratorKey
Fuse m
TopLevelConfig blk
VolatileDB m blk
ImmutableDB m blk
LgrDB m blk
ChainSelQueue m blk
cdbImmutableDB :: ImmutableDB m blk
cdbVolatileDB :: VolatileDB m blk
cdbLgrDB :: LgrDB m blk
cdbChain :: StrictTVar m (AnchoredFragment (Header blk))
cdbTentativeState :: StrictTVar m (TentativeHeaderState blk)
cdbTentativeHeader :: StrictTVar m (StrictMaybe (Header blk))
cdbIterators :: StrictTVar m (Map IteratorKey (m ()))
cdbFollowers :: StrictTVar m (Map FollowerKey (FollowerHandle m blk))
cdbTopLevelConfig :: TopLevelConfig blk
cdbInvalid :: StrictTVar m (WithFingerprint (InvalidBlocks blk))
cdbNextIteratorKey :: StrictTVar m IteratorKey
cdbNextFollowerKey :: StrictTVar m FollowerKey
cdbCopyFuse :: Fuse m
cdbChainSelFuse :: Fuse m
cdbTracer :: Tracer m (TraceEvent blk)
cdbRegistry :: ResourceRegistry m
cdbGcDelay :: DiffTime
cdbGcInterval :: DiffTime
cdbKillBgThreads :: StrictTVar m (m ())
cdbChainSelQueue :: ChainSelQueue m blk
cdbLoE :: m (LoE (AnchoredFragment (Header blk)))
cdbImmutableDB :: forall (m :: * -> *) blk. ChainDbEnv m blk -> ImmutableDB m blk
cdbVolatileDB :: forall (m :: * -> *) blk. ChainDbEnv m blk -> VolatileDB m blk
cdbLgrDB :: forall (m :: * -> *) blk. ChainDbEnv m blk -> LgrDB m blk
cdbChain :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m (AnchoredFragment (Header blk))
cdbTentativeState :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m (TentativeHeaderState blk)
cdbTentativeHeader :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m (StrictMaybe (Header blk))
cdbIterators :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m (Map IteratorKey (m ()))
cdbFollowers :: forall (m :: * -> *) blk.
ChainDbEnv m blk
-> StrictTVar m (Map FollowerKey (FollowerHandle m blk))
cdbTopLevelConfig :: forall (m :: * -> *) blk. ChainDbEnv m blk -> TopLevelConfig blk
cdbInvalid :: forall (m :: * -> *) blk.
ChainDbEnv m blk
-> StrictTVar m (WithFingerprint (InvalidBlocks blk))
cdbNextIteratorKey :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m IteratorKey
cdbNextFollowerKey :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m FollowerKey
cdbCopyFuse :: forall (m :: * -> *) blk. ChainDbEnv m blk -> Fuse m
cdbChainSelFuse :: forall (m :: * -> *) blk. ChainDbEnv m blk -> Fuse m
cdbTracer :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> Tracer m (TraceEvent blk)
cdbRegistry :: forall (m :: * -> *) blk. ChainDbEnv m blk -> ResourceRegistry m
cdbGcDelay :: forall (m :: * -> *) blk. ChainDbEnv m blk -> DiffTime
cdbGcInterval :: forall (m :: * -> *) blk. ChainDbEnv m blk -> DiffTime
cdbKillBgThreads :: forall (m :: * -> *) blk. ChainDbEnv m blk -> StrictTVar m (m ())
cdbChainSelQueue :: forall (m :: * -> *) blk. ChainDbEnv m blk -> ChainSelQueue m blk
cdbLoE :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> m (LoE (AnchoredFragment (Header blk)))
..} = IteratorEnv {
itImmutableDB :: ImmutableDB m blk
itImmutableDB = ImmutableDB m blk
cdbImmutableDB
, itVolatileDB :: VolatileDB m blk
itVolatileDB = VolatileDB m blk
cdbVolatileDB
, itIterators :: StrictTVar m (Map IteratorKey (m ()))
itIterators = StrictTVar m (Map IteratorKey (m ()))
cdbIterators
, itNextIteratorKey :: StrictTVar m IteratorKey
itNextIteratorKey = StrictTVar m IteratorKey
cdbNextIteratorKey
, itTracer :: Tracer m (TraceIteratorEvent blk)
itTracer = (TraceIteratorEvent blk -> TraceEvent blk)
-> Tracer m (TraceEvent blk) -> Tracer m (TraceIteratorEvent blk)
forall a' a. (a' -> a) -> Tracer m a -> Tracer m a'
forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap TraceIteratorEvent blk -> TraceEvent blk
forall blk. TraceIteratorEvent blk -> TraceEvent blk
TraceIteratorEvent Tracer m (TraceEvent blk)
cdbTracer
}
newIterator ::
forall m blk b. (IOLike m, HasHeader blk, HasCallStack)
=> IteratorEnv m blk
-> (forall r. (IteratorEnv m blk -> m r) -> m r)
-> ResourceRegistry m
-> BlockComponent blk b
-> StreamFrom blk
-> StreamTo blk
-> m (Either (UnknownRange blk) (Iterator m blk b))
newIterator :: forall (m :: * -> *) blk b.
(IOLike m, HasHeader blk, HasCallStack) =>
IteratorEnv m blk
-> (forall r. (IteratorEnv m blk -> m r) -> m r)
-> ResourceRegistry m
-> BlockComponent blk b
-> StreamFrom blk
-> StreamTo blk
-> m (Either (UnknownRange blk) (Iterator m blk b))
newIterator itEnv :: IteratorEnv m blk
itEnv@IteratorEnv{Tracer m (TraceIteratorEvent blk)
StrictTVar m (Map IteratorKey (m ()))
StrictTVar m IteratorKey
VolatileDB m blk
ImmutableDB m blk
itImmutableDB :: forall (m :: * -> *) blk. IteratorEnv m blk -> ImmutableDB m blk
itVolatileDB :: forall (m :: * -> *) blk. IteratorEnv m blk -> VolatileDB m blk
itIterators :: forall (m :: * -> *) blk.
IteratorEnv m blk -> StrictTVar m (Map IteratorKey (m ()))
itNextIteratorKey :: forall (m :: * -> *) blk.
IteratorEnv m blk -> StrictTVar m IteratorKey
itTracer :: forall (m :: * -> *) blk.
IteratorEnv m blk -> Tracer m (TraceIteratorEvent blk)
itImmutableDB :: ImmutableDB m blk
itVolatileDB :: VolatileDB m blk
itIterators :: StrictTVar m (Map IteratorKey (m ()))
itNextIteratorKey :: StrictTVar m IteratorKey
itTracer :: Tracer m (TraceIteratorEvent blk)
..} forall r. (IteratorEnv m blk -> m r) -> m r
getItEnv ResourceRegistry m
registry BlockComponent blk b
blockComponent StreamFrom blk
from StreamTo blk
to = do
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (StreamFrom blk -> StreamTo blk -> Bool
forall blk.
StandardHash blk =>
StreamFrom blk -> StreamTo blk -> Bool
validBounds StreamFrom blk
from StreamTo blk
to) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
ChainDbError blk -> m ()
forall e a. Exception e => e -> m a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO (ChainDbError blk -> m ()) -> ChainDbError blk -> m ()
forall a b. (a -> b) -> a -> b
$ StreamFrom blk -> StreamTo blk -> ChainDbError blk
forall blk. StreamFrom blk -> StreamTo blk -> ChainDbError blk
InvalidIteratorRange StreamFrom blk
from StreamTo blk
to
Either (UnknownRange blk) (Iterator m blk b)
res <- ExceptT (UnknownRange blk) m (Iterator m blk b)
-> m (Either (UnknownRange blk) (Iterator m blk b))
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT ExceptT (UnknownRange blk) m (Iterator m blk b)
HasCallStack => ExceptT (UnknownRange blk) m (Iterator m blk b)
start
case Either (UnknownRange blk) (Iterator m blk b)
res of
Left UnknownRange blk
e -> TraceIteratorEvent blk -> m ()
trace (TraceIteratorEvent blk -> m ()) -> TraceIteratorEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ UnknownRange blk -> TraceIteratorEvent blk
forall blk. UnknownRange blk -> TraceIteratorEvent blk
UnknownRangeRequested UnknownRange blk
e
Either (UnknownRange blk) (Iterator m blk b)
_ -> () -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Either (UnknownRange blk) (Iterator m blk b)
-> m (Either (UnknownRange blk) (Iterator m blk b))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Either (UnknownRange blk) (Iterator m blk b)
res
where
trace :: TraceIteratorEvent blk -> m ()
trace = Tracer m (TraceIteratorEvent blk) -> TraceIteratorEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (TraceIteratorEvent blk)
itTracer
endPoint :: RealPoint blk
endPoint :: RealPoint blk
endPoint = case StreamTo blk
to of
StreamToInclusive RealPoint blk
pt -> RealPoint blk
pt
start :: HasCallStack
=> ExceptT (UnknownRange blk) m (Iterator m blk b)
start :: HasCallStack => ExceptT (UnknownRange blk) m (Iterator m blk b)
start = m (WithOrigin (Tip blk))
-> ExceptT (UnknownRange blk) m (WithOrigin (Tip blk))
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (UnknownRange blk) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (STM m (WithOrigin (Tip blk)) -> m (WithOrigin (Tip blk))
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (ImmutableDB m blk -> STM m (WithOrigin (Tip blk))
forall (m :: * -> *) blk.
HasCallStack =>
ImmutableDB m blk -> STM m (WithOrigin (Tip blk))
ImmutableDB.getTip ImmutableDB m blk
itImmutableDB)) ExceptT (UnknownRange blk) m (WithOrigin (Tip blk))
-> (WithOrigin (Tip blk)
-> ExceptT (UnknownRange blk) m (Iterator m blk b))
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a b.
ExceptT (UnknownRange blk) m a
-> (a -> ExceptT (UnknownRange blk) m b)
-> ExceptT (UnknownRange blk) m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
WithOrigin (Tip blk)
Origin -> ExceptT (UnknownRange blk) m (Iterator m blk b)
HasCallStack => ExceptT (UnknownRange blk) m (Iterator m blk b)
findPathInVolatileDB
NotOrigin ImmutableDB.Tip { SlotNo
tipSlotNo :: SlotNo
tipSlotNo :: forall blk. Tip blk -> SlotNo
tipSlotNo, HeaderHash blk
tipHash :: HeaderHash blk
tipHash :: forall blk. Tip blk -> HeaderHash blk
tipHash, IsEBB
tipIsEBB :: IsEBB
tipIsEBB :: forall blk. Tip blk -> IsEBB
tipIsEBB } ->
case RealPoint blk -> SlotNo
forall blk. RealPoint blk -> SlotNo
realPointSlot RealPoint blk
endPoint SlotNo -> SlotNo -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` SlotNo
tipSlotNo of
Ordering
LT -> ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromImmutableDB
Ordering
EQ | RealPoint blk -> HeaderHash blk
forall blk. RealPoint blk -> HeaderHash blk
realPointHash RealPoint blk
endPoint HeaderHash blk -> HeaderHash blk -> Bool
forall a. Eq a => a -> a -> Bool
== HeaderHash blk
tipHash
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromImmutableDB
| IsEBB
IsNotEBB <- IsEBB
tipIsEBB
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromImmutableDB ExceptT (UnknownRange blk) m (Iterator m blk b)
-> (UnknownRange blk
-> ExceptT (UnknownRange blk) m (Iterator m blk b))
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a.
ExceptT (UnknownRange blk) m a
-> (UnknownRange blk -> ExceptT (UnknownRange blk) m a)
-> ExceptT (UnknownRange blk) m a
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError`
ExceptT (UnknownRange blk) m (Iterator m blk b)
-> UnknownRange blk
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a b. a -> b -> a
const (UnknownRange blk -> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a. UnknownRange blk -> ExceptT (UnknownRange blk) m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (UnknownRange blk
-> ExceptT (UnknownRange blk) m (Iterator m blk b))
-> UnknownRange blk
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a b. (a -> b) -> a -> b
$ StreamFrom blk -> UnknownRange blk
forall blk. StreamFrom blk -> UnknownRange blk
ForkTooOld StreamFrom blk
from)
| Bool
otherwise
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
HasCallStack => ExceptT (UnknownRange blk) m (Iterator m blk b)
findPathInVolatileDB
Ordering
GT -> ExceptT (UnknownRange blk) m (Iterator m blk b)
HasCallStack => ExceptT (UnknownRange blk) m (Iterator m blk b)
findPathInVolatileDB
findPathInVolatileDB ::
HasCallStack => ExceptT (UnknownRange blk) m (Iterator m blk b)
findPathInVolatileDB :: HasCallStack => ExceptT (UnknownRange blk) m (Iterator m blk b)
findPathInVolatileDB = do
Path blk
path <- m (Path blk) -> ExceptT (UnknownRange blk) m (Path blk)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (UnknownRange blk) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Path blk) -> ExceptT (UnknownRange blk) m (Path blk))
-> m (Path blk) -> ExceptT (UnknownRange blk) m (Path blk)
forall a b. (a -> b) -> a -> b
$ VolatileDB m blk -> StreamFrom blk -> StreamTo blk -> m (Path blk)
forall (m :: * -> *) blk.
(IOLike m, HasHeader blk) =>
VolatileDB m blk -> StreamFrom blk -> StreamTo blk -> m (Path blk)
computePathVolatileDB VolatileDB m blk
itVolatileDB StreamFrom blk
from StreamTo blk
to
case Path blk
path of
NotInVolatileDB RealPoint blk
_hash -> UnknownRange blk -> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a. UnknownRange blk -> ExceptT (UnknownRange blk) m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (UnknownRange blk
-> ExceptT (UnknownRange blk) m (Iterator m blk b))
-> UnknownRange blk
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a b. (a -> b) -> a -> b
$ StreamFrom blk -> UnknownRange blk
forall blk. StreamFrom blk -> UnknownRange blk
ForkTooOld StreamFrom blk
from
PartiallyInVolatileDB HeaderHash blk
predHash [RealPoint blk]
pts -> HasCallStack =>
HeaderHash blk
-> [RealPoint blk]
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
HeaderHash blk
-> [RealPoint blk]
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromBoth HeaderHash blk
predHash [RealPoint blk]
pts
CompletelyInVolatileDB [RealPoint blk]
pts -> case [RealPoint blk] -> Maybe (NonEmpty (RealPoint blk))
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [RealPoint blk]
pts of
Just NonEmpty (RealPoint blk)
pts' -> m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (UnknownRange blk) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b))
-> m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a b. (a -> b) -> a -> b
$ NonEmpty (RealPoint blk) -> m (Iterator m blk b)
streamFromVolatileDB NonEmpty (RealPoint blk)
pts'
Maybe (NonEmpty (RealPoint blk))
Nothing -> m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (UnknownRange blk) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b))
-> m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a b. (a -> b) -> a -> b
$ m (Iterator m blk b)
emptyIterator
streamFromVolatileDB :: NonEmpty (RealPoint blk) -> m (Iterator m blk b)
streamFromVolatileDB :: NonEmpty (RealPoint blk) -> m (Iterator m blk b)
streamFromVolatileDB NonEmpty (RealPoint blk)
pts = do
TraceIteratorEvent blk -> m ()
trace (TraceIteratorEvent blk -> m ()) -> TraceIteratorEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ StreamFrom blk
-> StreamTo blk -> [RealPoint blk] -> TraceIteratorEvent blk
forall blk.
StreamFrom blk
-> StreamTo blk -> [RealPoint blk] -> TraceIteratorEvent blk
StreamFromVolatileDB StreamFrom blk
from StreamTo blk
to (NonEmpty (RealPoint blk) -> [RealPoint blk]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (RealPoint blk)
pts)
IteratorState m blk b -> m (Iterator m blk b)
createIterator (IteratorState m blk b -> m (Iterator m blk b))
-> IteratorState m blk b -> m (Iterator m blk b)
forall a b. (a -> b) -> a -> b
$ StreamFrom blk -> NonEmpty (RealPoint blk) -> IteratorState m blk b
forall (m :: * -> *) blk b.
StreamFrom blk -> NonEmpty (RealPoint blk) -> IteratorState m blk b
InVolatileDB StreamFrom blk
from NonEmpty (RealPoint blk)
pts
streamFromImmutableDB :: ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromImmutableDB :: ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromImmutableDB = do
m () -> ExceptT (UnknownRange blk) m ()
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (UnknownRange blk) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ExceptT (UnknownRange blk) m ())
-> m () -> ExceptT (UnknownRange blk) m ()
forall a b. (a -> b) -> a -> b
$ TraceIteratorEvent blk -> m ()
trace (TraceIteratorEvent blk -> m ()) -> TraceIteratorEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ StreamFrom blk -> StreamTo blk -> TraceIteratorEvent blk
forall blk.
StreamFrom blk -> StreamTo blk -> TraceIteratorEvent blk
StreamFromImmutableDB StreamFrom blk
from StreamTo blk
to
StreamTo blk -> ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromImmutableDBHelper StreamTo blk
to
streamFromImmutableDBHelper ::
StreamTo blk
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromImmutableDBHelper :: StreamTo blk -> ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromImmutableDBHelper StreamTo blk
to' = do
Iterator m blk (Point blk, b)
immIt <-
(MissingBlock blk -> UnknownRange blk)
-> ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b))
-> ExceptT (UnknownRange blk) m (Iterator m blk (Point blk, b))
forall (m :: * -> *) e e' a.
Functor m =>
(e -> e') -> ExceptT e m a -> ExceptT e' m a
withExceptT MissingBlock blk -> UnknownRange blk
forall blk. MissingBlock blk -> UnknownRange blk
missingBlockToUnknownRange (ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b))
-> ExceptT (UnknownRange blk) m (Iterator m blk (Point blk, b)))
-> ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b))
-> ExceptT (UnknownRange blk) m (Iterator m blk (Point blk, b))
forall a b. (a -> b) -> a -> b
$ m (Either (MissingBlock blk) (Iterator m blk (Point blk, b)))
-> ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b))
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (m (Either (MissingBlock blk) (Iterator m blk (Point blk, b)))
-> ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b)))
-> m (Either (MissingBlock blk) (Iterator m blk (Point blk, b)))
-> ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b))
forall a b. (a -> b) -> a -> b
$
ImmutableDB m blk
-> ResourceRegistry m
-> BlockComponent blk (Point blk, b)
-> StreamFrom blk
-> StreamTo blk
-> m (Either (MissingBlock blk) (Iterator m blk (Point blk, b)))
forall (m :: * -> *) blk b.
HasCallStack =>
ImmutableDB m blk
-> ResourceRegistry m
-> BlockComponent blk b
-> StreamFrom blk
-> StreamTo blk
-> m (Either (MissingBlock blk) (Iterator m blk b))
ImmutableDB.stream
ImmutableDB m blk
itImmutableDB
ResourceRegistry m
registry
((,) (Point blk -> b -> (Point blk, b))
-> BlockComponent blk (Point blk)
-> BlockComponent blk (b -> (Point blk, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BlockComponent blk (Point blk)
forall blk. BlockComponent blk (Point blk)
getPoint BlockComponent blk (b -> (Point blk, b))
-> BlockComponent blk b -> BlockComponent blk (Point blk, b)
forall a b.
BlockComponent blk (a -> b)
-> BlockComponent blk a -> BlockComponent blk b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> BlockComponent blk b
blockComponent)
StreamFrom blk
from
StreamTo blk
to'
m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (UnknownRange blk) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b))
-> m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a b. (a -> b) -> a -> b
$ IteratorState m blk b -> m (Iterator m blk b)
createIterator (IteratorState m blk b -> m (Iterator m blk b))
-> IteratorState m blk b -> m (Iterator m blk b)
forall a b. (a -> b) -> a -> b
$ StreamFrom blk
-> Iterator m blk (Point blk, b)
-> InImmutableDBEnd blk
-> IteratorState m blk b
forall (m :: * -> *) blk b.
StreamFrom blk
-> Iterator m blk (Point blk, b)
-> InImmutableDBEnd blk
-> IteratorState m blk b
InImmutableDB StreamFrom blk
from Iterator m blk (Point blk, b)
immIt (StreamTo blk -> InImmutableDBEnd blk
forall blk. StreamTo blk -> InImmutableDBEnd blk
StreamTo StreamTo blk
to')
streamFromBoth ::
HasCallStack
=> HeaderHash blk
-> [RealPoint blk]
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromBoth :: HasCallStack =>
HeaderHash blk
-> [RealPoint blk]
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromBoth HeaderHash blk
predHash [RealPoint blk]
pts = do
m () -> ExceptT (UnknownRange blk) m ()
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (UnknownRange blk) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ExceptT (UnknownRange blk) m ())
-> m () -> ExceptT (UnknownRange blk) m ()
forall a b. (a -> b) -> a -> b
$ TraceIteratorEvent blk -> m ()
trace (TraceIteratorEvent blk -> m ()) -> TraceIteratorEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ StreamFrom blk
-> StreamTo blk -> [RealPoint blk] -> TraceIteratorEvent blk
forall blk.
StreamFrom blk
-> StreamTo blk -> [RealPoint blk] -> TraceIteratorEvent blk
StreamFromBoth StreamFrom blk
from StreamTo blk
to [RealPoint blk]
pts
m (WithOrigin (RealPoint blk))
-> ExceptT (UnknownRange blk) m (WithOrigin (RealPoint blk))
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (UnknownRange blk) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((Tip blk -> RealPoint blk)
-> WithOrigin (Tip blk) -> WithOrigin (RealPoint blk)
forall a b. (a -> b) -> WithOrigin a -> WithOrigin b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Tip blk -> RealPoint blk
forall blk. Tip blk -> RealPoint blk
ImmutableDB.tipToRealPoint (WithOrigin (Tip blk) -> WithOrigin (RealPoint blk))
-> m (WithOrigin (Tip blk)) -> m (WithOrigin (RealPoint blk))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
STM m (WithOrigin (Tip blk)) -> m (WithOrigin (Tip blk))
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (ImmutableDB m blk -> STM m (WithOrigin (Tip blk))
forall (m :: * -> *) blk.
HasCallStack =>
ImmutableDB m blk -> STM m (WithOrigin (Tip blk))
ImmutableDB.getTip ImmutableDB m blk
itImmutableDB)) ExceptT (UnknownRange blk) m (WithOrigin (RealPoint blk))
-> (WithOrigin (RealPoint blk)
-> ExceptT (UnknownRange blk) m (Iterator m blk b))
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a b.
ExceptT (UnknownRange blk) m a
-> (a -> ExceptT (UnknownRange blk) m b)
-> ExceptT (UnknownRange blk) m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
WithOrigin (RealPoint blk)
Origin -> UnknownRange blk -> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a. UnknownRange blk -> ExceptT (UnknownRange blk) m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (UnknownRange blk
-> ExceptT (UnknownRange blk) m (Iterator m blk b))
-> UnknownRange blk
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a b. (a -> b) -> a -> b
$ StreamFrom blk -> UnknownRange blk
forall blk. StreamFrom blk -> UnknownRange blk
ForkTooOld StreamFrom blk
from
NotOrigin pt :: RealPoint blk
pt@(RealPoint SlotNo
_ HeaderHash blk
tipHash)
| HeaderHash blk
tipHash HeaderHash blk -> HeaderHash blk -> Bool
forall a. Eq a => a -> a -> Bool
== HeaderHash blk
predHash
-> case [RealPoint blk] -> Maybe (NonEmpty (RealPoint blk))
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [RealPoint blk]
pts of
Just NonEmpty (RealPoint blk)
pts' -> RealPoint blk
-> NonEmpty (RealPoint blk)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
startStream RealPoint blk
pt NonEmpty (RealPoint blk)
pts'
Maybe (NonEmpty (RealPoint blk))
Nothing -> StreamTo blk -> ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromImmutableDBHelper (RealPoint blk -> StreamTo blk
forall blk. RealPoint blk -> StreamTo blk
StreamToInclusive RealPoint blk
pt)
| Bool
otherwise -> case (RealPoint blk -> Bool) -> [RealPoint blk] -> [RealPoint blk]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (RealPoint blk -> RealPoint blk -> Bool
forall a. Eq a => a -> a -> Bool
/= RealPoint blk
pt) [RealPoint blk]
pts of
[] -> UnknownRange blk -> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a. UnknownRange blk -> ExceptT (UnknownRange blk) m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (UnknownRange blk
-> ExceptT (UnknownRange blk) m (Iterator m blk b))
-> UnknownRange blk
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a b. (a -> b) -> a -> b
$ StreamFrom blk -> UnknownRange blk
forall blk. StreamFrom blk -> UnknownRange blk
ForkTooOld StreamFrom blk
from
RealPoint blk
_tipPt:RealPoint blk
pt':[RealPoint blk]
pts' -> RealPoint blk
-> NonEmpty (RealPoint blk)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
startStream RealPoint blk
pt (RealPoint blk
pt' RealPoint blk -> [RealPoint blk] -> NonEmpty (RealPoint blk)
forall a. a -> [a] -> NonEmpty a
NE.:| [RealPoint blk]
pts')
[RealPoint blk
_tipPt] -> StreamTo blk -> ExceptT (UnknownRange blk) m (Iterator m blk b)
streamFromImmutableDBHelper (RealPoint blk -> StreamTo blk
forall blk. RealPoint blk -> StreamTo blk
StreamToInclusive RealPoint blk
pt)
where
startStream ::
RealPoint blk
-> NonEmpty (RealPoint blk)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
startStream :: RealPoint blk
-> NonEmpty (RealPoint blk)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
startStream RealPoint blk
immTip NonEmpty (RealPoint blk)
pts' = do
let immEnd :: InImmutableDBEnd blk
immEnd = StreamTo blk -> NonEmpty (RealPoint blk) -> InImmutableDBEnd blk
forall blk.
StreamTo blk -> NonEmpty (RealPoint blk) -> InImmutableDBEnd blk
SwitchToVolatileDBFrom (RealPoint blk -> StreamTo blk
forall blk. RealPoint blk -> StreamTo blk
StreamToInclusive RealPoint blk
immTip) NonEmpty (RealPoint blk)
pts'
Iterator m blk (Point blk, b)
immIt <- (MissingBlock blk -> UnknownRange blk)
-> ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b))
-> ExceptT (UnknownRange blk) m (Iterator m blk (Point blk, b))
forall (m :: * -> *) e e' a.
Functor m =>
(e -> e') -> ExceptT e m a -> ExceptT e' m a
withExceptT MissingBlock blk -> UnknownRange blk
forall blk. MissingBlock blk -> UnknownRange blk
missingBlockToUnknownRange (ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b))
-> ExceptT (UnknownRange blk) m (Iterator m blk (Point blk, b)))
-> ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b))
-> ExceptT (UnknownRange blk) m (Iterator m blk (Point blk, b))
forall a b. (a -> b) -> a -> b
$ m (Either (MissingBlock blk) (Iterator m blk (Point blk, b)))
-> ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b))
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (m (Either (MissingBlock blk) (Iterator m blk (Point blk, b)))
-> ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b)))
-> m (Either (MissingBlock blk) (Iterator m blk (Point blk, b)))
-> ExceptT (MissingBlock blk) m (Iterator m blk (Point blk, b))
forall a b. (a -> b) -> a -> b
$
ImmutableDB m blk
-> ResourceRegistry m
-> BlockComponent blk (Point blk, b)
-> StreamFrom blk
-> StreamTo blk
-> m (Either (MissingBlock blk) (Iterator m blk (Point blk, b)))
forall (m :: * -> *) blk b.
HasCallStack =>
ImmutableDB m blk
-> ResourceRegistry m
-> BlockComponent blk b
-> StreamFrom blk
-> StreamTo blk
-> m (Either (MissingBlock blk) (Iterator m blk b))
ImmutableDB.stream
ImmutableDB m blk
itImmutableDB
ResourceRegistry m
registry
((,) (Point blk -> b -> (Point blk, b))
-> BlockComponent blk (Point blk)
-> BlockComponent blk (b -> (Point blk, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BlockComponent blk (Point blk)
forall blk. BlockComponent blk (Point blk)
getPoint BlockComponent blk (b -> (Point blk, b))
-> BlockComponent blk b -> BlockComponent blk (Point blk, b)
forall a b.
BlockComponent blk (a -> b)
-> BlockComponent blk a -> BlockComponent blk b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> BlockComponent blk b
blockComponent)
StreamFrom blk
from
(RealPoint blk -> StreamTo blk
forall blk. RealPoint blk -> StreamTo blk
StreamToInclusive RealPoint blk
immTip)
m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (UnknownRange blk) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b))
-> m (Iterator m blk b)
-> ExceptT (UnknownRange blk) m (Iterator m blk b)
forall a b. (a -> b) -> a -> b
$ IteratorState m blk b -> m (Iterator m blk b)
createIterator (IteratorState m blk b -> m (Iterator m blk b))
-> IteratorState m blk b -> m (Iterator m blk b)
forall a b. (a -> b) -> a -> b
$ StreamFrom blk
-> Iterator m blk (Point blk, b)
-> InImmutableDBEnd blk
-> IteratorState m blk b
forall (m :: * -> *) blk b.
StreamFrom blk
-> Iterator m blk (Point blk, b)
-> InImmutableDBEnd blk
-> IteratorState m blk b
InImmutableDB StreamFrom blk
from Iterator m blk (Point blk, b)
immIt InImmutableDBEnd blk
immEnd
makeIterator ::
Bool
-> IteratorState m blk b
-> m (Iterator m blk b)
makeIterator :: Bool -> IteratorState m blk b -> m (Iterator m blk b)
makeIterator Bool
register IteratorState m blk b
itState = do
IteratorKey
iteratorKey <- m IteratorKey
makeNewIteratorKey
StrictTVar m (IteratorState m blk b)
varItState <- IteratorState m blk b -> m (StrictTVar m (IteratorState m blk b))
forall (m :: * -> *) a.
(HasCallStack, MonadSTM m, NoThunks a) =>
a -> m (StrictTVar m a)
newTVarIO IteratorState m blk b
itState
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
register (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (Map IteratorKey (m ()))
-> (Map IteratorKey (m ()) -> Map IteratorKey (m ())) -> STM m ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> (a -> a) -> STM m ()
modifyTVar StrictTVar m (Map IteratorKey (m ()))
itIterators ((Map IteratorKey (m ()) -> Map IteratorKey (m ())) -> STM m ())
-> (Map IteratorKey (m ()) -> Map IteratorKey (m ())) -> STM m ()
forall a b. (a -> b) -> a -> b
$
IteratorKey
-> m () -> Map IteratorKey (m ()) -> Map IteratorKey (m ())
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert IteratorKey
iteratorKey (StrictTVar m (IteratorState m blk b)
-> IteratorKey -> IteratorEnv m blk -> m ()
forall (m :: * -> *) blk b.
IOLike m =>
StrictTVar m (IteratorState m blk b)
-> IteratorKey -> IteratorEnv m blk -> m ()
implIteratorClose StrictTVar m (IteratorState m blk b)
varItState IteratorKey
iteratorKey IteratorEnv m blk
itEnv)
Iterator m blk b -> m (Iterator m blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Iterator {
iteratorNext :: m (IteratorResult blk b)
iteratorNext = (IteratorEnv m blk -> m (IteratorResult blk b))
-> m (IteratorResult blk b)
forall r. (IteratorEnv m blk -> m r) -> m r
getItEnv ((IteratorEnv m blk -> m (IteratorResult blk b))
-> m (IteratorResult blk b))
-> (IteratorEnv m blk -> m (IteratorResult blk b))
-> m (IteratorResult blk b)
forall a b. (a -> b) -> a -> b
$
ResourceRegistry m
-> StrictTVar m (IteratorState m blk b)
-> BlockComponent blk b
-> IteratorEnv m blk
-> m (IteratorResult blk b)
forall (m :: * -> *) blk b.
(IOLike m, HasHeader blk) =>
ResourceRegistry m
-> StrictTVar m (IteratorState m blk b)
-> BlockComponent blk b
-> IteratorEnv m blk
-> m (IteratorResult blk b)
implIteratorNext ResourceRegistry m
registry StrictTVar m (IteratorState m blk b)
varItState BlockComponent blk b
blockComponent
, iteratorClose :: m ()
iteratorClose = (IteratorEnv m blk -> m ()) -> m ()
forall r. (IteratorEnv m blk -> m r) -> m r
getItEnv ((IteratorEnv m blk -> m ()) -> m ())
-> (IteratorEnv m blk -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$
StrictTVar m (IteratorState m blk b)
-> IteratorKey -> IteratorEnv m blk -> m ()
forall (m :: * -> *) blk b.
IOLike m =>
StrictTVar m (IteratorState m blk b)
-> IteratorKey -> IteratorEnv m blk -> m ()
implIteratorClose StrictTVar m (IteratorState m blk b)
varItState IteratorKey
iteratorKey
}
emptyIterator :: m (Iterator m blk b)
emptyIterator :: m (Iterator m blk b)
emptyIterator = Bool -> IteratorState m blk b -> m (Iterator m blk b)
makeIterator Bool
False IteratorState m blk b
forall (m :: * -> *) blk b. IteratorState m blk b
Closed
createIterator :: IteratorState m blk b -> m (Iterator m blk b)
createIterator :: IteratorState m blk b -> m (Iterator m blk b)
createIterator = Bool -> IteratorState m blk b -> m (Iterator m blk b)
makeIterator Bool
True
makeNewIteratorKey :: m IteratorKey
makeNewIteratorKey :: m IteratorKey
makeNewIteratorKey = STM m IteratorKey -> m IteratorKey
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m IteratorKey -> m IteratorKey)
-> STM m IteratorKey -> m IteratorKey
forall a b. (a -> b) -> a -> b
$ do
IteratorKey
newIteratorKey <- StrictTVar m IteratorKey -> STM m IteratorKey
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar StrictTVar m IteratorKey
itNextIteratorKey
StrictTVar m IteratorKey
-> (IteratorKey -> IteratorKey) -> STM m ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> (a -> a) -> STM m ()
modifyTVar StrictTVar m IteratorKey
itNextIteratorKey IteratorKey -> IteratorKey
forall a. Enum a => a -> a
succ
IteratorKey -> STM m IteratorKey
forall a. a -> STM m a
forall (m :: * -> *) a. Monad m => a -> m a
return IteratorKey
newIteratorKey
computePathVolatileDB ::
(IOLike m, HasHeader blk)
=> VolatileDB m blk
-> StreamFrom blk
-> StreamTo blk
-> m (Path blk)
computePathVolatileDB :: forall (m :: * -> *) blk.
(IOLike m, HasHeader blk) =>
VolatileDB m blk -> StreamFrom blk -> StreamTo blk -> m (Path blk)
computePathVolatileDB VolatileDB m blk
volatileDB StreamFrom blk
from StreamTo blk
to = do
HeaderHash blk -> Maybe (BlockInfo blk)
lookupBlockInfo <- STM m (HeaderHash blk -> Maybe (BlockInfo blk))
-> m (HeaderHash blk -> Maybe (BlockInfo blk))
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m (HeaderHash blk -> Maybe (BlockInfo blk))
-> m (HeaderHash blk -> Maybe (BlockInfo blk)))
-> STM m (HeaderHash blk -> Maybe (BlockInfo blk))
-> m (HeaderHash blk -> Maybe (BlockInfo blk))
forall a b. (a -> b) -> a -> b
$ VolatileDB m blk
-> HasCallStack => STM m (HeaderHash blk -> Maybe (BlockInfo blk))
forall (m :: * -> *) blk.
VolatileDB m blk
-> HasCallStack => STM m (HeaderHash blk -> Maybe (BlockInfo blk))
VolatileDB.getBlockInfo VolatileDB m blk
volatileDB
case (HeaderHash blk -> Maybe (BlockInfo blk))
-> StreamFrom blk -> StreamTo blk -> Maybe (Path blk)
forall blk.
HasHeader blk =>
LookupBlockInfo blk
-> StreamFrom blk -> StreamTo blk -> Maybe (Path blk)
computePath HeaderHash blk -> Maybe (BlockInfo blk)
lookupBlockInfo StreamFrom blk
from StreamTo blk
to of
Just Path blk
path -> Path blk -> m (Path blk)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Path blk
path
Maybe (Path blk)
Nothing -> ChainDbError blk -> m (Path blk)
forall e a. Exception e => e -> m a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO (ChainDbError blk -> m (Path blk))
-> ChainDbError blk -> m (Path blk)
forall a b. (a -> b) -> a -> b
$ StreamFrom blk -> StreamTo blk -> ChainDbError blk
forall blk. StreamFrom blk -> StreamTo blk -> ChainDbError blk
InvalidIteratorRange StreamFrom blk
from StreamTo blk
to
implIteratorClose ::
IOLike m
=> StrictTVar m (IteratorState m blk b)
-> IteratorKey
-> IteratorEnv m blk
-> m ()
implIteratorClose :: forall (m :: * -> *) blk b.
IOLike m =>
StrictTVar m (IteratorState m blk b)
-> IteratorKey -> IteratorEnv m blk -> m ()
implIteratorClose StrictTVar m (IteratorState m blk b)
varItState IteratorKey
itrKey IteratorEnv{Tracer m (TraceIteratorEvent blk)
StrictTVar m (Map IteratorKey (m ()))
StrictTVar m IteratorKey
VolatileDB m blk
ImmutableDB m blk
itImmutableDB :: forall (m :: * -> *) blk. IteratorEnv m blk -> ImmutableDB m blk
itVolatileDB :: forall (m :: * -> *) blk. IteratorEnv m blk -> VolatileDB m blk
itIterators :: forall (m :: * -> *) blk.
IteratorEnv m blk -> StrictTVar m (Map IteratorKey (m ()))
itNextIteratorKey :: forall (m :: * -> *) blk.
IteratorEnv m blk -> StrictTVar m IteratorKey
itTracer :: forall (m :: * -> *) blk.
IteratorEnv m blk -> Tracer m (TraceIteratorEvent blk)
itImmutableDB :: ImmutableDB m blk
itVolatileDB :: VolatileDB m blk
itIterators :: StrictTVar m (Map IteratorKey (m ()))
itNextIteratorKey :: StrictTVar m IteratorKey
itTracer :: Tracer m (TraceIteratorEvent blk)
..} = do
Maybe (Iterator m blk (Point blk, b))
mbImmIt <- STM m (Maybe (Iterator m blk (Point blk, b)))
-> m (Maybe (Iterator m blk (Point blk, b)))
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m (Maybe (Iterator m blk (Point blk, b)))
-> m (Maybe (Iterator m blk (Point blk, b))))
-> STM m (Maybe (Iterator m blk (Point blk, b)))
-> m (Maybe (Iterator m blk (Point blk, b)))
forall a b. (a -> b) -> a -> b
$ do
StrictTVar m (Map IteratorKey (m ()))
-> (Map IteratorKey (m ()) -> Map IteratorKey (m ())) -> STM m ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> (a -> a) -> STM m ()
modifyTVar StrictTVar m (Map IteratorKey (m ()))
itIterators (IteratorKey -> Map IteratorKey (m ()) -> Map IteratorKey (m ())
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete IteratorKey
itrKey)
Maybe (Iterator m blk (Point blk, b))
mbImmIt <- IteratorState m blk b -> Maybe (Iterator m blk (Point blk, b))
forall (m :: * -> *) blk b.
IteratorState m blk b -> Maybe (Iterator m blk (Point blk, b))
iteratorStateImmutableIt (IteratorState m blk b -> Maybe (Iterator m blk (Point blk, b)))
-> STM m (IteratorState m blk b)
-> STM m (Maybe (Iterator m blk (Point blk, b)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictTVar m (IteratorState m blk b)
-> STM m (IteratorState m blk b)
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar StrictTVar m (IteratorState m blk b)
varItState
StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState IteratorState m blk b
forall (m :: * -> *) blk b. IteratorState m blk b
Closed
Maybe (Iterator m blk (Point blk, b))
-> STM m (Maybe (Iterator m blk (Point blk, b)))
forall a. a -> STM m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Iterator m blk (Point blk, b))
mbImmIt
(Iterator m blk (Point blk, b) -> m ())
-> Maybe (Iterator m blk (Point blk, b)) -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Iterator m blk (Point blk, b) -> m ()
Iterator m blk (Point blk, b) -> HasCallStack => m ()
forall (m :: * -> *) blk b.
Iterator m blk b -> HasCallStack => m ()
ImmutableDB.iteratorClose Maybe (Iterator m blk (Point blk, b))
mbImmIt
data IteratorState m blk b
= InImmutableDB
!(StreamFrom blk)
!(ImmutableDB.Iterator m blk (Point blk, b))
!(InImmutableDBEnd blk)
| InVolatileDB
!(StreamFrom blk)
!(NonEmpty (RealPoint blk))
| InImmutableDBRetry
!(StreamFrom blk)
!(ImmutableDB.Iterator m blk (Point blk, b))
!(NonEmpty (RealPoint blk))
| Closed
deriving ((forall x. IteratorState m blk b -> Rep (IteratorState m blk b) x)
-> (forall x.
Rep (IteratorState m blk b) x -> IteratorState m blk b)
-> Generic (IteratorState m blk b)
forall x. Rep (IteratorState m blk b) x -> IteratorState m blk b
forall x. IteratorState m blk b -> Rep (IteratorState m blk b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (m :: * -> *) blk b x.
Rep (IteratorState m blk b) x -> IteratorState m blk b
forall (m :: * -> *) blk b x.
IteratorState m blk b -> Rep (IteratorState m blk b) x
$cfrom :: forall (m :: * -> *) blk b x.
IteratorState m blk b -> Rep (IteratorState m blk b) x
from :: forall x. IteratorState m blk b -> Rep (IteratorState m blk b) x
$cto :: forall (m :: * -> *) blk b x.
Rep (IteratorState m blk b) x -> IteratorState m blk b
to :: forall x. Rep (IteratorState m blk b) x -> IteratorState m blk b
Generic)
instance (Typeable blk, StandardHash blk)
=> NoThunks (IteratorState m blk b)
iteratorStateImmutableIt ::
IteratorState m blk b
-> Maybe (ImmutableDB.Iterator m blk (Point blk, b))
iteratorStateImmutableIt :: forall (m :: * -> *) blk b.
IteratorState m blk b -> Maybe (Iterator m blk (Point blk, b))
iteratorStateImmutableIt = \case
IteratorState m blk b
Closed -> Maybe (Iterator m blk (Point blk, b))
forall a. Maybe a
Nothing
InImmutableDB StreamFrom blk
_ Iterator m blk (Point blk, b)
immIt InImmutableDBEnd blk
_ -> Iterator m blk (Point blk, b)
-> Maybe (Iterator m blk (Point blk, b))
forall a. a -> Maybe a
Just Iterator m blk (Point blk, b)
immIt
InImmutableDBRetry StreamFrom blk
_ Iterator m blk (Point blk, b)
immIt NonEmpty (RealPoint blk)
_ -> Iterator m blk (Point blk, b)
-> Maybe (Iterator m blk (Point blk, b))
forall a. a -> Maybe a
Just Iterator m blk (Point blk, b)
immIt
InVolatileDB {} -> Maybe (Iterator m blk (Point blk, b))
forall a. Maybe a
Nothing
data InImmutableDBEnd blk =
StreamAll
| StreamTo !(StreamTo blk)
| SwitchToVolatileDBFrom !(StreamTo blk) !(NonEmpty (RealPoint blk))
deriving ((forall x. InImmutableDBEnd blk -> Rep (InImmutableDBEnd blk) x)
-> (forall x. Rep (InImmutableDBEnd blk) x -> InImmutableDBEnd blk)
-> Generic (InImmutableDBEnd blk)
forall x. Rep (InImmutableDBEnd blk) x -> InImmutableDBEnd blk
forall x. InImmutableDBEnd blk -> Rep (InImmutableDBEnd blk) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall blk x. Rep (InImmutableDBEnd blk) x -> InImmutableDBEnd blk
forall blk x. InImmutableDBEnd blk -> Rep (InImmutableDBEnd blk) x
$cfrom :: forall blk x. InImmutableDBEnd blk -> Rep (InImmutableDBEnd blk) x
from :: forall x. InImmutableDBEnd blk -> Rep (InImmutableDBEnd blk) x
$cto :: forall blk x. Rep (InImmutableDBEnd blk) x -> InImmutableDBEnd blk
to :: forall x. Rep (InImmutableDBEnd blk) x -> InImmutableDBEnd blk
Generic, Context -> InImmutableDBEnd blk -> IO (Maybe ThunkInfo)
Proxy (InImmutableDBEnd blk) -> String
(Context -> InImmutableDBEnd blk -> IO (Maybe ThunkInfo))
-> (Context -> InImmutableDBEnd blk -> IO (Maybe ThunkInfo))
-> (Proxy (InImmutableDBEnd blk) -> String)
-> NoThunks (InImmutableDBEnd blk)
forall blk.
(StandardHash blk, Typeable blk) =>
Context -> InImmutableDBEnd blk -> IO (Maybe ThunkInfo)
forall blk.
(StandardHash blk, Typeable blk) =>
Proxy (InImmutableDBEnd blk) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: forall blk.
(StandardHash blk, Typeable blk) =>
Context -> InImmutableDBEnd blk -> IO (Maybe ThunkInfo)
noThunks :: Context -> InImmutableDBEnd blk -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall blk.
(StandardHash blk, Typeable blk) =>
Context -> InImmutableDBEnd blk -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> InImmutableDBEnd blk -> IO (Maybe ThunkInfo)
$cshowTypeOf :: forall blk.
(StandardHash blk, Typeable blk) =>
Proxy (InImmutableDBEnd blk) -> String
showTypeOf :: Proxy (InImmutableDBEnd blk) -> String
NoThunks)
implIteratorNext ::
forall m blk b. (IOLike m, HasHeader blk)
=> ResourceRegistry m
-> StrictTVar m (IteratorState m blk b)
-> BlockComponent blk b
-> IteratorEnv m blk
-> m (IteratorResult blk b)
implIteratorNext :: forall (m :: * -> *) blk b.
(IOLike m, HasHeader blk) =>
ResourceRegistry m
-> StrictTVar m (IteratorState m blk b)
-> BlockComponent blk b
-> IteratorEnv m blk
-> m (IteratorResult blk b)
implIteratorNext ResourceRegistry m
registry StrictTVar m (IteratorState m blk b)
varItState BlockComponent blk b
blockComponent IteratorEnv{Tracer m (TraceIteratorEvent blk)
StrictTVar m (Map IteratorKey (m ()))
StrictTVar m IteratorKey
VolatileDB m blk
ImmutableDB m blk
itImmutableDB :: forall (m :: * -> *) blk. IteratorEnv m blk -> ImmutableDB m blk
itVolatileDB :: forall (m :: * -> *) blk. IteratorEnv m blk -> VolatileDB m blk
itIterators :: forall (m :: * -> *) blk.
IteratorEnv m blk -> StrictTVar m (Map IteratorKey (m ()))
itNextIteratorKey :: forall (m :: * -> *) blk.
IteratorEnv m blk -> StrictTVar m IteratorKey
itTracer :: forall (m :: * -> *) blk.
IteratorEnv m blk -> Tracer m (TraceIteratorEvent blk)
itImmutableDB :: ImmutableDB m blk
itVolatileDB :: VolatileDB m blk
itIterators :: StrictTVar m (Map IteratorKey (m ()))
itNextIteratorKey :: StrictTVar m IteratorKey
itTracer :: Tracer m (TraceIteratorEvent blk)
..} =
STM m (IteratorState m blk b) -> m (IteratorState m blk b)
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (StrictTVar m (IteratorState m blk b)
-> STM m (IteratorState m blk b)
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar StrictTVar m (IteratorState m blk b)
varItState) m (IteratorState m blk b)
-> (IteratorState m blk b -> m (IteratorResult blk b))
-> m (IteratorResult blk b)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
IteratorState m blk b
Closed ->
IteratorResult blk b -> m (IteratorResult blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return IteratorResult blk b
forall blk b. IteratorResult blk b
IteratorExhausted
InImmutableDB StreamFrom blk
continueAfter Iterator m blk (Point blk, b)
immIt InImmutableDBEnd blk
immEnd ->
StreamFrom blk
-> Iterator m blk (Point blk, b)
-> InImmutableDBEnd blk
-> m (IteratorResult blk b)
nextInImmutableDB StreamFrom blk
continueAfter Iterator m blk (Point blk, b)
immIt InImmutableDBEnd blk
immEnd
InImmutableDBRetry StreamFrom blk
continueAfter Iterator m blk (Point blk, b)
immIt NonEmpty (RealPoint blk)
immPts ->
Maybe (StreamFrom blk)
-> Iterator m blk (Point blk, b)
-> NonEmpty (RealPoint blk)
-> m (IteratorResult blk b)
nextInImmutableDBRetry (StreamFrom blk -> Maybe (StreamFrom blk)
forall a. a -> Maybe a
Just StreamFrom blk
continueAfter) Iterator m blk (Point blk, b)
immIt NonEmpty (RealPoint blk)
immPts
InVolatileDB StreamFrom blk
continueAfter NonEmpty (RealPoint blk)
volPts ->
StreamFrom blk
-> NonEmpty (RealPoint blk) -> m (IteratorResult blk b)
nextInVolatileDB StreamFrom blk
continueAfter NonEmpty (RealPoint blk)
volPts
where
trace :: TraceIteratorEvent blk -> m ()
trace = Tracer m (TraceIteratorEvent blk) -> TraceIteratorEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (TraceIteratorEvent blk)
itTracer
nextInVolatileDB ::
StreamFrom blk
-> NonEmpty (RealPoint blk)
-> m (IteratorResult blk b)
nextInVolatileDB :: StreamFrom blk
-> NonEmpty (RealPoint blk) -> m (IteratorResult blk b)
nextInVolatileDB StreamFrom blk
continueFrom (pt :: RealPoint blk
pt@(RealPoint blk -> HeaderHash blk
forall blk. RealPoint blk -> HeaderHash blk
realPointHash -> HeaderHash blk
hash) NE.:| [RealPoint blk]
pts) =
VolatileDB m blk
-> forall b.
HasCallStack =>
BlockComponent blk b -> HeaderHash blk -> m (Maybe b)
forall (m :: * -> *) blk.
VolatileDB m blk
-> forall b.
HasCallStack =>
BlockComponent blk b -> HeaderHash blk -> m (Maybe b)
VolatileDB.getBlockComponent VolatileDB m blk
itVolatileDB BlockComponent blk b
blockComponent HeaderHash blk
hash m (Maybe b)
-> (Maybe b -> m (IteratorResult blk b))
-> m (IteratorResult blk b)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Maybe b
Nothing -> do
TraceIteratorEvent blk -> m ()
trace (TraceIteratorEvent blk -> m ()) -> TraceIteratorEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ RealPoint blk -> TraceIteratorEvent blk
forall blk. RealPoint blk -> TraceIteratorEvent blk
BlockMissingFromVolatileDB RealPoint blk
pt
((Tip blk -> RealPoint blk)
-> WithOrigin (Tip blk) -> WithOrigin (RealPoint blk)
forall a b. (a -> b) -> WithOrigin a -> WithOrigin b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Tip blk -> RealPoint blk
forall blk. Tip blk -> RealPoint blk
ImmutableDB.tipToRealPoint (WithOrigin (Tip blk) -> WithOrigin (RealPoint blk))
-> m (WithOrigin (Tip blk)) -> m (WithOrigin (RealPoint blk))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
STM m (WithOrigin (Tip blk)) -> m (WithOrigin (Tip blk))
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (ImmutableDB m blk -> STM m (WithOrigin (Tip blk))
forall (m :: * -> *) blk.
HasCallStack =>
ImmutableDB m blk -> STM m (WithOrigin (Tip blk))
ImmutableDB.getTip ImmutableDB m blk
itImmutableDB)) m (WithOrigin (RealPoint blk))
-> (WithOrigin (RealPoint blk) -> m (IteratorResult blk b))
-> m (IteratorResult blk b)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
WithOrigin (RealPoint blk)
Origin ->
String -> m (IteratorResult blk b)
forall a. HasCallStack => String -> a
error String
"nextInVolatileDB: impossible"
NotOrigin RealPoint blk
tip -> do
Either (MissingBlock blk) (Iterator m blk (Point blk, b))
errOrIt <- ImmutableDB m blk
-> ResourceRegistry m
-> BlockComponent blk (Point blk, b)
-> StreamFrom blk
-> StreamTo blk
-> m (Either (MissingBlock blk) (Iterator m blk (Point blk, b)))
forall (m :: * -> *) blk b.
HasCallStack =>
ImmutableDB m blk
-> ResourceRegistry m
-> BlockComponent blk b
-> StreamFrom blk
-> StreamTo blk
-> m (Either (MissingBlock blk) (Iterator m blk b))
ImmutableDB.stream
ImmutableDB m blk
itImmutableDB
ResourceRegistry m
registry
((,) (Point blk -> b -> (Point blk, b))
-> BlockComponent blk (Point blk)
-> BlockComponent blk (b -> (Point blk, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BlockComponent blk (Point blk)
forall blk. BlockComponent blk (Point blk)
getPoint BlockComponent blk (b -> (Point blk, b))
-> BlockComponent blk b -> BlockComponent blk (Point blk, b)
forall a b.
BlockComponent blk (a -> b)
-> BlockComponent blk a -> BlockComponent blk b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> BlockComponent blk b
blockComponent)
StreamFrom blk
continueFrom
(RealPoint blk -> StreamTo blk
forall blk. RealPoint blk -> StreamTo blk
StreamToInclusive RealPoint blk
tip)
case Either (MissingBlock blk) (Iterator m blk (Point blk, b))
errOrIt of
Left MissingBlock blk
_ -> do
TraceIteratorEvent blk -> m ()
trace (TraceIteratorEvent blk -> m ()) -> TraceIteratorEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ RealPoint blk -> TraceIteratorEvent blk
forall blk. RealPoint blk -> TraceIteratorEvent blk
BlockGCedFromVolatileDB RealPoint blk
pt
IteratorResult blk b -> m (IteratorResult blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IteratorResult blk b -> m (IteratorResult blk b))
-> IteratorResult blk b -> m (IteratorResult blk b)
forall a b. (a -> b) -> a -> b
$ RealPoint blk -> IteratorResult blk b
forall blk b. RealPoint blk -> IteratorResult blk b
IteratorBlockGCed RealPoint blk
pt
Right Iterator m blk (Point blk, b)
immIt ->
Maybe (StreamFrom blk)
-> Iterator m blk (Point blk, b)
-> NonEmpty (RealPoint blk)
-> m (IteratorResult blk b)
nextInImmutableDBRetry Maybe (StreamFrom blk)
forall a. Maybe a
Nothing Iterator m blk (Point blk, b)
immIt (RealPoint blk
pt RealPoint blk -> [RealPoint blk] -> NonEmpty (RealPoint blk)
forall a. a -> [a] -> NonEmpty a
NE.:| [RealPoint blk]
pts)
Just b
b | Just NonEmpty (RealPoint blk)
pts' <- [RealPoint blk] -> Maybe (NonEmpty (RealPoint blk))
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [RealPoint blk]
pts -> do
let continueFrom' :: StreamFrom blk
continueFrom' = Point blk -> StreamFrom blk
forall blk. Point blk -> StreamFrom blk
StreamFromExclusive (RealPoint blk -> Point blk
forall blk. RealPoint blk -> Point blk
realPointToPoint RealPoint blk
pt)
STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState (StreamFrom blk -> NonEmpty (RealPoint blk) -> IteratorState m blk b
forall (m :: * -> *) blk b.
StreamFrom blk -> NonEmpty (RealPoint blk) -> IteratorState m blk b
InVolatileDB StreamFrom blk
continueFrom' NonEmpty (RealPoint blk)
pts')
IteratorResult blk b -> m (IteratorResult blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IteratorResult blk b -> m (IteratorResult blk b))
-> IteratorResult blk b -> m (IteratorResult blk b)
forall a b. (a -> b) -> a -> b
$ b -> IteratorResult blk b
forall blk b. b -> IteratorResult blk b
IteratorResult b
b
Just b
b -> do
STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState IteratorState m blk b
forall (m :: * -> *) blk b. IteratorState m blk b
Closed
IteratorResult blk b -> m (IteratorResult blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IteratorResult blk b -> m (IteratorResult blk b))
-> IteratorResult blk b -> m (IteratorResult blk b)
forall a b. (a -> b) -> a -> b
$ b -> IteratorResult blk b
forall blk b. b -> IteratorResult blk b
IteratorResult b
b
nextInImmutableDB ::
StreamFrom blk
-> ImmutableDB.Iterator m blk (Point blk, b)
-> InImmutableDBEnd blk
-> m (IteratorResult blk b)
nextInImmutableDB :: StreamFrom blk
-> Iterator m blk (Point blk, b)
-> InImmutableDBEnd blk
-> m (IteratorResult blk b)
nextInImmutableDB StreamFrom blk
continueFrom Iterator m blk (Point blk, b)
immIt InImmutableDBEnd blk
immEnd =
Iterator m blk (Point blk, b) -> m (Done (Point blk, b))
selectResult Iterator m blk (Point blk, b)
immIt m (Done (Point blk, b))
-> (Done (Point blk, b) -> m (IteratorResult blk b))
-> m (IteratorResult blk b)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
NotDone (Point blk
pt, b
b) -> do
let continueFrom' :: StreamFrom blk
continueFrom' = Point blk -> StreamFrom blk
forall blk. Point blk -> StreamFrom blk
StreamFromExclusive Point blk
pt
STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState (StreamFrom blk
-> Iterator m blk (Point blk, b)
-> InImmutableDBEnd blk
-> IteratorState m blk b
forall (m :: * -> *) blk b.
StreamFrom blk
-> Iterator m blk (Point blk, b)
-> InImmutableDBEnd blk
-> IteratorState m blk b
InImmutableDB StreamFrom blk
continueFrom' Iterator m blk (Point blk, b)
immIt InImmutableDBEnd blk
immEnd)
IteratorResult blk b -> m (IteratorResult blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IteratorResult blk b -> m (IteratorResult blk b))
-> IteratorResult blk b -> m (IteratorResult blk b)
forall a b. (a -> b) -> a -> b
$ b -> IteratorResult blk b
forall blk b. b -> IteratorResult blk b
IteratorResult b
b
DoneAfter (Point blk
pt, b
b) | SwitchToVolatileDBFrom StreamTo blk
_ NonEmpty (RealPoint blk)
pts <- InImmutableDBEnd blk
immEnd -> do
let continueFrom' :: StreamFrom blk
continueFrom' = Point blk -> StreamFrom blk
forall blk. Point blk -> StreamFrom blk
StreamFromExclusive Point blk
pt
STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState (StreamFrom blk -> NonEmpty (RealPoint blk) -> IteratorState m blk b
forall (m :: * -> *) blk b.
StreamFrom blk -> NonEmpty (RealPoint blk) -> IteratorState m blk b
InVolatileDB StreamFrom blk
continueFrom' NonEmpty (RealPoint blk)
pts)
IteratorResult blk b -> m (IteratorResult blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IteratorResult blk b -> m (IteratorResult blk b))
-> IteratorResult blk b -> m (IteratorResult blk b)
forall a b. (a -> b) -> a -> b
$ b -> IteratorResult blk b
forall blk b. b -> IteratorResult blk b
IteratorResult b
b
DoneAfter (Point blk
_pt, b
b) -> do
STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState IteratorState m blk b
forall (m :: * -> *) blk b. IteratorState m blk b
Closed
IteratorResult blk b -> m (IteratorResult blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IteratorResult blk b -> m (IteratorResult blk b))
-> IteratorResult blk b -> m (IteratorResult blk b)
forall a b. (a -> b) -> a -> b
$ b -> IteratorResult blk b
forall blk b. b -> IteratorResult blk b
IteratorResult b
b
Done (Point blk, b)
Done | SwitchToVolatileDBFrom StreamTo blk
_ NonEmpty (RealPoint blk)
pts <- InImmutableDBEnd blk
immEnd ->
StreamFrom blk
-> NonEmpty (RealPoint blk) -> m (IteratorResult blk b)
nextInVolatileDB StreamFrom blk
continueFrom NonEmpty (RealPoint blk)
pts
Done (Point blk, b)
Done -> do
STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState IteratorState m blk b
forall (m :: * -> *) blk b. IteratorState m blk b
Closed
IteratorResult blk b -> m (IteratorResult blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return IteratorResult blk b
forall blk b. IteratorResult blk b
IteratorExhausted
nextInImmutableDBRetry ::
Maybe (StreamFrom blk)
-> ImmutableDB.Iterator m blk (Point blk, b)
-> NonEmpty (RealPoint blk)
-> m (IteratorResult blk b)
nextInImmutableDBRetry :: Maybe (StreamFrom blk)
-> Iterator m blk (Point blk, b)
-> NonEmpty (RealPoint blk)
-> m (IteratorResult blk b)
nextInImmutableDBRetry Maybe (StreamFrom blk)
mbContinueFrom Iterator m blk (Point blk, b)
immIt (RealPoint blk
expectedPt NE.:| [RealPoint blk]
pts) =
Iterator m blk (Point blk, b) -> m (Done (Point blk, b))
selectResult Iterator m blk (Point blk, b)
immIt m (Done (Point blk, b))
-> (Done (Point blk, b) -> m (IteratorResult blk b))
-> m (IteratorResult blk b)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
NotDone (Point blk
actualPt, b
b) | Point blk
actualPt Point blk -> Point blk -> Bool
forall a. Eq a => a -> a -> Bool
== RealPoint blk -> Point blk
forall blk. RealPoint blk -> Point blk
realPointToPoint RealPoint blk
expectedPt -> do
TraceIteratorEvent blk -> m ()
trace (TraceIteratorEvent blk -> m ()) -> TraceIteratorEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ RealPoint blk -> TraceIteratorEvent blk
forall blk. RealPoint blk -> TraceIteratorEvent blk
BlockWasCopiedToImmutableDB RealPoint blk
expectedPt
let continueFrom' :: StreamFrom blk
continueFrom' = Point blk -> StreamFrom blk
forall blk. Point blk -> StreamFrom blk
StreamFromExclusive (RealPoint blk -> Point blk
forall blk. RealPoint blk -> Point blk
realPointToPoint RealPoint blk
expectedPt)
case [RealPoint blk] -> Maybe (NonEmpty (RealPoint blk))
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [RealPoint blk]
pts of
Maybe (NonEmpty (RealPoint blk))
Nothing -> do
STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState IteratorState m blk b
forall (m :: * -> *) blk b. IteratorState m blk b
Closed
Iterator m blk (Point blk, b) -> HasCallStack => m ()
forall (m :: * -> *) blk b.
Iterator m blk b -> HasCallStack => m ()
ImmutableDB.iteratorClose Iterator m blk (Point blk, b)
immIt
Just NonEmpty (RealPoint blk)
pts' ->
STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState (IteratorState m blk b -> STM m ())
-> IteratorState m blk b -> STM m ()
forall a b. (a -> b) -> a -> b
$
StreamFrom blk
-> Iterator m blk (Point blk, b)
-> NonEmpty (RealPoint blk)
-> IteratorState m blk b
forall (m :: * -> *) blk b.
StreamFrom blk
-> Iterator m blk (Point blk, b)
-> NonEmpty (RealPoint blk)
-> IteratorState m blk b
InImmutableDBRetry StreamFrom blk
continueFrom' Iterator m blk (Point blk, b)
immIt NonEmpty (RealPoint blk)
pts'
IteratorResult blk b -> m (IteratorResult blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IteratorResult blk b -> m (IteratorResult blk b))
-> IteratorResult blk b -> m (IteratorResult blk b)
forall a b. (a -> b) -> a -> b
$ b -> IteratorResult blk b
forall blk b. b -> IteratorResult blk b
IteratorResult b
b
DoneAfter (Point blk
actualPt, b
b) | Point blk
actualPt Point blk -> Point blk -> Bool
forall a. Eq a => a -> a -> Bool
== RealPoint blk -> Point blk
forall blk. RealPoint blk -> Point blk
realPointToPoint RealPoint blk
expectedPt -> do
TraceIteratorEvent blk -> m ()
trace (TraceIteratorEvent blk -> m ()) -> TraceIteratorEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ RealPoint blk -> TraceIteratorEvent blk
forall blk. RealPoint blk -> TraceIteratorEvent blk
BlockWasCopiedToImmutableDB RealPoint blk
expectedPt
let continueFrom' :: StreamFrom blk
continueFrom' = Point blk -> StreamFrom blk
forall blk. Point blk -> StreamFrom blk
StreamFromExclusive (RealPoint blk -> Point blk
forall blk. RealPoint blk -> Point blk
realPointToPoint RealPoint blk
expectedPt)
case [RealPoint blk] -> Maybe (NonEmpty (RealPoint blk))
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [RealPoint blk]
pts of
Maybe (NonEmpty (RealPoint blk))
Nothing -> STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState IteratorState m blk b
forall (m :: * -> *) blk b. IteratorState m blk b
Closed
Just NonEmpty (RealPoint blk)
pts' -> do
STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState (IteratorState m blk b -> STM m ())
-> IteratorState m blk b -> STM m ()
forall a b. (a -> b) -> a -> b
$ StreamFrom blk -> NonEmpty (RealPoint blk) -> IteratorState m blk b
forall (m :: * -> *) blk b.
StreamFrom blk -> NonEmpty (RealPoint blk) -> IteratorState m blk b
InVolatileDB StreamFrom blk
continueFrom' NonEmpty (RealPoint blk)
pts'
TraceIteratorEvent blk -> m ()
trace TraceIteratorEvent blk
forall blk. TraceIteratorEvent blk
SwitchBackToVolatileDB
IteratorResult blk b -> m (IteratorResult blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IteratorResult blk b -> m (IteratorResult blk b))
-> IteratorResult blk b -> m (IteratorResult blk b)
forall a b. (a -> b) -> a -> b
$ b -> IteratorResult blk b
forall blk b. b -> IteratorResult blk b
IteratorResult b
b
Done (Point blk, b)
_ -> Iterator m blk (Point blk, b) -> HasCallStack => m ()
forall (m :: * -> *) blk b.
Iterator m blk b -> HasCallStack => m ()
ImmutableDB.iteratorClose Iterator m blk (Point blk, b)
immIt m () -> m (IteratorResult blk b) -> m (IteratorResult blk b)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> case Maybe (StreamFrom blk)
mbContinueFrom of
Maybe (StreamFrom blk)
Nothing -> do
STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ StrictTVar m (IteratorState m blk b)
-> IteratorState m blk b -> STM m ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar m (IteratorState m blk b)
varItState IteratorState m blk b
forall (m :: * -> *) blk b. IteratorState m blk b
Closed
TraceIteratorEvent blk -> m ()
trace (TraceIteratorEvent blk -> m ()) -> TraceIteratorEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ RealPoint blk -> TraceIteratorEvent blk
forall blk. RealPoint blk -> TraceIteratorEvent blk
BlockGCedFromVolatileDB RealPoint blk
expectedPt
IteratorResult blk b -> m (IteratorResult blk b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IteratorResult blk b -> m (IteratorResult blk b))
-> IteratorResult blk b -> m (IteratorResult blk b)
forall a b. (a -> b) -> a -> b
$ RealPoint blk -> IteratorResult blk b
forall blk b. RealPoint blk -> IteratorResult blk b
IteratorBlockGCed RealPoint blk
expectedPt
Just StreamFrom blk
continueFrom -> do
TraceIteratorEvent blk -> m ()
trace TraceIteratorEvent blk
forall blk. TraceIteratorEvent blk
SwitchBackToVolatileDB
StreamFrom blk
-> NonEmpty (RealPoint blk) -> m (IteratorResult blk b)
nextInVolatileDB StreamFrom blk
continueFrom (RealPoint blk
expectedPt RealPoint blk -> [RealPoint blk] -> NonEmpty (RealPoint blk)
forall a. a -> [a] -> NonEmpty a
NE.:| [RealPoint blk]
pts)
selectResult ::
ImmutableDB.Iterator m blk (Point blk, b)
-> m (Done (Point blk, b))
selectResult :: Iterator m blk (Point blk, b) -> m (Done (Point blk, b))
selectResult Iterator m blk (Point blk, b)
immIt = do
IteratorResult (Point blk, b)
itRes <- Iterator m blk (Point blk, b)
-> HasCallStack => m (IteratorResult (Point blk, b))
forall (m :: * -> *) blk b.
Iterator m blk b -> HasCallStack => m (IteratorResult b)
ImmutableDB.iteratorNext Iterator m blk (Point blk, b)
immIt
Bool
hasNext <- Maybe (RealPoint blk) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (RealPoint blk) -> Bool)
-> m (Maybe (RealPoint blk)) -> m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM m (Maybe (RealPoint blk)) -> m (Maybe (RealPoint blk))
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (Iterator m blk (Point blk, b)
-> HasCallStack => STM m (Maybe (RealPoint blk))
forall (m :: * -> *) blk b.
Iterator m blk b -> HasCallStack => STM m (Maybe (RealPoint blk))
ImmutableDB.iteratorHasNext Iterator m blk (Point blk, b)
immIt)
case IteratorResult (Point blk, b)
itRes of
ImmutableDB.IteratorResult (Point blk, b)
blk -> (Point blk, b) -> Bool -> m (Done (Point blk, b))
forall {blk}. blk -> Bool -> m (Done blk)
select (Point blk, b)
blk Bool
hasNext
IteratorResult (Point blk, b)
ImmutableDB.IteratorExhausted -> Done (Point blk, b) -> m (Done (Point blk, b))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Done (Point blk, b)
forall blk. Done blk
Done
where
select :: blk -> Bool -> m (Done blk)
select blk
blk Bool
hasNext
| Bool
hasNext
= Done blk -> m (Done blk)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Done blk -> m (Done blk)) -> Done blk -> m (Done blk)
forall a b. (a -> b) -> a -> b
$ blk -> Done blk
forall blk. blk -> Done blk
NotDone blk
blk
| Bool
otherwise
= Iterator m blk (Point blk, b) -> HasCallStack => m ()
forall (m :: * -> *) blk b.
Iterator m blk b -> HasCallStack => m ()
ImmutableDB.iteratorClose Iterator m blk (Point blk, b)
immIt m () -> Done blk -> m (Done blk)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> blk -> Done blk
forall blk. blk -> Done blk
DoneAfter blk
blk
data Done blk =
Done
| DoneAfter blk
| NotDone blk
missingBlockToUnknownRange ::
ImmutableDB.MissingBlock blk
-> UnknownRange blk
missingBlockToUnknownRange :: forall blk. MissingBlock blk -> UnknownRange blk
missingBlockToUnknownRange = RealPoint blk -> UnknownRange blk
forall blk. RealPoint blk -> UnknownRange blk
MissingBlock (RealPoint blk -> UnknownRange blk)
-> (MissingBlock blk -> RealPoint blk)
-> MissingBlock blk
-> UnknownRange blk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MissingBlock blk -> RealPoint blk
forall blk. MissingBlock blk -> RealPoint blk
ImmutableDB.missingBlockPoint
closeAllIterators :: IOLike m => ChainDbEnv m blk -> m ()
closeAllIterators :: forall (m :: * -> *) blk. IOLike m => ChainDbEnv m blk -> m ()
closeAllIterators CDB{m (LoE (AnchoredFragment (Header blk)))
Tracer m (TraceEvent blk)
DiffTime
ResourceRegistry m
StrictTVar m (m ())
StrictTVar m (Map FollowerKey (FollowerHandle m blk))
StrictTVar m (Map IteratorKey (m ()))
StrictTVar m (StrictMaybe (Header blk))
StrictTVar m (AnchoredFragment (Header blk))
StrictTVar m (TentativeHeaderState blk)
StrictTVar m (WithFingerprint (InvalidBlocks blk))
StrictTVar m FollowerKey
StrictTVar m IteratorKey
Fuse m
TopLevelConfig blk
VolatileDB m blk
ImmutableDB m blk
LgrDB m blk
ChainSelQueue m blk
cdbImmutableDB :: forall (m :: * -> *) blk. ChainDbEnv m blk -> ImmutableDB m blk
cdbVolatileDB :: forall (m :: * -> *) blk. ChainDbEnv m blk -> VolatileDB m blk
cdbLgrDB :: forall (m :: * -> *) blk. ChainDbEnv m blk -> LgrDB m blk
cdbChain :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m (AnchoredFragment (Header blk))
cdbTentativeState :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m (TentativeHeaderState blk)
cdbTentativeHeader :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m (StrictMaybe (Header blk))
cdbIterators :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m (Map IteratorKey (m ()))
cdbFollowers :: forall (m :: * -> *) blk.
ChainDbEnv m blk
-> StrictTVar m (Map FollowerKey (FollowerHandle m blk))
cdbTopLevelConfig :: forall (m :: * -> *) blk. ChainDbEnv m blk -> TopLevelConfig blk
cdbInvalid :: forall (m :: * -> *) blk.
ChainDbEnv m blk
-> StrictTVar m (WithFingerprint (InvalidBlocks blk))
cdbNextIteratorKey :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m IteratorKey
cdbNextFollowerKey :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> StrictTVar m FollowerKey
cdbCopyFuse :: forall (m :: * -> *) blk. ChainDbEnv m blk -> Fuse m
cdbChainSelFuse :: forall (m :: * -> *) blk. ChainDbEnv m blk -> Fuse m
cdbTracer :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> Tracer m (TraceEvent blk)
cdbRegistry :: forall (m :: * -> *) blk. ChainDbEnv m blk -> ResourceRegistry m
cdbGcDelay :: forall (m :: * -> *) blk. ChainDbEnv m blk -> DiffTime
cdbGcInterval :: forall (m :: * -> *) blk. ChainDbEnv m blk -> DiffTime
cdbKillBgThreads :: forall (m :: * -> *) blk. ChainDbEnv m blk -> StrictTVar m (m ())
cdbChainSelQueue :: forall (m :: * -> *) blk. ChainDbEnv m blk -> ChainSelQueue m blk
cdbLoE :: forall (m :: * -> *) blk.
ChainDbEnv m blk -> m (LoE (AnchoredFragment (Header blk)))
cdbImmutableDB :: ImmutableDB m blk
cdbVolatileDB :: VolatileDB m blk
cdbLgrDB :: LgrDB m blk
cdbChain :: StrictTVar m (AnchoredFragment (Header blk))
cdbTentativeState :: StrictTVar m (TentativeHeaderState blk)
cdbTentativeHeader :: StrictTVar m (StrictMaybe (Header blk))
cdbIterators :: StrictTVar m (Map IteratorKey (m ()))
cdbFollowers :: StrictTVar m (Map FollowerKey (FollowerHandle m blk))
cdbTopLevelConfig :: TopLevelConfig blk
cdbInvalid :: StrictTVar m (WithFingerprint (InvalidBlocks blk))
cdbNextIteratorKey :: StrictTVar m IteratorKey
cdbNextFollowerKey :: StrictTVar m FollowerKey
cdbCopyFuse :: Fuse m
cdbChainSelFuse :: Fuse m
cdbTracer :: Tracer m (TraceEvent blk)
cdbRegistry :: ResourceRegistry m
cdbGcDelay :: DiffTime
cdbGcInterval :: DiffTime
cdbKillBgThreads :: StrictTVar m (m ())
cdbChainSelQueue :: ChainSelQueue m blk
cdbLoE :: m (LoE (AnchoredFragment (Header blk)))
..} = do
[m ()]
iteratorClosers <- STM m [m ()] -> m [m ()]
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m [m ()] -> m [m ()]) -> STM m [m ()] -> m [m ()]
forall a b. (a -> b) -> a -> b
$ Map IteratorKey (m ()) -> [m ()]
forall k a. Map k a -> [a]
Map.elems (Map IteratorKey (m ()) -> [m ()])
-> STM m (Map IteratorKey (m ())) -> STM m [m ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictTVar m (Map IteratorKey (m ()))
-> STM m (Map IteratorKey (m ()))
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar StrictTVar m (Map IteratorKey (m ()))
cdbIterators
[m ()] -> m ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ [m ()]
iteratorClosers