README

Lfan-ke/raft-moonbit/tracker does not have a README file

#
Inflight

pub(all) struct Inflight {
index : UInt64
bytes : UInt64
} derive(Eq)

One in-flight AppendEntries message: the index of its last entry and the total byte size of the entries it carries.

#
Inflights

pub struct Inflights {
start : Int
count : Int
bytes : UInt64
size : Int
max_bytes : UInt64
buffer : Array[Inflight]
}

A sliding-window flow controller for the AppendEntries messages a leader has sent to one follower but not yet had acknowledged. It caps both the number of outstanding messages (size) and their total byte size (max_bytes), which is what stops a leader from flooding a lagging follower. Callers check full before sending, add on each send, and free_le on each ack.

#
Inflights::add

fn Inflights::add(self : Inflights, index : UInt64, bytes : UInt64) -> Unit

Record that a message ending at index and carrying bytes bytes has been dispatched. full must be false first, and consecutive calls must pass a monotonic sequence of indexes.

#
Inflights::clone

fn Inflights::clone(self : Inflights) -> Inflights

A deep copy that shares no buffer memory with the receiver.

#
Inflights::count

fn Inflights::count(self : Inflights) -> Int

The number of in-flight messages.

#
Inflights::free_le

fn Inflights::free_le(self : Inflights, to : UInt64) -> Unit

Free every in-flight message with last index at or below to, releasing its quota. Acks out of the left edge of the window are ignored.

#
Inflights::full

fn Inflights::full(self : Inflights) -> Bool

Whether no more messages may be sent right now: the message count is at its cap, or the byte budget is exhausted.

#
Inflights::max_bytes

fn Inflights::max_bytes(self : Inflights) -> UInt64

