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 <discord9@163.com>

* 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 <discord9@163.com>

* 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 <discord9@163.com>

---------

Signed-off-by: discord9 <discord9@163.com>
This commit is contained in:
discord9
2026-11-30 10:58:22 +00:00
committed by GitHub
parent 4d8e55909a
commit c25a1f462d
4 changed files with 35 additions and 4 deletions
+21
View File
@@ -131,6 +131,27 @@ pub async fn compact_table(e: &Pool<MySql>, 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<MySql>, 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";
@@ -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();
@@ -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)
@@ -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())