Skip to content

Commit 6005548

Browse files
committed
docs: clarify RaftNetworkV2 design and streaming options
Make explicit that `RaftNetworkV2` is designed for unary request-response RPCs and document the three paths to stream-oriented AppendEntries, so implementers can pick the right level of effort for their throughput needs: 1. Default — implement only unary `append_entries`; the default `stream_append` adapts it sequentially via `stream_append_sequential`. 2. Override `RaftNetworkV2::stream_append` for true streaming (e.g. native gRPC bidi or pipelined AppendEntries) without abandoning the unified interface for the other RPCs. 3. Implement the individual sub-traits directly when even more flexibility is needed; these are the exact bounds on `RaftNetworkFactory::Network`. Also enumerate the six sub-traits (`NetAppend`, `NetVote`, `NetSnapshot`, `NetStreamAppend`, `NetTransferLeader`, `NetBackoff`) with one-line purposes and add intra-doc link references for the new mentions.
1 parent 30dc1f0 commit 6005548

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

openraft/src/network/v2/network.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,37 @@ use crate::type_config::alias::VoteOf;
3535
/// (`append_entries`, `vote`, `full_snapshot`) and the sub-traits ([`NetAppend`], [`NetVote`],
3636
/// [`NetSnapshot`], etc.) will be automatically derived via blanket implementations.
3737
///
38-
/// For advanced use cases requiring fine-grained control, applications may implement
39-
/// the individual sub-traits directly instead of this trait. See [`NetStreamAppend`] for
40-
/// an example where direct implementation enables native gRPC bidirectional streaming.
38+
/// # Design: unary RPCs with streaming compatibility
39+
///
40+
/// `RaftNetworkV2` is designed around **request-response (unary) RPCs** — `append_entries`,
41+
/// `vote`, and `full_snapshot` each send one request and produce one response. When this
42+
/// trait was introduced, it was not designed for stream-oriented AppendEntries.
43+
///
44+
/// It remains **compatible** with the stream-oriented API, however: if an application only
45+
/// implements the unary `append_entries`, Openraft adapts it into a stream by calling it
46+
/// sequentially via the default [`stream_append`](Self::stream_append) implementation
47+
/// (see [`stream_append_sequential`](crate::network::stream_append_sequential)). This is
48+
/// convenient but not optimal for throughput.
49+
///
50+
/// For true streaming performance while keeping the unified interface, an application can
51+
/// **override the default [`stream_append`](Self::stream_append)** on `RaftNetworkV2` itself
52+
/// with a custom implementation (e.g. native gRPC bidirectional streaming or pipelined
53+
/// AppendEntries) — without giving up the convenience of `RaftNetworkV2` for the other RPCs.
54+
///
55+
/// # Implementing sub-traits directly for optimal performance
56+
///
57+
/// For best performance — for example, native gRPC bidirectional streaming for
58+
/// AppendEntries — implement the individual sub-traits directly instead of `RaftNetworkV2`.
59+
/// These are the exact bounds required by [`RaftNetworkFactory::Network`], so any
60+
/// combination of direct impls satisfies the factory:
61+
///
62+
/// - [`NetAppend`] — unary AppendEntries
63+
/// - [`NetVote`] — RequestVote
64+
/// - [`NetSnapshot`] — full snapshot transfer
65+
/// - [`NetStreamAppend`] — stream-oriented AppendEntries (implement directly for native gRPC bidi
66+
/// streaming or pipelining)
67+
/// - [`NetTransferLeader`] — TransferLeader notification
68+
/// - [`NetBackoff`] — backoff strategy on `Unreachable`
4169
///
4270
/// See the [network chapter of the guide](crate::docs::getting_started#4-implement-raftnetwork)
4371
/// for details and discussion on this trait and how to implement it.
@@ -55,6 +83,9 @@ use crate::type_config::alias::VoteOf;
5583
/// [`NetVote`]: crate::network::NetVote
5684
/// [`NetSnapshot`]: crate::network::NetSnapshot
5785
/// [`NetStreamAppend`]: crate::network::NetStreamAppend
86+
/// [`NetTransferLeader`]: crate::network::NetTransferLeader
87+
/// [`NetBackoff`]: crate::network::NetBackoff
88+
/// [`RaftNetworkFactory::Network`]: crate::network::RaftNetworkFactory::Network
5889
/// [correct-node]: `crate::docs::cluster_control::dynamic_membership#ensure-connection-to-the-correct-node`
5990
#[since(version = "0.10.0")]
6091
#[add_async_trait]

0 commit comments

Comments
 (0)