From c25a1f462d472e85c843d3ab748e22046672dc3c Mon Sep 17 00:00:00 2001 From: discord9 Date: Mon, 30 Nov 2026 10:58:22 +0000 Subject: [PATCH] test(fuzz): materialise before a repartition merge (#10738) * test(fuzz): materialise before a repartition merge Since #10646 a merge is refused while a participant still holds an SST stamped by another region, which is exactly what a split hands its children. The three repartition fuzz targets merge right after splitting, so the statement failed and the target panicked on every run. Compact with the strict-window mode before issuing a merge: it rewrites even a lone inherited file under the region's own expression, which is what the refusal asks for. Splits keep running without a compaction, and a failed statement still panics. Signed-off-by: discord9 * docs(fuzz): trim the pre-merge comments to the reason The three blocks said the same thing at length; the commit message and the PR carry the full rationale, the code only needs why the compaction is there and why it precedes the chaos injection. Signed-off-by: discord9 * test(fuzz): share the strict-window compaction, drop it from chaos Review: the chaos target creates a fresh table, inserts and runs a single repartition, so no split precedes the merge and nothing can hold a foreign SST; the compaction only costs time there. The other two targets now call one helper in utils next to the existing compact_table instead of repeating the statement and its error context. Signed-off-by: discord9 --------- Signed-off-by: discord9 --- tests-fuzz/src/utils.rs | 21 +++++++++++++++++++ .../ddl/fuzz_repartition_metric_table.rs | 9 ++++++-- .../targets/ddl/fuzz_repartition_table.rs | 8 +++++-- .../ddl/fuzz_repartition_table_chaos.rs | 1 + 4 files changed, 35 insertions(+), 4 deletions(-) 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())