Skip to content

Commit cb28052

Browse files
committed
topology: use a structure to represent a row from system.{local,peers}
Thanks to scylladb#628, it is now possible to provide an explicit path to a crate which provides necessary items for the FromRow macro. It is now possible to use this macro from the `scylla` crate itself, as we just need to point it to the `scylla-cql` crate instead. The NodeInfoRow struct is introduced to represent rows fetched from system.local and system.peers. It looks nicer than using a 5-element tuple and will reduce some noise when performing refactors in the commits that follow.
1 parent 1a28f25 commit cb28052

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

scylla/src/transport/topology.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use futures::future::try_join_all;
1313
use itertools::Itertools;
1414
use rand::seq::SliceRandom;
1515
use rand::{thread_rng, Rng};
16+
use scylla_macros::FromRow;
1617
use std::borrow::BorrowMut;
1718
use std::collections::HashMap;
1819
use std::fmt;
@@ -476,6 +477,16 @@ async fn query_metadata(
476477
Ok(Metadata { peers, keyspaces })
477478
}
478479

480+
#[derive(FromRow)]
481+
#[scylla_crate = "scylla_cql"]
482+
struct NodeInfoRow {
483+
host_id: Option<Uuid>,
484+
untranslated_ip_addr: IpAddr,
485+
datacenter: Option<String>,
486+
rack: Option<String>,
487+
tokens: Option<Vec<String>>,
488+
}
489+
479490
async fn query_peers(
480491
conn: &Arc<Connection>,
481492
connect_port: u16,
@@ -501,35 +512,23 @@ async fn query_peers(
501512
"system.local query response was not Rows",
502513
))?;
503514

504-
let typed_peers_rows = peers_rows.into_typed::<(
505-
Option<Uuid>,
506-
IpAddr,
507-
Option<String>,
508-
Option<String>,
509-
Option<Vec<String>>,
510-
)>();
515+
let typed_peers_rows = peers_rows.into_typed::<NodeInfoRow>();
511516

512517
let local_ip: IpAddr = conn.get_connect_address().ip();
513518
let local_address = SocketAddr::new(local_ip, connect_port);
514519

515-
let typed_local_rows = local_rows.into_typed::<(
516-
Option<Uuid>,
517-
IpAddr,
518-
Option<String>,
519-
Option<String>,
520-
Option<Vec<String>>,
521-
)>();
520+
let typed_local_rows = local_rows.into_typed::<NodeInfoRow>();
522521

523522
let untranslated_rows = typed_peers_rows
524523
.map(|res| res.map(|peer_row| (false, peer_row)))
525524
.chain(typed_local_rows.map(|res| res.map(|local_row| (true, local_row))));
526525

527526
let translated_peers_futures = untranslated_rows
528-
.filter_map_ok(|(is_local, (host_id, ip, dc, rack, tokens))| if let Some(host_id) = host_id {
529-
Some((is_local, (host_id, ip, dc, rack, tokens)))
527+
.filter_map_ok(|(is_local, NodeInfoRow { host_id, untranslated_ip_addr, datacenter, rack, tokens })| if let Some(host_id) = host_id {
528+
Some((is_local, (host_id, untranslated_ip_addr, datacenter, rack, tokens)))
530529
} else {
531530
let who = if is_local { "Local node" } else { "Peer" };
532-
warn!("{} (untranslated ip: {}, dc: {:?}, rack: {:?}) has Host ID set to null; skipping node.", who, ip, dc, rack);
531+
warn!("{} (untranslated ip: {}, dc: {:?}, rack: {:?}) has Host ID set to null; skipping node.", who, untranslated_ip_addr, datacenter, rack);
533532
None
534533
})
535534
.map(|untranslated_row| async {

0 commit comments

Comments
 (0)