Skip to content

Commit c7c8ce9

Browse files
committed
latency_awareness: don't reinvent Iterator::partition
There exists `Iterator::partition` method that achieves what my manual imperative iteration used to achieve, so I introduced `Iterator::partition` there instead.
1 parent 4b4aa1d commit c7c8ce9

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

scylla/src/policies/load_balancing/default.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,10 +2786,7 @@ mod latency_awareness {
27862786
let average_latencies = self.node_avgs.read().unwrap();
27872787
let targets = fallback;
27882788

2789-
let mut fast_targets = vec![];
2790-
let mut penalised_targets = vec![];
2791-
2792-
for node_and_shard @ (node, _shard) in targets {
2789+
let (fast_targets, penalised_targets): (Vec<_>, Vec<_>) = targets.partition(|(node, _shard)|{
27932790
match fast_enough(
27942791
average_latencies.deref(),
27952792
node.host_id,
@@ -2798,17 +2795,14 @@ mod latency_awareness {
27982795
self.minimum_measurements,
27992796
min_avg_latency,
28002797
) {
2801-
FastEnough::Yes => fast_targets.push(node_and_shard),
2798+
FastEnough::Yes => true,
28022799
FastEnough::No { average } => {
28032800
trace!("Latency awareness: Penalising node {{address={}, datacenter={:?}, rack={:?}}} for being on average at least {} times slower (latency: {}ms) than the fastest ({}ms).",
28042801
node.address, node.datacenter, node.rack, self.exclusion_threshold, average.as_millis(), min_avg_latency.as_millis());
2805-
penalised_targets.push(node_and_shard);
2802+
false
28062803
}
28072804
}
2808-
}
2809-
2810-
let fast_targets = fast_targets.into_iter();
2811-
let penalised_targets = penalised_targets.into_iter();
2805+
});
28122806

28132807
let skipping_penalised_targets_iterator =
28142808
fast_targets.into_iter().chain(penalised_targets);

0 commit comments

Comments
 (0)