Skip to main content

FetcherState

Struct FetcherState 

Source
pub struct FetcherState { /* private fields */ }
Expand description

Logical state for Git fetches happening in the node.

A fetch can either be:

  • ActiveFetch: meaning it is currently being fetched from another node on the network
  • QueuedFetch: meaning it is expected to be fetched from a given node, but the repository is already being fetched, or the node is at capacity.

For any given repository, identified by its RepoId, there can only be one fetch occurring for it at a given time. This prevents any concurrent fetches from clobbering overlapping references.

If the repository is actively being fetched, then that fetch will be queued for a later attempt.

For any given node, there is a configurable capacity so that only N number of fetches can happen with it concurrently. This does not guarantee that the node will actually allow this node to fetch from it – since it will maintain its own capacity for connections and load.

Implementations§

Source§

impl FetcherState

Source

pub fn new(config: Config) -> Self

Initialize the FetcherState with the given Config.

Source§

impl FetcherState

Source

pub fn handle(&mut self, command: Command) -> Event

Process the handling of a Command, delegating to its corresponding method, and returning the corresponding Event.

This method is useful if the FetcherState is used in batch processing and does need to be explicit about the underlying method.

Source

pub fn fetch(&mut self, _: Fetch) -> Fetch

Process a Fetch command, which transitions the given fetch to active, if possible.

The fetch will only transition to being active if:

  • A fetch is not already happening for that repository, in which case it gets queued.
  • The node to be fetched from is not already at capacity, again it will be queued.
Source

pub fn fetched(&mut self, _: Fetched) -> Fetched

Process a Fetched command, which removes the given fetch from the set of active fetches. Note that this is agnostic of whether the fetch succeeded or failed.

The caller will be notified if the completed fetch did not exist in the active set.

Source

pub fn dequeue(&mut self, from: &NodeId) -> Option<QueuedFetch>

Attempt to dequeue a QueuedFetch for the given node.

This will only dequeue the fetch if it is not active, and the given node is not at capacity.

Source

pub fn cancel(&mut self, _: Cancel) -> Cancel

Process a Cancel command, which cancels any active and/or queued fetches for that given node.

Source§

impl FetcherState

Source

pub fn queued_fetches(&self) -> &BTreeMap<NodeId, Queue>

Get the set of queued fetches.

Source

pub fn active_fetches(&self) -> &BTreeMap<RepoId, ActiveFetch>

Get the set of active fetches.

Source

pub fn get_active_fetch(&self, rid: &RepoId) -> Option<&ActiveFetch>

Get the ActiveFetch for the provided RepoId, returning None if it does not exist.

Trait Implementations§

Source§

impl Clone for FetcherState

Source§

fn clone(&self) -> FetcherState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FetcherState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FetcherState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for FetcherState

Source§

fn eq(&self, other: &FetcherState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for FetcherState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for FetcherState

Source§

impl StructuralPartialEq for FetcherState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T