Skip to content

Commit

Permalink
Merge pull request #1255 from gsson/update-rand
Browse files Browse the repository at this point in the history
Update `rand` crate 0.8.5 -> 0.9.0
  • Loading branch information
Lorak-mmk authored Feb 25, 2025
2 parents fc694ec + a4e5130 commit c24db77
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 45 deletions.
83 changes: 67 additions & 16 deletions Cargo.lock.msrv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ uuid = { version = "1.0", features = ["v1"] }
tower = "0.4"
stats_alloc = "0.1"
clap = { version = "3.2.4", features = ["derive"] }
rand = "0.8.5"
rand = "0.9.0"
env_logger = "0.10"

[[example]]
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_load_balancing_policy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use rand::thread_rng;
use rand::rng;
use rand::Rng;
use scylla::client::execution_profile::ExecutionProfile;
use scylla::client::session::Session;
Expand All @@ -23,7 +23,7 @@ fn with_random_shard(node: NodeRef) -> (NodeRef, Option<Shard>) {
.sharder()
.map(|sharder| sharder.nr_shards.get())
.unwrap_or(1);
(node, Some(thread_rng().gen_range(0..nr_shards) as Shard))
(node, Some(rng().random_range(0..nr_shards) as Shard))
}

impl LoadBalancingPolicy for CustomLoadBalancingPolicy {
Expand Down
2 changes: 1 addition & 1 deletion scylla-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bigdecimal = "0.4"
num-bigint = "0.3"
tracing = "0.1.25"
chrono = { version = "0.4", default-features = false }
rand = "0.8.5"
rand = "0.9.0"

[dev-dependencies]
assert_matches = "1.5.0"
Expand Down
4 changes: 2 additions & 2 deletions scylla-proxy/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Condition {
})
.unwrap_or(false),
Condition::RandomWithProbability(probability) => {
rand::thread_rng().gen_bool(*probability)
rand::rng().random_bool(*probability)
}

