mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-12 03:34:20 +01:00
fold some SimulatorOpts fields to Profile
This commit is contained in:
@@ -1444,9 +1444,10 @@ fn property_faulty_query<R: rand::Rng>(
|
||||
impl ArbitraryFrom<(&SimulatorEnv, &InteractionStats)> for Property {
|
||||
fn arbitrary_from<R: rand::Rng, C: GenerationContext>(
|
||||
rng: &mut R,
|
||||
_context: &C,
|
||||
context: &C,
|
||||
(env, stats): (&SimulatorEnv, &InteractionStats),
|
||||
) -> Self {
|
||||
let opts = context.opts();
|
||||
let remaining_ = remaining(env.opts.max_interactions, &env.profile.query, stats);
|
||||
|
||||
frequency(
|
||||
@@ -1509,7 +1510,7 @@ impl ArbitraryFrom<(&SimulatorEnv, &InteractionStats)> for Property {
|
||||
Box::new(|rng: &mut R| property_select_select_optimizer(rng, env)),
|
||||
),
|
||||
(
|
||||
if env.opts.experimental_indexes && !env.opts.disable_where_true_false_null {
|
||||
if opts.indexes && !env.opts.disable_where_true_false_null {
|
||||
remaining_.select / 2
|
||||
} else {
|
||||
0
|
||||
@@ -1517,9 +1518,7 @@ impl ArbitraryFrom<(&SimulatorEnv, &InteractionStats)> for Property {
|
||||
Box::new(|rng: &mut R| property_where_true_false_null(rng, env)),
|
||||
),
|
||||
(
|
||||
if env.opts.experimental_indexes
|
||||
&& !env.opts.disable_union_all_preserves_cardinality
|
||||
{
|
||||
if opts.indexes && !env.opts.disable_union_all_preserves_cardinality {
|
||||
remaining_.select / 3
|
||||
} else {
|
||||
0
|
||||
@@ -1527,7 +1526,7 @@ impl ArbitraryFrom<(&SimulatorEnv, &InteractionStats)> for Property {
|
||||
Box::new(|rng: &mut R| property_union_all_preserves_cardinality(rng, env)),
|
||||
),
|
||||
(
|
||||
if !env.opts.disable_fsync_no_wait {
|
||||
if env.profile.io.enable && !env.opts.disable_fsync_no_wait {
|
||||
50 // Freestyle number
|
||||
} else {
|
||||
0
|
||||
@@ -1535,7 +1534,7 @@ impl ArbitraryFrom<(&SimulatorEnv, &InteractionStats)> for Property {
|
||||
Box::new(|rng: &mut R| property_fsync_no_wait(rng, env, &remaining_)),
|
||||
),
|
||||
(
|
||||
if !env.opts.disable_faulty_query {
|
||||
if env.profile.io.enable && !env.opts.disable_faulty_query {
|
||||
20
|
||||
} else {
|
||||
0
|
||||
|
||||
@@ -38,7 +38,6 @@ fn main() -> anyhow::Result<()> {
|
||||
|
||||
let profile = Profile::parse_from_type(cli_opts.profile.clone())?;
|
||||
tracing::debug!(sim_profile = ?profile);
|
||||
dbg!(&profile);
|
||||
|
||||
match cli_opts.subcommand {
|
||||
Some(SimulatorCommand::List) => {
|
||||
|
||||
@@ -114,28 +114,16 @@ pub struct SimulatorCLI {
|
||||
pub disable_faulty_query: bool,
|
||||
#[clap(long, help = "disable Reopen-Database fault", default_value_t = false)]
|
||||
pub disable_reopen_database: bool,
|
||||
#[clap(
|
||||
long = "latency-prob",
|
||||
help = "added IO latency probability",
|
||||
default_value_t = 1
|
||||
)]
|
||||
pub latency_probability: usize,
|
||||
#[clap(
|
||||
long,
|
||||
help = "Minimum tick time in microseconds for simulated time",
|
||||
default_value_t = 1
|
||||
)]
|
||||
pub min_tick: u64,
|
||||
#[clap(
|
||||
long,
|
||||
help = "Maximum tick time in microseconds for simulated time",
|
||||
default_value_t = 30
|
||||
)]
|
||||
pub max_tick: u64,
|
||||
#[clap(long = "latency-prob", help = "added IO latency probability")]
|
||||
pub latency_probability: Option<usize>,
|
||||
#[clap(long, help = "Minimum tick time in microseconds for simulated time")]
|
||||
pub min_tick: Option<u64>,
|
||||
#[clap(long, help = "Maximum tick time in microseconds for simulated time")]
|
||||
pub max_tick: Option<u64>,
|
||||
#[clap(long, help = "Enable experimental MVCC feature")]
|
||||
pub experimental_mvcc: bool,
|
||||
pub experimental_mvcc: Option<bool>,
|
||||
#[clap(long, help = "Disable experimental indexing feature")]
|
||||
pub disable_experimental_indexes: bool,
|
||||
pub disable_experimental_indexes: Option<bool>,
|
||||
#[clap(
|
||||
long,
|
||||
help = "Keep all database and plan files",
|
||||
@@ -202,10 +190,10 @@ impl SimulatorCLI {
|
||||
anyhow::bail!("Cannot set seed and load plan at the same time");
|
||||
}
|
||||
|
||||
if self.latency_probability > 100 {
|
||||
if self.latency_probability.is_some_and(|prob| prob > 100) {
|
||||
anyhow::bail!(
|
||||
"latency probability must be a number between 0 and 100. Got `{}`",
|
||||
self.latency_probability
|
||||
self.latency_probability.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ use std::panic::UnwindSafe;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use garde::Validate;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand_chacha::ChaCha8Rng;
|
||||
use sql_generation::model::table::Table;
|
||||
@@ -96,13 +97,15 @@ impl SimulatorEnv {
|
||||
self.connections.iter_mut().for_each(|c| c.disconnect());
|
||||
self.rng = ChaCha8Rng::seed_from_u64(self.opts.seed);
|
||||
|
||||
let latency_prof = &self.profile.io.latency;
|
||||
|
||||
let io = Arc::new(
|
||||
SimulatorIO::new(
|
||||
self.opts.seed,
|
||||
self.opts.page_size,
|
||||
self.opts.latency_probability,
|
||||
self.opts.min_tick,
|
||||
self.opts.max_tick,
|
||||
latency_prof.latency_probability,
|
||||
latency_prof.min_tick,
|
||||
latency_prof.max_tick,
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
@@ -122,8 +125,8 @@ impl SimulatorEnv {
|
||||
let db = match Database::open_file(
|
||||
io.clone(),
|
||||
db_path.to_str().unwrap(),
|
||||
self.opts.experimental_mvcc,
|
||||
self.opts.experimental_indexes,
|
||||
self.profile.experimental_mvcc,
|
||||
self.profile.query.gen_opts.indexes,
|
||||
) {
|
||||
Ok(db) => db,
|
||||
Err(e) => {
|
||||
@@ -243,24 +246,8 @@ impl SimulatorEnv {
|
||||
as u32,
|
||||
max_time_simulation: cli_opts.maximum_time,
|
||||
disable_reopen_database: cli_opts.disable_reopen_database,
|
||||
latency_probability: cli_opts.latency_probability,
|
||||
experimental_mvcc: cli_opts.experimental_mvcc,
|
||||
experimental_indexes: !cli_opts.disable_experimental_indexes,
|
||||
min_tick: cli_opts.min_tick,
|
||||
max_tick: cli_opts.max_tick,
|
||||
};
|
||||
|
||||
let io = Arc::new(
|
||||
SimulatorIO::new(
|
||||
seed,
|
||||
opts.page_size,
|
||||
cli_opts.latency_probability,
|
||||
cli_opts.min_tick,
|
||||
cli_opts.max_tick,
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
// Remove existing database file if it exists
|
||||
let db_path = paths.db(&simulation_type, &SimulationPhase::Test);
|
||||
|
||||
@@ -273,11 +260,44 @@ impl SimulatorEnv {
|
||||
std::fs::remove_file(&wal_path).unwrap();
|
||||
}
|
||||
|
||||
let mut profile = profile.clone();
|
||||
// Conditionals here so that we can override some profile options from the CLI
|
||||
if let Some(mvcc) = cli_opts.experimental_mvcc {
|
||||
profile.experimental_mvcc = mvcc;
|
||||
}
|
||||
if let Some(indexes) = cli_opts.disable_experimental_indexes {
|
||||
profile.query.gen_opts.indexes = indexes;
|
||||
}
|
||||
if let Some(latency_prob) = cli_opts.latency_probability {
|
||||
profile.io.latency.latency_probability = latency_prob;
|
||||
}
|
||||
if let Some(max_tick) = cli_opts.max_tick {
|
||||
profile.io.latency.max_tick = max_tick;
|
||||
}
|
||||
if let Some(min_tick) = cli_opts.min_tick {
|
||||
profile.io.latency.min_tick = min_tick;
|
||||
}
|
||||
|
||||
profile.validate().unwrap();
|
||||
|
||||
let latency_prof = &profile.io.latency;
|
||||
|
||||
let io = Arc::new(
|
||||
SimulatorIO::new(
|
||||
seed,
|
||||
opts.page_size,
|
||||
latency_prof.latency_probability,
|
||||
latency_prof.min_tick,
|
||||
latency_prof.max_tick,
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
let db = match Database::open_file(
|
||||
io.clone(),
|
||||
db_path.to_str().unwrap(),
|
||||
opts.experimental_mvcc,
|
||||
opts.experimental_indexes,
|
||||
profile.experimental_mvcc,
|
||||
profile.query.gen_opts.indexes,
|
||||
) {
|
||||
Ok(db) => db,
|
||||
Err(e) => {
|
||||
@@ -409,11 +429,6 @@ pub(crate) struct SimulatorOpts {
|
||||
pub(crate) max_interactions: u32,
|
||||
pub(crate) page_size: usize,
|
||||
pub(crate) max_time_simulation: usize,
|
||||
pub(crate) latency_probability: usize,
|
||||
pub(crate) experimental_mvcc: bool,
|
||||
pub(crate) experimental_indexes: bool,
|
||||
pub min_tick: u64,
|
||||
pub max_tick: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user