diff --git a/tests-fuzz/src/utils.rs b/tests-fuzz/src/utils.rs index 0983d51352c..e899cd5e553 100644 --- a/tests-fuzz/src/utils.rs +++ b/tests-fuzz/src/utils.rs @@ -131,6 +131,27 @@ pub async fn compact_table(e: &Pool, table_name: &Ident) -> Result<()> { Ok(()) } +/// Compacts `table_name` with the strict-window mode, which rewrites even a lone file. +/// +/// A merge is refused while a participant still holds an SST another region created, and a split +/// hands the parent's files to its children unchanged; this is what materialises them again. +pub async fn compact_table_strict_window(e: &Pool, table_name: &Ident) -> Result<()> { + let sql = format!( + "admin compact_table(\"{}\", \"strict_window\", \"window=3600\")", + table_name + ); + let result = sqlx::query(sqlx::AssertSqlSafe(sql.as_str())) + .execute(e) + .await + .context(error::ExecuteQuerySnafu { sql })?; + info!( + "Strict-window compact table: {}\n\nResult: {result:?}\n\n", + table_name + ); + + Ok(()) +} + pub const GT_FUZZ_INPUT_MAX_ROWS: &str = "GT_FUZZ_INPUT_MAX_ROWS"; pub const GT_FUZZ_INPUT_MAX_TABLES: &str = "GT_FUZZ_INPUT_MAX_TABLES"; pub const GT_FUZZ_INPUT_MAX_COLUMNS: &str = "GT_FUZZ_INPUT_MAX_COLUMNS"; diff --git a/tests-fuzz/targets/ddl/fuzz_repartition_metric_table.rs b/tests-fuzz/targets/ddl/fuzz_repartition_metric_table.rs index 461bfe51daa..7ea1346705e 100644 --- a/tests-fuzz/targets/ddl/fuzz_repartition_metric_table.rs +++ b/tests-fuzz/targets/ddl/fuzz_repartition_metric_table.rs @@ -55,8 +55,9 @@ use tests_fuzz::utils::csv_dump_writer::{CsvDumpMetadata, CsvDumpSession}; use tests_fuzz::utils::retry::retry_with_backoff; use tests_fuzz::utils::sql_dump_writer::SqlDumpSession; use tests_fuzz::utils::{ - Connections, get_fuzz_override, get_gt_fuzz_input_max_alter_actions, - get_gt_fuzz_input_max_tables, init_greptime_connections_via_env, + Connections, compact_table_strict_window, get_fuzz_override, + get_gt_fuzz_input_max_alter_actions, get_gt_fuzz_input_max_tables, + init_greptime_connections_via_env, }; use tests_fuzz::validator::row::count_values; use tokio::sync::{mpsc, oneshot}; @@ -569,6 +570,10 @@ async fn execute_repartition_metric_table(ctx: FuzzContext, input: FuzzInput) -> let repartition_expr = repartition_operation(&physical_table_ctx, &mut rng)?; let translator = RepartitionExprTranslator; let sql = translator.translate(&repartition_expr)?; + // Logical tables share the physical table's regions, so compacting it covers the merge. + if matches!(repartition_expr, RepartitionExpr::Merge(_)) { + compact_table_strict_window(&ctx.greptime, &physical_table_ctx.name).await?; + } info!("Repartition sql: {sql}"); let started_at_ms = current_time_millis(); let now = Instant::now(); diff --git a/tests-fuzz/targets/ddl/fuzz_repartition_table.rs b/tests-fuzz/targets/ddl/fuzz_repartition_table.rs index d1f633014b0..7ff6763aad5 100644 --- a/tests-fuzz/targets/ddl/fuzz_repartition_table.rs +++ b/tests-fuzz/targets/ddl/fuzz_repartition_table.rs @@ -48,8 +48,8 @@ use tests_fuzz::translator::mysql::create_expr::CreateTableExprTranslator; use tests_fuzz::translator::mysql::insert_expr::InsertIntoExprTranslator; use tests_fuzz::translator::mysql::repartition_expr::RepartitionExprTranslator; use tests_fuzz::utils::{ - Connections, get_fuzz_override, get_gt_fuzz_input_max_alter_actions, - init_greptime_connections_via_env, + Connections, compact_table_strict_window, get_fuzz_override, + get_gt_fuzz_input_max_alter_actions, init_greptime_connections_via_env, }; use tests_fuzz::validator; use tests_fuzz::validator::row::count_values; @@ -305,6 +305,10 @@ async fn execute_repartition_table(ctx: FuzzContext, input: FuzzInput) -> Result let expr = repartition_operation(&table_ctx, &mut rng)?; let translator = RepartitionExprTranslator; let sql = translator.translate(&expr)?; + // A split hands the parent's SSTs to its children unchanged, and a merge refuses those. + if matches!(expr, RepartitionExpr::Merge(_)) { + compact_table_strict_window(&ctx.greptime, &table_ctx.name).await?; + } info!("Repartition sql: {sql}"); let result = sqlx::query(sqlx::AssertSqlSafe(sql.as_str())) .execute(&ctx.greptime) diff --git a/tests-fuzz/targets/ddl/fuzz_repartition_table_chaos.rs b/tests-fuzz/targets/ddl/fuzz_repartition_table_chaos.rs index ed0b963908b..bf6198dbe34 100644 --- a/tests-fuzz/targets/ddl/fuzz_repartition_table_chaos.rs +++ b/tests-fuzz/targets/ddl/fuzz_repartition_table_chaos.rs @@ -462,6 +462,7 @@ async fn execute_repartition_chaos(ctx: FuzzContext, input: FuzzInput) -> Result } else { alter_table_partitions_expr_from_table_ctx(&before_table_ctx, &mut rng, false) }; + let after_table_ctx = Arc::new( Arc::unwrap_or_clone(before_table_ctx.clone()) .repartition(repartition_expr.clone())