Skip to main content

Replica

Struct Replica 

pub struct Replica {
    pub id: ReplicaId,
    pub n: u8,
    /* private fields */
}

Fields§

§id: ReplicaId§n: u8

Implementations§

§

impl Replica

pub fn new( id: ReplicaId, n: u8, rec: Recovered, timing: Timing, seed: u64, now: u64, ) -> Self

pub fn sealed(&self) -> bool

A reconfiguration is in the uncommitted log: the epoch ends with it, so nothing more is proposed in it.

pub fn membership(&self) -> &Membership

pub fn retired(&self) -> bool

Not a member of its epoch any more: it takes part in nothing.

pub fn joining(&self) -> bool

A new member that has not yet learned the epoch that includes it.

pub fn reconfigure( &mut self, members: &[(ReplicaId, String)], out: &mut Vec<Action>, ) -> Result<Op, &'static str>

Primary: proposes the next epoch’s membership as the last entry of this epoch (see Membership). Returns the entry’s op; the change is done once this replica’s membership reaches the next epoch.

pub fn lease_until(&self) -> Option<u64>

Primary: the time (on this replica’s clock) until which it may serve reads from its own state: no other replica can lead a newer view before then. None when it holds no lease.

pub fn lease_valid(&self, now: u64) -> bool

pub fn peer_closed(&mut self, from: ReplicaId, now: u64)

The host noticed that from’s stream to this replica closed. If it is this backup’s primary, the backup does not wait out the election timeout: it elects as soon as its promise allows (a crashed process closes its sockets at once; a silent one is still caught by the timeout).

pub fn election_due(&self, now: u64) -> bool

Whether a tick at now would start a view change because the primary went quiet. A host whose thread was descheduled reads its sockets first: the heartbeats may be waiting there.

pub fn view(&self) -> u64

pub fn timing(&self) -> &Timing

pub fn status(&self) -> Status

pub fn last_normal(&self) -> u64

pub fn op(&self) -> Op

pub fn commit(&self) -> Op

pub fn durable(&self) -> Op

pub fn commit_waits_on_own_durability(&self) -> bool

Primary: whether its own log becoming durable through its last op would advance the commit position, because enough other members already acknowledged entries above it. The host asks before it waits, to know whether its own write finishing must wake it; when this is false only another acknowledgment can commit more.

pub fn primary_of(&self, view: u64) -> ReplicaId

The primary of view in this replica’s epoch (none for another).

pub fn is_primary(&self) -> bool

pub fn entry(&self, op: Op) -> Option<&Entry>

pub fn entries(&self) -> impl DoubleEndedIterator<Item = &Entry>

pub fn entries_after(&self, op: Op) -> impl DoubleEndedIterator<Item = &Entry>

The entries above op, in order, without walking those below.

pub fn base(&self) -> Op

First position represented by the durable checkpoint.

pub fn committed_page(&self, first: Op, last: Op) -> Vec<Entry>

A checkpoint donor can serve this range even while changing views. Never expose uncommitted entries as a repair for a decided position.

pub fn compact_through(&mut self, op: Op, checksum: u64) -> bool

An immutable local image is already durable. Keep every operation after it, including prepares a backup has acknowledged in this view.

pub fn compact_through_taking( &mut self, op: Op, checksum: u64, ) -> Option<BTreeMap<Op, Entry>>

compact_through, returning the entries it dropped (for a host to free off its I/O thread), or None if it refused.

pub fn accepts_checkpoint( &self, from: ReplicaId, view: u64, base: Op, donor_commit: Op, ) -> bool

Only the established primary, or the donor selected by a view-change quorum, can supply the contents of a remote checkpoint.

pub fn checkpoint_suffix(&self, base: Op, checksum: u64) -> Vec<Entry>

Preserve the remaining durable suffix when it chains to the checkpoint. Corrupt entries are never used to advance the new base.

pub fn checkpoint_progress(&mut self, now: u64)

pub fn checkpoint_matches( &self, base: Op, checksum: u64, tail: &[Entry], ) -> bool

Validate against every known committed checksum before replacing any durable files. A receiver with a higher committed watermark requires a complete chain through that watermark.

pub fn chain_intact(base: Op, checksum: u64, tail: &[Entry]) -> bool

The parts of checkpoint_matches that need nothing of the replica, which a host checks off its I/O thread: consecutive positions after base, each entry’s parent the previous checksum (checksum first), each entry intact.

pub fn checkpoint_matches_checked( &self, base: Op, checksum: u64, tail: &[Entry], intact: usize, ) -> bool

checkpoint_matches for a tail whose first intact entries chain_intact checked already: those are not hashed again.

pub fn installed_checkpoint( &mut self, from: ReplicaId, view: u64, base: Op, checksum: u64, donor_commit: Op, tail: Vec<Entry>, now: u64, out: &mut Vec<Action>, ) -> bool

The host has atomically installed this image and the checked suffix. In the normal path all acknowledged prepares must survive installation.

pub fn install_matched( &mut self, from: ReplicaId, view: u64, base: Op, checksum: u64, log: BTreeMap<Op, Entry>, last: Op, now: u64, out: &mut Vec<Action>, ) -> Option<BTreeMap<Op, Entry>>

The rest of installed_checkpoint for a tail the host checked (accepts_checkpoint and checkpoint_matches_checked), given as the log it becomes (built off the host’s I/O thread; last its last position). Returns the log it replaced, for the host to free elsewhere, or None if it refused.

pub fn holds_checkpoint( &self, from: ReplicaId, view: u64, base: Op, checksum: u64, donor_commit: Op, ) -> bool

Whether a received checkpoint at base can be installed by compacting this replica’s own log (install_own): a backup in normal operation that holds base, committed, with this checksum, and nothing to repair or adopt.

pub fn install_own( &mut self, from: ReplicaId, view: u64, base: Op, checksum: u64, donor_commit: Op, now: u64, out: &mut Vec<Action>, ) -> Option<BTreeMap<Op, Entry>>

Installs a received checkpoint whose base this replica’s own log holds (holds_checkpoint): the host has made the image and this log’s entries after base its durable generation, so the log is compacted rather than replaced, as install_matched would leave it. Returns the entries dropped, for the host to free elsewhere, or None if it refused.

pub fn propose(&mut self, body: Payload, out: &mut Vec<Action>) -> Option<Op>

Primary: appends a new entry and replicates it. Returns its op.

pub fn propose_many( &mut self, bodies: impl IntoIterator<Item = Payload>, out: &mut Vec<Action>, ) -> Option<(Op, Op)>

Primary: appends one entry per body, in order, and replicates them in one Prepare (one frame per backup) and one local write. Returns the first and last op, or None (nothing appended) if this replica is not the primary or there is no body.

pub fn on_durable(&mut self, op: Op, out: &mut Vec<Action>)

The local log is durable through op.

pub fn on_tick(&mut self, now: u64, out: &mut Vec<Action>)

pub fn on_message( &mut self, from: ReplicaId, msg: Msg, now: u64, out: &mut Vec<Action>, )

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.