1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! Cluster-side dispatch hook.
//!
//! Routing decisions (whether to send a request to the local
//! datastore, fan it out across racks, or relay it to a remote DC)
//! land in Stage 10's cluster module. Stage 9 only owns the
//! per-connection FSMs and exposes a seam, [`Dispatcher`], that
//! Stage 10 plugs into.
//!
//! [`Dispatcher`] is the seam between the two stages. The Stage 9
//! client / dnode-client FSMs hand each fully parsed [`Msg`] to a
//! `Dispatcher` and inspect [`DispatchOutcome`] to decide whether
//! the response can be returned synchronously or whether they
//! should wait for a downstream response. Stage 10 will provide a
//! cluster-aware implementation; tests in this stage exercise the
//! seam with [`NoopDispatcher`].
//!
//! [`Msg`]: crate::msg::Msg
use Arc;
use mpsc;
use crateMsg;
/// Outcome of dispatching a parsed message.
/// Cluster-side dispatch hook implemented by Stage 10 and by tests.
///
/// The dispatcher is invoked from a tokio task; implementations may
/// do async work but should avoid blocking. The trait uses
/// `&self` so the dispatcher can be shared across many connections.
/// Channel the dispatcher uses to send responses back to a client
/// FSM. The FSM owns the receiving half.
pub type ServerSink = Sender;
/// Envelope wrapping a dispatcher response and the request id it
/// corresponds to.
///
/// `span` carries the originating request span back to the
/// client-side FSM so the response writeback nests under the
/// originating client span. The default is
/// [`tracing::Span::none`].
///
/// `source_peer_idx` identifies the peer this response came from
/// when the dispatcher fanned the request to multiple replicas.
/// `None` is used for synthetic / inline / single-target paths
/// where the source is unambiguous.
/// Dispatcher that drops every request and emits no response.
///
/// Useful as a placeholder in tests that only exercise framing.
;