pub struct SegmentManager(/* private fields */);Expand description
Keeps the public segments of every (src, dst) pair that is in use available and fresh.
A pair starts being managed the first time it is asked for, is refetched before its
segments expire, and is evicted once it has not been used for
SegmentManagerConfig::idle_eviction_time.
A consumer that keeps using a pair longer than that must hold a PairGuard from
Self::hold_pair on it, which exempts it from eviction.
Cheap to clone; all clones share the same state.
Implementations§
Source§impl SegmentManager
impl SegmentManager
Sourcepub fn new(
config: SegmentManagerConfig,
segment_fetcher: Box<dyn SegmentsDiscovery>,
) -> Result<Self>
pub fn new( config: SegmentManagerConfig, segment_fetcher: Box<dyn SegmentsDiscovery>, ) -> Result<Self>
Creates a new, empty segment manager with the timings of config.
Returns an error if config does not SegmentManagerConfig::validate.
Sourcepub async fn segment(
&self,
id: SegmentStoreId,
now: SystemTime,
) -> Option<SignedPathSegment>
pub async fn segment( &self, id: SegmentStoreId, now: SystemTime, ) -> Option<SignedPathSegment>
Returns the segment with the given fingerprint, if it is in the store.
Counts as a use of the segment’s (src, dst) pair.
Sourcepub async fn hold_pair(
&self,
src: IsdAsn,
dst: IsdAsn,
now: SystemTime,
) -> Result<PairGuard>
pub async fn hold_pair( &self, src: IsdAsn, dst: IsdAsn, now: SystemTime, ) -> Result<PairGuard>
Keeps the given (src, dst) pair managed for as long as the returned guard is held, fetching its segments if it is not managed yet.
A guarded pair is exempt from idle eviction, so a long lived consumer cannot have the segments it depends on evicted out from under it. Refreshing is unaffected: a guarded pair keeps being refetched as its segments approach expiry.
Sourcepub async fn segments<'this>(
&'this self,
src: IsdAsn,
dst: IsdAsn,
now: SystemTime,
) -> Result<SegmentsIter<'this>>
pub async fn segments<'this>( &'this self, src: IsdAsn, dst: IsdAsn, now: SystemTime, ) -> Result<SegmentsIter<'this>>
Returns a SegmentsIter for the given (src, dst) pair, fetching segments if
necessary.
Allows iterating over all core and non-core segments for the given (src, dst) pair.
Sourcepub async fn run(&self)
pub async fn run(&self)
Runs the maintenance loop for the segment manager, which periodically evicts unused (src, dst) pairs and refetches the ones that are due for a refresh.
Reads the wall clock itself, unlike every other entry point. Never returns.
Sourcepub async fn maintain(&self, now: SystemTime) -> SystemTime
pub async fn maintain(&self, now: SystemTime) -> SystemTime
Maintains the segment store by removing unused entries and fetching new segments for (src, dst) pairs that are due for refresh.
Returns the next scheduled maintenance time, which is the earliest next refresh time of all (src, dst) pairs in the store.
If no (src, dst) pairs are due for refresh, the next maintenance time is the maximum segment fetch interval from now.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for SegmentManager
impl !UnwindSafe for SegmentManager
impl Freeze for SegmentManager
impl Send for SegmentManager
impl Sync for SegmentManager
impl Unpin for SegmentManager
impl UnsafeUnpin for SegmentManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more