Skip to main content

Scheduler

Struct Scheduler 

Source
pub struct Scheduler {
    pub stats: Stats,
    /* private fields */
}

Fields§

§stats: Stats

Implementations§

Source§

impl Scheduler

Source

pub fn new(size: u64, sources: Vec<Source>, conns_per_source: &[usize]) -> Self

Source

pub fn with_theta_scale(self, s: f64) -> Self

Source

pub fn with_health_ranking(self, on: bool) -> Self

Disable health-ranked victim selection (for A/B measurement only).

Source

pub fn with_stall_timeout(self, t: f64) -> Self

Source

pub fn mark_done(&mut self, lo: u64, hi: u64)

Mark [lo, hi) as already held, for resuming a partial transfer.

Must be called before the first tick: the initial split assigns all unassigned work, and bytes already on disk must not be part of it.

Source

pub fn conn_health(&self, j: usize) -> Health

Health grade of a connection, for the progress UI and for tests.

Source

pub fn conn_source(&self, j: usize) -> usize

Source index a connection belongs to, for the progress UI.

Source

pub fn conn_rate(&self, j: usize) -> f64

Smoothed rate estimate of a connection (bytes/s), for the progress UI.

Source

pub fn conn_range(&self, j: usize) -> Option<(u64, u64, u64)>

Active range of a connection, for the progress UI.

Source

pub fn n_conns(&self) -> usize

Source

pub fn is_complete(&self) -> bool

Source

pub fn bytes_held(&self) -> u64

Source

pub fn held_ranges(&self) -> Vec<(u64, u64)>

The ranges that are complete on disk, as (lo, hi) pairs.

This is the complement of the unassigned set minus what is still in flight, and it is what a resume record must contain. Reporting only a byte COUNT is not enough: positioned writes land ranges out of order, so “2 MB held” says nothing about which 2 MB, and a resume that assumed a contiguous prefix would skip holes and silently corrupt the file.

Source

pub fn worst_delta(&self) -> f64

Coverage audit: held + outstanding + unassigned == size.

This is a SAFETY invariant and it does NOT imply liveness – the livelock this code is written to avoid (a fully-stolen range leaving a connection idle with a non-empty queue) satisfies it at every instant. liveness_holds is the property that matters. The largest measured request setup cost across sources, in seconds.

Exposed because a transport-layer watchdog must express its patience in units of what a request actually costs on this path rather than as a hardcoded constant: delta differs by an order of magnitude between a LAN mirror and a TLS connection through a proxy, and a fixed timeout is either trigger-happy on the slow path or useless on the fast one.

This is the same quantity the repair deadband is built from (theta = scale * sqrt(delta * T_rem / n)), so a client that widens delta widens both together, which is the intended coupling.

Source

pub fn stall_timeout(&self) -> f64

The configured stall timeout, in seconds.

Source

pub fn coverage_holds(&self) -> bool

Source

pub fn liveness_holds(&self) -> bool

True when some enabled transition strictly decreases the unheld-byte count. False means the scheduler is stuck.

Source

pub fn on_bytes(&mut self, conn: usize, n: u64, now: f64, dt: f64)

Record n bytes arriving on conn at time now over dt seconds.

Convenience wrapper that assumes the arrival is contiguous at the connection’s cursor. Real transports must use Scheduler::on_bytes_at: a response still draining from a range that was completed or stolen would otherwise be credited against whatever range the connection holds NOW, silently advancing a cursor over bytes that never arrived and leaving a hole of zeros in the output file.

Source

pub fn on_bytes_at(&mut self, conn: usize, off: u64, n: u64, now: f64, dt: f64)

Record n bytes that landed at absolute offset off.

Arrivals that do not begin exactly at the connection’s cursor are stale (they belong to a superseded request) and are discarded: the bytes are still written to the file by the transport, but they are not credited, so the scheduler’s coverage accounting stays exact.

Source

pub fn suspend_source(&mut self, src: usize, until: f64)

Suspend a source (429/503 with Retry-After) and reclaim its ranges.

Source

pub fn tick(&mut self, now: f64) -> Vec<Action>

Advance the scheduler. Returns the actions the caller must perform.

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> 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, 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.