pub struct Generation { /* private fields */ }Expand description
A process generation keeps admitted sessions alive until their leases drop.
Implementations§
Source§impl Generation
impl Generation
Sourcepub async fn run_until_retired<F, Fut>(
&self,
interval: Duration,
staging_lifetime: Duration,
refresh: F,
) -> Retirement
pub async fn run_until_retired<F, Fut>( &self, interval: Duration, staging_lifetime: Duration, refresh: F, ) -> Retirement
Refresh application discovery until this process can retire. This loop owns session wakeups and retirement; the callback reads application selection and may invoke the shared replacement transaction.
With a drain limit, the loop also wakes when the limit passes, and checks
it before and after every refresh, so no refresh starts once it has
passed. A refresh callback that never completes still delays retirement.
Sourcepub fn new(own: u64, selected: u64, staged: bool) -> Self
pub fn new(own: u64, selected: u64, staged: bool) -> Self
Initialize from the persisted selection and the process’s startup record.
Sourcepub fn with_drain_limit(self, limit: Duration) -> Self
pub fn with_drain_limit(self, limit: Duration) -> Self
Bound how long a superseded generation waits for its session leases.
Without a limit a held lease keeps a superseded generation alive
indefinitely. With one, Self::retire and Self::run_until_retired
retire it once the limit has passed since a newer generation was first
selected, whatever leases remain.
Sourcepub fn select(&self, selected: u64) -> Result<()>
pub fn select(&self, selected: u64) -> Result<()>
Observe a committed selection. Binary rollback still requires a larger epoch.
Sourcepub fn admit(self: &Arc<Self>) -> Option<SessionLease>
pub fn admit(self: &Arc<Self>) -> Option<SessionLease>
Admit a session unless retirement closed admission.
Sourcepub fn retire_if_idle(&self, staging_lifetime: Duration) -> bool
pub fn retire_if_idle(&self, staging_lifetime: Duration) -> bool
Retire only an idle superseded generation or expired unselected candidate.
Ignores the drain limit; see Self::retire.
Sourcepub fn retire(&self, staging_lifetime: Duration) -> Option<Retirement>
pub fn retire(&self, staging_lifetime: Duration) -> Option<Retirement>
Retire an idle superseded generation or expired unselected candidate, or a superseded generation whose drain limit has passed.
Sourcepub fn subscribe(&self) -> Receiver<()>
pub fn subscribe(&self) -> Receiver<()>
Subscribe before reading state so a concurrent release is not missed.
Notifies when the selected generation advances and when a session lease
is released: the transitions that can make retirement possible.
Admission and SessionLease::mark_legacy do not notify, so
Self::run_until_retired does not refresh once per new session.