mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-23 06:09:59 +00:00
Bump rand crate to 0.9 (#12674)
This commit is contained in:
47
Cargo.lock
generated
47
Cargo.lock
generated
@@ -1451,7 +1451,7 @@ name = "consumption_metrics"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1854,7 +1854,7 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"hex",
|
"hex",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot 0.12.1",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"tracing",
|
"tracing",
|
||||||
"utils",
|
"utils",
|
||||||
@@ -2099,7 +2099,7 @@ dependencies = [
|
|||||||
"itertools 0.10.5",
|
"itertools 0.10.5",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
"prometheus",
|
"prometheus",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"remote_storage",
|
"remote_storage",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -3782,8 +3782,8 @@ dependencies = [
|
|||||||
"once_cell",
|
"once_cell",
|
||||||
"procfs",
|
"procfs",
|
||||||
"prometheus",
|
"prometheus",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"rand_distr 0.4.3",
|
"rand_distr",
|
||||||
"twox-hash",
|
"twox-hash",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3875,7 +3875,7 @@ dependencies = [
|
|||||||
"lock_api",
|
"lock_api",
|
||||||
"nix 0.30.1",
|
"nix 0.30.1",
|
||||||
"rand 0.9.1",
|
"rand 0.9.1",
|
||||||
"rand_distr 0.5.1",
|
"rand_distr",
|
||||||
"rustc-hash 2.1.1",
|
"rustc-hash 2.1.1",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror 1.0.69",
|
"thiserror 1.0.69",
|
||||||
@@ -4351,7 +4351,7 @@ dependencies = [
|
|||||||
"pageserver_client_grpc",
|
"pageserver_client_grpc",
|
||||||
"pageserver_page_api",
|
"pageserver_page_api",
|
||||||
"pprof",
|
"pprof",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -4448,7 +4448,7 @@ dependencies = [
|
|||||||
"pprof",
|
"pprof",
|
||||||
"pq_proto",
|
"pq_proto",
|
||||||
"procfs",
|
"procfs",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"range-set-blaze",
|
"range-set-blaze",
|
||||||
"regex",
|
"regex",
|
||||||
"remote_storage",
|
"remote_storage",
|
||||||
@@ -4515,7 +4515,7 @@ dependencies = [
|
|||||||
"postgres_ffi_types",
|
"postgres_ffi_types",
|
||||||
"postgres_versioninfo",
|
"postgres_versioninfo",
|
||||||
"posthog_client_lite",
|
"posthog_client_lite",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"remote_storage",
|
"remote_storage",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -4585,7 +4585,7 @@ dependencies = [
|
|||||||
"once_cell",
|
"once_cell",
|
||||||
"pageserver_api",
|
"pageserver_api",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"svg_fmt",
|
"svg_fmt",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
@@ -4958,7 +4958,7 @@ dependencies = [
|
|||||||
"fallible-iterator",
|
"fallible-iterator",
|
||||||
"hmac",
|
"hmac",
|
||||||
"memchr",
|
"memchr",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"sha2",
|
"sha2",
|
||||||
"stringprep",
|
"stringprep",
|
||||||
"tokio",
|
"tokio",
|
||||||
@@ -5150,7 +5150,7 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"itertools 0.10.5",
|
"itertools 0.10.5",
|
||||||
"postgres-protocol",
|
"postgres-protocol",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"serde",
|
"serde",
|
||||||
"thiserror 1.0.69",
|
"thiserror 1.0.69",
|
||||||
"tokio",
|
"tokio",
|
||||||
@@ -5414,8 +5414,9 @@ dependencies = [
|
|||||||
"postgres-protocol2",
|
"postgres-protocol2",
|
||||||
"postgres_backend",
|
"postgres_backend",
|
||||||
"pq_proto",
|
"pq_proto",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"rand_distr 0.4.3",
|
"rand_core 0.6.4",
|
||||||
|
"rand_distr",
|
||||||
"rcgen",
|
"rcgen",
|
||||||
"redis",
|
"redis",
|
||||||
"regex",
|
"regex",
|
||||||
@@ -5617,16 +5618,6 @@ dependencies = [
|
|||||||
"getrandom 0.3.3",
|
"getrandom 0.3.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_distr"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31"
|
|
||||||
dependencies = [
|
|
||||||
"num-traits",
|
|
||||||
"rand 0.8.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_distr"
|
name = "rand_distr"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
@@ -5840,7 +5831,7 @@ dependencies = [
|
|||||||
"metrics",
|
"metrics",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"scopeguard",
|
"scopeguard",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -6330,7 +6321,7 @@ dependencies = [
|
|||||||
"postgres_versioninfo",
|
"postgres_versioninfo",
|
||||||
"pprof",
|
"pprof",
|
||||||
"pq_proto",
|
"pq_proto",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"regex",
|
"regex",
|
||||||
"remote_storage",
|
"remote_storage",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
@@ -7024,7 +7015,7 @@ dependencies = [
|
|||||||
"pageserver_client",
|
"pageserver_client",
|
||||||
"postgres_connection",
|
"postgres_connection",
|
||||||
"posthog_client_lite",
|
"posthog_client_lite",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"routerify",
|
"routerify",
|
||||||
@@ -8305,7 +8296,7 @@ dependencies = [
|
|||||||
"postgres_connection",
|
"postgres_connection",
|
||||||
"pprof",
|
"pprof",
|
||||||
"pq_proto",
|
"pq_proto",
|
||||||
"rand 0.8.5",
|
"rand 0.9.1",
|
||||||
"regex",
|
"regex",
|
||||||
"scopeguard",
|
"scopeguard",
|
||||||
"sentry",
|
"sentry",
|
||||||
|
|||||||
@@ -158,7 +158,9 @@ procfs = "0.16"
|
|||||||
prometheus = {version = "0.13", default-features=false, features = ["process"]} # removes protobuf dependency
|
prometheus = {version = "0.13", default-features=false, features = ["process"]} # removes protobuf dependency
|
||||||
prost = "0.13.5"
|
prost = "0.13.5"
|
||||||
prost-types = "0.13.5"
|
prost-types = "0.13.5"
|
||||||
rand = "0.8"
|
rand = "0.9"
|
||||||
|
# Remove after p256 is updated to 0.14.
|
||||||
|
rand_core = "=0.6"
|
||||||
redis = { version = "0.29.2", features = ["tokio-rustls-comp", "keep-alive"] }
|
redis = { version = "0.29.2", features = ["tokio-rustls-comp", "keep-alive"] }
|
||||||
regex = "1.10.2"
|
regex = "1.10.2"
|
||||||
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }
|
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ mod tests {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.as_millis();
|
.as_millis();
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
let random = rand::thread_rng().r#gen::<u32>();
|
let random = rand::rng().random::<u32>();
|
||||||
|
|
||||||
let s3_config = remote_storage::S3Config {
|
let s3_config = remote_storage::S3Config {
|
||||||
bucket_name: var(REAL_S3_BUCKET).unwrap(),
|
bucket_name: var(REAL_S3_BUCKET).unwrap(),
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ impl<'a> IdempotencyKey<'a> {
|
|||||||
IdempotencyKey {
|
IdempotencyKey {
|
||||||
now: Utc::now(),
|
now: Utc::now(),
|
||||||
node_id,
|
node_id,
|
||||||
nonce: rand::thread_rng().gen_range(0..=9999),
|
nonce: rand::rng().random_range(0..=9999),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ impl NodeOs {
|
|||||||
|
|
||||||
/// Generate a random number in range [0, max).
|
/// Generate a random number in range [0, max).
|
||||||
pub fn random(&self, max: u64) -> u64 {
|
pub fn random(&self, max: u64) -> u64 {
|
||||||
self.internal.rng.lock().gen_range(0..max)
|
self.internal.rng.lock().random_range(0..max)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Append a new event to the world event log.
|
/// Append a new event to the world event log.
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ impl Delay {
|
|||||||
/// Generate a random delay in range [min, max]. Return None if the
|
/// Generate a random delay in range [min, max]. Return None if the
|
||||||
/// message should be dropped.
|
/// message should be dropped.
|
||||||
pub fn delay(&self, rng: &mut StdRng) -> Option<u64> {
|
pub fn delay(&self, rng: &mut StdRng) -> Option<u64> {
|
||||||
if rng.gen_bool(self.fail_prob) {
|
if rng.random_bool(self.fail_prob) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(rng.gen_range(self.min..=self.max))
|
Some(rng.random_range(self.min..=self.max))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ impl World {
|
|||||||
/// Create a new random number generator.
|
/// Create a new random number generator.
|
||||||
pub fn new_rng(&self) -> StdRng {
|
pub fn new_rng(&self) -> StdRng {
|
||||||
let mut rng = self.rng.lock();
|
let mut rng = self.rng.lock();
|
||||||
StdRng::from_rng(rng.deref_mut()).unwrap()
|
StdRng::from_rng(rng.deref_mut())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new node.
|
/// Create a new node.
|
||||||
|
|||||||
@@ -17,5 +17,5 @@ procfs.workspace = true
|
|||||||
measured-process.workspace = true
|
measured-process.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = "0.8"
|
rand.workspace = true
|
||||||
rand_distr = "0.4.3"
|
rand_distr = "0.5"
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cardinality_small() {
|
fn test_cardinality_small() {
|
||||||
let (actual, estimate) = test_cardinality(100, Zipf::new(100, 1.2f64).unwrap());
|
let (actual, estimate) = test_cardinality(100, Zipf::new(100.0, 1.2f64).unwrap());
|
||||||
|
|
||||||
assert_eq!(actual, [46, 30, 32]);
|
assert_eq!(actual, [46, 30, 32]);
|
||||||
assert!(51.3 < estimate[0] && estimate[0] < 51.4);
|
assert!(51.3 < estimate[0] && estimate[0] < 51.4);
|
||||||
@@ -270,7 +270,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cardinality_medium() {
|
fn test_cardinality_medium() {
|
||||||
let (actual, estimate) = test_cardinality(10000, Zipf::new(10000, 1.2f64).unwrap());
|
let (actual, estimate) = test_cardinality(10000, Zipf::new(10000.0, 1.2f64).unwrap());
|
||||||
|
|
||||||
assert_eq!(actual, [2529, 1618, 1629]);
|
assert_eq!(actual, [2529, 1618, 1629]);
|
||||||
assert!(2309.1 < estimate[0] && estimate[0] < 2309.2);
|
assert!(2309.1 < estimate[0] && estimate[0] < 2309.2);
|
||||||
@@ -280,7 +280,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cardinality_large() {
|
fn test_cardinality_large() {
|
||||||
let (actual, estimate) = test_cardinality(1_000_000, Zipf::new(1_000_000, 1.2f64).unwrap());
|
let (actual, estimate) =
|
||||||
|
test_cardinality(1_000_000, Zipf::new(1_000_000.0, 1.2f64).unwrap());
|
||||||
|
|
||||||
assert_eq!(actual, [129077, 79579, 79630]);
|
assert_eq!(actual, [129077, 79579, 79630]);
|
||||||
assert!(126067.2 < estimate[0] && estimate[0] < 126067.3);
|
assert!(126067.2 < estimate[0] && estimate[0] < 126067.3);
|
||||||
@@ -290,7 +291,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cardinality_small2() {
|
fn test_cardinality_small2() {
|
||||||
let (actual, estimate) = test_cardinality(100, Zipf::new(200, 0.8f64).unwrap());
|
let (actual, estimate) = test_cardinality(100, Zipf::new(200.0, 0.8f64).unwrap());
|
||||||
|
|
||||||
assert_eq!(actual, [92, 58, 60]);
|
assert_eq!(actual, [92, 58, 60]);
|
||||||
assert!(116.1 < estimate[0] && estimate[0] < 116.2);
|
assert!(116.1 < estimate[0] && estimate[0] < 116.2);
|
||||||
@@ -300,7 +301,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cardinality_medium2() {
|
fn test_cardinality_medium2() {
|
||||||
let (actual, estimate) = test_cardinality(10000, Zipf::new(20000, 0.8f64).unwrap());
|
let (actual, estimate) = test_cardinality(10000, Zipf::new(20000.0, 0.8f64).unwrap());
|
||||||
|
|
||||||
assert_eq!(actual, [8201, 5131, 5051]);
|
assert_eq!(actual, [8201, 5131, 5051]);
|
||||||
assert!(6846.4 < estimate[0] && estimate[0] < 6846.5);
|
assert!(6846.4 < estimate[0] && estimate[0] < 6846.5);
|
||||||
@@ -310,7 +311,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cardinality_large2() {
|
fn test_cardinality_large2() {
|
||||||
let (actual, estimate) = test_cardinality(1_000_000, Zipf::new(2_000_000, 0.8f64).unwrap());
|
let (actual, estimate) =
|
||||||
|
test_cardinality(1_000_000, Zipf::new(2_000_000.0, 0.8f64).unwrap());
|
||||||
|
|
||||||
assert_eq!(actual, [777847, 482069, 482246]);
|
assert_eq!(actual, [777847, 482069, 482246]);
|
||||||
assert!(699437.4 < estimate[0] && estimate[0] < 699437.5);
|
assert!(699437.4 < estimate[0] && estimate[0] < 699437.5);
|
||||||
|
|||||||
@@ -16,5 +16,5 @@ rustc-hash.workspace = true
|
|||||||
tempfile = "3.14.0"
|
tempfile = "3.14.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = "0.9"
|
rand.workspace = true
|
||||||
rand_distr = "0.5.1"
|
rand_distr = "0.5.1"
|
||||||
|
|||||||
@@ -981,12 +981,12 @@ mod tests {
|
|||||||
let mut rng = rand::rngs::StdRng::seed_from_u64(42);
|
let mut rng = rand::rngs::StdRng::seed_from_u64(42);
|
||||||
|
|
||||||
let key = Key {
|
let key = Key {
|
||||||
field1: rng.r#gen(),
|
field1: rng.random(),
|
||||||
field2: rng.r#gen(),
|
field2: rng.random(),
|
||||||
field3: rng.r#gen(),
|
field3: rng.random(),
|
||||||
field4: rng.r#gen(),
|
field4: rng.random(),
|
||||||
field5: rng.r#gen(),
|
field5: rng.random(),
|
||||||
field6: rng.r#gen(),
|
field6: rng.random(),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(key, Key::from_str(&format!("{key}")).unwrap());
|
assert_eq!(key, Key::from_str(&format!("{key}")).unwrap());
|
||||||
|
|||||||
@@ -443,9 +443,9 @@ pub struct ImportPgdataIdempotencyKey(pub String);
|
|||||||
impl ImportPgdataIdempotencyKey {
|
impl ImportPgdataIdempotencyKey {
|
||||||
pub fn random() -> Self {
|
pub fn random() -> Self {
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distr::Alphanumeric;
|
||||||
Self(
|
Self(
|
||||||
rand::thread_rng()
|
rand::rng()
|
||||||
.sample_iter(&Alphanumeric)
|
.sample_iter(&Alphanumeric)
|
||||||
.take(20)
|
.take(20)
|
||||||
.map(char::from)
|
.map(char::from)
|
||||||
|
|||||||
@@ -203,12 +203,12 @@ impl fmt::Display for CancelKeyData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use rand::distributions::{Distribution, Standard};
|
use rand::distr::{Distribution, StandardUniform};
|
||||||
impl Distribution<CancelKeyData> for Standard {
|
impl Distribution<CancelKeyData> for StandardUniform {
|
||||||
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> CancelKeyData {
|
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> CancelKeyData {
|
||||||
CancelKeyData {
|
CancelKeyData {
|
||||||
backend_pid: rng.r#gen(),
|
backend_pid: rng.random(),
|
||||||
cancel_key: rng.r#gen(),
|
cancel_key: rng.random(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,10 +155,10 @@ pub struct ScramSha256 {
|
|||||||
|
|
||||||
fn nonce() -> String {
|
fn nonce() -> String {
|
||||||
// rand 0.5's ThreadRng is cryptographically secure
|
// rand 0.5's ThreadRng is cryptographically secure
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::rng();
|
||||||
(0..NONCE_LENGTH)
|
(0..NONCE_LENGTH)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let mut v = rng.gen_range(0x21u8..0x7e);
|
let mut v = rng.random_range(0x21u8..0x7e);
|
||||||
if v == 0x2c {
|
if v == 0x2c {
|
||||||
v = 0x7e
|
v = 0x7e
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const SCRAM_DEFAULT_SALT_LEN: usize = 16;
|
|||||||
/// special characters that would require escaping in an SQL command.
|
/// special characters that would require escaping in an SQL command.
|
||||||
pub async fn scram_sha_256(password: &[u8]) -> String {
|
pub async fn scram_sha_256(password: &[u8]) -> String {
|
||||||
let mut salt: [u8; SCRAM_DEFAULT_SALT_LEN] = [0; SCRAM_DEFAULT_SALT_LEN];
|
let mut salt: [u8; SCRAM_DEFAULT_SALT_LEN] = [0; SCRAM_DEFAULT_SALT_LEN];
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::rng();
|
||||||
rng.fill_bytes(&mut salt);
|
rng.fill_bytes(&mut salt);
|
||||||
scram_sha_256_salt(password, salt).await
|
scram_sha_256_salt(password, salt).await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ itertools.workspace = true
|
|||||||
sync_wrapper = { workspace = true, features = ["futures"] }
|
sync_wrapper = { workspace = true, features = ["futures"] }
|
||||||
|
|
||||||
byteorder = "1.4"
|
byteorder = "1.4"
|
||||||
rand = "0.8.5"
|
rand.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
camino-tempfile.workspace = true
|
camino-tempfile.workspace = true
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ impl UnreliableWrapper {
|
|||||||
///
|
///
|
||||||
fn attempt(&self, op: RemoteOp) -> anyhow::Result<u64> {
|
fn attempt(&self, op: RemoteOp) -> anyhow::Result<u64> {
|
||||||
let mut attempts = self.attempts.lock().unwrap();
|
let mut attempts = self.attempts.lock().unwrap();
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::rng();
|
||||||
|
|
||||||
match attempts.entry(op) {
|
match attempts.entry(op) {
|
||||||
Entry::Occupied(mut e) => {
|
Entry::Occupied(mut e) => {
|
||||||
@@ -94,7 +94,7 @@ impl UnreliableWrapper {
|
|||||||
/* BEGIN_HADRON */
|
/* BEGIN_HADRON */
|
||||||
// If there are more attempts to fail, fail the request by probability.
|
// If there are more attempts to fail, fail the request by probability.
|
||||||
if (attempts_before_this < self.attempts_to_fail)
|
if (attempts_before_this < self.attempts_to_fail)
|
||||||
&& (rng.gen_range(0..=100) < self.attempt_failure_probability)
|
&& (rng.random_range(0..=100) < self.attempt_failure_probability)
|
||||||
{
|
{
|
||||||
let error =
|
let error =
|
||||||
anyhow::anyhow!("simulated failure of remote operation {:?}", e.key());
|
anyhow::anyhow!("simulated failure of remote operation {:?}", e.key());
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ async fn create_azure_client(
|
|||||||
.as_millis();
|
.as_millis();
|
||||||
|
|
||||||
// because nanos can be the same for two threads so can millis, add randomness
|
// because nanos can be the same for two threads so can millis, add randomness
|
||||||
let random = rand::thread_rng().r#gen::<u32>();
|
let random = rand::rng().random::<u32>();
|
||||||
|
|
||||||
let remote_storage_config = RemoteStorageConfig {
|
let remote_storage_config = RemoteStorageConfig {
|
||||||
storage: RemoteStorageKind::AzureContainer(AzureConfig {
|
storage: RemoteStorageKind::AzureContainer(AzureConfig {
|
||||||
|
|||||||
@@ -385,7 +385,7 @@ async fn create_s3_client(
|
|||||||
.as_millis();
|
.as_millis();
|
||||||
|
|
||||||
// because nanos can be the same for two threads so can millis, add randomness
|
// because nanos can be the same for two threads so can millis, add randomness
|
||||||
let random = rand::thread_rng().r#gen::<u32>();
|
let random = rand::rng().random::<u32>();
|
||||||
|
|
||||||
let remote_storage_config = RemoteStorageConfig {
|
let remote_storage_config = RemoteStorageConfig {
|
||||||
storage: RemoteStorageKind::AwsS3(S3Config {
|
storage: RemoteStorageKind::AwsS3(S3Config {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ impl Id {
|
|||||||
|
|
||||||
pub fn generate() -> Self {
|
pub fn generate() -> Self {
|
||||||
let mut tli_buf = [0u8; 16];
|
let mut tli_buf = [0u8; 16];
|
||||||
rand::thread_rng().fill(&mut tli_buf);
|
rand::rng().fill(&mut tli_buf);
|
||||||
Id::from(tli_buf)
|
Id::from(tli_buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -364,42 +364,37 @@ impl MonotonicCounter<Lsn> for RecordLsn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implements [`rand::distributions::uniform::UniformSampler`] so we can sample [`Lsn`]s.
|
/// Implements [`rand::distr::uniform::UniformSampler`] so we can sample [`Lsn`]s.
|
||||||
///
|
///
|
||||||
/// This is used by the `pagebench` pageserver benchmarking tool.
|
/// This is used by the `pagebench` pageserver benchmarking tool.
|
||||||
pub struct LsnSampler(<u64 as rand::distributions::uniform::SampleUniform>::Sampler);
|
pub struct LsnSampler(<u64 as rand::distr::uniform::SampleUniform>::Sampler);
|
||||||
|
|
||||||
impl rand::distributions::uniform::SampleUniform for Lsn {
|
impl rand::distr::uniform::SampleUniform for Lsn {
|
||||||
type Sampler = LsnSampler;
|
type Sampler = LsnSampler;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl rand::distributions::uniform::UniformSampler for LsnSampler {
|
impl rand::distr::uniform::UniformSampler for LsnSampler {
|
||||||
type X = Lsn;
|
type X = Lsn;
|
||||||
|
|
||||||
fn new<B1, B2>(low: B1, high: B2) -> Self
|
fn new<B1, B2>(low: B1, high: B2) -> Result<Self, rand::distr::uniform::Error>
|
||||||
where
|
where
|
||||||
B1: rand::distributions::uniform::SampleBorrow<Self::X> + Sized,
|
B1: rand::distr::uniform::SampleBorrow<Self::X> + Sized,
|
||||||
B2: rand::distributions::uniform::SampleBorrow<Self::X> + Sized,
|
B2: rand::distr::uniform::SampleBorrow<Self::X> + Sized,
|
||||||
{
|
{
|
||||||
Self(
|
<u64 as rand::distr::uniform::SampleUniform>::Sampler::new(low.borrow().0, high.borrow().0)
|
||||||
<u64 as rand::distributions::uniform::SampleUniform>::Sampler::new(
|
.map(Self)
|
||||||
low.borrow().0,
|
|
||||||
high.borrow().0,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self
|
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Result<Self, rand::distr::uniform::Error>
|
||||||
where
|
where
|
||||||
B1: rand::distributions::uniform::SampleBorrow<Self::X> + Sized,
|
B1: rand::distr::uniform::SampleBorrow<Self::X> + Sized,
|
||||||
B2: rand::distributions::uniform::SampleBorrow<Self::X> + Sized,
|
B2: rand::distr::uniform::SampleBorrow<Self::X> + Sized,
|
||||||
{
|
{
|
||||||
Self(
|
<u64 as rand::distr::uniform::SampleUniform>::Sampler::new_inclusive(
|
||||||
<u64 as rand::distributions::uniform::SampleUniform>::Sampler::new_inclusive(
|
|
||||||
low.borrow().0,
|
low.borrow().0,
|
||||||
high.borrow().0,
|
high.borrow().0,
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
.map(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sample<R: rand::prelude::Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
|
fn sample<R: rand::prelude::Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ use pageserver::tenant::layer_map::LayerMap;
|
|||||||
use pageserver::tenant::storage_layer::{LayerName, PersistentLayerDesc};
|
use pageserver::tenant::storage_layer::{LayerName, PersistentLayerDesc};
|
||||||
use pageserver_api::key::Key;
|
use pageserver_api::key::Key;
|
||||||
use pageserver_api::shard::TenantShardId;
|
use pageserver_api::shard::TenantShardId;
|
||||||
use rand::prelude::{SeedableRng, SliceRandom, StdRng};
|
use rand::prelude::{SeedableRng, StdRng};
|
||||||
|
use rand::seq::IndexedRandom;
|
||||||
use utils::id::{TenantId, TimelineId};
|
use utils::id::{TenantId, TimelineId};
|
||||||
use utils::lsn::Lsn;
|
use utils::lsn::Lsn;
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ async fn simulate(cmd: &SimulateCmd, results_path: &Path) -> anyhow::Result<()>
|
|||||||
let cold_key_range = splitpoint..key_range.end;
|
let cold_key_range = splitpoint..key_range.end;
|
||||||
|
|
||||||
for i in 0..cmd.num_records {
|
for i in 0..cmd.num_records {
|
||||||
let chosen_range = if rand::thread_rng().gen_bool(0.9) {
|
let chosen_range = if rand::rng().random_bool(0.9) {
|
||||||
&hot_key_range
|
&hot_key_range
|
||||||
} else {
|
} else {
|
||||||
&cold_key_range
|
&cold_key_range
|
||||||
|
|||||||
@@ -300,9 +300,9 @@ impl MockTimeline {
|
|||||||
key_range: &Range<Key>,
|
key_range: &Range<Key>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
crate::helpers::union_to_keyspace(&mut self.keyspace, vec![key_range.clone()]);
|
crate::helpers::union_to_keyspace(&mut self.keyspace, vec![key_range.clone()]);
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::rng();
|
||||||
for _ in 0..num_records {
|
for _ in 0..num_records {
|
||||||
self.ingest_record(rng.gen_range(key_range.clone()), len);
|
self.ingest_record(rng.random_range(key_range.clone()), len);
|
||||||
self.wal_ingested += len;
|
self.wal_ingested += len;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -188,9 +188,9 @@ async fn main_impl(
|
|||||||
start_work_barrier.wait().await;
|
start_work_barrier.wait().await;
|
||||||
loop {
|
loop {
|
||||||
let (timeline, work) = {
|
let (timeline, work) = {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::rng();
|
||||||
let target = all_targets.choose(&mut rng).unwrap();
|
let target = all_targets.choose(&mut rng).unwrap();
|
||||||
let lsn = target.lsn_range.clone().map(|r| rng.gen_range(r));
|
let lsn = target.lsn_range.clone().map(|r| rng.random_range(r));
|
||||||
(target.timeline, Work { lsn })
|
(target.timeline, Work { lsn })
|
||||||
};
|
};
|
||||||
let sender = work_senders.get(&timeline).unwrap();
|
let sender = work_senders.get(&timeline).unwrap();
|
||||||
|
|||||||
@@ -326,8 +326,7 @@ async fn main_impl(
|
|||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
let weights =
|
let weights =
|
||||||
rand::distributions::weighted::WeightedIndex::new(ranges.iter().map(|v| v.len()))
|
rand::distr::weighted::WeightedIndex::new(ranges.iter().map(|v| v.len())).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let scheme = match Url::parse(&args.page_service_connstring) {
|
let scheme = match Url::parse(&args.page_service_connstring) {
|
||||||
@@ -427,7 +426,7 @@ async fn run_worker(
|
|||||||
cancel: CancellationToken,
|
cancel: CancellationToken,
|
||||||
rps_period: Option<Duration>,
|
rps_period: Option<Duration>,
|
||||||
ranges: Vec<KeyRange>,
|
ranges: Vec<KeyRange>,
|
||||||
weights: rand::distributions::weighted::WeightedIndex<i128>,
|
weights: rand::distr::weighted::WeightedIndex<i128>,
|
||||||
) {
|
) {
|
||||||
shared_state.start_work_barrier.wait().await;
|
shared_state.start_work_barrier.wait().await;
|
||||||
let client_start = Instant::now();
|
let client_start = Instant::now();
|
||||||
@@ -469,9 +468,9 @@ async fn run_worker(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pick a random page from a random relation.
|
// Pick a random page from a random relation.
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::rng();
|
||||||
let r = &ranges[weights.sample(&mut rng)];
|
let r = &ranges[weights.sample(&mut rng)];
|
||||||
let key: i128 = rng.gen_range(r.start..r.end);
|
let key: i128 = rng.random_range(r.start..r.end);
|
||||||
let (rel_tag, block_no) = key_to_block(key);
|
let (rel_tag, block_no) = key_to_block(key);
|
||||||
|
|
||||||
let mut blks = VecDeque::with_capacity(batch_size);
|
let mut blks = VecDeque::with_capacity(batch_size);
|
||||||
@@ -502,7 +501,7 @@ async fn run_worker(
|
|||||||
// We assume that the entire batch can fit within the relation.
|
// We assume that the entire batch can fit within the relation.
|
||||||
assert_eq!(blks.len(), batch_size, "incomplete batch");
|
assert_eq!(blks.len(), batch_size, "incomplete batch");
|
||||||
|
|
||||||
let req_lsn = if rng.gen_bool(args.req_latest_probability) {
|
let req_lsn = if rng.random_bool(args.req_latest_probability) {
|
||||||
Lsn::MAX
|
Lsn::MAX
|
||||||
} else {
|
} else {
|
||||||
r.timeline_lsn
|
r.timeline_lsn
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use std::time::{Duration, Instant};
|
|||||||
use pageserver_api::models::HistoricLayerInfo;
|
use pageserver_api::models::HistoricLayerInfo;
|
||||||
use pageserver_api::shard::TenantShardId;
|
use pageserver_api::shard::TenantShardId;
|
||||||
use pageserver_client::mgmt_api;
|
use pageserver_client::mgmt_api;
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::IndexedMutRandom;
|
||||||
use tokio::sync::{OwnedSemaphorePermit, mpsc};
|
use tokio::sync::{OwnedSemaphorePermit, mpsc};
|
||||||
use tokio::task::JoinSet;
|
use tokio::task::JoinSet;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
@@ -260,7 +260,7 @@ async fn timeline_actor(
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
let layer_tx = {
|
let layer_tx = {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::rng();
|
||||||
timeline.layers.choose_mut(&mut rng).expect("no layers")
|
timeline.layers.choose_mut(&mut rng).expect("no layers")
|
||||||
};
|
};
|
||||||
match layer_tx.try_send(permit.take().unwrap()) {
|
match layer_tx.try_send(permit.take().unwrap()) {
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ impl FeatureResolver {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let tenant_properties = PerTenantProperties {
|
let tenant_properties = PerTenantProperties {
|
||||||
remote_size_mb: Some(rand::thread_rng().gen_range(100.0..1000000.00)),
|
remote_size_mb: Some(rand::rng().random_range(100.0..1000000.00)),
|
||||||
}
|
}
|
||||||
.into_posthog_properties();
|
.into_posthog_properties();
|
||||||
|
|
||||||
|
|||||||
@@ -6161,11 +6161,11 @@ mod tests {
|
|||||||
use pageserver_api::keyspace::KeySpaceRandomAccum;
|
use pageserver_api::keyspace::KeySpaceRandomAccum;
|
||||||
use pageserver_api::models::{CompactionAlgorithm, CompactionAlgorithmSettings, LsnLease};
|
use pageserver_api::models::{CompactionAlgorithm, CompactionAlgorithmSettings, LsnLease};
|
||||||
use pageserver_compaction::helpers::overlaps_with;
|
use pageserver_compaction::helpers::overlaps_with;
|
||||||
|
use rand::Rng;
|
||||||
#[cfg(feature = "testing")]
|
#[cfg(feature = "testing")]
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
#[cfg(feature = "testing")]
|
#[cfg(feature = "testing")]
|
||||||
use rand::rngs::StdRng;
|
use rand::rngs::StdRng;
|
||||||
use rand::{Rng, thread_rng};
|
|
||||||
#[cfg(feature = "testing")]
|
#[cfg(feature = "testing")]
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use storage_layer::{IoConcurrency, PersistentLayerKey};
|
use storage_layer::{IoConcurrency, PersistentLayerKey};
|
||||||
@@ -6286,8 +6286,8 @@ mod tests {
|
|||||||
while lsn < lsn_range.end {
|
while lsn < lsn_range.end {
|
||||||
let mut key = key_range.start;
|
let mut key = key_range.start;
|
||||||
while key < key_range.end {
|
while key < key_range.end {
|
||||||
let gap = random.gen_range(1..=100) <= spec.gap_chance;
|
let gap = random.random_range(1..=100) <= spec.gap_chance;
|
||||||
let will_init = random.gen_range(1..=100) <= spec.will_init_chance;
|
let will_init = random.random_range(1..=100) <= spec.will_init_chance;
|
||||||
|
|
||||||
if gap {
|
if gap {
|
||||||
continue;
|
continue;
|
||||||
@@ -6330,8 +6330,8 @@ mod tests {
|
|||||||
while lsn < lsn_range.end {
|
while lsn < lsn_range.end {
|
||||||
let mut key = key_range.start;
|
let mut key = key_range.start;
|
||||||
while key < key_range.end {
|
while key < key_range.end {
|
||||||
let gap = random.gen_range(1..=100) <= spec.gap_chance;
|
let gap = random.random_range(1..=100) <= spec.gap_chance;
|
||||||
let will_init = random.gen_range(1..=100) <= spec.will_init_chance;
|
let will_init = random.random_range(1..=100) <= spec.will_init_chance;
|
||||||
|
|
||||||
if gap {
|
if gap {
|
||||||
continue;
|
continue;
|
||||||
@@ -7808,7 +7808,7 @@ mod tests {
|
|||||||
for _ in 0..50 {
|
for _ in 0..50 {
|
||||||
for _ in 0..NUM_KEYS {
|
for _ in 0..NUM_KEYS {
|
||||||
lsn = Lsn(lsn.0 + 0x10);
|
lsn = Lsn(lsn.0 + 0x10);
|
||||||
let blknum = thread_rng().gen_range(0..NUM_KEYS);
|
let blknum = rand::rng().random_range(0..NUM_KEYS);
|
||||||
test_key.field6 = blknum as u32;
|
test_key.field6 = blknum as u32;
|
||||||
let mut writer = tline.writer().await;
|
let mut writer = tline.writer().await;
|
||||||
writer
|
writer
|
||||||
@@ -7897,7 +7897,7 @@ mod tests {
|
|||||||
|
|
||||||
for _ in 0..NUM_KEYS {
|
for _ in 0..NUM_KEYS {
|
||||||
lsn = Lsn(lsn.0 + 0x10);
|
lsn = Lsn(lsn.0 + 0x10);
|
||||||
let blknum = thread_rng().gen_range(0..NUM_KEYS);
|
let blknum = rand::rng().random_range(0..NUM_KEYS);
|
||||||
test_key.field6 = blknum as u32;
|
test_key.field6 = blknum as u32;
|
||||||
let mut writer = tline.writer().await;
|
let mut writer = tline.writer().await;
|
||||||
writer
|
writer
|
||||||
@@ -7965,7 +7965,7 @@ mod tests {
|
|||||||
|
|
||||||
for _ in 0..NUM_KEYS {
|
for _ in 0..NUM_KEYS {
|
||||||
lsn = Lsn(lsn.0 + 0x10);
|
lsn = Lsn(lsn.0 + 0x10);
|
||||||
let blknum = thread_rng().gen_range(0..NUM_KEYS);
|
let blknum = rand::rng().random_range(0..NUM_KEYS);
|
||||||
test_key.field6 = blknum as u32;
|
test_key.field6 = blknum as u32;
|
||||||
let mut writer = tline.writer().await;
|
let mut writer = tline.writer().await;
|
||||||
writer
|
writer
|
||||||
@@ -8229,7 +8229,7 @@ mod tests {
|
|||||||
|
|
||||||
for _ in 0..NUM_KEYS {
|
for _ in 0..NUM_KEYS {
|
||||||
lsn = Lsn(lsn.0 + 0x10);
|
lsn = Lsn(lsn.0 + 0x10);
|
||||||
let blknum = thread_rng().gen_range(0..NUM_KEYS);
|
let blknum = rand::rng().random_range(0..NUM_KEYS);
|
||||||
test_key.field6 = (blknum * STEP) as u32;
|
test_key.field6 = (blknum * STEP) as u32;
|
||||||
let mut writer = tline.writer().await;
|
let mut writer = tline.writer().await;
|
||||||
writer
|
writer
|
||||||
@@ -8502,7 +8502,7 @@ mod tests {
|
|||||||
for iter in 1..=10 {
|
for iter in 1..=10 {
|
||||||
for _ in 0..NUM_KEYS {
|
for _ in 0..NUM_KEYS {
|
||||||
lsn = Lsn(lsn.0 + 0x10);
|
lsn = Lsn(lsn.0 + 0x10);
|
||||||
let blknum = thread_rng().gen_range(0..NUM_KEYS);
|
let blknum = rand::rng().random_range(0..NUM_KEYS);
|
||||||
test_key.field6 = (blknum * STEP) as u32;
|
test_key.field6 = (blknum * STEP) as u32;
|
||||||
let mut writer = tline.writer().await;
|
let mut writer = tline.writer().await;
|
||||||
writer
|
writer
|
||||||
@@ -11291,10 +11291,10 @@ mod tests {
|
|||||||
#[cfg(feature = "testing")]
|
#[cfg(feature = "testing")]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_read_path() -> anyhow::Result<()> {
|
async fn test_read_path() -> anyhow::Result<()> {
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::IndexedRandom;
|
||||||
|
|
||||||
let seed = if cfg!(feature = "fuzz-read-path") {
|
let seed = if cfg!(feature = "fuzz-read-path") {
|
||||||
let seed: u64 = thread_rng().r#gen();
|
let seed: u64 = rand::rng().random();
|
||||||
seed
|
seed
|
||||||
} else {
|
} else {
|
||||||
// Use a hard-coded seed when not in fuzzing mode.
|
// Use a hard-coded seed when not in fuzzing mode.
|
||||||
@@ -11308,8 +11308,8 @@ mod tests {
|
|||||||
|
|
||||||
let (queries, will_init_chance, gap_chance) = if cfg!(feature = "fuzz-read-path") {
|
let (queries, will_init_chance, gap_chance) = if cfg!(feature = "fuzz-read-path") {
|
||||||
const QUERIES: u64 = 5000;
|
const QUERIES: u64 = 5000;
|
||||||
let will_init_chance: u8 = random.gen_range(0..=10);
|
let will_init_chance: u8 = random.random_range(0..=10);
|
||||||
let gap_chance: u8 = random.gen_range(0..=50);
|
let gap_chance: u8 = random.random_range(0..=50);
|
||||||
|
|
||||||
(QUERIES, will_init_chance, gap_chance)
|
(QUERIES, will_init_chance, gap_chance)
|
||||||
} else {
|
} else {
|
||||||
@@ -11410,7 +11410,8 @@ mod tests {
|
|||||||
|
|
||||||
while used_keys.len() < tenant.conf.max_get_vectored_keys.get() {
|
while used_keys.len() < tenant.conf.max_get_vectored_keys.get() {
|
||||||
let selected_lsn = interesting_lsns.choose(&mut random).expect("not empty");
|
let selected_lsn = interesting_lsns.choose(&mut random).expect("not empty");
|
||||||
let mut selected_key = start_key.add(random.gen_range(0..KEY_DIMENSION_SIZE));
|
let mut selected_key =
|
||||||
|
start_key.add(random.random_range(0..KEY_DIMENSION_SIZE));
|
||||||
|
|
||||||
while used_keys.len() < tenant.conf.max_get_vectored_keys.get() {
|
while used_keys.len() < tenant.conf.max_get_vectored_keys.get() {
|
||||||
if used_keys.contains(&selected_key)
|
if used_keys.contains(&selected_key)
|
||||||
@@ -11425,7 +11426,7 @@ mod tests {
|
|||||||
.add_key(selected_key);
|
.add_key(selected_key);
|
||||||
used_keys.insert(selected_key);
|
used_keys.insert(selected_key);
|
||||||
|
|
||||||
let pick_next = random.gen_range(0..=100) <= PICK_NEXT_CHANCE;
|
let pick_next = random.random_range(0..=100) <= PICK_NEXT_CHANCE;
|
||||||
if pick_next {
|
if pick_next {
|
||||||
selected_key = selected_key.next();
|
selected_key = selected_key.next();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -535,8 +535,8 @@ pub(crate) mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn random_array(len: usize) -> Vec<u8> {
|
pub(crate) fn random_array(len: usize) -> Vec<u8> {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::rng();
|
||||||
(0..len).map(|_| rng.r#gen()).collect::<_>()
|
(0..len).map(|_| rng.random()).collect::<_>()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -588,9 +588,9 @@ pub(crate) mod tests {
|
|||||||
let mut rng = rand::rngs::StdRng::seed_from_u64(42);
|
let mut rng = rand::rngs::StdRng::seed_from_u64(42);
|
||||||
let blobs = (0..1024)
|
let blobs = (0..1024)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let mut sz: u16 = rng.r#gen();
|
let mut sz: u16 = rng.random();
|
||||||
// Make 50% of the arrays small
|
// Make 50% of the arrays small
|
||||||
if rng.r#gen() {
|
if rng.random() {
|
||||||
sz &= 63;
|
sz &= 63;
|
||||||
}
|
}
|
||||||
random_array(sz.into())
|
random_array(sz.into())
|
||||||
|
|||||||
@@ -1090,7 +1090,7 @@ pub(crate) mod tests {
|
|||||||
const NUM_KEYS: usize = 100000;
|
const NUM_KEYS: usize = 100000;
|
||||||
let mut all_data: BTreeMap<u128, u64> = BTreeMap::new();
|
let mut all_data: BTreeMap<u128, u64> = BTreeMap::new();
|
||||||
for idx in 0..NUM_KEYS {
|
for idx in 0..NUM_KEYS {
|
||||||
let u: f64 = rand::thread_rng().gen_range(0.0..1.0);
|
let u: f64 = rand::rng().random_range(0.0..1.0);
|
||||||
let t = -(f64::ln(u));
|
let t = -(f64::ln(u));
|
||||||
let key_int = (t * 1000000.0) as u128;
|
let key_int = (t * 1000000.0) as u128;
|
||||||
|
|
||||||
@@ -1116,7 +1116,7 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
// Test get() operations on random keys, most of which will not exist
|
// Test get() operations on random keys, most of which will not exist
|
||||||
for _ in 0..100000 {
|
for _ in 0..100000 {
|
||||||
let key_int = rand::thread_rng().r#gen::<u128>();
|
let key_int = rand::rng().random::<u128>();
|
||||||
let search_key = u128::to_be_bytes(key_int);
|
let search_key = u128::to_be_bytes(key_int);
|
||||||
assert!(reader.get(&search_key, &ctx).await? == all_data.get(&key_int).cloned());
|
assert!(reader.get(&search_key, &ctx).await? == all_data.get(&key_int).cloned());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -508,8 +508,8 @@ mod tests {
|
|||||||
|
|
||||||
let write_nbytes = cap * 2 + cap / 2;
|
let write_nbytes = cap * 2 + cap / 2;
|
||||||
|
|
||||||
let content: Vec<u8> = rand::thread_rng()
|
let content: Vec<u8> = rand::rng()
|
||||||
.sample_iter(rand::distributions::Standard)
|
.sample_iter(rand::distr::StandardUniform)
|
||||||
.take(write_nbytes)
|
.take(write_nbytes)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -565,8 +565,8 @@ mod tests {
|
|||||||
let cap = writer.mutable().capacity();
|
let cap = writer.mutable().capacity();
|
||||||
drop(writer);
|
drop(writer);
|
||||||
|
|
||||||
let content: Vec<u8> = rand::thread_rng()
|
let content: Vec<u8> = rand::rng()
|
||||||
.sample_iter(rand::distributions::Standard)
|
.sample_iter(rand::distr::StandardUniform)
|
||||||
.take(cap * 2 + cap / 2)
|
.take(cap * 2 + cap / 2)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -614,8 +614,8 @@ mod tests {
|
|||||||
let cap = mutable.capacity();
|
let cap = mutable.capacity();
|
||||||
let align = mutable.align();
|
let align = mutable.align();
|
||||||
drop(writer);
|
drop(writer);
|
||||||
let content: Vec<u8> = rand::thread_rng()
|
let content: Vec<u8> = rand::rng()
|
||||||
.sample_iter(rand::distributions::Standard)
|
.sample_iter(rand::distr::StandardUniform)
|
||||||
.take(cap * 2 + cap / 2)
|
.take(cap * 2 + cap / 2)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use pageserver_api::shard::{
|
|||||||
};
|
};
|
||||||
use pageserver_api::upcall_api::ReAttachResponseTenant;
|
use pageserver_api::upcall_api::ReAttachResponseTenant;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distr::Alphanumeric;
|
||||||
use remote_storage::TimeoutOrCancel;
|
use remote_storage::TimeoutOrCancel;
|
||||||
use sysinfo::SystemExt;
|
use sysinfo::SystemExt;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
@@ -218,7 +218,7 @@ async fn safe_rename_tenant_dir(path: impl AsRef<Utf8Path>) -> std::io::Result<U
|
|||||||
std::io::ErrorKind::InvalidInput,
|
std::io::ErrorKind::InvalidInput,
|
||||||
"Path must be absolute",
|
"Path must be absolute",
|
||||||
))?;
|
))?;
|
||||||
let rand_suffix = rand::thread_rng()
|
let rand_suffix = rand::rng()
|
||||||
.sample_iter(&Alphanumeric)
|
.sample_iter(&Alphanumeric)
|
||||||
.take(8)
|
.take(8)
|
||||||
.map(char::from)
|
.map(char::from)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ pub(super) fn period_jitter(d: Duration, pct: u32) -> Duration {
|
|||||||
if d == Duration::ZERO {
|
if d == Duration::ZERO {
|
||||||
d
|
d
|
||||||
} else {
|
} else {
|
||||||
rand::thread_rng().gen_range((d * (100 - pct)) / 100..(d * (100 + pct)) / 100)
|
rand::rng().random_range((d * (100 - pct)) / 100..(d * (100 + pct)) / 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ pub(super) fn period_warmup(period: Duration) -> Duration {
|
|||||||
if period == Duration::ZERO {
|
if period == Duration::ZERO {
|
||||||
period
|
period
|
||||||
} else {
|
} else {
|
||||||
rand::thread_rng().gen_range(Duration::ZERO..period)
|
rand::rng().random_range(Duration::ZERO..period)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1634,7 +1634,8 @@ pub(crate) mod test {
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use itertools::MinMaxResult;
|
use itertools::MinMaxResult;
|
||||||
use postgres_ffi::PgMajorVersion;
|
use postgres_ffi::PgMajorVersion;
|
||||||
use rand::prelude::{SeedableRng, SliceRandom, StdRng};
|
use rand::prelude::{SeedableRng, StdRng};
|
||||||
|
use rand::seq::IndexedRandom;
|
||||||
use rand::{Rng, RngCore};
|
use rand::{Rng, RngCore};
|
||||||
|
|
||||||
/// Construct an index for a fictional delta layer and and then
|
/// Construct an index for a fictional delta layer and and then
|
||||||
@@ -1788,14 +1789,14 @@ pub(crate) mod test {
|
|||||||
|
|
||||||
let mut entries = Vec::new();
|
let mut entries = Vec::new();
|
||||||
for _ in 0..constants::KEY_COUNT {
|
for _ in 0..constants::KEY_COUNT {
|
||||||
let count = rng.gen_range(1..constants::MAX_ENTRIES_PER_KEY);
|
let count = rng.random_range(1..constants::MAX_ENTRIES_PER_KEY);
|
||||||
let mut lsns_iter =
|
let mut lsns_iter =
|
||||||
std::iter::successors(Some(Lsn(constants::LSN_OFFSET.0 + 0x08)), |lsn| {
|
std::iter::successors(Some(Lsn(constants::LSN_OFFSET.0 + 0x08)), |lsn| {
|
||||||
Some(Lsn(lsn.0 + 0x08))
|
Some(Lsn(lsn.0 + 0x08))
|
||||||
});
|
});
|
||||||
let mut lsns = Vec::new();
|
let mut lsns = Vec::new();
|
||||||
while lsns.len() < count as usize {
|
while lsns.len() < count as usize {
|
||||||
let take = rng.gen_bool(0.5);
|
let take = rng.random_bool(0.5);
|
||||||
let lsn = lsns_iter.next().unwrap();
|
let lsn = lsns_iter.next().unwrap();
|
||||||
if take {
|
if take {
|
||||||
lsns.push(lsn);
|
lsns.push(lsn);
|
||||||
@@ -1869,12 +1870,13 @@ pub(crate) mod test {
|
|||||||
for _ in 0..constants::RANGES_COUNT {
|
for _ in 0..constants::RANGES_COUNT {
|
||||||
let mut range: Option<Range<Key>> = Option::default();
|
let mut range: Option<Range<Key>> = Option::default();
|
||||||
while range.is_none() || keyspace.overlaps(range.as_ref().unwrap()) {
|
while range.is_none() || keyspace.overlaps(range.as_ref().unwrap()) {
|
||||||
let range_start = rng.gen_range(start..end);
|
let range_start = rng.random_range(start..end);
|
||||||
let range_end_offset = range_start + constants::MIN_RANGE_SIZE;
|
let range_end_offset = range_start + constants::MIN_RANGE_SIZE;
|
||||||
if range_end_offset >= end {
|
if range_end_offset >= end {
|
||||||
range = Some(Key::from_i128(range_start)..Key::from_i128(end));
|
range = Some(Key::from_i128(range_start)..Key::from_i128(end));
|
||||||
} else {
|
} else {
|
||||||
let range_end = rng.gen_range((range_start + constants::MIN_RANGE_SIZE)..end);
|
let range_end =
|
||||||
|
rng.random_range((range_start + constants::MIN_RANGE_SIZE)..end);
|
||||||
range = Some(Key::from_i128(range_start)..Key::from_i128(range_end));
|
range = Some(Key::from_i128(range_start)..Key::from_i128(range_end));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -440,8 +440,8 @@ mod tests {
|
|||||||
impl InMemoryFile {
|
impl InMemoryFile {
|
||||||
fn new_random(len: usize) -> Self {
|
fn new_random(len: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
content: rand::thread_rng()
|
content: rand::rng()
|
||||||
.sample_iter(rand::distributions::Standard)
|
.sample_iter(rand::distr::StandardUniform)
|
||||||
.take(len)
|
.take(len)
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
@@ -498,7 +498,7 @@ mod tests {
|
|||||||
len
|
len
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
rand::Rng::fill(&mut rand::thread_rng(), &mut dst_slice[nread..]); // to discover bugs
|
rand::Rng::fill(&mut rand::rng(), &mut dst_slice[nread..]); // to discover bugs
|
||||||
Ok((dst, nread))
|
Ok((dst, nread))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -763,7 +763,7 @@ mod tests {
|
|||||||
let len = std::cmp::min(dst.bytes_total(), mocked_bytes.len());
|
let len = std::cmp::min(dst.bytes_total(), mocked_bytes.len());
|
||||||
let dst_slice: &mut [u8] = dst.as_mut_rust_slice_full_zeroed();
|
let dst_slice: &mut [u8] = dst.as_mut_rust_slice_full_zeroed();
|
||||||
dst_slice[..len].copy_from_slice(&mocked_bytes[..len]);
|
dst_slice[..len].copy_from_slice(&mocked_bytes[..len]);
|
||||||
rand::Rng::fill(&mut rand::thread_rng(), &mut dst_slice[len..]); // to discover bugs
|
rand::Rng::fill(&mut rand::rng(), &mut dst_slice[len..]); // to discover bugs
|
||||||
Ok((dst, len))
|
Ok((dst, len))
|
||||||
}
|
}
|
||||||
Err(e) => Err(std::io::Error::other(e)),
|
Err(e) => Err(std::io::Error::other(e)),
|
||||||
|
|||||||
@@ -515,7 +515,7 @@ pub(crate) async fn sleep_random_range(
|
|||||||
interval: RangeInclusive<Duration>,
|
interval: RangeInclusive<Duration>,
|
||||||
cancel: &CancellationToken,
|
cancel: &CancellationToken,
|
||||||
) -> Result<Duration, Cancelled> {
|
) -> Result<Duration, Cancelled> {
|
||||||
let delay = rand::thread_rng().gen_range(interval);
|
let delay = rand::rng().random_range(interval);
|
||||||
if delay == Duration::ZERO {
|
if delay == Duration::ZERO {
|
||||||
return Ok(delay);
|
return Ok(delay);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2826,7 +2826,7 @@ impl Timeline {
|
|||||||
if r.numerator == 0 {
|
if r.numerator == 0 {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
rand::thread_rng().gen_range(0..r.denominator) < r.numerator
|
rand::rng().random_range(0..r.denominator) < r.numerator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => false,
|
None => false,
|
||||||
@@ -3908,7 +3908,7 @@ impl Timeline {
|
|||||||
// 1hour base
|
// 1hour base
|
||||||
(60_i64 * 60_i64)
|
(60_i64 * 60_i64)
|
||||||
// 10min jitter
|
// 10min jitter
|
||||||
+ rand::thread_rng().gen_range(-10 * 60..10 * 60),
|
+ rand::rng().random_range(-10 * 60..10 * 60),
|
||||||
)
|
)
|
||||||
.expect("10min < 1hour"),
|
.expect("10min < 1hour"),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1275,8 +1275,8 @@ mod tests {
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use owned_buffers_io::io_buf_ext::IoBufExt;
|
use owned_buffers_io::io_buf_ext::IoBufExt;
|
||||||
|
use rand::Rng;
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use rand::{Rng, thread_rng};
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::context::DownloadBehavior;
|
use crate::context::DownloadBehavior;
|
||||||
@@ -1358,7 +1358,7 @@ mod tests {
|
|||||||
|
|
||||||
// Check that all the other FDs still work too. Use them in random order for
|
// Check that all the other FDs still work too. Use them in random order for
|
||||||
// good measure.
|
// good measure.
|
||||||
file_b_dupes.as_mut_slice().shuffle(&mut thread_rng());
|
file_b_dupes.as_mut_slice().shuffle(&mut rand::rng());
|
||||||
for vfile in file_b_dupes.iter_mut() {
|
for vfile in file_b_dupes.iter_mut() {
|
||||||
assert_first_512_eq(vfile, b"content_b").await;
|
assert_first_512_eq(vfile, b"content_b").await;
|
||||||
}
|
}
|
||||||
@@ -1413,9 +1413,8 @@ mod tests {
|
|||||||
let ctx = ctx.detached_child(TaskKind::UnitTest, DownloadBehavior::Error);
|
let ctx = ctx.detached_child(TaskKind::UnitTest, DownloadBehavior::Error);
|
||||||
let hdl = rt.spawn(async move {
|
let hdl = rt.spawn(async move {
|
||||||
let mut buf = IoBufferMut::with_capacity_zeroed(SIZE);
|
let mut buf = IoBufferMut::with_capacity_zeroed(SIZE);
|
||||||
let mut rng = rand::rngs::OsRng;
|
|
||||||
for _ in 1..1000 {
|
for _ in 1..1000 {
|
||||||
let f = &files[rng.gen_range(0..files.len())];
|
let f = &files[rand::rng().random_range(0..files.len())];
|
||||||
buf = f
|
buf = f
|
||||||
.read_exact_at(buf.slice_full(), 0, &ctx)
|
.read_exact_at(buf.slice_full(), 0, &ctx)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ postgres-client = { package = "tokio-postgres2", path = "../libs/proxy/tokio-pos
|
|||||||
postgres-protocol = { package = "postgres-protocol2", path = "../libs/proxy/postgres-protocol2" }
|
postgres-protocol = { package = "postgres-protocol2", path = "../libs/proxy/postgres-protocol2" }
|
||||||
pq_proto.workspace = true
|
pq_proto.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
|
rand_core.workspace = true
|
||||||
regex.workspace = true
|
regex.workspace = true
|
||||||
remote_storage = { version = "0.1", path = "../libs/remote_storage/" }
|
remote_storage = { version = "0.1", path = "../libs/remote_storage/" }
|
||||||
reqwest = { workspace = true, features = ["rustls-tls-native-roots"] }
|
reqwest = { workspace = true, features = ["rustls-tls-native-roots"] }
|
||||||
@@ -133,6 +134,6 @@ pbkdf2 = { workspace = true, features = ["simple", "std"] }
|
|||||||
rcgen.workspace = true
|
rcgen.workspace = true
|
||||||
rstest.workspace = true
|
rstest.workspace = true
|
||||||
walkdir.workspace = true
|
walkdir.workspace = true
|
||||||
rand_distr = "0.4"
|
rand_distr = "0.5"
|
||||||
tokio-postgres.workspace = true
|
tokio-postgres.workspace = true
|
||||||
tracing-test = "0.2"
|
tracing-test = "0.2"
|
||||||
|
|||||||
@@ -803,7 +803,7 @@ mod tests {
|
|||||||
use http_body_util::Full;
|
use http_body_util::Full;
|
||||||
use hyper::service::service_fn;
|
use hyper::service::service_fn;
|
||||||
use hyper_util::rt::TokioIo;
|
use hyper_util::rt::TokioIo;
|
||||||
use rand::rngs::OsRng;
|
use rand_core::OsRng;
|
||||||
use rsa::pkcs8::DecodePrivateKey;
|
use rsa::pkcs8::DecodePrivateKey;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use arc_swap::ArcSwapOption;
|
|||||||
use camino::Utf8PathBuf;
|
use camino::Utf8PathBuf;
|
||||||
use futures::future::Either;
|
use futures::future::Either;
|
||||||
use itertools::{Itertools, Position};
|
use itertools::{Itertools, Position};
|
||||||
use rand::{Rng, thread_rng};
|
use rand::Rng;
|
||||||
use remote_storage::RemoteStorageConfig;
|
use remote_storage::RemoteStorageConfig;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
#[cfg(any(test, feature = "testing"))]
|
#[cfg(any(test, feature = "testing"))]
|
||||||
@@ -573,7 +573,7 @@ pub async fn run() -> anyhow::Result<()> {
|
|||||||
attempt.into_inner()
|
attempt.into_inner()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let jitter = thread_rng().gen_range(0..100);
|
let jitter = rand::rng().random_range(0..100);
|
||||||
tokio::time::sleep(Duration::from_millis(1000 + jitter)).await;
|
tokio::time::sleep(Duration::from_millis(1000 + jitter)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
proxy/src/cache/project_info.rs
vendored
4
proxy/src/cache/project_info.rs
vendored
@@ -5,7 +5,7 @@ use std::time::Duration;
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use clashmap::ClashMap;
|
use clashmap::ClashMap;
|
||||||
use clashmap::mapref::one::Ref;
|
use clashmap::mapref::one::Ref;
|
||||||
use rand::{Rng, thread_rng};
|
use rand::Rng;
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
@@ -343,7 +343,7 @@ impl ProjectInfoCacheImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn gc(&self) {
|
fn gc(&self) {
|
||||||
let shard = thread_rng().gen_range(0..self.project2ep.shards().len());
|
let shard = rand::rng().random_range(0..self.project2ep.shards().len());
|
||||||
debug!(shard, "project_info_cache: performing epoch reclamation");
|
debug!(shard, "project_info_cache: performing epoch reclamation");
|
||||||
|
|
||||||
// acquire a random shard lock
|
// acquire a random shard lock
|
||||||
|
|||||||
@@ -523,29 +523,29 @@ mod tests {
|
|||||||
|
|
||||||
fn generate_request_data(rng: &mut impl Rng) -> RequestData {
|
fn generate_request_data(rng: &mut impl Rng) -> RequestData {
|
||||||
RequestData {
|
RequestData {
|
||||||
session_id: uuid::Builder::from_random_bytes(rng.r#gen()).into_uuid(),
|
session_id: uuid::Builder::from_random_bytes(rng.random()).into_uuid(),
|
||||||
peer_addr: Ipv4Addr::from(rng.r#gen::<[u8; 4]>()).to_string(),
|
peer_addr: Ipv4Addr::from(rng.random::<[u8; 4]>()).to_string(),
|
||||||
timestamp: chrono::DateTime::from_timestamp_millis(
|
timestamp: chrono::DateTime::from_timestamp_millis(
|
||||||
rng.gen_range(1703862754..1803862754),
|
rng.random_range(1703862754..1803862754),
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.naive_utc(),
|
.naive_utc(),
|
||||||
application_name: Some("test".to_owned()),
|
application_name: Some("test".to_owned()),
|
||||||
user_agent: Some("test-user-agent".to_owned()),
|
user_agent: Some("test-user-agent".to_owned()),
|
||||||
username: Some(hex::encode(rng.r#gen::<[u8; 4]>())),
|
username: Some(hex::encode(rng.random::<[u8; 4]>())),
|
||||||
endpoint_id: Some(hex::encode(rng.r#gen::<[u8; 16]>())),
|
endpoint_id: Some(hex::encode(rng.random::<[u8; 16]>())),
|
||||||
database: Some(hex::encode(rng.r#gen::<[u8; 16]>())),
|
database: Some(hex::encode(rng.random::<[u8; 16]>())),
|
||||||
project: Some(hex::encode(rng.r#gen::<[u8; 16]>())),
|
project: Some(hex::encode(rng.random::<[u8; 16]>())),
|
||||||
branch: Some(hex::encode(rng.r#gen::<[u8; 16]>())),
|
branch: Some(hex::encode(rng.random::<[u8; 16]>())),
|
||||||
pg_options: None,
|
pg_options: None,
|
||||||
auth_method: None,
|
auth_method: None,
|
||||||
jwt_issuer: None,
|
jwt_issuer: None,
|
||||||
protocol: ["tcp", "ws", "http"][rng.gen_range(0..3)],
|
protocol: ["tcp", "ws", "http"][rng.random_range(0..3)],
|
||||||
region: String::new(),
|
region: String::new(),
|
||||||
error: None,
|
error: None,
|
||||||
success: rng.r#gen(),
|
success: rng.random(),
|
||||||
cold_start_info: "no",
|
cold_start_info: "no",
|
||||||
duration_us: rng.gen_range(0..30_000_000),
|
duration_us: rng.random_range(0..30_000_000),
|
||||||
disconnect_timestamp: None,
|
disconnect_timestamp: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -622,15 +622,15 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
file_stats,
|
file_stats,
|
||||||
[
|
[
|
||||||
(1313953, 3, 6000),
|
(1313878, 3, 6000),
|
||||||
(1313942, 3, 6000),
|
(1313891, 3, 6000),
|
||||||
(1314001, 3, 6000),
|
(1314058, 3, 6000),
|
||||||
(1313958, 3, 6000),
|
(1313914, 3, 6000),
|
||||||
(1314094, 3, 6000),
|
(1313760, 3, 6000),
|
||||||
(1313931, 3, 6000),
|
(1314084, 3, 6000),
|
||||||
(1313725, 3, 6000),
|
(1313965, 3, 6000),
|
||||||
(1313960, 3, 6000),
|
(1313911, 3, 6000),
|
||||||
(438318, 1, 2000)
|
(438290, 1, 2000)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -662,11 +662,11 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
file_stats,
|
file_stats,
|
||||||
[
|
[
|
||||||
(1205810, 5, 10000),
|
(1206039, 5, 10000),
|
||||||
(1205534, 5, 10000),
|
(1205798, 5, 10000),
|
||||||
(1205835, 5, 10000),
|
(1205776, 5, 10000),
|
||||||
(1205820, 5, 10000),
|
(1206051, 5, 10000),
|
||||||
(1206074, 5, 10000)
|
(1205746, 5, 10000)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -691,15 +691,15 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
file_stats,
|
file_stats,
|
||||||
[
|
[
|
||||||
(1313953, 3, 6000),
|
(1313878, 3, 6000),
|
||||||
(1313942, 3, 6000),
|
(1313891, 3, 6000),
|
||||||
(1314001, 3, 6000),
|
(1314058, 3, 6000),
|
||||||
(1313958, 3, 6000),
|
(1313914, 3, 6000),
|
||||||
(1314094, 3, 6000),
|
(1313760, 3, 6000),
|
||||||
(1313931, 3, 6000),
|
(1314084, 3, 6000),
|
||||||
(1313725, 3, 6000),
|
(1313965, 3, 6000),
|
||||||
(1313960, 3, 6000),
|
(1313911, 3, 6000),
|
||||||
(438318, 1, 2000)
|
(438290, 1, 2000)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -736,7 +736,7 @@ mod tests {
|
|||||||
// files are smaller than the size threshold, but they took too long to fill so were flushed early
|
// files are smaller than the size threshold, but they took too long to fill so were flushed early
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
file_stats,
|
file_stats,
|
||||||
[(658584, 2, 3001), (658298, 2, 3000), (658094, 2, 2999)]
|
[(658552, 2, 3001), (658265, 2, 3000), (658061, 2, 2999)]
|
||||||
);
|
);
|
||||||
|
|
||||||
tmpdir.close().unwrap();
|
tmpdir.close().unwrap();
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ mod tests {
|
|||||||
use rand::{Rng, SeedableRng};
|
use rand::{Rng, SeedableRng};
|
||||||
use rand_distr::Zipf;
|
use rand_distr::Zipf;
|
||||||
|
|
||||||
let endpoint_dist = Zipf::new(500000, 0.8).unwrap();
|
let endpoint_dist = Zipf::new(500000.0, 0.8).unwrap();
|
||||||
let endpoints = StdRng::seed_from_u64(272488357).sample_iter(endpoint_dist);
|
let endpoints = StdRng::seed_from_u64(272488357).sample_iter(endpoint_dist);
|
||||||
|
|
||||||
let interner = MyId::get_interner();
|
let interner = MyId::get_interner();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use std::io::{self, Cursor};
|
|||||||
|
|
||||||
use bytes::{Buf, BufMut};
|
use bytes::{Buf, BufMut};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rand::distributions::{Distribution, Standard};
|
use rand::distr::{Distribution, StandardUniform};
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
||||||
use zerocopy::{FromBytes, Immutable, IntoBytes, big_endian};
|
use zerocopy::{FromBytes, Immutable, IntoBytes, big_endian};
|
||||||
|
|
||||||
@@ -458,9 +458,9 @@ impl fmt::Display for CancelKeyData {
|
|||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Distribution<CancelKeyData> for Standard {
|
impl Distribution<CancelKeyData> for StandardUniform {
|
||||||
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> CancelKeyData {
|
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> CancelKeyData {
|
||||||
id_to_cancel_key(rng.r#gen())
|
id_to_cancel_key(rng.random())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -338,8 +338,8 @@ async fn scram_auth_mock() -> anyhow::Result<()> {
|
|||||||
let proxy = tokio::spawn(dummy_proxy(client, Some(server_config), Scram::mock()));
|
let proxy = tokio::spawn(dummy_proxy(client, Some(server_config), Scram::mock()));
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distr::Alphanumeric;
|
||||||
let password: String = rand::thread_rng()
|
let password: String = rand::rng()
|
||||||
.sample_iter(&Alphanumeric)
|
.sample_iter(&Alphanumeric)
|
||||||
.take(rand::random::<u8>() as usize)
|
.take(rand::random::<u8>() as usize)
|
||||||
.map(char::from)
|
.map(char::from)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
|||||||
|
|
||||||
use ahash::RandomState;
|
use ahash::RandomState;
|
||||||
use clashmap::ClashMap;
|
use clashmap::ClashMap;
|
||||||
use rand::{Rng, thread_rng};
|
use rand::Rng;
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use utils::leaky_bucket::LeakyBucketState;
|
use utils::leaky_bucket::LeakyBucketState;
|
||||||
@@ -61,7 +61,7 @@ impl<K: Hash + Eq> LeakyBucketRateLimiter<K> {
|
|||||||
self.map.len()
|
self.map.len()
|
||||||
);
|
);
|
||||||
let n = self.map.shards().len();
|
let n = self.map.shards().len();
|
||||||
let shard = thread_rng().gen_range(0..n);
|
let shard = rand::rng().random_range(0..n);
|
||||||
self.map.shards()[shard]
|
self.map.shards()[shard]
|
||||||
.write()
|
.write()
|
||||||
.retain(|(_, value)| !value.bucket_is_empty(now));
|
.retain(|(_, value)| !value.bucket_is_empty(now));
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ impl RateBucketInfo {
|
|||||||
|
|
||||||
impl<K: Hash + Eq> BucketRateLimiter<K> {
|
impl<K: Hash + Eq> BucketRateLimiter<K> {
|
||||||
pub fn new(info: impl Into<Cow<'static, [RateBucketInfo]>>) -> Self {
|
pub fn new(info: impl Into<Cow<'static, [RateBucketInfo]>>) -> Self {
|
||||||
Self::new_with_rand_and_hasher(info, StdRng::from_entropy(), RandomState::new())
|
Self::new_with_rand_and_hasher(info, StdRng::from_os_rng(), RandomState::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ impl<K: Hash + Eq, R: Rng, S: BuildHasher + Clone> BucketRateLimiter<K, R, S> {
|
|||||||
let n = self.map.shards().len();
|
let n = self.map.shards().len();
|
||||||
// this lock is ok as the periodic cycle of do_gc makes this very unlikely to collide
|
// this lock is ok as the periodic cycle of do_gc makes this very unlikely to collide
|
||||||
// (impossible, infact, unless we have 2048 threads)
|
// (impossible, infact, unless we have 2048 threads)
|
||||||
let shard = self.rand.lock_propagate_poison().gen_range(0..n);
|
let shard = self.rand.lock_propagate_poison().random_range(0..n);
|
||||||
self.map.shards()[shard].write().clear();
|
self.map.shards()[shard].write().clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,11 +86,11 @@ mod tests {
|
|||||||
|
|
||||||
for _ in 0..n {
|
for _ in 0..n {
|
||||||
// number to insert at once
|
// number to insert at once
|
||||||
let n = rng.gen_range(1..4096);
|
let n = rng.random_range(1..4096);
|
||||||
// number of insert operations
|
// number of insert operations
|
||||||
let m = rng.gen_range(1..100);
|
let m = rng.random_range(1..100);
|
||||||
|
|
||||||
let id = uuid::Builder::from_random_bytes(rng.r#gen()).into_uuid();
|
let id = uuid::Builder::from_random_bytes(rng.random()).into_uuid();
|
||||||
ids.push((id, n, m));
|
ids.push((id, n, m));
|
||||||
|
|
||||||
// N = sum(actual)
|
// N = sum(actual)
|
||||||
@@ -140,8 +140,8 @@ mod tests {
|
|||||||
// probably numbers are too small to truly represent the probabilities.
|
// probably numbers are too small to truly represent the probabilities.
|
||||||
assert_eq!(eval_precision(100, 4096.0, 0.90), 100);
|
assert_eq!(eval_precision(100, 4096.0, 0.90), 100);
|
||||||
assert_eq!(eval_precision(1000, 4096.0, 0.90), 1000);
|
assert_eq!(eval_precision(1000, 4096.0, 0.90), 1000);
|
||||||
assert_eq!(eval_precision(100, 4096.0, 0.1), 96);
|
assert_eq!(eval_precision(100, 4096.0, 0.1), 100);
|
||||||
assert_eq!(eval_precision(1000, 4096.0, 0.1), 988);
|
assert_eq!(eval_precision(1000, 4096.0, 0.1), 978);
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns memory usage in bytes, and the time complexity per insert.
|
// returns memory usage in bytes, and the time complexity per insert.
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ impl ThreadPool {
|
|||||||
*state = Some(ThreadRt {
|
*state = Some(ThreadRt {
|
||||||
pool: pool.clone(),
|
pool: pool.clone(),
|
||||||
id: ThreadPoolWorkerId(worker_id.fetch_add(1, Ordering::Relaxed)),
|
id: ThreadPoolWorkerId(worker_id.fetch_add(1, Ordering::Relaxed)),
|
||||||
rng: SmallRng::from_entropy(),
|
rng: SmallRng::from_os_rng(),
|
||||||
// used to determine whether we should temporarily skip tasks for fairness.
|
// used to determine whether we should temporarily skip tasks for fairness.
|
||||||
// 99% of estimates will overcount by no more than 4096 samples
|
// 99% of estimates will overcount by no more than 4096 samples
|
||||||
countmin: CountMinSketch::with_params(
|
countmin: CountMinSketch::with_params(
|
||||||
@@ -120,7 +120,7 @@ impl ThreadRt {
|
|||||||
// in which case the SKETCH_RESET_INTERVAL represents 1 second. Thus, the rates above
|
// in which case the SKETCH_RESET_INTERVAL represents 1 second. Thus, the rates above
|
||||||
// are in requests per second.
|
// are in requests per second.
|
||||||
let probability = P.ln() / (P + rate as f64).ln();
|
let probability = P.ln() / (P + rate as f64).ln();
|
||||||
self.rng.gen_bool(probability)
|
self.rng.random_bool(probability)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use ed25519_dalek::SigningKey;
|
|||||||
use hyper_util::rt::{TokioExecutor, TokioIo, TokioTimer};
|
use hyper_util::rt::{TokioExecutor, TokioIo, TokioTimer};
|
||||||
use jose_jwk::jose_b64;
|
use jose_jwk::jose_b64;
|
||||||
use postgres_client::config::SslMode;
|
use postgres_client::config::SslMode;
|
||||||
use rand::rngs::OsRng;
|
use rand_core::OsRng;
|
||||||
use rustls::pki_types::{DnsName, ServerName};
|
use rustls::pki_types::{DnsName, ServerName};
|
||||||
use tokio::net::{TcpStream, lookup_host};
|
use tokio::net::{TcpStream, lookup_host};
|
||||||
use tokio_rustls::TlsConnector;
|
use tokio_rustls::TlsConnector;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use rand::{Rng, thread_rng};
|
use rand::distr::uniform::{UniformSampler, UniformUsize};
|
||||||
use rustc_hash::FxHasher;
|
use rustc_hash::FxHasher;
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
@@ -39,8 +39,9 @@ impl CancelSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn take(&self) -> Option<CancellationToken> {
|
pub(crate) fn take(&self) -> Option<CancellationToken> {
|
||||||
|
let dist = UniformUsize::new_inclusive(0, usize::MAX).expect("valid bounds");
|
||||||
for _ in 0..4 {
|
for _ in 0..4 {
|
||||||
if let Some(token) = self.take_raw(thread_rng().r#gen()) {
|
if let Some(token) = self.take_raw(dist.sample(&mut rand::rng())) {
|
||||||
return Some(token);
|
return Some(token);
|
||||||
}
|
}
|
||||||
tracing::trace!("failed to get cancel token");
|
tracing::trace!("failed to get cancel token");
|
||||||
@@ -48,7 +49,7 @@ impl CancelSet {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn take_raw(&self, rng: usize) -> Option<CancellationToken> {
|
fn take_raw(&self, rng: usize) -> Option<CancellationToken> {
|
||||||
NonZeroUsize::new(self.shards.len())
|
NonZeroUsize::new(self.shards.len())
|
||||||
.and_then(|len| self.shards[rng % len].lock().take(rng / len))
|
.and_then(|len| self.shards[rng % len].lock().take(rng / len))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ where
|
|||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
|
|
||||||
let shard = rng.gen_range(0..self.global_pool.shards().len());
|
let shard = rng.random_range(0..self.global_pool.shards().len());
|
||||||
self.gc(shard);
|
self.gc(shard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ pub async fn task_main(
|
|||||||
{
|
{
|
||||||
let conn_pool = Arc::clone(&conn_pool);
|
let conn_pool = Arc::clone(&conn_pool);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
conn_pool.gc_worker(StdRng::from_entropy()).await;
|
conn_pool.gc_worker(StdRng::from_os_rng()).await;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ pub async fn task_main(
|
|||||||
{
|
{
|
||||||
let http_conn_pool = Arc::clone(&http_conn_pool);
|
let http_conn_pool = Arc::clone(&http_conn_pool);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
http_conn_pool.gc_worker(StdRng::from_entropy()).await;
|
http_conn_pool.gc_worker(StdRng::from_os_rng()).await;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,6 @@ impl RateLimiter {
|
|||||||
|
|
||||||
/// Generate a random duration that is a fraction of the given duration.
|
/// Generate a random duration that is a fraction of the given duration.
|
||||||
pub fn rand_duration(duration: &std::time::Duration) -> std::time::Duration {
|
pub fn rand_duration(duration: &std::time::Duration) -> std::time::Duration {
|
||||||
let randf64 = rand::thread_rng().gen_range(0.0..1.0);
|
let randf64 = rand::rng().random_range(0.0..1.0);
|
||||||
duration.mul_f64(randf64)
|
duration.mul_f64(randf64)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ fn test_random_schedules() -> anyhow::Result<()> {
|
|||||||
let mut config = TestConfig::new(Some(clock));
|
let mut config = TestConfig::new(Some(clock));
|
||||||
|
|
||||||
for _ in 0..500 {
|
for _ in 0..500 {
|
||||||
let seed: u64 = rand::thread_rng().r#gen();
|
let seed: u64 = rand::rng().random();
|
||||||
config.network = generate_network_opts(seed);
|
config.network = generate_network_opts(seed);
|
||||||
|
|
||||||
let test = config.start(seed);
|
let test = config.start(seed);
|
||||||
|
|||||||
@@ -394,13 +394,13 @@ pub fn generate_schedule(seed: u64) -> Schedule {
|
|||||||
let mut schedule = Vec::new();
|
let mut schedule = Vec::new();
|
||||||
let mut time = 0;
|
let mut time = 0;
|
||||||
|
|
||||||
let cnt = rng.gen_range(1..100);
|
let cnt = rng.random_range(1..100);
|
||||||
|
|
||||||
for _ in 0..cnt {
|
for _ in 0..cnt {
|
||||||
time += rng.gen_range(0..500);
|
time += rng.random_range(0..500);
|
||||||
let action = match rng.gen_range(0..3) {
|
let action = match rng.random_range(0..3) {
|
||||||
0 => TestAction::WriteTx(rng.gen_range(1..10)),
|
0 => TestAction::WriteTx(rng.random_range(1..10)),
|
||||||
1 => TestAction::RestartSafekeeper(rng.gen_range(0..3)),
|
1 => TestAction::RestartSafekeeper(rng.random_range(0..3)),
|
||||||
2 => TestAction::RestartWalProposer,
|
2 => TestAction::RestartWalProposer,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
@@ -413,13 +413,13 @@ pub fn generate_schedule(seed: u64) -> Schedule {
|
|||||||
pub fn generate_network_opts(seed: u64) -> NetworkOptions {
|
pub fn generate_network_opts(seed: u64) -> NetworkOptions {
|
||||||
let mut rng = rand::rngs::StdRng::seed_from_u64(seed);
|
let mut rng = rand::rngs::StdRng::seed_from_u64(seed);
|
||||||
|
|
||||||
let timeout = rng.gen_range(100..2000);
|
let timeout = rng.random_range(100..2000);
|
||||||
let max_delay = rng.gen_range(1..2 * timeout);
|
let max_delay = rng.random_range(1..2 * timeout);
|
||||||
let min_delay = rng.gen_range(1..=max_delay);
|
let min_delay = rng.random_range(1..=max_delay);
|
||||||
|
|
||||||
let max_fail_prob = rng.gen_range(0.0..0.9);
|
let max_fail_prob = rng.random_range(0.0..0.9);
|
||||||
let connect_fail_prob = rng.gen_range(0.0..max_fail_prob);
|
let connect_fail_prob = rng.random_range(0.0..max_fail_prob);
|
||||||
let send_fail_prob = rng.gen_range(0.0..connect_fail_prob);
|
let send_fail_prob = rng.random_range(0.0..connect_fail_prob);
|
||||||
|
|
||||||
NetworkOptions {
|
NetworkOptions {
|
||||||
keepalive_timeout: Some(timeout),
|
keepalive_timeout: Some(timeout),
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ static CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01
|
|||||||
/// Generate a random string of `length` that can be used as a password. The generated string
|
/// Generate a random string of `length` that can be used as a password. The generated string
|
||||||
/// contains alphanumeric characters and special characters (!@#$%^&*())
|
/// contains alphanumeric characters and special characters (!@#$%^&*())
|
||||||
pub fn generate_random_password(length: usize) -> String {
|
pub fn generate_random_password(length: usize) -> String {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::rng();
|
||||||
(0..length)
|
(0..length)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let idx = rng.gen_range(0..CHARSET.len());
|
let idx = rng.random_range(0..CHARSET.len());
|
||||||
CHARSET[idx] as char
|
CHARSET[idx] as char
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use pageserver_api::controller_api::ShardSchedulingPolicy;
|
use pageserver_api::controller_api::ShardSchedulingPolicy;
|
||||||
use rand::seq::SliceRandom;
|
use rand::Rng;
|
||||||
use rand::{Rng, thread_rng};
|
use rand::seq::{IndexedRandom, SliceRandom};
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
use utils::id::NodeId;
|
use utils::id::NodeId;
|
||||||
use utils::shard::TenantShardId;
|
use utils::shard::TenantShardId;
|
||||||
@@ -72,7 +72,7 @@ impl ChaosInjector {
|
|||||||
let cron_interval = self.get_cron_interval_sleep_future();
|
let cron_interval = self.get_cron_interval_sleep_future();
|
||||||
let chaos_type = tokio::select! {
|
let chaos_type = tokio::select! {
|
||||||
_ = interval.tick() => {
|
_ = interval.tick() => {
|
||||||
if thread_rng().gen_bool(0.5) {
|
if rand::rng().random_bool(0.5) {
|
||||||
ChaosEvent::MigrationsToSecondary
|
ChaosEvent::MigrationsToSecondary
|
||||||
} else {
|
} else {
|
||||||
ChaosEvent::GracefulMigrationsAnywhere
|
ChaosEvent::GracefulMigrationsAnywhere
|
||||||
@@ -134,7 +134,7 @@ impl ChaosInjector {
|
|||||||
let Some(new_location) = shard
|
let Some(new_location) = shard
|
||||||
.intent
|
.intent
|
||||||
.get_secondary()
|
.get_secondary()
|
||||||
.choose(&mut thread_rng())
|
.choose(&mut rand::rng())
|
||||||
.cloned()
|
.cloned()
|
||||||
else {
|
else {
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
@@ -190,7 +190,7 @@ impl ChaosInjector {
|
|||||||
// Pick our victims: use a hand-rolled loop rather than choose_multiple() because we want
|
// Pick our victims: use a hand-rolled loop rather than choose_multiple() because we want
|
||||||
// to take the mutable refs from our candidates rather than ref'ing them.
|
// to take the mutable refs from our candidates rather than ref'ing them.
|
||||||
while !candidates.is_empty() && victims.len() < batch_size {
|
while !candidates.is_empty() && victims.len() < batch_size {
|
||||||
let i = thread_rng().gen_range(0..candidates.len());
|
let i = rand::rng().random_range(0..candidates.len());
|
||||||
victims.push(candidates.swap_remove(i));
|
victims.push(candidates.swap_remove(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +210,7 @@ impl ChaosInjector {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let Some(victim_node) = candidate_nodes.choose(&mut thread_rng()) else {
|
let Some(victim_node) = candidate_nodes.choose(&mut rand::rng()) else {
|
||||||
// This can happen if e.g. we are in a small region with only one pageserver per AZ.
|
// This can happen if e.g. we are in a small region with only one pageserver per AZ.
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"no candidate nodes found for migrating shard {tenant_shard_id} within its home AZ",
|
"no candidate nodes found for migrating shard {tenant_shard_id} within its home AZ",
|
||||||
@@ -264,7 +264,7 @@ impl ChaosInjector {
|
|||||||
out_of_home_az.len()
|
out_of_home_az.len()
|
||||||
);
|
);
|
||||||
|
|
||||||
out_of_home_az.shuffle(&mut thread_rng());
|
out_of_home_az.shuffle(&mut rand::rng());
|
||||||
victims.extend(out_of_home_az.into_iter().take(batch_size));
|
victims.extend(out_of_home_az.into_iter().take(batch_size));
|
||||||
} else {
|
} else {
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
@@ -274,7 +274,7 @@ impl ChaosInjector {
|
|||||||
);
|
);
|
||||||
|
|
||||||
victims.extend(out_of_home_az);
|
victims.extend(out_of_home_az);
|
||||||
in_home_az.shuffle(&mut thread_rng());
|
in_home_az.shuffle(&mut rand::rng());
|
||||||
victims.extend(in_home_az.into_iter().take(batch_size - victims.len()));
|
victims.extend(in_home_az.into_iter().take(batch_size - victims.len()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user