Skip to content

Commit

Permalink
Improve SlotMap printing in logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nihohit committed Oct 3, 2023
1 parent 60b3fc6 commit b482d01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion redis/src/cluster_async/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ where
num_of_nodes_to_query,
inner.cluster_params.read_from_replicas,
)?;
info!("Found slot map: {new_slots:?}");
info!("Found slot map: {new_slots}");
let connections = &*read_guard;
// Create a new connection vector of the found nodes
let mut nodes = new_slots.values().flatten().collect::<Vec<_>>();
Expand Down
18 changes: 18 additions & 0 deletions redis/src/cluster_topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::cluster_routing::{MultipleNodeRoutingInfo, Route, Slot, SlotAddr, Slo
use crate::{cluster::TlsMode, ErrorKind, RedisError, RedisResult, Value};
use derivative::Derivative;
use std::collections::{hash_map::DefaultHasher, BTreeMap, HashMap, HashSet};
use std::fmt::Display;
use std::hash::{Hash, Hasher};
use std::sync::atomic::AtomicUsize;
use std::time::Duration;
Expand Down Expand Up @@ -167,6 +168,23 @@ impl SlotMap {
}
}

impl Display for SlotMap {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Strategy: {:?}. Slot mapping:\n", self.read_from_replica)?;
for (end, slot_map_value) in self.slots.iter() {
writeln!(
f,
"({}-{}): primary: {}, replicas: {:?}",
slot_map_value.start,
end,
slot_map_value.addrs.primary,
slot_map_value.addrs.replicas
)?;
}
Ok(())
}
}

pub(crate) fn slot(key: &[u8]) -> u16 {
crc16::State::<crc16::XMODEM>::calculate(key) % SLOT_SIZE
}
Expand Down

0 comments on commit b482d01

Please sign in to comment.