Condition::TrueForLimitedTimes(times) => {
Expand Down Expand Up @@ -592,7 +592,7 @@ impl ResponseForger {
|| example_db_errors::other(2137),
];
RequestReaction::forge_with_error_lazy_delay(
Box::new(|| ERRORS[rand::thread_rng().next_u32() as usize % ERRORS.len()]()),
Box::new(|| ERRORS[rand::rng().next_u32() as usize % ERRORS.len()]()),
delay,
)
}
Expand Down
2 changes: 1 addition & 1 deletion scylla-proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ mod tests {
fn random_body() -> Bytes {
let body_len = (rand::random::<u32>() % 1000) as usize;
let mut body = BytesMut::zeroed(body_len);
rand::thread_rng().fill_bytes(body.as_mut());
rand::rng().fill_bytes(body.as_mut());
body.freeze()
}

Expand Down
6 changes: 3 additions & 3 deletions scylla/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ tokio = { version = "1.34", features = [
] }
snap = "1.0"
uuid = { version = "1.0", features = ["v4"] }
rand = "0.8.3"
rand = "0.9.0"
thiserror = "2.0.6"
itertools = "0.13.0"
tracing = "0.1.36"
Expand All @@ -74,7 +74,7 @@ serde = { version = "1.0", features = ["derive"], optional = true }
serde_yaml = { version = "0.9.14", optional = true }
url = { version = "2.3.1", optional = true }
base64 = { version = "0.22.1", optional = true }
rand_pcg = "0.3.1"
rand_pcg = "0.9.0"
socket2 = { version = "0.5.3", features = ["all"] }
lazy_static = "1"

Expand All @@ -88,7 +88,7 @@ criterion = "0.4" # Note: v
tokio = { version = "1.34", features = ["test-util"] }
tracing-subscriber = { version = "0.3.14", features = ["env-filter"] }
assert_matches = "1.5.0"
rand_chacha = "0.3.1"
rand_chacha = "0.9.0"
time = "0.3"

[[bench]]
Expand Down
12 changes: 6 additions & 6 deletions scylla/src/cluster/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use crate::utils::pretty::{CommaSeparatedDisplayer, DisplayUsingDebug};
use futures::future::{self, FutureExt};
use futures::stream::{self, StreamExt, TryStreamExt};
use futures::Stream;
use rand::seq::SliceRandom;
use rand::{thread_rng, Rng};
use rand::seq::{IndexedRandom, SliceRandom};
use rand::{rng, Rng};
use scylla_macros::DeserializeRow;
use std::borrow::BorrowMut;
use std::cell::Cell;
Expand Down Expand Up @@ -416,7 +416,7 @@ impl MetadataReader {

let control_connection_endpoint = UntranslatedEndpoint::ContactPoint(
initial_peers
.choose(&mut thread_rng())
.choose(&mut rng())
.expect("Tried to initialize MetadataReader with empty initial_known_nodes list!")
.clone(),
);
Expand Down Expand Up @@ -469,7 +469,7 @@ impl MetadataReader {
// Therefore, we try to fetch metadata from other known peers, in order.

// shuffle known_peers to iterate through them in random order later
self.known_peers.shuffle(&mut thread_rng());
self.known_peers.shuffle(&mut rng());
debug!(
"Known peers: {}",
CommaSeparatedDisplayer(self.known_peers.iter().map(DisplayUsingDebug))
Expand Down Expand Up @@ -641,7 +641,7 @@ impl MetadataReader {
if !self.known_peers.is_empty() {
self.control_connection_endpoint = self
.known_peers
.choose(&mut thread_rng())
.choose(&mut rng())
.expect("known_peers is empty - should be impossible")
.clone();

Expand Down Expand Up @@ -856,7 +856,7 @@ async fn create_peer_from_row(
// Also, we could implement support for Cassandra's other standard partitioners
// like RandomPartitioner or ByteOrderedPartitioner.
trace!("Couldn't parse tokens as 64-bit integers: {}, proceeding with a dummy token. If you're using a partitioner with different token size, consider migrating to murmur3", e);
vec![Token::new(rand::thread_rng().gen::<i64>())]
vec![Token::new(rand::rng().random::<i64>())]
}
};

Expand Down
6 changes: 3 additions & 3 deletions scylla/src/network/connection_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl NodeConnectionPool {
sharder,
connections,
} => {
let shard: u16 = rand::thread_rng().gen_range(0..sharder.nr_shards.get());
let shard: u16 = rand::rng().random_range(0..sharder.nr_shards.get());
Self::connection_for_shard_helper(shard, sharder.nr_shards, connections.as_slice())
}
})
Expand All @@ -308,7 +308,7 @@ impl NodeConnectionPool {

let orig_shard = shard;
while !shards_to_try.is_empty() {
let idx = rand::thread_rng().gen_range(0..shards_to_try.len());
let idx = rand::rng().random_range(0..shards_to_try.len());
let shard = shards_to_try.swap_remove(idx);

if let Some(conn) =
Expand Down Expand Up @@ -381,7 +381,7 @@ impl NodeConnectionPool {
} else if v.len() == 1 {
Some(v[0].clone())
} else {
let idx = rand::thread_rng().gen_range(0..v.len());
let idx = rand::rng().random_range(0..v.len());
Some(v[idx].clone())
}
}
Expand Down
8 changes: 4 additions & 4 deletions scylla/src/policies/load_balancing/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
routing::{Shard, Token},
};
use itertools::{Either, Itertools};
use rand::{prelude::SliceRandom, thread_rng, Rng};
use rand::{prelude::SliceRandom, rng, Rng};
use rand_pcg::Pcg32;
use scylla_cql::frame::response::result::TableSpec;
use scylla_cql::frame::types::SerialConsistency;
Expand Down Expand Up @@ -815,7 +815,7 @@ impl DefaultPolicy {
let mut gen = Pcg32::new(fixed, 0);
replica_set.choose_filtered(&mut gen, |(node, shard)| predicate(node, *shard))
} else {
replica_set.choose_filtered(&mut thread_rng(), |(node, shard)| predicate(node, *shard))
replica_set.choose_filtered(&mut rng(), |(node, shard)| predicate(node, *shard))
}
}

Expand Down Expand Up @@ -853,7 +853,7 @@ impl DefaultPolicy {
// Create a randomly rotated slice view
let nodes_len = nodes.len();
if nodes_len > 0 {
let index = rand::thread_rng().gen_range(0..nodes_len); // gen_range() panics when range is empty!
let index = rng().random_range(0..nodes_len); // gen_range() panics when range is empty!
Either::Left(
nodes[index..]
.iter()
Expand Down Expand Up @@ -896,7 +896,7 @@ impl DefaultPolicy {
let mut gen = Pcg32::new(fixed, 0);
vec.shuffle(&mut gen);
} else {
vec.shuffle(&mut thread_rng());
vec.shuffle(&mut rng());
}

vec.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions scylla/src/policies/load_balancing/plan.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rand::{thread_rng, Rng};
use rand::{rng, Rng};
use tracing::error;

use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo};
Expand Down Expand Up @@ -98,7 +98,7 @@ impl<'a> Plan<'a> {
.sharder()
.map(|sharder| sharder.nr_shards.get())
.unwrap_or(1);
thread_rng().gen_range(0..nr_shards).into()
rng().random_range(0..nr_shards).into()
}),
)
}
Expand Down
2 changes: 1 addition & 1 deletion scylla/src/routing/locator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl<'a> ReplicaSet<'a> {
{
let len = self.len();
if len > 0 {
let index = rng.gen_range(0..len);
let index = rng.random_range(0..len);

match &self.inner {
ReplicaSetInner::Plain(replicas) => replicas
Expand Down
Loading

0 comments on commit c24db77

Please sign in to comment.