Skip to main content

nodedb_cluster/distributed_array/
rpc.rs

1// SPDX-License-Identifier: BUSL-1.1
2
3//! RPC dispatch trait for array shard fan-out.
4//!
5//! `ShardRpcDispatch` abstracts the transport used to send one request
6//! envelope to a shard and receive one response envelope. The cluster
7//! crate defines the trait; the main `nodedb` binary implements it,
8//! wiring the QUIC connection pool or an in-process loopback for local
9//! shards.
10//!
11//! Fan-out functions in `scatter.rs` accept `Arc<dyn ShardRpcDispatch>`
12//! so they can be tested with mock implementations without a real cluster.
13
14use crate::error::Result;
15use crate::wire::VShardEnvelope;
16
17/// Send one request envelope to a shard and await one response envelope.
18///
19/// Implementors are responsible for:
20/// - Routing the envelope to the correct peer (local loopback or QUIC).
21/// - Applying per-call timeouts (the caller sets `timeout_ms` in
22///   `FanOutParams`; the implementor enforces it).
23/// - Returning `Err` on transport failure so the coordinator can
24///   propagate the error rather than silently dropping the shard.
25#[async_trait::async_trait]
26pub trait ShardRpcDispatch: Send + Sync + 'static {
27    /// Send `req` to the shard identified by `req.vshard_id` and return
28    /// the shard's response envelope.
29    async fn call(&self, req: VShardEnvelope, timeout_ms: u64) -> Result<VShardEnvelope>;
30}