mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-12-03 16:05:28 +00:00
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 <wenymedia@gmail.com>
This commit is contained in:
+46
-2
@@ -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<bool> = 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;
|
||||
|
||||
@@ -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<u64>,
|
||||
#[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)
|
||||
|
||||
Reference in New Issue
Block a user