Struct Replica
pub struct Replica {
pub id: ReplicaId,
pub n: u8,
/* private fields */
}Fields§
§id: ReplicaId§n: u8Implementations§
§impl Replica
impl Replica
pub fn new( id: ReplicaId, n: u8, rec: Recovered, timing: Timing, seed: u64, now: u64, ) -> Self
pub fn sealed(&self) -> bool
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 reconfigure(
&mut self,
members: &[(ReplicaId, String)],
out: &mut Vec<Action>,
) -> Result<Op, &'static str>
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>
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)
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
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
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
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>
pub fn entries_after(&self, op: Op) -> impl DoubleEndedIterator<Item = &Entry>
The entries above op, in order, without walking those below.
pub fn committed_page(&self, first: Op, last: Op) -> Vec<Entry>
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
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>>
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
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>
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
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
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
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
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>>
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
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>>
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>
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)>
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>)
pub fn on_durable(&mut self, op: Op, out: &mut Vec<Action>)
The local log is durable through op.