mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-08-12 09:19:44 +00:00
chore: upgrade some dependencies (#5777)
* chore: upgrade some dependencies * chore: upgrade some dependencies * fix: cr * fix: ci * fix: test * fix: cargo fmt
This commit is contained in:
@@ -44,7 +44,7 @@ nix = { version = "0.28", features = ["process", "signal"], optional = true }
|
||||
partition = { workspace = true }
|
||||
paste.workspace = true
|
||||
rand = { workspace = true }
|
||||
rand_chacha = "0.3.1"
|
||||
rand_chacha = "0.9"
|
||||
reqwest = { workspace = true }
|
||||
schemars = "0.8"
|
||||
serde = { workspace = true }
|
||||
|
||||
@@ -16,6 +16,7 @@ use std::collections::HashSet;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use rand::prelude::IndexedRandom;
|
||||
use rand::seq::{IteratorRandom, SliceRandom};
|
||||
use rand::Rng;
|
||||
|
||||
@@ -33,9 +34,9 @@ lazy_static! {
|
||||
/// Modified from https://github.com/ucarion/faker_rand/blob/ea70c660e1ecd7320156eddb31d2830a511f8842/src/lib.rs
|
||||
macro_rules! faker_impl_from_values {
|
||||
($name: ident, $values: expr) => {
|
||||
impl rand::distributions::Distribution<$name> for rand::distributions::Standard {
|
||||
impl rand::distr::Distribution<$name> for rand::distr::StandardUniform {
|
||||
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> $name {
|
||||
$name($values[rng.gen_range(0..$values.len())].clone())
|
||||
$name($values[rng.random_range(0..$values.len())].clone())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +69,7 @@ pub fn random_capitalize_map<R: Rng + 'static>(rng: &mut R, s: Ident) -> Ident {
|
||||
let mut v = s.value.chars().collect::<Vec<_>>();
|
||||
|
||||
let str_len = s.value.len();
|
||||
let select = rng.gen_range(0..str_len);
|
||||
let select = rng.random_range(0..str_len);
|
||||
for idx in (0..str_len).choose_multiple(rng, select) {
|
||||
v[idx] = v[idx].to_uppercase().next().unwrap();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ fn add_column_options_generator<R: Rng>(
|
||||
// 0 -> NULL
|
||||
// 1 -> DEFAULT VALUE
|
||||
// 2 -> PRIMARY KEY + DEFAULT VALUE
|
||||
let idx = rng.gen_range(0..3);
|
||||
let idx = rng.random_range(0..3);
|
||||
match idx {
|
||||
0 => vec![ColumnOption::Null],
|
||||
1 => {
|
||||
@@ -79,15 +79,15 @@ impl<R: Rng + 'static> Generator<AlterTableExpr, R> for AlterExprAddColumnGenera
|
||||
type Error = Error;
|
||||
|
||||
fn generate(&self, rng: &mut R) -> Result<AlterTableExpr> {
|
||||
let with_location = self.location && rng.gen::<bool>();
|
||||
let with_location = self.location && rng.random::<bool>();
|
||||
let location = if with_location {
|
||||
let use_first = rng.gen::<bool>();
|
||||
let use_first = rng.random::<bool>();
|
||||
let location = if use_first {
|
||||
AddColumnLocation::First
|
||||
} else {
|
||||
AddColumnLocation::After {
|
||||
column_name: self.table_ctx.columns
|
||||
[rng.gen_range(0..self.table_ctx.columns.len())]
|
||||
[rng.random_range(0..self.table_ctx.columns.len())]
|
||||
.name
|
||||
.to_string(),
|
||||
}
|
||||
@@ -129,7 +129,7 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprDropColumnGenerator<R> {
|
||||
fn generate(&self, rng: &mut R) -> Result<AlterTableExpr> {
|
||||
let droppable = droppable_columns(&self.table_ctx.columns);
|
||||
ensure!(!droppable.is_empty(), error::DroppableColumnsSnafu);
|
||||
let name = droppable[rng.gen_range(0..droppable.len())].name.clone();
|
||||
let name = droppable[rng.random_range(0..droppable.len())].name.clone();
|
||||
Ok(AlterTableExpr {
|
||||
table_name: self.table_ctx.name.clone(),
|
||||
alter_kinds: AlterTableOperation::DropColumn { name },
|
||||
@@ -174,7 +174,7 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprModifyDataTypeGenerator<R
|
||||
|
||||
fn generate(&self, rng: &mut R) -> Result<AlterTableExpr> {
|
||||
let modifiable = modifiable_columns(&self.table_ctx.columns);
|
||||
let changed = modifiable[rng.gen_range(0..modifiable.len())].clone();
|
||||
let changed = modifiable[rng.random_range(0..modifiable.len())].clone();
|
||||
let mut to_type = self.column_type_generator.gen(rng);
|
||||
while !changed.column_type.can_arrow_type_cast_to(&to_type) {
|
||||
to_type = self.column_type_generator.gen(rng);
|
||||
@@ -209,8 +209,8 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprSetTableOptionsGenerator<
|
||||
let all_options = AlterTableOption::iter().collect::<Vec<_>>();
|
||||
// Generate random distinct options
|
||||
let mut option_templates_idx = vec![];
|
||||
for _ in 1..rng.gen_range(2..=all_options.len()) {
|
||||
let option = rng.gen_range(0..all_options.len());
|
||||
for _ in 1..rng.random_range(2..=all_options.len()) {
|
||||
let option = rng.random_range(0..all_options.len());
|
||||
if !option_templates_idx.contains(&option) {
|
||||
option_templates_idx.push(option);
|
||||
}
|
||||
@@ -219,10 +219,10 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprSetTableOptionsGenerator<
|
||||
.iter()
|
||||
.map(|idx| match all_options[*idx] {
|
||||
AlterTableOption::Ttl(_) => {
|
||||
let ttl_type = rng.gen_range(0..3);
|
||||
let ttl_type = rng.random_range(0..3);
|
||||
match ttl_type {
|
||||
0 => {
|
||||
let duration: u32 = rng.gen();
|
||||
let duration: u32 = rng.random();
|
||||
AlterTableOption::Ttl(Ttl::Duration((duration as i64).into()))
|
||||
}
|
||||
1 => AlterTableOption::Ttl(Ttl::Instant),
|
||||
@@ -231,27 +231,27 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprSetTableOptionsGenerator<
|
||||
}
|
||||
}
|
||||
AlterTableOption::TwcsTimeWindow(_) => {
|
||||
let time_window: u32 = rng.gen();
|
||||
let time_window: u32 = rng.random();
|
||||
AlterTableOption::TwcsTimeWindow((time_window as i64).into())
|
||||
}
|
||||
AlterTableOption::TwcsMaxOutputFileSize(_) => {
|
||||
let max_output_file_size: u64 = rng.gen();
|
||||
let max_output_file_size: u64 = rng.random();
|
||||
AlterTableOption::TwcsMaxOutputFileSize(ReadableSize(max_output_file_size))
|
||||
}
|
||||
AlterTableOption::TwcsMaxInactiveWindowRuns(_) => {
|
||||
let max_inactive_window_runs: u64 = rng.gen();
|
||||
let max_inactive_window_runs: u64 = rng.random();
|
||||
AlterTableOption::TwcsMaxInactiveWindowRuns(max_inactive_window_runs)
|
||||
}
|
||||
AlterTableOption::TwcsMaxActiveWindowFiles(_) => {
|
||||
let max_active_window_files: u64 = rng.gen();
|
||||
let max_active_window_files: u64 = rng.random();
|
||||
AlterTableOption::TwcsMaxActiveWindowFiles(max_active_window_files)
|
||||
}
|
||||
AlterTableOption::TwcsMaxActiveWindowRuns(_) => {
|
||||
let max_active_window_runs: u64 = rng.gen();
|
||||
let max_active_window_runs: u64 = rng.random();
|
||||
AlterTableOption::TwcsMaxActiveWindowRuns(max_active_window_runs)
|
||||
}
|
||||
AlterTableOption::TwcsMaxInactiveWindowFiles(_) => {
|
||||
let max_inactive_window_files: u64 = rng.gen();
|
||||
let max_inactive_window_files: u64 = rng.random();
|
||||
AlterTableOption::TwcsMaxInactiveWindowFiles(max_inactive_window_files)
|
||||
}
|
||||
})
|
||||
@@ -279,8 +279,8 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprUnsetTableOptionsGenerato
|
||||
let all_options = AlterTableOption::iter().collect::<Vec<_>>();
|
||||
// Generate random distinct options
|
||||
let mut option_templates_idx = vec![];
|
||||
for _ in 1..rng.gen_range(2..=all_options.len()) {
|
||||
let option = rng.gen_range(0..all_options.len());
|
||||
for _ in 1..rng.random_range(2..=all_options.len()) {
|
||||
let option = rng.random_range(0..all_options.len());
|
||||
if !option_templates_idx.contains(&option) {
|
||||
option_templates_idx.push(option);
|
||||
}
|
||||
@@ -325,7 +325,7 @@ mod tests {
|
||||
.generate(&mut rng)
|
||||
.unwrap();
|
||||
let serialized = serde_json::to_string(&expr).unwrap();
|
||||
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"AddColumn":{"column":{"name":{"value":"velit","quote_style":null},"column_type":{"Int32":{}},"options":[{"DefaultValue":{"Int32":1606462472}}]},"location":null}}}"#;
|
||||
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"AddColumn":{"column":{"name":{"value":"consequatur","quote_style":null},"column_type":{"Float64":{}},"options":[{"DefaultValue":{"Float64":0.48809950435391647}}]},"location":null}}}"#;
|
||||
assert_eq!(expected, serialized);
|
||||
|
||||
let expr = AlterExprRenameGeneratorBuilder::default()
|
||||
@@ -335,7 +335,7 @@ mod tests {
|
||||
.generate(&mut rng)
|
||||
.unwrap();
|
||||
let serialized = serde_json::to_string(&expr).unwrap();
|
||||
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"RenameTable":{"new_table_name":{"value":"nihil","quote_style":null}}}}"#;
|
||||
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"RenameTable":{"new_table_name":{"value":"voluptates","quote_style":null}}}}"#;
|
||||
assert_eq!(expected, serialized);
|
||||
|
||||
let expr = AlterExprDropColumnGeneratorBuilder::default()
|
||||
@@ -345,7 +345,7 @@ mod tests {
|
||||
.generate(&mut rng)
|
||||
.unwrap();
|
||||
let serialized = serde_json::to_string(&expr).unwrap();
|
||||
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"DropColumn":{"name":{"value":"cUmquE","quote_style":null}}}}"#;
|
||||
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"DropColumn":{"name":{"value":"ImPEDiT","quote_style":null}}}}"#;
|
||||
assert_eq!(expected, serialized);
|
||||
|
||||
let expr = AlterExprModifyDataTypeGeneratorBuilder::default()
|
||||
@@ -355,7 +355,7 @@ mod tests {
|
||||
.generate(&mut rng)
|
||||
.unwrap();
|
||||
let serialized = serde_json::to_string(&expr).unwrap();
|
||||
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"ModifyDataType":{"column":{"name":{"value":"toTAm","quote_style":null},"column_type":{"Int64":{}},"options":[]}}}}"#;
|
||||
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"ModifyDataType":{"column":{"name":{"value":"ADIpisci","quote_style":null},"column_type":{"Int64":{}},"options":[]}}}}"#;
|
||||
assert_eq!(expected, serialized);
|
||||
|
||||
let expr = AlterExprSetTableOptionsGeneratorBuilder::default()
|
||||
@@ -365,7 +365,7 @@ mod tests {
|
||||
.generate(&mut rng)
|
||||
.unwrap();
|
||||
let serialized = serde_json::to_string(&expr).unwrap();
|
||||
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"SetTableOptions":{"options":[{"TwcsMaxActiveWindowRuns":14908016120444947142},{"TwcsMaxActiveWindowFiles":5840340123887173415},{"TwcsMaxOutputFileSize":17740311466571102265}]}}}"#;
|
||||
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"SetTableOptions":{"options":[{"TwcsMaxOutputFileSize":16770910638250818741}]}}}"#;
|
||||
assert_eq!(expected, serialized);
|
||||
|
||||
let expr = AlterExprUnsetTableOptionsGeneratorBuilder::default()
|
||||
@@ -375,7 +375,7 @@ mod tests {
|
||||
.generate(&mut rng)
|
||||
.unwrap();
|
||||
let serialized = serde_json::to_string(&expr).unwrap();
|
||||
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"UnsetTableOptions":{"keys":["compaction.twcs.max_active_window_runs"]}}}"#;
|
||||
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"UnsetTableOptions":{"keys":["compaction.twcs.max_active_window_runs","compaction.twcs.max_output_file_size","compaction.twcs.time_window","compaction.twcs.max_inactive_window_files","compaction.twcs.max_active_window_files"]}}}"#;
|
||||
assert_eq!(expected, serialized);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,7 +399,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_table_expr_generator() {
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut rng = rand::rng();
|
||||
|
||||
let expr = CreateTableExprGeneratorBuilder::default()
|
||||
.columns(10)
|
||||
@@ -440,13 +440,13 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let serialized = serde_json::to_string(&expr).unwrap();
|
||||
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"columns":[{"name":{"value":"IMpEdIT","quote_style":null},"column_type":{"Float64":{}},"options":["PrimaryKey","NotNull"]},{"name":{"value":"natuS","quote_style":null},"column_type":{"Timestamp":{"Millisecond":null}},"options":["TimeIndex"]},{"name":{"value":"ADIPisCI","quote_style":null},"column_type":{"Float64":{}},"options":["Null"]},{"name":{"value":"EXpEdita","quote_style":null},"column_type":{"Int16":{}},"options":[{"DefaultValue":{"Int16":4864}}]},{"name":{"value":"cUlpA","quote_style":null},"column_type":{"Int64":{}},"options":["PrimaryKey"]},{"name":{"value":"MOLeStIAs","quote_style":null},"column_type":{"Float64":{}},"options":["NotNull"]},{"name":{"value":"cUmquE","quote_style":null},"column_type":{"Boolean":null},"options":["Null"]},{"name":{"value":"toTAm","quote_style":null},"column_type":{"Float32":{}},"options":[{"DefaultValue":{"Float32":0.21569687}}]},{"name":{"value":"deBitIs","quote_style":null},"column_type":{"Float64":{}},"options":["NotNull"]},{"name":{"value":"QUi","quote_style":null},"column_type":{"Float32":{}},"options":["Null"]}],"if_not_exists":true,"partition":{"partition_columns":["IMpEdIT"],"partition_bounds":[{"Expr":{"lhs":{"Column":"IMpEdIT"},"op":"Lt","rhs":{"Value":{"Float64":5.992310449541053e307}}}},{"Expr":{"lhs":{"Expr":{"lhs":{"Column":"IMpEdIT"},"op":"GtEq","rhs":{"Value":{"Float64":5.992310449541053e307}}}},"op":"And","rhs":{"Expr":{"lhs":{"Column":"IMpEdIT"},"op":"Lt","rhs":{"Value":{"Float64":1.1984620899082105e308}}}}}},{"Expr":{"lhs":{"Column":"IMpEdIT"},"op":"GtEq","rhs":{"Value":{"Float64":1.1984620899082105e308}}}}]},"engine":"mito2","options":{},"primary_keys":[0,4]}"#;
|
||||
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"columns":[{"name":{"value":"mOLEsTIAs","quote_style":null},"column_type":{"Float64":{}},"options":["PrimaryKey","Null"]},{"name":{"value":"CUMQUe","quote_style":null},"column_type":{"Timestamp":{"Second":null}},"options":["TimeIndex"]},{"name":{"value":"NaTus","quote_style":null},"column_type":{"Int64":{}},"options":[]},{"name":{"value":"EXPeDITA","quote_style":null},"column_type":{"Float64":{}},"options":[]},{"name":{"value":"ImPEDiT","quote_style":null},"column_type":{"Float32":{}},"options":[{"DefaultValue":{"Float32":0.56425774}}]},{"name":{"value":"ADIpisci","quote_style":null},"column_type":{"Float32":{}},"options":["PrimaryKey"]},{"name":{"value":"deBITIs","quote_style":null},"column_type":{"Float32":{}},"options":[{"DefaultValue":{"Float32":0.31315368}}]},{"name":{"value":"toTaM","quote_style":null},"column_type":{"Int32":{}},"options":["NotNull"]},{"name":{"value":"QuI","quote_style":null},"column_type":{"Float32":{}},"options":[{"DefaultValue":{"Float32":0.39941502}}]},{"name":{"value":"INVeNtOre","quote_style":null},"column_type":{"Boolean":null},"options":["PrimaryKey"]}],"if_not_exists":true,"partition":{"partition_columns":["mOLEsTIAs"],"partition_bounds":[{"Expr":{"lhs":{"Column":"mOLEsTIAs"},"op":"Lt","rhs":{"Value":{"Float64":5.992310449541053e307}}}},{"Expr":{"lhs":{"Expr":{"lhs":{"Column":"mOLEsTIAs"},"op":"GtEq","rhs":{"Value":{"Float64":5.992310449541053e307}}}},"op":"And","rhs":{"Expr":{"lhs":{"Column":"mOLEsTIAs"},"op":"Lt","rhs":{"Value":{"Float64":1.1984620899082105e308}}}}}},{"Expr":{"lhs":{"Column":"mOLEsTIAs"},"op":"GtEq","rhs":{"Value":{"Float64":1.1984620899082105e308}}}}]},"engine":"mito2","options":{},"primary_keys":[0,5,9]}"#;
|
||||
assert_eq!(expected, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_logical_table_expr_generator() {
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut rng = rand::rng();
|
||||
|
||||
let physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
|
||||
.if_not_exists(false)
|
||||
@@ -529,13 +529,13 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let logical_table_serialized = serde_json::to_string(&logical_table_expr).unwrap();
|
||||
let logical_table_expected = r#"{"table_name":{"value":"impedit","quote_style":null},"columns":[{"name":{"value":"ts","quote_style":null},"column_type":{"Timestamp":{"Millisecond":null}},"options":["TimeIndex"]},{"name":{"value":"val","quote_style":null},"column_type":{"Float64":{}},"options":[]},{"name":{"value":"qui","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"totam","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"molestias","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"natus","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"cumque","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]}],"if_not_exists":false,"partition":null,"engine":"metric","options":{"on_physical_table":{"String":"expedita"}},"primary_keys":[2,5,3,6,4]}"#;
|
||||
let logical_table_expected = r#"{"table_name":{"value":"impedit","quote_style":null},"columns":[{"name":{"value":"ts","quote_style":null},"column_type":{"Timestamp":{"Millisecond":null}},"options":["TimeIndex"]},{"name":{"value":"val","quote_style":null},"column_type":{"Float64":{}},"options":[]},{"name":{"value":"totam","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"cumque","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"natus","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"molestias","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"qui","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]}],"if_not_exists":false,"partition":null,"engine":"metric","options":{"on_physical_table":{"String":"expedita"}},"primary_keys":[4,2,3,6,5]}"#;
|
||||
assert_eq!(logical_table_expected, logical_table_serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_database_expr_generator() {
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut rng = rand::rng();
|
||||
|
||||
let expr = CreateDatabaseExprGeneratorBuilder::default()
|
||||
.if_not_exists(true)
|
||||
@@ -558,7 +558,7 @@ mod tests {
|
||||
|
||||
let serialized = serde_json::to_string(&expr).unwrap();
|
||||
let expected =
|
||||
r#"{"database_name":{"value":"eXPedITa","quote_style":null},"if_not_exists":true}"#;
|
||||
r#"{"database_name":{"value":"EXPediTA","quote_style":null},"if_not_exists":true}"#;
|
||||
assert_eq!(expected, serialized);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use std::marker::PhantomData;
|
||||
|
||||
use datatypes::value::Value;
|
||||
use derive_builder::Builder;
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::seq::{IndexedRandom, SliceRandom};
|
||||
use rand::Rng;
|
||||
|
||||
use super::TsValueGenerator;
|
||||
@@ -60,7 +60,7 @@ impl<R: Rng + 'static> Generator<InsertIntoExpr, R> for InsertExprGenerator<R> {
|
||||
let can_omit = column.is_nullable() || column.has_default_value();
|
||||
|
||||
// 50% chance to omit a column if it's not required
|
||||
if !can_omit || rng.gen_bool(0.5) {
|
||||
if !can_omit || rng.random_bool(0.5) {
|
||||
values_columns.push(column.clone());
|
||||
}
|
||||
}
|
||||
@@ -76,12 +76,12 @@ impl<R: Rng + 'static> Generator<InsertIntoExpr, R> for InsertExprGenerator<R> {
|
||||
for _ in 0..self.rows {
|
||||
let mut row = Vec::with_capacity(values_columns.len());
|
||||
for column in &values_columns {
|
||||
if column.is_nullable() && rng.gen_bool(0.2) {
|
||||
if column.is_nullable() && rng.random_bool(0.2) {
|
||||
row.push(RowValue::Value(Value::Null));
|
||||
continue;
|
||||
}
|
||||
|
||||
if column.has_default_value() && rng.gen_bool(0.2) {
|
||||
if column.has_default_value() && rng.random_bool(0.2) {
|
||||
row.push(RowValue::Default);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use derive_builder::Builder;
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::seq::{IndexedRandom, SliceRandom};
|
||||
use rand::Rng;
|
||||
|
||||
use crate::context::TableContextRef;
|
||||
@@ -37,7 +37,7 @@ impl<R: Rng + 'static> Generator<SelectExpr, R> for SelectExprGenerator<R> {
|
||||
type Error = Error;
|
||||
|
||||
fn generate(&self, rng: &mut R) -> Result<SelectExpr> {
|
||||
let selection = rng.gen_range(1..self.table_ctx.columns.len());
|
||||
let selection = rng.random_range(1..self.table_ctx.columns.len());
|
||||
let mut selected_columns = self
|
||||
.table_ctx
|
||||
.columns
|
||||
@@ -46,16 +46,16 @@ impl<R: Rng + 'static> Generator<SelectExpr, R> for SelectExprGenerator<R> {
|
||||
.collect::<Vec<_>>();
|
||||
selected_columns.shuffle(rng);
|
||||
|
||||
let order_by_selection = rng.gen_range(1..selection);
|
||||
let order_by_selection = rng.random_range(1..selection);
|
||||
|
||||
let order_by = selected_columns
|
||||
.choose_multiple(rng, order_by_selection)
|
||||
.map(|c| c.name.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let limit = rng.gen_range(1..self.max_limit);
|
||||
let limit = rng.random_range(1..self.max_limit);
|
||||
|
||||
let direction = if rng.gen_bool(1.0 / 2.0) {
|
||||
let direction = if rng.random_bool(1.0 / 2.0) {
|
||||
Direction::Asc
|
||||
} else {
|
||||
Direction::Desc
|
||||
|
||||
+19
-19
@@ -34,7 +34,7 @@ use datatypes::value::Value;
|
||||
use derive_builder::Builder;
|
||||
pub use insert_expr::InsertIntoExpr;
|
||||
use lazy_static::lazy_static;
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::seq::{IndexedRandom, SliceRandom};
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -146,15 +146,15 @@ pub fn generate_random_value<R: Rng>(
|
||||
random_str: Option<&dyn Random<Ident, R>>,
|
||||
) -> Value {
|
||||
match datatype {
|
||||
&ConcreteDataType::Boolean(_) => Value::from(rng.gen::<bool>()),
|
||||
ConcreteDataType::Int16(_) => Value::from(rng.gen::<i16>()),
|
||||
ConcreteDataType::Int32(_) => Value::from(rng.gen::<i32>()),
|
||||
ConcreteDataType::Int64(_) => Value::from(rng.gen::<i64>()),
|
||||
ConcreteDataType::Float32(_) => Value::from(rng.gen::<f32>()),
|
||||
ConcreteDataType::Float64(_) => Value::from(rng.gen::<f64>()),
|
||||
&ConcreteDataType::Boolean(_) => Value::from(rng.random::<bool>()),
|
||||
ConcreteDataType::Int16(_) => Value::from(rng.random::<i16>()),
|
||||
ConcreteDataType::Int32(_) => Value::from(rng.random::<i32>()),
|
||||
ConcreteDataType::Int64(_) => Value::from(rng.random::<i64>()),
|
||||
ConcreteDataType::Float32(_) => Value::from(rng.random::<f32>()),
|
||||
ConcreteDataType::Float64(_) => Value::from(rng.random::<f64>()),
|
||||
ConcreteDataType::String(_) => match random_str {
|
||||
Some(random) => Value::from(random.gen(rng).value),
|
||||
None => Value::from(rng.gen::<char>().to_string()),
|
||||
None => Value::from(rng.random::<char>().to_string()),
|
||||
},
|
||||
ConcreteDataType::Date(_) => generate_random_date(rng),
|
||||
|
||||
@@ -188,25 +188,25 @@ pub fn generate_random_timestamp<R: Rng>(rng: &mut R, ts_type: TimestampType) ->
|
||||
TimestampType::Second(_) => {
|
||||
let min = i64::from(Timestamp::MIN_SECOND);
|
||||
let max = i64::from(Timestamp::MAX_SECOND);
|
||||
let value = rng.gen_range(min..=max);
|
||||
let value = rng.random_range(min..=max);
|
||||
Timestamp::new_second(value)
|
||||
}
|
||||
TimestampType::Millisecond(_) => {
|
||||
let min = i64::from(Timestamp::MIN_MILLISECOND);
|
||||
let max = i64::from(Timestamp::MAX_MILLISECOND);
|
||||
let value = rng.gen_range(min..=max);
|
||||
let value = rng.random_range(min..=max);
|
||||
Timestamp::new_millisecond(value)
|
||||
}
|
||||
TimestampType::Microsecond(_) => {
|
||||
let min = i64::from(Timestamp::MIN_MICROSECOND);
|
||||
let max = i64::from(Timestamp::MAX_MICROSECOND);
|
||||
let value = rng.gen_range(min..=max);
|
||||
let value = rng.random_range(min..=max);
|
||||
Timestamp::new_microsecond(value)
|
||||
}
|
||||
TimestampType::Nanosecond(_) => {
|
||||
let min = i64::from(Timestamp::MIN_NANOSECOND);
|
||||
let max = i64::from(Timestamp::MAX_NANOSECOND);
|
||||
let value = rng.gen_range(min..=max);
|
||||
let value = rng.random_range(min..=max);
|
||||
Timestamp::new_nanosecond(value)
|
||||
}
|
||||
};
|
||||
@@ -219,25 +219,25 @@ pub fn generate_random_timestamp_for_mysql<R: Rng>(rng: &mut R, ts_type: Timesta
|
||||
TimestampType::Second(_) => {
|
||||
let min = 1;
|
||||
let max = 2_147_483_647;
|
||||
let value = rng.gen_range(min..=max);
|
||||
let value = rng.random_range(min..=max);
|
||||
Timestamp::new_second(value)
|
||||
}
|
||||
TimestampType::Millisecond(_) => {
|
||||
let min = 1000;
|
||||
let max = 2_147_483_647_499;
|
||||
let value = rng.gen_range(min..=max);
|
||||
let value = rng.random_range(min..=max);
|
||||
Timestamp::new_millisecond(value)
|
||||
}
|
||||
TimestampType::Microsecond(_) => {
|
||||
let min = 1_000_000;
|
||||
let max = 2_147_483_647_499_999;
|
||||
let value = rng.gen_range(min..=max);
|
||||
let value = rng.random_range(min..=max);
|
||||
Timestamp::new_microsecond(value)
|
||||
}
|
||||
TimestampType::Nanosecond(_) => {
|
||||
let min = 1_000_000_000;
|
||||
let max = 2_147_483_647_499_999_000;
|
||||
let value = rng.gen_range(min..=max);
|
||||
let value = rng.random_range(min..=max);
|
||||
Timestamp::new_nanosecond(value)
|
||||
}
|
||||
};
|
||||
@@ -247,7 +247,7 @@ pub fn generate_random_timestamp_for_mysql<R: Rng>(rng: &mut R, ts_type: Timesta
|
||||
fn generate_random_date<R: Rng>(rng: &mut R) -> Value {
|
||||
let min = i64::from(Timestamp::MIN_MILLISECOND);
|
||||
let max = i64::from(Timestamp::MAX_MILLISECOND);
|
||||
let value = rng.gen_range(min..=max);
|
||||
let value = rng.random_range(min..=max);
|
||||
let date = Timestamp::new_millisecond(value).to_chrono_date().unwrap();
|
||||
Value::from(Date::from(date))
|
||||
}
|
||||
@@ -411,7 +411,7 @@ pub fn column_options_generator<R: Rng>(
|
||||
// 2 -> DEFAULT VALUE
|
||||
// 3 -> PRIMARY KEY
|
||||
// 4 -> EMPTY
|
||||
let option_idx = rng.gen_range(0..5);
|
||||
let option_idx = rng.random_range(0..5);
|
||||
match option_idx {
|
||||
0 => vec![ColumnOption::Null],
|
||||
1 => vec![ColumnOption::NotNull],
|
||||
@@ -434,7 +434,7 @@ pub fn partible_column_options_generator<R: Rng + 'static>(
|
||||
// 1 -> NOT NULL
|
||||
// 2 -> DEFAULT VALUE
|
||||
// 3 -> PRIMARY KEY
|
||||
let option_idx = rng.gen_range(0..4);
|
||||
let option_idx = rng.random_range(0..4);
|
||||
match option_idx {
|
||||
0 => vec![ColumnOption::PrimaryKey, ColumnOption::Null],
|
||||
1 => vec![ColumnOption::PrimaryKey, ColumnOption::NotNull],
|
||||
|
||||
@@ -82,7 +82,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_insert_into_translator() {
|
||||
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0);
|
||||
let omit_column_list = rng.gen_bool(0.2);
|
||||
let omit_column_list = rng.random_bool(0.2);
|
||||
|
||||
let test_ctx = test_utils::new_test_ctx();
|
||||
let insert_expr_generator = InsertExprGeneratorBuilder::default()
|
||||
@@ -95,23 +95,23 @@ mod tests {
|
||||
let insert_expr = insert_expr_generator.generate(&mut rng).unwrap();
|
||||
|
||||
let output = InsertIntoExprTranslator.translate(&insert_expr).unwrap();
|
||||
let expected = r#"INSERT INTO test (ts, host, cpu_util) VALUES
|
||||
('+199601-11-07 21:32:56.695+0000', 'corrupti', 0.051130243193075464),
|
||||
('+40822-03-25 02:17:34.328+0000', NULL, 0.6552502332327004);"#;
|
||||
let expected = r#"INSERT INTO test (cpu_util, ts, host) VALUES
|
||||
(0.494276426950336, '+210328-02-20 15:44:23.848+0000', 'aut'),
|
||||
(0.5240550121500691, '-78231-02-16 05:32:41.400+0000', 'in');"#;
|
||||
assert_eq!(output, expected);
|
||||
|
||||
let insert_expr = insert_expr_generator.generate(&mut rng).unwrap();
|
||||
let output = InsertIntoExprTranslator.translate(&insert_expr).unwrap();
|
||||
let expected = r#"INSERT INTO test (ts, memory_util) VALUES
|
||||
('+22606-05-02 04:44:02.976+0000', 0.7074194466620976),
|
||||
('+33689-06-12 08:42:11.037+0000', 0.40987428386535585);"#;
|
||||
let expected = r#"INSERT INTO test (ts, host) VALUES
|
||||
('+137972-11-29 18:23:19.505+0000', 'repellendus'),
|
||||
('-237884-01-11 09:44:43.491+0000', 'a');"#;
|
||||
assert_eq!(output, expected);
|
||||
|
||||
let insert_expr = insert_expr_generator.generate(&mut rng).unwrap();
|
||||
let output = InsertIntoExprTranslator.translate(&insert_expr).unwrap();
|
||||
let expected = r#"INSERT INTO test (ts, disk_util, cpu_util, host) VALUES
|
||||
('+200107-10-22 01:36:36.924+0000', 0.9082597320638828, 0.020853190804573818, 'voluptates'),
|
||||
('+241156-12-16 20:52:15.185+0000', 0.6492772846116915, 0.18078027701087784, 'repellat');"#;
|
||||
let expected = r#"INSERT INTO test (disk_util, ts) VALUES
|
||||
(0.399415030703252, '+154545-01-21 09:38:13.768+0000'),
|
||||
(NULL, '-227688-03-19 14:23:24.582+0000');"#;
|
||||
assert_eq!(output, expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,8 @@ mod tests {
|
||||
|
||||
let select_expr = select_expr_generator.generate(&mut rng).unwrap();
|
||||
let output = SelectExprTranslator.translate(&select_expr).unwrap();
|
||||
let expected = r#"SELECT memory_util, ts, cpu_util, disk_util FROM test ORDER BY cpu_util, disk_util DESC;"#;
|
||||
let expected =
|
||||
r#"SELECT ts, memory_util, cpu_util, disk_util FROM test ORDER BY disk_util, ts DESC;"#;
|
||||
assert_eq!(output, expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,9 +191,9 @@ impl UnstableProcessController {
|
||||
self.running.store(true, Ordering::Relaxed);
|
||||
let mut rng = ChaChaRng::seed_from_u64(self.seed);
|
||||
while self.running.load(Ordering::Relaxed) {
|
||||
let min = rng.gen_range(50..100);
|
||||
let max = rng.gen_range(300..600);
|
||||
let ms = rng.gen_range(min..max);
|
||||
let min = rng.random_range(50..100);
|
||||
let max = rng.random_range(300..600);
|
||||
let ms = rng.random_range(min..max);
|
||||
let pid = self
|
||||
.start_process_with_retry(3)
|
||||
.await
|
||||
|
||||
@@ -69,16 +69,16 @@ impl Arbitrary<'_> for FuzzInput {
|
||||
let seed = u.int_in_range(u64::MIN..=u64::MAX)?;
|
||||
let mut rng = ChaChaRng::seed_from_u64(seed);
|
||||
let max_actions = get_gt_fuzz_input_max_alter_actions();
|
||||
let actions = rng.gen_range(1..max_actions);
|
||||
let actions = rng.random_range(1..max_actions);
|
||||
|
||||
Ok(FuzzInput { seed, actions })
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_create_physical_table_expr<R: Rng + 'static>(rng: &mut R) -> Result<CreateTableExpr> {
|
||||
let physical_table_if_not_exists = rng.gen_bool(0.5);
|
||||
let physical_table_if_not_exists = rng.random_bool(0.5);
|
||||
let mut with_clause = HashMap::new();
|
||||
if rng.gen_bool(0.5) {
|
||||
if rng.random_bool(0.5) {
|
||||
with_clause.insert("append_mode".to_string(), "true".to_string());
|
||||
}
|
||||
let create_physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
|
||||
@@ -97,8 +97,8 @@ fn generate_create_logical_table_expr<R: Rng + 'static>(
|
||||
physical_table_ctx: TableContextRef,
|
||||
rng: &mut R,
|
||||
) -> Result<CreateTableExpr> {
|
||||
let labels = rng.gen_range(1..=5);
|
||||
let logical_table_if_not_exists = rng.gen_bool(0.5);
|
||||
let labels = rng.random_range(1..=5);
|
||||
let logical_table_if_not_exists = rng.random_bool(0.5);
|
||||
|
||||
let create_logical_table_expr = CreateLogicalTableExprGeneratorBuilder::default()
|
||||
.name_generator(Box::new(MappedGenerator::new(
|
||||
|
||||
@@ -76,9 +76,9 @@ enum AlterTableKind {
|
||||
|
||||
fn generate_create_table_expr<R: Rng + 'static>(rng: &mut R) -> Result<CreateTableExpr> {
|
||||
let max_columns = get_gt_fuzz_input_max_columns();
|
||||
let columns = rng.gen_range(2..max_columns);
|
||||
let columns = rng.random_range(2..max_columns);
|
||||
let mut with_clause = HashMap::new();
|
||||
if rng.gen_bool(0.5) {
|
||||
if rng.random_bool(0.5) {
|
||||
with_clause.insert("append_mode".to_string(), "true".to_string());
|
||||
}
|
||||
let create_table_generator = CreateTableExprGeneratorBuilder::default()
|
||||
@@ -99,7 +99,7 @@ fn generate_alter_table_expr<R: Rng + 'static>(
|
||||
rng: &mut R,
|
||||
) -> Result<AlterTableExpr> {
|
||||
let kinds = AlterTableKind::iter().collect::<Vec<_>>();
|
||||
match kinds[rng.gen_range(0..kinds.len())] {
|
||||
match kinds[rng.random_range(0..kinds.len())] {
|
||||
AlterTableKind::DropColumn if !droppable_columns(&table_ctx.columns).is_empty() => {
|
||||
AlterExprDropColumnGeneratorBuilder::default()
|
||||
.table_ctx(table_ctx)
|
||||
@@ -138,7 +138,7 @@ fn generate_alter_table_expr<R: Rng + 'static>(
|
||||
expr_generator.generate(rng)
|
||||
}
|
||||
_ => {
|
||||
let location = rng.gen_bool(0.5);
|
||||
let location = rng.random_bool(0.5);
|
||||
let expr_generator = AlterExprAddColumnGeneratorBuilder::default()
|
||||
.table_ctx(table_ctx)
|
||||
.location(location)
|
||||
@@ -153,7 +153,7 @@ impl Arbitrary<'_> for FuzzInput {
|
||||
fn arbitrary(u: &mut Unstructured<'_>) -> arbitrary::Result<Self> {
|
||||
let seed = u.int_in_range(u64::MIN..=u64::MAX)?;
|
||||
let mut rng = ChaChaRng::seed_from_u64(seed);
|
||||
let actions = rng.gen_range(1..256);
|
||||
let actions = rng.random_range(1..256);
|
||||
|
||||
Ok(FuzzInput { seed, actions })
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ impl Arbitrary<'_> for FuzzInput {
|
||||
|
||||
fn generate_expr(input: FuzzInput) -> Result<CreateDatabaseExpr> {
|
||||
let mut rng = ChaChaRng::seed_from_u64(input.seed);
|
||||
let if_not_exists = rng.gen_bool(0.5);
|
||||
let if_not_exists = rng.random_bool(0.5);
|
||||
let create_database_generator = CreateDatabaseExprGeneratorBuilder::default()
|
||||
.name_generator(Box::new(MappedGenerator::new(
|
||||
WordGenerator,
|
||||
|
||||
@@ -68,9 +68,9 @@ async fn execute_create_logic_table(ctx: FuzzContext, input: FuzzInput) -> Resul
|
||||
let mut rng = ChaChaRng::seed_from_u64(input.seed);
|
||||
|
||||
// Create physical table
|
||||
let physical_table_if_not_exists = rng.gen_bool(0.5);
|
||||
let physical_table_if_not_exists = rng.random_bool(0.5);
|
||||
let mut with_clause = HashMap::new();
|
||||
if rng.gen_bool(0.5) {
|
||||
if rng.random_bool(0.5) {
|
||||
with_clause.insert("append_mode".to_string(), "true".to_string());
|
||||
}
|
||||
let create_physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
|
||||
@@ -113,8 +113,8 @@ async fn execute_create_logic_table(ctx: FuzzContext, input: FuzzInput) -> Resul
|
||||
|
||||
// Create logical table
|
||||
let physical_table_ctx = Arc::new(TableContext::from(&create_physical_table_expr));
|
||||
let labels = rng.gen_range(1..=5);
|
||||
let logical_table_if_not_exists = rng.gen_bool(0.5);
|
||||
let labels = rng.random_range(1..=5);
|
||||
let logical_table_if_not_exists = rng.random_bool(0.5);
|
||||
|
||||
let create_logical_table_expr = CreateLogicalTableExprGeneratorBuilder::default()
|
||||
.name_generator(Box::new(MappedGenerator::new(
|
||||
|
||||
@@ -59,16 +59,16 @@ impl Arbitrary<'_> for FuzzInput {
|
||||
let seed = u.int_in_range(u64::MIN..=u64::MAX)?;
|
||||
let mut rng = ChaChaRng::seed_from_u64(seed);
|
||||
let max_columns = get_gt_fuzz_input_max_columns();
|
||||
let columns = rng.gen_range(2..max_columns);
|
||||
let columns = rng.random_range(2..max_columns);
|
||||
Ok(FuzzInput { columns, seed })
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_expr(input: FuzzInput) -> Result<CreateTableExpr> {
|
||||
let mut rng = ChaChaRng::seed_from_u64(input.seed);
|
||||
let if_not_exists = rng.gen_bool(0.5);
|
||||
let if_not_exists = rng.random_bool(0.5);
|
||||
let mut with_clause = HashMap::new();
|
||||
if rng.gen_bool(0.5) {
|
||||
if rng.random_bool(0.5) {
|
||||
with_clause.insert("append_mode".to_string(), "true".to_string());
|
||||
}
|
||||
|
||||
|
||||
@@ -80,15 +80,15 @@ impl Arbitrary<'_> for FuzzInput {
|
||||
let seed = u.int_in_range(u64::MIN..=u64::MAX)?;
|
||||
let mut rng = ChaChaRng::seed_from_u64(seed);
|
||||
let max_rows = get_gt_fuzz_input_max_rows();
|
||||
let rows = rng.gen_range(2..max_rows);
|
||||
let rows = rng.random_range(2..max_rows);
|
||||
let max_tables = get_gt_fuzz_input_max_tables();
|
||||
let tables = rng.gen_range(1..max_tables);
|
||||
let tables = rng.random_range(1..max_tables);
|
||||
Ok(FuzzInput { rows, seed, tables })
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_create_physical_table_expr<R: Rng + 'static>(rng: &mut R) -> Result<CreateTableExpr> {
|
||||
let physical_table_if_not_exists = rng.gen_bool(0.5);
|
||||
let physical_table_if_not_exists = rng.random_bool(0.5);
|
||||
let create_physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
|
||||
.name_generator(Box::new(MappedGenerator::new(
|
||||
WordGenerator,
|
||||
@@ -121,8 +121,8 @@ fn generate_create_logical_table_expr<R: Rng + 'static>(
|
||||
physical_table_ctx: TableContextRef,
|
||||
rng: &mut R,
|
||||
) -> Result<CreateTableExpr> {
|
||||
let labels = rng.gen_range(1..=5);
|
||||
let logical_table_if_not_exists = rng.gen_bool(0.5);
|
||||
let labels = rng.random_range(1..=5);
|
||||
let logical_table_if_not_exists = rng.random_bool(0.5);
|
||||
|
||||
let create_logical_table_expr = CreateLogicalTableExprGeneratorBuilder::default()
|
||||
.name_generator(Box::new(MappedGenerator::new(
|
||||
@@ -208,10 +208,10 @@ async fn execute_failover(ctx: FuzzContext, input: FuzzInput) -> Result<()> {
|
||||
|
||||
let insert_expr =
|
||||
insert_values(input.rows, &ctx, &mut rng, logical_table_ctx.clone()).await?;
|
||||
if rng.gen_bool(0.1) {
|
||||
if rng.random_bool(0.1) {
|
||||
flush_memtable(&ctx.greptime, &physical_table_ctx.name).await?;
|
||||
}
|
||||
if rng.gen_bool(0.1) {
|
||||
if rng.random_bool(0.1) {
|
||||
compact_table(&ctx.greptime, &physical_table_ctx.name).await?;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ use common_telemetry::info;
|
||||
use common_time::util::current_time_millis;
|
||||
use futures::future::try_join_all;
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::seq::IndexedRandom;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand_chacha::{ChaCha20Rng, ChaChaRng};
|
||||
use snafu::{ensure, ResultExt};
|
||||
@@ -87,13 +87,13 @@ impl Arbitrary<'_> for FuzzInput {
|
||||
let seed = u.int_in_range(u64::MIN..=u64::MAX)?;
|
||||
let mut rng = ChaChaRng::seed_from_u64(seed);
|
||||
let max_columns = get_gt_fuzz_input_max_columns();
|
||||
let columns = rng.gen_range(2..max_columns);
|
||||
let columns = rng.random_range(2..max_columns);
|
||||
let max_rows = get_gt_fuzz_input_max_rows();
|
||||
let rows = rng.gen_range(2..max_rows);
|
||||
let rows = rng.random_range(2..max_rows);
|
||||
let max_tables = get_gt_fuzz_input_max_tables();
|
||||
let tables = rng.gen_range(2..max_tables);
|
||||
let tables = rng.random_range(2..max_tables);
|
||||
let max_inserts = get_gt_fuzz_input_max_insert_actions();
|
||||
let inserts = rng.gen_range(2..max_inserts);
|
||||
let inserts = rng.random_range(2..max_inserts);
|
||||
Ok(FuzzInput {
|
||||
columns,
|
||||
rows,
|
||||
@@ -116,7 +116,7 @@ fn generate_create_exprs<R: Rng + 'static>(
|
||||
|
||||
let base_table_name = name_generator.gen(rng);
|
||||
let min_column = columns / 2;
|
||||
let columns = rng.gen_range(min_column..columns);
|
||||
let columns = rng.random_range(min_column..columns);
|
||||
let mut exprs = Vec::with_capacity(tables);
|
||||
for i in 0..tables {
|
||||
let table_name = Ident {
|
||||
@@ -174,11 +174,11 @@ fn generate_insert_exprs<R: Rng + 'static>(
|
||||
) -> Result<Vec<Vec<InsertIntoExpr>>> {
|
||||
let mut exprs = Vec::with_capacity(tables.len());
|
||||
for table_ctx in tables {
|
||||
let omit_column_list = rng.gen_bool(0.2);
|
||||
let omit_column_list = rng.random_bool(0.2);
|
||||
let min_rows = rows / 2;
|
||||
let rows = rng.gen_range(min_rows..rows);
|
||||
let rows = rng.random_range(min_rows..rows);
|
||||
let min_inserts = inserts / 2;
|
||||
let inserts = rng.gen_range(min_inserts..inserts);
|
||||
let inserts = rng.random_range(min_inserts..inserts);
|
||||
|
||||
let insert_generator = InsertExprGeneratorBuilder::default()
|
||||
.table_ctx(table_ctx.clone())
|
||||
@@ -207,9 +207,9 @@ async fn execute_insert_exprs<R: Rng + 'static>(
|
||||
let semaphore = Arc::new(Semaphore::new(parallelism));
|
||||
|
||||
let tasks = inserts.into_iter().map(|inserts| {
|
||||
let flush_probability = rng.gen_range(0.0..1.0);
|
||||
let compact_probability = rng.gen_range(0.0..1.0);
|
||||
let seed: u64 = rng.gen();
|
||||
let flush_probability = rng.random_range(0.0..1.0);
|
||||
let compact_probability = rng.random_range(0.0..1.0);
|
||||
let seed: u64 = rng.random();
|
||||
|
||||
let semaphore = semaphore.clone();
|
||||
let greptime = ctx.greptime.clone();
|
||||
@@ -235,10 +235,10 @@ async fn execute_insert_exprs<R: Rng + 'static>(
|
||||
)
|
||||
}
|
||||
);
|
||||
if rng.gen_bool(flush_probability) {
|
||||
if rng.random_bool(flush_probability) {
|
||||
flush_memtable(&greptime, &insert_expr.table_name).await?;
|
||||
}
|
||||
if rng.gen_bool(compact_probability) {
|
||||
if rng.random_bool(compact_probability) {
|
||||
compact_table(&greptime, &insert_expr.table_name).await?;
|
||||
}
|
||||
total_affected += result.rows_affected();
|
||||
|
||||
@@ -69,9 +69,9 @@ impl Arbitrary<'_> for FuzzInput {
|
||||
let seed = u.int_in_range(u64::MIN..=u64::MAX)?;
|
||||
let mut rng = ChaChaRng::seed_from_u64(seed);
|
||||
let max_columns = get_gt_fuzz_input_max_columns();
|
||||
let columns = rng.gen_range(2..max_columns);
|
||||
let columns = rng.random_range(2..max_columns);
|
||||
let max_row = get_gt_fuzz_input_max_rows();
|
||||
let rows = rng.gen_range(1..max_row);
|
||||
let rows = rng.random_range(1..max_row);
|
||||
Ok(FuzzInput {
|
||||
columns,
|
||||
rows,
|
||||
@@ -85,7 +85,7 @@ fn generate_create_expr<R: Rng + 'static>(
|
||||
rng: &mut R,
|
||||
) -> Result<CreateTableExpr> {
|
||||
let mut with_clause = HashMap::new();
|
||||
if rng.gen_bool(0.5) {
|
||||
if rng.random_bool(0.5) {
|
||||
with_clause.insert("append_mode".to_string(), "true".to_string());
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ fn generate_insert_expr<R: Rng + 'static>(
|
||||
rng: &mut R,
|
||||
table_ctx: TableContextRef,
|
||||
) -> Result<InsertIntoExpr> {
|
||||
let omit_column_list = rng.gen_bool(0.2);
|
||||
let omit_column_list = rng.random_bool(0.2);
|
||||
|
||||
let insert_generator = InsertExprGeneratorBuilder::default()
|
||||
.table_ctx(table_ctx)
|
||||
@@ -155,7 +155,7 @@ async fn execute_insert(ctx: FuzzContext, input: FuzzInput) -> Result<()> {
|
||||
}
|
||||
);
|
||||
|
||||
if rng.gen_bool(0.5) {
|
||||
if rng.random_bool(0.5) {
|
||||
flush_memtable(&ctx.greptime, &create_expr.table_name).await?;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,17 +70,17 @@ impl Arbitrary<'_> for FuzzInput {
|
||||
let seed = u.int_in_range(u64::MIN..=u64::MAX)?;
|
||||
let mut rng = ChaChaRng::seed_from_u64(seed);
|
||||
let max_tables = get_gt_fuzz_input_max_tables();
|
||||
let tables = rng.gen_range(1..max_tables);
|
||||
let tables = rng.random_range(1..max_tables);
|
||||
let max_row = get_gt_fuzz_input_max_rows();
|
||||
let rows = rng.gen_range(1..max_row);
|
||||
let rows = rng.random_range(1..max_row);
|
||||
Ok(FuzzInput { tables, seed, rows })
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_create_physical_table_expr<R: Rng + 'static>(rng: &mut R) -> Result<CreateTableExpr> {
|
||||
let physical_table_if_not_exists = rng.gen_bool(0.5);
|
||||
let physical_table_if_not_exists = rng.random_bool(0.5);
|
||||
let mut with_clause = HashMap::new();
|
||||
if rng.gen_bool(0.5) {
|
||||
if rng.random_bool(0.5) {
|
||||
with_clause.insert("append_mode".to_string(), "true".to_string());
|
||||
}
|
||||
let create_physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
|
||||
@@ -99,8 +99,8 @@ fn generate_create_logical_table_expr<R: Rng + 'static>(
|
||||
physical_table_ctx: TableContextRef,
|
||||
rng: &mut R,
|
||||
) -> Result<CreateTableExpr> {
|
||||
let labels = rng.gen_range(1..=5);
|
||||
let logical_table_if_not_exists = rng.gen_bool(0.5);
|
||||
let labels = rng.random_range(1..=5);
|
||||
let logical_table_if_not_exists = rng.random_bool(0.5);
|
||||
|
||||
let create_logical_table_expr = CreateLogicalTableExprGeneratorBuilder::default()
|
||||
.name_generator(Box::new(MappedGenerator::new(
|
||||
@@ -259,11 +259,11 @@ async fn execute_insert(ctx: FuzzContext, input: FuzzInput) -> Result<()> {
|
||||
insert_values(input.rows, &ctx, &mut rng, logical_table_ctx.clone()).await?;
|
||||
validate_values(&ctx, logical_table_ctx.clone(), &insert_expr).await?;
|
||||
tables.insert(logical_table_ctx.name.clone(), logical_table_ctx.clone());
|
||||
if rng.gen_bool(0.1) {
|
||||
if rng.random_bool(0.1) {
|
||||
flush_memtable(&ctx.greptime, &physical_table_ctx.name).await?;
|
||||
validate_values(&ctx, logical_table_ctx.clone(), &insert_expr).await?;
|
||||
}
|
||||
if rng.gen_bool(0.1) {
|
||||
if rng.random_bool(0.1) {
|
||||
compact_table(&ctx.greptime, &physical_table_ctx.name).await?;
|
||||
validate_values(&ctx, logical_table_ctx.clone(), &insert_expr).await?;
|
||||
}
|
||||
|
||||
@@ -78,16 +78,16 @@ impl Arbitrary<'_> for FuzzInput {
|
||||
let seed = u.int_in_range(u64::MIN..=u64::MAX)?;
|
||||
let mut rng = ChaChaRng::seed_from_u64(seed);
|
||||
let max_rows = get_gt_fuzz_input_max_rows();
|
||||
let rows = rng.gen_range(2..max_rows);
|
||||
let rows = rng.random_range(2..max_rows);
|
||||
let max_tables = get_gt_fuzz_input_max_tables();
|
||||
let tables = rng.gen_range(1..max_tables);
|
||||
let tables = rng.random_range(1..max_tables);
|
||||
|
||||
Ok(FuzzInput { rows, seed, tables })
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_create_physical_table_expr<R: Rng + 'static>(rng: &mut R) -> Result<CreateTableExpr> {
|
||||
let physical_table_if_not_exists = rng.gen_bool(0.5);
|
||||
let physical_table_if_not_exists = rng.random_bool(0.5);
|
||||
let create_physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
|
||||
.name_generator(Box::new(MappedGenerator::new(
|
||||
WordGenerator,
|
||||
@@ -120,8 +120,8 @@ fn generate_create_logical_table_expr<R: Rng + 'static>(
|
||||
physical_table_ctx: TableContextRef,
|
||||
rng: &mut R,
|
||||
) -> Result<CreateTableExpr> {
|
||||
let labels = rng.gen_range(1..=5);
|
||||
let logical_table_if_not_exists = rng.gen_bool(0.5);
|
||||
let labels = rng.random_range(1..=5);
|
||||
let logical_table_if_not_exists = rng.random_bool(0.5);
|
||||
|
||||
let create_logical_table_expr = CreateLogicalTableExprGeneratorBuilder::default()
|
||||
.name_generator(Box::new(MappedGenerator::new(
|
||||
@@ -214,10 +214,10 @@ async fn create_logical_table_and_insert_values(
|
||||
let logical_table_ctx = Arc::new(TableContext::from(&create_logical_table_expr));
|
||||
|
||||
let insert_expr = insert_values(input.rows, ctx, rng, logical_table_ctx.clone()).await?;
|
||||
if rng.gen_bool(0.1) {
|
||||
if rng.random_bool(0.1) {
|
||||
flush_memtable(&ctx.greptime, &physical_table_ctx.name).await?;
|
||||
}
|
||||
if rng.gen_bool(0.1) {
|
||||
if rng.random_bool(0.1) {
|
||||
compact_table(&ctx.greptime, &physical_table_ctx.name).await?;
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ async fn execute_migration(ctx: FuzzContext, input: FuzzInput) -> Result<()> {
|
||||
let mut migrations = Vec::with_capacity(num_partitions);
|
||||
let mut new_distribution: BTreeMap<u64, HashSet<_>> = BTreeMap::new();
|
||||
for (datanode_id, regions) in region_distribution {
|
||||
let step = rng.gen_range(1..datanodes.len());
|
||||
let step = rng.random_range(1..datanodes.len());
|
||||
for region in regions {
|
||||
let to_peer = (datanode_id + step as u64) % datanodes.len() as u64;
|
||||
new_distribution.entry(to_peer).or_default().insert(region);
|
||||
|
||||
@@ -76,10 +76,10 @@ impl Arbitrary<'_> for FuzzInput {
|
||||
fn arbitrary(u: &mut Unstructured<'_>) -> arbitrary::Result<Self> {
|
||||
let seed = u.int_in_range(u64::MIN..=u64::MAX)?;
|
||||
let mut rng = ChaChaRng::seed_from_u64(seed);
|
||||
let partitions = rng.gen_range(3..32);
|
||||
let columns = rng.gen_range(2..30);
|
||||
let rows = rng.gen_range(128..1024);
|
||||
let inserts = rng.gen_range(2..8);
|
||||
let partitions = rng.random_range(3..32);
|
||||
let columns = rng.random_range(2..30);
|
||||
let rows = rng.random_range(128..1024);
|
||||
let inserts = rng.random_range(2..8);
|
||||
Ok(FuzzInput {
|
||||
seed,
|
||||
columns,
|
||||
@@ -113,7 +113,7 @@ fn generate_insert_exprs<R: Rng + 'static>(
|
||||
rng: &mut R,
|
||||
table_ctx: TableContextRef,
|
||||
) -> Result<Vec<InsertIntoExpr>> {
|
||||
let omit_column_list = rng.gen_bool(0.2);
|
||||
let omit_column_list = rng.random_bool(0.2);
|
||||
let insert_generator = InsertExprGeneratorBuilder::default()
|
||||
.table_ctx(table_ctx.clone())
|
||||
.omit_column_list(omit_column_list)
|
||||
@@ -161,10 +161,10 @@ async fn insert_values<R: Rng + 'static>(
|
||||
)
|
||||
}
|
||||
);
|
||||
if rng.gen_bool(0.2) {
|
||||
if rng.random_bool(0.2) {
|
||||
flush_memtable(&ctx.greptime, &table_ctx.name).await?;
|
||||
}
|
||||
if rng.gen_bool(0.1) {
|
||||
if rng.random_bool(0.1) {
|
||||
compact_table(&ctx.greptime, &table_ctx.name).await?;
|
||||
}
|
||||
}
|
||||
@@ -309,7 +309,7 @@ async fn execute_region_migration(ctx: FuzzContext, input: FuzzInput) -> Result<
|
||||
let mut migrations = Vec::with_capacity(num_partitions);
|
||||
let mut new_distribution: BTreeMap<u64, HashSet<_>> = BTreeMap::new();
|
||||
for (datanode_id, regions) in region_distribution {
|
||||
let step = rng.gen_range(1..datanodes.len());
|
||||
let step = rng.random_range(1..datanodes.len());
|
||||
for region in regions {
|
||||
let to_peer = (datanode_id + step as u64) % datanodes.len() as u64;
|
||||
new_distribution.entry(to_peer).or_default().insert(region);
|
||||
|
||||
@@ -69,7 +69,7 @@ impl Arbitrary<'_> for FuzzInput {
|
||||
let seed = u.int_in_range(u64::MIN..=u64::MAX)?;
|
||||
let mut rng = ChaChaRng::seed_from_u64(seed);
|
||||
let max_tables = get_gt_fuzz_input_max_tables();
|
||||
let tables = rng.gen_range(1..max_tables);
|
||||
let tables = rng.random_range(1..max_tables);
|
||||
Ok(FuzzInput { seed, tables })
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ const DEFAULT_MYSQL_URL: &str = "127.0.0.1:4002";
|
||||
const DEFAULT_HTTP_HEALTH_URL: &str = "http://127.0.0.1:4000/health";
|
||||
|
||||
fn generate_create_table_expr<R: Rng + 'static>(rng: &mut R) -> CreateTableExpr {
|
||||
let columns = rng.gen_range(2..30);
|
||||
let columns = rng.random_range(2..30);
|
||||
let create_table_generator = CreateTableExprGeneratorBuilder::default()
|
||||
.name_generator(Box::new(MappedGenerator::new(
|
||||
WordGenerator,
|
||||
|
||||
Reference in New Issue
Block a user