From 3ad0b60c4b3f253d8a3777a466a87073c6b52d1b Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" <6406592+v0y4g3r@users.noreply.github.com> Date: Thu, 25 Dec 2025 11:55:17 +0800 Subject: [PATCH] chore(metric-engine): set default compaction time window for data region (#7474) chore: set compaction time window for metric engine data region to 1 day by default Signed-off-by: Lei, HUANG --- src/metric-engine/src/engine/options.rs | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/metric-engine/src/engine/options.rs b/src/metric-engine/src/engine/options.rs index 838e5b4e45..232d3e93c5 100644 --- a/src/metric-engine/src/engine/options.rs +++ b/src/metric-engine/src/engine/options.rs @@ -23,6 +23,7 @@ use store_api::metric_engine_consts::{ METRIC_ENGINE_INDEX_SKIPPING_INDEX_GRANULARITY_OPTION, METRIC_ENGINE_INDEX_SKIPPING_INDEX_GRANULARITY_OPTION_DEFAULT, METRIC_ENGINE_INDEX_TYPE_OPTION, }; +use store_api::mito_engine_options::{COMPACTION_TYPE, COMPACTION_TYPE_TWCS, TWCS_TIME_WINDOW}; use crate::error::{Error, ParseRegionOptionsSnafu, Result}; @@ -32,6 +33,9 @@ use crate::error::{Error, ParseRegionOptionsSnafu, Result}; /// value and appropriately increasing the size of the index, it results in an improved indexing effect. const SEG_ROW_COUNT_FOR_DATA_REGION: u32 = 256; +/// The default compaction time window for metric engine data regions. +const DEFAULT_DATA_REGION_COMPACTION_TIME_WINDOW: &str = "1d"; + /// Physical region options. #[derive(Debug, Clone, Copy, PartialEq)] pub struct PhysicalRegionOptions { @@ -72,6 +76,16 @@ pub fn set_data_region_options( "sparse".to_string(), ); } + if !options.contains_key(TWCS_TIME_WINDOW) { + options.insert( + COMPACTION_TYPE.to_string(), + COMPACTION_TYPE_TWCS.to_string(), + ); + options.insert( + TWCS_TIME_WINDOW.to_string(), + DEFAULT_DATA_REGION_COMPACTION_TIME_WINDOW.to_string(), + ); + } } impl TryFrom<&HashMap> for PhysicalRegionOptions { @@ -192,4 +206,29 @@ mod tests { } ); } + + #[test] + fn test_set_data_region_options_default_compaction_time_window() { + // Test that default time window is set when not specified + let mut options = HashMap::new(); + set_data_region_options(&mut options, false); + + assert_eq!( + options.get(COMPACTION_TYPE), + Some(&COMPACTION_TYPE_TWCS.to_string()) + ); + assert_eq!(options.get(TWCS_TIME_WINDOW), Some(&"1d".to_string())); + } + + #[test] + fn test_set_data_region_options_respects_user_compaction_time_window() { + // Test that user-specified time window is preserved + let mut options = HashMap::new(); + options.insert(TWCS_TIME_WINDOW.to_string(), "2h".to_string()); + options.insert(COMPACTION_TYPE.to_string(), "twcs".to_string()); + set_data_region_options(&mut options, false); + + // User's time window should be preserved + assert_eq!(options.get(TWCS_TIME_WINDOW), Some(&"2h".to_string())); + } }