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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
pub use crate::common::{DataMessage, LogLevel, LogMessage, SharedMemoryId, Timestamped};
use crate::{
DataflowId, current_crate_version,
id::{DataId, NodeId},
metadata::Metadata,
versions_compatible,
};
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub enum DaemonRequest {
Register(NodeRegisterRequest),
Subscribe,
SendMessage {
output_id: DataId,
metadata: Metadata,
data: Option<DataMessage>,
},
OutputSent {
output_id: DataId,
metadata: Metadata,
},
CloseOutputs(Vec<DataId>),
/// Signals that the node is finished sending outputs.
OutputsDone,
NextEvent,
EventStreamDropped,
NodeConfig {
node_id: NodeId,
},
/// Store an opaque value in the daemon's dataflow-scoped extension table.
///
/// dora attaches no meaning to `namespace`, `key` or `value`: this is the
/// out-of-band channel for transports that live outside the tree (see
/// `docs/extensions.md`). The daemon tracks who stored a key and who has
/// read it, so it can notify readers on removal and reclaim the entry when
/// the dataflow ends.
ExtensionStore {
namespace: String,
key: String,
value: Vec<u8>,
},
/// Read an opaque value back. `remove: true` drops it in the same round
/// trip, so a consume-once handoff needs one request rather than two.
ExtensionLoad {
namespace: String,
key: String,
remove: bool,
},
/// Drop an opaque value. Every node that stored or loaded the key is sent
/// [`NodeEvent::ExtensionDropped`] so it can release whatever the value
/// referred to.
ExtensionDrop {
namespace: String,
key: String,
},
/// An opaque request from a node to the extension registered under
/// `namespace` on its daemon. dora never interprets either field.
///
/// Complements the extension table (`ExtensionStore`/`ExtensionLoad`/
/// `ExtensionDrop`), which brokers descriptor *lifetime*. This one
/// carries a call the extension's daemon half must service — the
/// tensor-pool uses it for cross-machine registration and pool writes.
ExtensionRequest {
namespace: String,
#[serde(with = "crate::bulk_bytes::vec")]
payload: Vec<u8>,
},
}
impl DaemonRequest {
/// Bulk bytes this request will contribute to its encoding, for
/// [`crate::encode_presized`].
///
/// Matched exhaustively on purpose: a new payload-carrying variant that
/// forgets to report its size would silently fall back to growing the
/// buffer from empty, which is the cost `encode_presized` exists to avoid
/// and which no test would catch.
pub fn encode_size_hint(&self) -> usize {
match self {
DaemonRequest::SendMessage { data, .. } => data.as_ref().map_or(0, DataMessage::len),
DaemonRequest::Register(_)
| DaemonRequest::Subscribe
| DaemonRequest::OutputSent { .. }
| DaemonRequest::CloseOutputs(_)
| DaemonRequest::OutputsDone
| DaemonRequest::NextEvent
| DaemonRequest::EventStreamDropped
| DaemonRequest::NodeConfig { .. } => 0,
// The stored value dominates; the namespace and key are short.
DaemonRequest::ExtensionStore { value, .. } => value.len(),
DaemonRequest::ExtensionLoad { .. } | DaemonRequest::ExtensionDrop { .. } => 0,
DaemonRequest::ExtensionRequest { payload, .. } => payload.len(),
}
}
pub fn expects_tcp_binary_reply(&self) -> bool {
#[allow(clippy::match_like_matches_macro)]
match self {
DaemonRequest::SendMessage { .. }
| DaemonRequest::OutputSent { .. }
| DaemonRequest::NodeConfig { .. } => false,
DaemonRequest::Register(NodeRegisterRequest { .. })
| DaemonRequest::Subscribe
| DaemonRequest::CloseOutputs(_)
| DaemonRequest::OutputsDone
| DaemonRequest::NextEvent
| DaemonRequest::EventStreamDropped
| DaemonRequest::ExtensionRequest { .. }
| DaemonRequest::ExtensionStore { .. }
| DaemonRequest::ExtensionLoad { .. }
| DaemonRequest::ExtensionDrop { .. } => true,
}
}
pub fn expects_tcp_json_reply(&self) -> bool {
#[allow(clippy::match_like_matches_macro)]
match self {
DaemonRequest::NodeConfig { .. } => true,
DaemonRequest::Register(NodeRegisterRequest { .. })
| DaemonRequest::Subscribe
| DaemonRequest::CloseOutputs(_)
| DaemonRequest::OutputsDone
| DaemonRequest::NextEvent
| DaemonRequest::SendMessage { .. }
| DaemonRequest::OutputSent { .. }
| DaemonRequest::EventStreamDropped
| DaemonRequest::ExtensionRequest { .. }
| DaemonRequest::ExtensionStore { .. }
| DaemonRequest::ExtensionLoad { .. }
| DaemonRequest::ExtensionDrop { .. } => false,
}
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct NodeRegisterRequest {
pub dataflow_id: DataflowId,
pub node_id: NodeId,
dora_version: semver::Version,
/// The metadata wire-format version this node was built against
/// ([`Metadata::CURRENT_VERSION`]).
///
/// The `dora_version` semver check above is too coarse to catch a
/// message-format break within a release series: two builds that both
/// report `1.0.0-rc` are "compatible" by semver even when the payload
/// layout differs (as it did across #2366). Carrying the format version
/// explicitly lets the daemon reject an incompatible peer at register with
/// a clear message, instead of the node desyncing mid-stream into a
/// cryptic bad-enum-discriminant deserialization error (#2742).
///
/// This covers *layout* drift within one encoding. It cannot cover a change
/// of the encoding itself: the register frame is encoded the same way as
/// everything else, so a peer from before the bincode→postcard move fails
/// while decoding the frame that carries this field, never reaching the
/// check. Such changes are gated by the release notes instead.
metadata_version: u16,
}
impl NodeRegisterRequest {
pub fn new(dataflow_id: DataflowId, node_id: NodeId) -> Self {
Self {
dataflow_id,
node_id,
dora_version: semver::Version::parse(env!("CARGO_PKG_VERSION")).unwrap(),
metadata_version: Metadata::CURRENT_VERSION,
}
}
pub fn check_version(&self) -> Result<(), String> {
let crate_version = current_crate_version();
let specified_version = &self.dora_version;
if !versions_compatible(&crate_version, specified_version)? {
return Err(format!(
"version mismatch: message format v{} is not compatible \
with expected message format v{crate_version}",
self.dora_version
));
}
// Even when the semver check passes, the payload wire format can still
// differ within a release series (#2366 dropped a `Metadata` field
// without changing the version). Reject that here so the failure is a
// legible register-time error rather than a mid-stream desync (#2742).
if self.metadata_version != Metadata::CURRENT_VERSION {
return Err(format!(
"message wire-format mismatch: node speaks metadata format v{} \
but this daemon speaks v{}. The node and daemon were built from \
dora revisions with incompatible message formats; rebuild both \
from the same revision.",
self.metadata_version,
Metadata::CURRENT_VERSION
));
}
Ok(())
}
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub enum DynamicNodeEvent {
NodeConfig { node_id: NodeId },
}
#[cfg(test)]
mod register_version_tests {
use super::*;
fn request() -> NodeRegisterRequest {
NodeRegisterRequest::new(uuid::Uuid::nil(), NodeId::from("test-node".to_string()))
}
#[test]
fn new_stamps_current_metadata_version() {
assert_eq!(request().metadata_version, Metadata::CURRENT_VERSION);
}
#[test]
fn check_version_accepts_a_matching_request() {
// A request built by this same crate version passes both the semver
// and the wire-format gate.
request().check_version().unwrap();
}
#[test]
fn check_version_rejects_a_wire_format_mismatch() {
// A peer built from a dora revision with a different metadata wire
// format — same semver, incompatible bytes. This is the #2366 / #2742
// shape: it must be rejected at register with a legible message rather
// than desyncing mid-stream into a cryptic deserialization error.
let mut req = request();
req.metadata_version = Metadata::CURRENT_VERSION.wrapping_add(1);
let err = req
.check_version()
.expect_err("mismatched metadata wire version must be rejected");
assert!(
err.contains("wire-format") && err.contains(&Metadata::CURRENT_VERSION.to_string()),
"error should name the wire-format mismatch and the expected version, got: {err}"
);
}
}