From e9f5d441fcaa63ce89c51de600e5d4e701a67693 Mon Sep 17 00:00:00 2001 From: WenyXu Date: Mon, 23 Nov 2026 03:19:15 +0000 Subject: [PATCH] feat(mito2): allow disabling ingestion SST cache preloading Add an opt-out for ingestion Parquet and Puffin preloading, enabled by default. Preserve import and staging behavior and cover publication with cache warming enabled and disabled. Signed-off-by: WenyXu --- src/mito2/src/engine.rs | 48 +++++++++++++++++++++++- src/mito2/src/engine/edit_region_test.rs | 24 +++++++++++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/mito2/src/engine.rs b/src/mito2/src/engine.rs index 85b88ac8d87..afa62fdb439 100644 --- a/src/mito2/src/engine.rs +++ b/src/mito2/src/engine.rs @@ -108,7 +108,7 @@ mod puffin_index; use std::any::Any; use std::collections::{HashMap, HashSet}; -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, LazyLock, RwLock}; use std::time::Instant; use api::region::RegionResponse; @@ -299,6 +299,31 @@ impl<'a, S: LogStore> MitoEngineBuilder<'a, S> { } } +const INGEST_PRELOAD_SST_CACHE_ENV: &str = "GREPTIMEDB_EXPERIMENTAL_INGEST_PRELOAD_SST_CACHE"; + +/// PoC switch, read once on first ingestion. Cache warming never gates publication. +static INGEST_PRELOAD_SST_CACHE: LazyLock = LazyLock::new(|| { + let value = std::env::var(INGEST_PRELOAD_SST_CACHE_ENV).ok(); + let enabled = parse_ingest_preload_sst_cache(value.as_deref()); + info!( + "Bulk ingestion SST cache preloading: {enabled}, configured by {INGEST_PRELOAD_SST_CACHE_ENV}" + ); + enabled +}); + +fn parse_ingest_preload_sst_cache(value: Option<&str>) -> bool { + match value { + None | Some("true" | "1") => true, + Some("false" | "0") => false, + Some(_) => { + warn!( + "Invalid {INGEST_PRELOAD_SST_CACHE_ENV}: expected true, false, 1 or 0; preloading remains enabled" + ); + true + } + } +} + /// Region engine implementation for timeseries data. #[derive(Clone)] pub struct MitoEngine { @@ -577,7 +602,11 @@ impl MitoEngine { ); let (tx, rx) = oneshot::channel(); - let mut request = RegionEditRequest::new(region_id, edit, true, tx); + // Only external ingestion uses this switch. Imports retain their existing + // policy; staging publication already explicitly disables preloading. + let preload_sst_cache = + !matches!(kind, RegionEditKind::Ingest) || *INGEST_PRELOAD_SST_CACHE; + let mut request = RegionEditRequest::new(region_id, edit, preload_sst_cache, tx); request.kind = kind; let request = WorkerRequest::EditRegion(request); self.inner @@ -2053,6 +2082,21 @@ mod tests { use super::*; use crate::sst::file::FileMeta; + #[test] + fn test_ingest_preload_sst_cache_option() { + for (value, expected) in [ + (None, true), + (Some("true"), true), + (Some("1"), true), + (Some("false"), false), + (Some("0"), false), + (Some(""), true), + (Some("invalid"), true), + ] { + assert_eq!(parse_ingest_preload_sst_cache(value), expected, "{value:?}"); + } + } + #[test] fn test_manifest_region_predicates() { use super::manifest_region_matches; diff --git a/src/mito2/src/engine/edit_region_test.rs b/src/mito2/src/engine/edit_region_test.rs index a1b1d9e76cd..625ae05bc9a 100644 --- a/src/mito2/src/engine/edit_region_test.rs +++ b/src/mito2/src/engine/edit_region_test.rs @@ -240,6 +240,7 @@ async fn test_edit_region_schedule_compaction_with_format( async fn test_edit_region_fill_cache( #[values(false, true)] flat_format: bool, #[case] index_file_size: Option, + #[values(false, true)] ingestion: bool, ) { let mut env = TestEnv::new().await; @@ -327,7 +328,28 @@ async fn test_edit_region_fill_cache( committed_sequence: None, ..Default::default() }; - engine.edit_region(region.region_id, edit).await.unwrap(); + if ingestion { + engine.ingest_ssts(region.region_id, edit).await.unwrap(); + } else { + engine.edit_region(region.region_id, edit).await.unwrap(); + } + + if ingestion && !*super::INGEST_PRELOAD_SST_CACHE { + // Publication completes even though neither artifact is warmed. + assert!( + region + .version() + .ssts + .levels() + .iter() + .any(|level| level.files.contains_key(&file_id)) + ); + let cache_manager = engine.cache_manager(); + let file_cache = cache_manager.write_cache().unwrap().file_cache(); + assert!(!file_cache.contains_key(&IndexKey::new(region_id, file_id, FileType::Parquet))); + assert!(!file_cache.contains_key(&IndexKey::new(region_id, file_id, FileType::Puffin(3)))); + return; + } // Asserts that the background downloading of the SST is succeeded. let actual = tokio::time::timeout(Duration::from_secs(9), rx)