Skip to content

Commit 757dbae

Browse files
committed
node: add server_version field to Node.
This is a non-breaking change, because `Node` already has some private fields. I decided not to include `server_version` in `PeerEndpoint` to avoid needless cloning. To obtain the server_version from `Peer`, one can use `Peer::into_peer_endpoint_tokens_and_server_version()`. This consumes the `Peer` and moves the `server_version` to the caller.
1 parent fcf1c1c commit 757dbae

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

scylla/src/cluster/metadata.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ impl Peer {
179179
}
180180
}
181181

182-
pub(crate) fn into_peer_endpoint_and_tokens(self) -> (PeerEndpoint, Vec<Token>) {
182+
pub(crate) fn into_peer_endpoint_tokens_and_server_version(
183+
self,
184+
) -> (PeerEndpoint, Vec<Token>, Option<String>) {
183185
(
184186
PeerEndpoint {
185187
host_id: self.host_id,
@@ -188,6 +190,7 @@ impl Peer {
188190
rack: self.rack,
189191
},
190192
self.tokens,
193+
self.server_version,
191194
)
192195
}
193196
}

scylla/src/cluster/node.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl Display for NodeAddr {
7575
#[derive(Debug)]
7676
pub struct Node {
7777
pub host_id: Uuid,
78+
pub server_version: Option<String>,
7879
pub address: NodeAddr,
7980
pub datacenter: Option<String>,
8081
pub rack: Option<String>,
@@ -92,6 +93,7 @@ impl Node {
9293
/// Creates a new node which starts connecting in the background.
9394
pub(crate) fn new(
9495
peer: PeerEndpoint,
96+
server_version: Option<String>,
9597
pool_config: &PoolConfig,
9698
keyspace_name: Option<VerifiedKeyspaceName>,
9799
enabled: bool,
@@ -117,6 +119,7 @@ impl Node {
117119

118120
Node {
119121
host_id,
122+
server_version,
120123
address,
121124
datacenter,
122125
rack,
@@ -133,13 +136,18 @@ impl Node {
133136
///
134137
/// - `node` - previous definition of that node
135138
/// - `address` - new address to connect to
136-
pub(crate) fn inherit_with_ip_changed(node: &Node, endpoint: PeerEndpoint) -> Self {
139+
pub(crate) fn inherit_with_ip_changed(
140+
node: &Node,
141+
endpoint: PeerEndpoint,
142+
server_version: Option<String>,
143+
) -> Self {
137144
let address = endpoint.address;
138145
if let Some(ref pool) = node.pool {
139146
pool.update_endpoint(endpoint);
140147
}
141148
Self {
142149
address,
150+
server_version,
143151
down_marker: false.into(),
144152
datacenter: node.datacenter.clone(),
145153
rack: node.rack.clone(),
@@ -367,6 +375,7 @@ mod tests {
367375
) -> Self {
368376
Self {
369377
host_id: id.unwrap_or(Uuid::new_v4()),
378+
server_version: None,
370379
address: address.unwrap_or(NodeAddr::Translatable(SocketAddr::from((
371380
[255, 255, 255, 255],
372381
0,

scylla/src/cluster/state.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,28 @@ impl ClusterState {
8484

8585
let node: Arc<Node> = match known_peers.get(&peer_host_id) {
8686
Some(node) if node.datacenter == peer.datacenter && node.rack == peer.rack => {
87-
let (peer_endpoint, tokens) = peer.into_peer_endpoint_and_tokens();
87+
let (peer_endpoint, tokens, server_version) =
88+
peer.into_peer_endpoint_tokens_and_server_version();
8889
peer_tokens = tokens;
8990
if node.address == peer_address {
9091
node.clone()
9192
} else {
9293
// If IP changes, the Node struct is recreated, but the underlying pool is preserved and notified about the IP change.
93-
Arc::new(Node::inherit_with_ip_changed(node, peer_endpoint))
94+
Arc::new(Node::inherit_with_ip_changed(
95+
node,
96+
peer_endpoint,
97+
server_version,
98+
))
9499
}
95100
}
96101
_ => {
97102
let is_enabled = host_filter.map_or(true, |f| f.accept(&peer));
98-
let (peer_endpoint, tokens) = peer.into_peer_endpoint_and_tokens();
103+
let (peer_endpoint, tokens, server_version) =
104+
peer.into_peer_endpoint_tokens_and_server_version();
99105
peer_tokens = tokens;
100106
Arc::new(Node::new(
101107
peer_endpoint,
108+
server_version,
102109
pool_config,
103110
used_keyspace.clone(),
104111
is_enabled,

scylla/src/routing/locator/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ pub(crate) fn create_ring(metadata: &Metadata) -> impl Iterator<Item = (Token, A
191191
for peer in &metadata.peers {
192192
let node = Arc::new(Node::new(
193193
peer.to_peer_endpoint(),
194+
None,
194195
&pool_config,
195196
None,
196197
true,

0 commit comments

Comments
 (0)