Skip to content

Commit fa77480

Browse files
committed
Try to adapt to rand API changes
1 parent 2477c03 commit fa77480

File tree

25 files changed

+126
-124
lines changed

25 files changed

+126
-124
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/adapter/src/coord/message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl Coordinator {
335335
EpochMillis::try_from(self.storage_usage_collection_interval.as_millis())
336336
.expect("storage usage collection interval must fit into u64");
337337
let offset =
338-
rngs::SmallRng::from_seed(seed).gen_range(0..storage_usage_collection_interval_ms);
338+
rngs::SmallRng::from_seed(seed).random_range(0..storage_usage_collection_interval_ms);
339339
let now_ts: EpochMillis = self.peek_local_write_ts().await.into();
340340

341341
// 2) Determine the amount of ms between now and the next collection time.

src/adapter/src/coord/statement_logging.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use mz_sql_parser::ast::{statement_kind_label_value, StatementKind};
2626
use mz_storage_client::controller::IntrospectionType;
2727
use qcell::QCell;
2828
use rand::SeedableRng;
29-
use rand::{distributions::Bernoulli, prelude::Distribution, thread_rng};
29+
use rand::{distr::Bernoulli, prelude::Distribution, rng};
3030
use sha2::{Digest, Sha256};
3131
use tokio::time::MissedTickBehavior;
3232
use tracing::debug;
@@ -131,7 +131,7 @@ pub(crate) struct StatementLogging {
131131
unlogged_sessions: BTreeMap<Uuid, SessionHistoryEvent>,
132132

133133
/// A reproducible RNG for deciding whether to sample statement executions.
134-
/// Only used by tests; otherwise, `rand::thread_rng()` is used.
134+
/// Only used by tests; otherwise, `rand::rng()` is used.
135135
/// Controlled by the system var `statement_logging_use_reproducible_rng`.
136136
reproducible_rng: rand_chacha::ChaCha8Rng,
137137

@@ -682,7 +682,7 @@ impl Coordinator {
682682
{
683683
distribution.sample(&mut self.statement_logging.reproducible_rng)
684684
} else {
685-
distribution.sample(&mut thread_rng())
685+
distribution.sample(&mut rng())
686686
};
687687

688688
// Track how many statements we're recording.

src/adapter/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<T: TimestampManipulation> Session<T> {
328328
notices_tx,
329329
notices_rx,
330330
next_transaction_id: 0,
331-
secret_key: rand::thread_rng().gen(),
331+
secret_key: rand::rng().random(),
332332
external_metadata_rx,
333333
qcell_owner: QCellOwner::new(),
334334
session_oracles: BTreeMap::new(),

src/catalog/src/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ impl Fingerprint for &BuiltinTable {
382382
format!("{}{}", self.desc.fingerprint(), whitespace)
383383
}
384384
Some((UnsafeBuiltinTableFingerprintWhitespace::Half, whitespace)) => {
385-
let mut rng = rand::thread_rng();
386-
let migrate: bool = rng.gen();
385+
let mut rng = rand::rng();
386+
let migrate: bool = rng.random();
387387
if migrate {
388388
format!("{}{}", self.desc.fingerprint(), whitespace)
389389
} else {

src/cloud-resources/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ futures = "0.3.25"
1616
k8s-openapi = { version = "0.22.0", features = ["schemars", "v1_29"] }
1717
kube = { version = "0.92.1", default-features = false, features = ["client", "derive", "openssl-tls", "ws"] }
1818
mz-ore = { path = "../ore", default-features = false }
19-
rand = "0.9.0"
19+
rand = "0.8.5"
2020
schemars = { version = "0.8", features = ["uuid1"] }
2121
semver = "1.0.16"
2222
serde = "1.0.152"

src/environmentd/tests/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2970,7 +2970,7 @@ fn test_invalid_webhook_body() {
29702970

29712971
// No matter what is in the body, we should always succeed.
29722972
let mut data = [0u8; 128];
2973-
rand::thread_rng().fill_bytes(&mut data);
2973+
rand::rng().fill_bytes(&mut data);
29742974
println!("Random bytes: {data:?}");
29752975
let resp = http_client
29762976
.post(webhook_url)

src/expr/benches/window_functions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
1414
use mz_expr::ColumnOrder;
1515
use mz_repr::adt::timestamp::CheckedTimestamp;
1616
use mz_repr::{Datum, RowArena};
17-
use rand::distributions::{Distribution, Uniform};
17+
use rand::distr::{Distribution, Uniform};
1818

1919
/// Microbenchmark to test an important part of window function evaluation.
2020
///
@@ -53,7 +53,7 @@ fn order_aggregate_datums_benchmark(c: &mut Criterion) {
5353
let scale = 1000000;
5454

5555
group.bench_function("order_aggregate_datums", |b| {
56-
let mut rng = rand::thread_rng();
56+
let mut rng = rand::rng();
5757
let temp_storage = RowArena::new();
5858

5959
let order_by = vec![ColumnOrder {

src/kafka-util/src/bin/kgen.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ use mz_kafka_util::client::MzClientContext;
2323
use mz_ore::cast::CastFrom;
2424
use mz_ore::cli::{self, CliConfig};
2525
use mz_ore::retry::Retry;
26-
use rand::distributions::uniform::SampleUniform;
27-
use rand::distributions::{Alphanumeric, Bernoulli, Uniform, WeightedIndex};
26+
use rand::distr::uniform::SampleUniform;
27+
use rand::distr::weighted::WeightedIndex;
28+
use rand::distr::{Alphanumeric, Bernoulli, Uniform};
2829
use rand::prelude::{Distribution, ThreadRng};
29-
use rand::thread_rng;
30+
use rand::rng;
3031
use rdkafka::error::KafkaError;
3132
use rdkafka::producer::{BaseRecord, Producer, ThreadedProducer};
3233
use rdkafka::types::RDKafkaErrorCode;
@@ -247,21 +248,21 @@ impl<'a> RandomAvroGenerator<'a> {
247248
x[0].as_i64().unwrap().try_into().unwrap(),
248249
x[1].as_i64().unwrap().try_into().unwrap(),
249250
);
250-
let dist = Uniform::new_inclusive(min, max);
251+
let dist = Uniform::new_inclusive(min, max).unwrap();
251252
move |rng| dist.sample(rng)
252253
}
253254
fn float_dist(json: &serde_json::Value) -> impl FnMut(&mut ThreadRng) -> f32 + Clone {
254255
let x = json.as_array().unwrap();
255256
// TODO(benesch): rewrite to avoid `as`.
256257
#[allow(clippy::as_conversions)]
257258
let (min, max) = (x[0].as_f64().unwrap() as f32, x[1].as_f64().unwrap() as f32);
258-
let dist = Uniform::new_inclusive(min, max);
259+
let dist = Uniform::new_inclusive(min, max).unwrap();
259260
move |rng| dist.sample(rng)
260261
}
261262
fn double_dist(json: &serde_json::Value) -> impl FnMut(&mut ThreadRng) -> f64 + Clone {
262263
let x = json.as_array().unwrap();
263264
let (min, max) = (x[0].as_f64().unwrap(), x[1].as_f64().unwrap());
264-
let dist = Uniform::new_inclusive(min, max);
265+
let dist = Uniform::new_inclusive(min, max).unwrap();
265266
move |rng| dist.sample(rng)
266267
}
267268
fn string_dist(json: &serde_json::Value) -> impl FnMut(&mut ThreadRng) -> Vec<u8> + Clone {
@@ -276,7 +277,7 @@ impl<'a> RandomAvroGenerator<'a> {
276277
let mut len = integral_dist::<usize>(json);
277278
move |rng| {
278279
let len = len(rng);
279-
let bd = Uniform::new_inclusive(0, 255);
280+
let bd = Uniform::new_inclusive(0, 255).unwrap();
280281
iter::repeat_with(|| bd.sample(rng)).take(len).collect()
281282
}
282283
}
@@ -302,7 +303,7 @@ impl<'a> RandomAvroGenerator<'a> {
302303
min,
303304
precision
304305
);
305-
let dist = Uniform::<i64>::new_inclusive(min, max);
306+
let dist = Uniform::<i64>::new_inclusive(min, max).unwrap();
306307
move |rng| dist.sample(rng).to_be_bytes().to_vec()
307308
}
308309
// TODO(benesch): rewrite to avoid `as`.
@@ -602,8 +603,9 @@ async fn main() -> anyhow::Result<()> {
602603
bail!("cannot specify --avro-distribution without --values=avro");
603604
}
604605
let len =
605-
Uniform::new_inclusive(args.min_value_size.unwrap(), args.max_value_size.unwrap());
606-
let bytes = Uniform::new_inclusive(0, 255);
606+
Uniform::new_inclusive(args.min_value_size.unwrap(), args.max_value_size.unwrap())
607+
.unwrap();
608+
let bytes = Uniform::new_inclusive(0, 255).unwrap();
607609

608610
ValueGenerator::UniformBytes { len, bytes }
609611
}
@@ -677,10 +679,7 @@ async fn main() -> anyhow::Result<()> {
677679
}
678680
};
679681
let key_dist = if let KeyFormat::Random = args.key_format {
680-
Some(Uniform::new_inclusive(
681-
args.key_min.unwrap(),
682-
args.key_max.unwrap(),
683-
))
682+
Some(Uniform::new_inclusive(args.key_min.unwrap(), args.key_max.unwrap()).unwrap())
684683
} else {
685684
None
686685
};
@@ -711,7 +710,7 @@ async fn main() -> anyhow::Result<()> {
711710
n += 1;
712711
}
713712
scope.spawn(move |_| {
714-
let mut rng = thread_rng();
713+
let mut rng = rng();
715714
for _ in 0..n {
716715
let i = counter.fetch_add(1, Ordering::Relaxed);
717716
if !args.quiet && i % 100_000 == 0 {

src/orchestratord/src/controller/materialize/environmentd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use k8s_openapi::{
3030
};
3131
use kube::{api::ObjectMeta, runtime::controller::Action, Api, Client, ResourceExt};
3232
use maplit::btreemap;
33-
use rand::{thread_rng, Rng};
33+
use rand::{rng, Rng};
3434
use serde::{Deserialize, Serialize};
3535
use sha2::{Digest, Sha256};
3636
use tracing::trace;
@@ -175,7 +175,7 @@ impl Resources {
175175
// promotion step, this will no longer make a difference and we can
176176
// remove the extra codepath.
177177
if increment_generation {
178-
let retry_action = Action::requeue(Duration::from_secs(thread_rng().gen_range(5..10)));
178+
let retry_action = Action::requeue(Duration::from_secs(rng().random_range(5..10)));
179179

180180
let statefulset = get_resource(
181181
&statefulset_api,

0 commit comments

Comments
 (0)