Skip to main content

ubiquisync_core/sync/
source.rs

1//! [`LogSource`]: the read side of a replica.
2
3use async_trait::async_trait;
4
5use crate::codec::DecodedEntry;
6use crate::sync::cursors::HasCursors;
7use crate::uuid::Uuid;
8
9use super::error::SyncError;
10
11/// The pull side of replication: publish progress as cursors, hand back entries
12/// past a position.
13///
14/// A driver diffs a peer's cursors against its own and pulls only the gap.
15/// Keeping the cheap cursor digest separate from the payload avoids a thundering
16/// herd — many holders advertise "I have X" for almost nothing, and the receiver
17/// fetches X once. Object-safe, like [`LogProcessor`](super::LogProcessor).
18#[async_trait]
19pub trait LogSource<E>: HasCursors {
20    /// A bounded batch of `peer`'s entries at or after `from`, ascending
21    /// (expunged markers included). Empty means drained at `from`; the caller
22    /// loops with an advancing `from` until then.
23    async fn read_since(
24        &self,
25        peer: Uuid,
26        from: u64,
27    ) -> Result<Vec<(u64, DecodedEntry<E>)>, SyncError>;
28}