From 916cbc1a397af3b629e637df3046e4a16bd99c12 Mon Sep 17 00:00:00 2001 From: Shachar Langbeheim Date: Mon, 14 Aug 2023 13:33:18 +0000 Subject: [PATCH] temp --- redis/src/cluster_topology.rs | 27 ++++++++++++++------------- redis/tests/test_cluster_async.rs | 10 +++++----- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/redis/src/cluster_topology.rs b/redis/src/cluster_topology.rs index 75c68dcbe..26fc68c03 100644 --- a/redis/src/cluster_topology.rs +++ b/redis/src/cluster_topology.rs @@ -88,21 +88,22 @@ pub(crate) struct SlotMap { read_from_replica: ReadFromReplicaStrategy, } -fn get_address_from_slot<'a>( - slot: &'a SlotMapValue, - read_from_replica: &'a ReadFromReplicaStrategy, +fn get_address_from_slot( + slot: &SlotMapValue, + read_from_replica: ReadFromReplicaStrategy, slot_addr: SlotAddr, -) -> &'a str { - if slot_addr == SlotAddr::Master || slot.replicas.is_empty() { - return slot.primary.as_str(); +) -> &str { + if slot_addr == SlotAddr::Master || slot.addrs.replicas.is_empty() { + return slot.addrs.primary.as_str(); } match read_from_replica { - ReadFromReplicaStrategy::AlwaysFromPrimary => slot.primary.as_str(), + ReadFromReplicaStrategy::AlwaysFromPrimary => slot.addrs.primary.as_str(), ReadFromReplicaStrategy::RoundRobin => { - let index = s; - latest_read_replica_index.fetch_add(1, std::sync::atomic::Ordering::Relaxed) - % slot.replicas.len(); - slot.replicas[index].as_str() + let index = slot + .latest_used_replica + .fetch_add(1, std::sync::atomic::Ordering::Relaxed) + % slot.addrs.replicas.len(); + slot.addrs.replicas[index].as_str() } } } @@ -132,8 +133,8 @@ impl SlotMap { .and_then(|(end, slot_value)| { if slot <= *end && slot_value.start <= slot { Some(get_address_from_slot( - &slot_value.addrs, - &self.read_from_replica, + slot_value, + self.read_from_replica, route.slot_addr(), )) } else { diff --git a/redis/tests/test_cluster_async.rs b/redis/tests/test_cluster_async.rs index df911e5d6..e2c1dfa37 100644 --- a/redis/tests/test_cluster_async.rs +++ b/redis/tests/test_cluster_async.rs @@ -1680,16 +1680,16 @@ fn test_async_cluster_round_robin_read_from_replica() { .query_async::<_, ()>(&mut connection) .await .unwrap(); - cmd("GET") - .arg("foo") - .query_async::<_, ()>(&mut connection) - .await - .unwrap(); cmd("GET") .arg("bar") .query_async::<_, ()>(&mut connection) .await .unwrap(); + cmd("GET") + .arg("foo") + .query_async::<_, ()>(&mut connection) + .await + .unwrap(); cmd("GET") .arg("bar") .query_async::<_, ()>(&mut connection)