pub struct PrimarySender { /* private fields */ }Expand description
Primary-side replication sender. Manages connections to all configured secondaries, sends operations, and routes ACKs back to the QuorumTracker.
Non-blocking design (matching SF): send_to_all enqueues ops into
per-secondary unbounded channels and returns immediately. Each secondary
has a background drain task that reads from the unbounded channel and
writes to the gRPC stream. A slow secondary’s drain task blocks
independently without affecting the actor or other secondaries.
Pending ops for new replicas are replayed from the ReplicationQueue
at add_secondary time — no build buffers needed.
Implementations§
Source§impl PrimarySender
impl PrimarySender
pub fn new(primary_id: ReplicaId, epoch: Epoch) -> Self
pub fn set_epoch(&mut self, epoch: Epoch)
Sourcepub async fn add_secondary(
&mut self,
replica_id: ReplicaId,
address: String,
quorum_tracker: Arc<Mutex<QuorumTracker>>,
partition_state: Arc<PartitionState>,
) -> Result<()>
pub async fn add_secondary( &mut self, replica_id: ReplicaId, address: String, quorum_tracker: Arc<Mutex<QuorumTracker>>, partition_state: Arc<PartitionState>, ) -> Result<()>
Connect to a secondary’s replication gRPC endpoint. If ops were buffered during build, they are replayed first.
Spawns two background tasks per secondary:
- Drain task: reads from unbounded channel, writes to bounded gRPC stream. May block on slow secondary — only blocks this task.
- ACK reader: reads ACKs from gRPC response stream, routes to QuorumTracker.
Sourcepub fn send_to_one(
&self,
replica_id: ReplicaId,
lsn: Lsn,
data: &Bytes,
committed_lsn: Lsn,
)
pub fn send_to_one( &self, replica_id: ReplicaId, lsn: Lsn, data: &Bytes, committed_lsn: Lsn, )
Send a single item to a specific secondary (for replay from queue).
Sourcepub fn remove_secondary(&mut self, replica_id: ReplicaId)
pub fn remove_secondary(&mut self, replica_id: ReplicaId)
Remove a secondary connection.
Sourcepub fn send_to_all(&mut self, lsn: Lsn, data: &Bytes, committed_lsn: Lsn)
pub fn send_to_all(&mut self, lsn: Lsn, data: &Bytes, committed_lsn: Lsn)
Send an operation to all connected secondaries. Non-blocking — uses unbounded channels. Matches SF’s fire-and-forget dispatch.
Sourcepub fn connection_count(&self) -> usize
pub fn connection_count(&self) -> usize
Number of connected secondaries.
Sourcepub fn has_connection(&self, replica_id: &ReplicaId) -> bool
pub fn has_connection(&self, replica_id: &ReplicaId) -> bool
Check if a secondary is connected.
Sourcepub fn connected_ids(&self) -> Vec<ReplicaId> ⓘ
pub fn connected_ids(&self) -> Vec<ReplicaId> ⓘ
Get all connected replica IDs.
Auto Trait Implementations§
impl Freeze for PrimarySender
impl RefUnwindSafe for PrimarySender
impl Send for PrimarySender
impl Sync for PrimarySender
impl Unpin for PrimarySender
impl UnsafeUnpin for PrimarySender
impl UnwindSafe for PrimarySender
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request