The configured byte budget (etcd's MaxInflightBytes); 0 means no limit.

#
Inflights::new

fn Inflights::new(size : Int, max_bytes : UInt64) -> Inflights

A tracker allowing up to size in-flight messages and up to max_bytes total bytes. max_bytes of 0 means no byte limit. The byte limit is soft: one message that crosses it is still accepted.

#
Inflights::reset

fn Inflights::reset(self : Inflights) -> Unit

Free all in-flight messages, e.g. when a follower's progress is reset.

#
Progress

pub(all) struct Progress {
next_index : UInt64
match_index : UInt64
state : ProgressState
recent_active : Bool
msg_app_flow_paused : Bool
pending_snapshot : UInt64
is_learner : Bool
sent_commit : UInt64
inflights : Inflights
}

The leader's view of one follower's replication progress. next_index is the next log index to send; match_index is the highest index known to be stored on the follower. recent_active records whether the follower has answered since the last liveness sweep, which the read-index and lease paths use to confirm the leader still commands a quorum.

#
Progress::become_probe

fn Progress::become_probe(self : Progress) -> Unit

Move back to cautious probing, one entry at a time. Coming out of Snapshot, resume just past the snapshot the follower was sent (etcd's BecomeProbe).

#
Progress::become_replicate

fn Progress::become_replicate(self : Progress) -> Unit

Move to streaming replication, sending from just past the match point.

#
Progress::become_snapshot

fn Progress::become_snapshot(self : Progress, snapshot_index : UInt64) -> Unit

Mark the follower as needing a snapshot up to snapshot_index; probing will resume just past it once the snapshot is acknowledged.

#
Progress::can_bump_commit

fn Progress::can_bump_commit(self : Progress, index : UInt64) -> Bool

Whether sending index as the commit index could still advance this follower's commit (etcd CanBumpCommit). True only when index is past what we last put in flight and that in-flight commit has not already reached the last acknowledged-in-flight entry (next_index - 1) — so the ③-path can skip redundant commit-only MsgApps. Staged for the 0.4.0 replication wiring.

#
Progress::copy

fn Progress::copy(self : Progress) -> Progress

A deep copy sharing no mutable state (used by the confchange Changer, which preserves a demoted voter's progress across a joint transition).

#
Progress::free_le

fn Progress::free_le(self : Progress, index : UInt64) -> Unit

Free every in-flight slot up through the acknowledged index.

#
Progress::is_active

fn Progress::is_active(self : Progress) -> Bool

Whether the follower has answered since the last sweep.

#
Progress::is_paused

fn Progress::is_paused(self : Progress) -> Bool

Whether replication to this follower is currently throttled: while a snapshot is pending, or whenever the MsgApp flow has been paused (a probe in flight, or a full in-flight window).

#
Progress::mark_active

fn Progress::mark_active(self : Progress) -> Unit

Record that the follower answered during the current liveness sweep.

#
Progress::maybe_decr_to

fn Progress::maybe_decr_to(self : Progress, rejected : UInt64, match_hint : UInt64) -> Bool

Adjust to a rejected AppendEntries (etcd MaybeDecrTo). rejected is the prev-index the follower rejected; match_hint is where we want to retry (the leader-side findConflictByTerm result). A rejection is stale — and ignored — if it cannot pertain to an entry still in flight. Returns whether next_index moved.

#
Progress::maybe_decrease

fn Progress::maybe_decrease(self : Progress, hint : UInt64) -> Bool

Back off after a rejected AppendEntries, using the follower's conflict hint to jump rather than decrement by one. Never rewinds below the match point or below index 1. Returns whether next_index actually moved.

#
Progress::maybe_update

fn Progress::maybe_update(self : Progress, index : UInt64) -> Bool

Fold in a successful acknowledgement up through index. Advances the match and next indices, never backwards, and returns whether the match point moved forward (which is what can let the leader commit new entries).

#
Progress::new

fn Progress::new(next : UInt64, max_inflight? : Int, max_inflight_bytes? : UInt64) -> Progress

A fresh progress that will start probing from next, with a replication flow-control window of max_inflight outstanding AppendEntries and, when max_inflight_bytes is non-zero, at most that many outstanding bytes (etcd's MaxInflightBytes; 0 = no byte limit). The byte budget is threaded straight into the Inflights window so the ③-path only has to pass the real entry size to sent_entries once its Config carries the knob.

#
Progress::note_commit_sent

fn Progress::note_commit_sent(self : Progress, commit : UInt64) -> Unit

Record the highest commit index put in flight to this follower (etcd SentCommit). The ③-path calls this after emitting an append/commit MsgApp.

#
Progress::optimistic_advance

fn Progress::optimistic_advance(self : Progress, last : UInt64) -> Unit

Optimistically advance next_index past last while streaming, so the next AppendEntries carries the following batch without waiting for the ack.

#
Progress::reset_active

fn Progress::reset_active(self : Progress) -> Unit

Clear the liveness flag at the start of a new sweep.

#
Progress::sent_entries

fn Progress::sent_entries(self : Progress, last : UInt64, has_entries : Bool, bytes? : UInt64) -> Unit

Record that a replication message ending at last, carrying has_entries entries totalling bytes bytes, was sent. In Replicate this consumes an in-flight slot (against both the message-count and the byte budget) and pauses once the window fills; in Probe any non-empty send pauses until acked. bytes defaults to 0: while the ③-path send loop does not yet supply the real encoded size (see Progress::new), byte accounting is inert because the byte budget is disabled — the message-count limit still applies exactly as before. Pass the real size to activate MaxInflightBytes.

#
Progress::to_string

fn Progress::to_string(self : Progress) -> String

A one-line, self-describing summary of this progress (etcd's Progress.String).

#
Progress::unpause

fn Progress::unpause(self : Progress) -> Unit

Clear the flow-control throttle (on an ack or a heartbeat response), so one more message may be sent.

#
ProgressState

pub(all) enum ProgressState {
Probe
Replicate
Snapshot
} derive(Eq)

How the leader is currently replicating to one follower.

Probe sends one AppendEntries at a time until the follower's match point is found; Replicate streams entries once the logs are known to agree; and Snapshot means the follower is so far behind that the next thing it needs has already been compacted, so a snapshot must be shipped first (etcd's three progress states).