Skip to content

Commit a65acf6

Browse files
committed
chore(distribute): address rand breaking changes
see rust-random/rand#1382. in particular, this part of the change: https://github.com/rust-random/rand/pull/1382/files#diff-b0eb1b0ef894742b65e07f23af6cbeffae64ec8311adb6ea606603e978023e0cL116-R113 see also rust-random/rand#1470. Signed-off-by: katelyn martin <[email protected]>
1 parent 39283dc commit a65acf6

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

linkerd/distribute/src/keys.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ahash::{HashMap, HashMapExt};
22
use rand::{
3-
distributions::{WeightedError, WeightedIndex},
3+
distr::weighted::{Error as WeightedError, WeightedIndex},
44
prelude::Distribution as _,
55
Rng,
66
};

linkerd/distribute/src/params.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{
33
WeightedServiceKeys,
44
};
55
use ahash::AHashSet;
6-
use rand::distributions::WeightedError;
76
use std::{fmt::Debug, hash::Hash, sync::Arc};
87

98
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -73,7 +72,7 @@ impl<K> Distribution<K> {
7372

7473
pub fn random_available<T: IntoIterator<Item = (K, u32)>>(
7574
iter: T,
76-
) -> Result<Self, WeightedError> {
75+
) -> Result<Self, rand::distr::weighted::Error> {
7776
let weighted_keys = WeightedServiceKeys::new(
7877
iter.into_iter()
7978
.map(|(key, weight)| WeightedKey { key, weight }),

linkerd/distribute/src/service/random.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{keys::KeyId, WeightedServiceKeys};
22
use ahash::HashMap;
33
use linkerd_stack::{NewService, Service};
4-
use rand::{distributions::WeightedError, rngs::SmallRng, SeedableRng};
4+
use rand::{rngs::SmallRng, SeedableRng};
55
use std::{
66
hash::Hash,
77
sync::Arc,
@@ -21,7 +21,7 @@ pub(crate) struct RandomAvailableSelection<K, S> {
2121
}
2222

2323
fn new_rng() -> SmallRng {
24-
SmallRng::from_rng(rand::thread_rng()).expect("RNG must initialize")
24+
SmallRng::from_rng(&mut rand::rng())
2525
}
2626

2727
impl<K, S> RandomAvailableSelection<K, S> {
@@ -92,7 +92,7 @@ where
9292
// to `poll_ready` can try this backend again.
9393
match selector.disable_backend(id) {
9494
Ok(()) => {}
95-
Err(WeightedError::AllWeightsZero) => {
95+
Err(rand::distr::weighted::Error::InsufficientNonZero) => {
9696
// There are no backends remaining.
9797
break;
9898
}

0 commit comments

Comments
 (0)