Expand description
Primary-side replication source — bounded backlog of recent mutations, indexed by monotonic offset.
Behaviour at a glance:
ReplicationSource::push_mutationis called on every applied write. It assigns the next monotonic offset, encodes the frame withcrate::wire::encode_frame, and appends to the backlog.- The backlog is bounded by a byte budget (
max_bytes, fed from[replication]replication_buffer_sizein config). When a new frame would exceed the budget, the oldest frames are dropped to make room. - Replicas that disconnect and reconnect within the backlog window
resume via
ReplicationSource::frames_from. Replicas that fall off the back of the buffer getErr(FromOffset::TooOld)and the caller initiates a full snapshot ship.
The source does not know about replicas — slot tracking lives
in crate::slot::SlotTable. The source is a passive structure
the streaming loop reads; mutation/serialisation lock policy is the
wiring layer’s concern.
use kevy_replicate::source::{FromOffset, ReplicationSource};
let set = kevy_resp::Argv::from(vec![b"SET".to_vec(), b"k".to_vec(), b"v".to_vec()]);
let frame_len = kevy_replicate::wire::encode_frame(0, &set).len();
let mut backlog = ReplicationSource::new(2 * frame_len); // room for two frames
for _ in 0..3 {
backlog.push_mutation(&set);
}
// a replica that acked offset 2 resumes from the backlog ...
assert_eq!(backlog.frames_from(2).map(Iterator::count), Ok(1));
// ... one still at offset 0 fell off the back and needs a snapshot
assert!(matches!(backlog.frames_from(0), Err(FromOffset::TooOld)));Structs§
- Frame
- One encoded mutation frame parked in the backlog.
- Frames
Iter - Iterator over backlog frames returned by
ReplicationSource::frames_from. - Replication
Source - Bounded backlog of recent replicated mutations.
Enums§
- From
Offset - Reason
ReplicationSource::frames_fromcannot serve a replica from the backlog.