Skip to content

Commit 4d2b63c

Browse files
committed
Cargo.toml: upgrade rand and petname
1 parent 8f1fd6d commit 4d2b63c

File tree

7 files changed

+35
-31
lines changed

7 files changed

+35
-31
lines changed

Cargo.lock

Lines changed: 9 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ fs4 = "0.13"
2323
hdrhistogram = "7.5"
2424
itertools = "0.14"
2525
log = "0.4"
26-
petname = "2.0"
27-
rand = "0.8"
26+
petname = "3.0.0-alpha.2"
27+
rand = "0.9"
2828
regex = "1.10"
2929
rustyline = "17.0"
3030
rustyline-derive = "0.11"

src/bin/workload.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use hdrhistogram::Histogram;
1818
use itertools::Itertools as _;
1919
use petname::Generator as _;
2020
use rand::SeedableRng as _;
21-
use rand::distributions::Distribution as _;
21+
use rand::distr::Distribution as _;
2222
use rand::rngs::StdRng;
2323

2424
use toydb::error::Result;
@@ -128,7 +128,7 @@ impl Runner {
128128
// Spawn work generator.
129129
{
130130
println!("Running workload {}...", workload);
131-
let generator = workload.generate(rng).take(self.count);
131+
let generator = workload.generate(rng)?.take(self.count);
132132
s.spawn(move || -> Result<()> {
133133
for item in generator {
134134
work_tx.send(item)?;
@@ -189,7 +189,7 @@ trait Workload: std::fmt::Display {
189189
fn prepare(&self, client: &mut Client, rng: &mut StdRng) -> Result<()>;
190190

191191
/// Generates work items as an iterator.
192-
fn generate(&self, rng: StdRng) -> impl Iterator<Item = Self::Item> + Send + 'static;
192+
fn generate(&self, rng: StdRng) -> Result<impl Iterator<Item = Self::Item> + Send + 'static>;
193193

194194
/// Executes a single work item. This will automatically be retried on
195195
/// certain errors, and must use a transaction where appropriate.
@@ -234,7 +234,7 @@ impl Workload for Read {
234234
client.execute(r#"DROP TABLE IF EXISTS "read""#)?;
235235
client.execute(r#"CREATE TABLE "read" (id INT PRIMARY KEY, value STRING NOT NULL)"#)?;
236236

237-
let chars = &mut rand::distributions::Alphanumeric.sample_iter(rng).map(|b| b as char);
237+
let chars = &mut rand::distr::Alphanumeric.sample_iter(rng).map(|b| b as char);
238238
let rows = (1..=self.rows).map(|id| (id, chars.take(self.size).collect::<String>()));
239239
let chunks = rows.chunks(100);
240240
let queries = chunks.into_iter().map(|chunk| {
@@ -250,12 +250,12 @@ impl Workload for Read {
250250
Ok(())
251251
}
252252

253-
fn generate(&self, rng: StdRng) -> impl Iterator<Item = Self::Item> + 'static {
254-
ReadGenerator {
253+
fn generate(&self, rng: StdRng) -> Result<impl Iterator<Item = Self::Item> + 'static> {
254+
Ok(ReadGenerator {
255255
batch: self.batch,
256-
dist: rand::distributions::Uniform::new(1, self.rows + 1),
256+
dist: rand::distr::Uniform::new(1, self.rows + 1)?,
257257
rng,
258-
}
258+
})
259259
}
260260

261261
fn execute(client: &mut Client, item: &Self::Item) -> Result<()> {
@@ -280,7 +280,7 @@ impl Workload for Read {
280280
struct ReadGenerator {
281281
batch: usize,
282282
rng: StdRng,
283-
dist: rand::distributions::Uniform<u64>,
283+
dist: rand::distr::Uniform<u64>,
284284
}
285285

286286
impl Iterator for ReadGenerator {
@@ -331,8 +331,8 @@ impl Workload for Write {
331331
Ok(())
332332
}
333333

334-
fn generate(&self, rng: StdRng) -> impl Iterator<Item = Self::Item> + 'static {
335-
WriteGenerator { next_id: 1, size: self.size, batch: self.batch, rng }
334+
fn generate(&self, rng: StdRng) -> Result<impl Iterator<Item = Self::Item> + 'static> {
335+
Ok(WriteGenerator { next_id: 1, size: self.size, batch: self.batch, rng })
336336
}
337337

338338
fn execute(client: &mut Client, item: &Self::Item) -> Result<()> {
@@ -369,8 +369,7 @@ impl Iterator for WriteGenerator {
369369
type Item = <Write as Workload>::Item;
370370

371371
fn next(&mut self) -> Option<Self::Item> {
372-
let chars =
373-
&mut rand::distributions::Alphanumeric.sample_iter(&mut self.rng).map(|b| b as char);
372+
let chars = &mut rand::distr::Alphanumeric.sample_iter(&mut self.rng).map(|b| b as char);
374373
let mut rows = Vec::with_capacity(self.batch);
375374
while rows.len() < self.batch {
376375
rows.push((self.next_id, chars.take(self.size).collect()));
@@ -451,16 +450,16 @@ impl Workload for Bank {
451450
Ok(())
452451
}
453452

454-
fn generate(&self, rng: StdRng) -> impl Iterator<Item = Self::Item> + 'static {
453+
fn generate(&self, rng: StdRng) -> Result<impl Iterator<Item = Self::Item> + 'static> {
455454
let customers = self.customers;
456455
let max_transfer = self.max_transfer;
457456
// Generate random u64s, then pick random from,to,amount as the
458457
// remainder of the max customer and amount.
459-
rand::distributions::Uniform::new_inclusive(0, u64::MAX)
458+
Ok(rand::distr::Uniform::new_inclusive(0, u64::MAX)?
460459
.sample_iter(rng)
461460
.tuples()
462461
.map(move |(a, b, c)| (a % customers + 1, b % customers + 1, c % max_transfer + 1))
463-
.filter(|(from, to, _)| from != to)
462+
.filter(|(from, to, _)| from != to))
464463
}
465464

466465
fn execute(client: &mut Client, item: &Self::Item) -> Result<()> {

src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Client {
104104
// to MAX_WAIT, but randomize the wait time in this interval
105105
// to reduce the chance of collisions.
106106
let mut wait = MAX_WAIT.min(MIN_WAIT * 2_u64.pow(retries));
107-
wait = rand::thread_rng().gen_range(MIN_WAIT..=wait);
107+
wait = rand::rng().random_range(MIN_WAIT..=wait);
108108
std::thread::sleep(Duration::from_millis(wait));
109109
retries += 1;
110110
}

src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ impl From<log::SetLoggerError> for Error {
163163
}
164164
}
165165

166+
impl From<rand::distr::uniform::Error> for Error {
167+
fn from(err: rand::distr::uniform::Error) -> Self {
168+
Error::InvalidInput(err.to_string())
169+
}
170+
}
171+
166172
impl From<regex::Error> for Error {
167173
fn from(err: regex::Error) -> Self {
168174
panic!("{err}") // faulty code

src/raft/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<R: Role> RawNode<R> {
214214

215215
/// Generates a random election timeout.
216216
fn random_election_timeout(&self) -> Ticks {
217-
rand::thread_rng().gen_range(self.opts.election_timeout_range.clone())
217+
rand::rng().random_range(self.opts.election_timeout_range.clone())
218218
}
219219

220220
/// Sends a message to the given recipient.

tests/testcluster.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl TestCluster {
6969
/// toysql is too annoying, since we have to deal with rustyline, PTYs,
7070
/// echoing, multiline editing, etc.
7171
pub fn connect(&self) -> Result<Client, Box<dyn Error>> {
72-
let id = rand::thread_rng().gen_range(1..=self.servers.len()) as NodeID;
72+
let id = rand::rng().random_range(1..=self.servers.len()) as NodeID;
7373
self.servers.get(&id).unwrap().connect()
7474
}
7575
}

0 commit comments

Comments
 (0)