fix(mito2): honor ingestion preload policy for shared references

Signed-off-by: WenyXu <wenymedia@gmail.com>
This commit is contained in:
WenyXu
2026-11-27 12:59:14 +00:00
parent f0b106f0b2
commit 913e8ae557
3 changed files with 83 additions and 10 deletions
+9 -7
View File
@@ -574,7 +574,7 @@ impl MitoEngine {
/// Other region editing intention will result in an "invalid request" error.
/// Also note that if a region is to be edited directly, we MUST not write data to it thereafter.
pub async fn edit_region(&self, region_id: RegionId, edit: RegionEdit) -> Result<()> {
self.edit_region_with_kind(region_id, edit, RegionEditKind::Import)
self.edit_region_with_kind(region_id, edit, RegionEditKind::Import, true)
.await
}
@@ -588,8 +588,13 @@ impl MitoEngine {
reason: "SST ingestion cannot remove files"
}
);
self.edit_region_with_kind(region_id, edit, RegionEditKind::Ingest)
.await
self.edit_region_with_kind(
region_id,
edit,
RegionEditKind::Ingest,
*INGEST_PRELOAD_SST_CACHE,
)
.await
}
async fn edit_region_with_kind(
@@ -597,6 +602,7 @@ impl MitoEngine {
region_id: RegionId,
edit: RegionEdit,
kind: RegionEditKind,
preload_sst_cache: bool,
) -> Result<()> {
let _timer = HANDLE_REQUEST_ELAPSED
.with_label_values(&["edit_region"])
@@ -611,10 +617,6 @@ impl MitoEngine {
);
let (tx, rx) = oneshot::channel();
// 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);
+49 -2
View File
@@ -314,6 +314,25 @@ async fn test_edit_region_fill_cache(
#[values(false, true)] flat_format: bool,
#[case] index_file_size: Option<u64>,
#[values(false, true)] ingestion: bool,
) {
check_edit_region_fill_cache(flat_format, index_file_size, ingestion, false).await;
}
#[cfg(feature = "enterprise")]
#[rstest::rstest]
#[case::without_index(None)]
#[case::known_index_size(Some(7))]
#[case::unknown_index_size(Some(0))]
#[tokio::test]
async fn test_shared_ingestion_fill_cache(#[case] index_file_size: Option<u64>) {
check_edit_region_fill_cache(true, index_file_size, false, true).await;
}
async fn check_edit_region_fill_cache(
flat_format: bool,
index_file_size: Option<u64>,
ingestion: bool,
shared: bool,
) {
let mut env = TestEnv::new().await;
@@ -369,9 +388,13 @@ async fn test_edit_region_fill_cache(
let mut meta = FileMeta {
region_id,
file_id,
file_size: 1,
index_version: 3,
..Default::default()
};
if shared {
meta.level = crate::sst::file::LEVEL_SHARED;
}
if let Some(size) = index_file_size {
meta.index_file_size = size;
meta.indexes.push(ColumnIndexMetadata {
@@ -401,13 +424,30 @@ async fn test_edit_region_fill_cache(
committed_sequence: None,
..Default::default()
};
if ingestion {
if shared {
#[cfg(feature = "enterprise")]
{
engine
.ingest_shared_ssts(region.region_id, edit)
.await
.unwrap();
assert_eq!(
engine
.get_region_statistic(region_id)
.unwrap()
.ingested_parquet_bytes,
0
);
}
#[cfg(not(feature = "enterprise"))]
unreachable!("Shared ingestion requires enterprise");
} else 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 {
if (ingestion || shared) && !*super::INGEST_PRELOAD_SST_CACHE {
// Publication completes even though neither artifact is warmed.
assert!(
region
@@ -421,6 +461,13 @@ async fn test_edit_region_fill_cache(
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))));
assert!(
tokio::time::timeout(Duration::from_millis(200), rx)
.await
.is_err()
);
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;
}
+25 -1
View File
@@ -30,7 +30,7 @@ use crate::manifest::action::RegionEdit;
use crate::region::options::RegionOptions;
use crate::region::{MitoRegionRef, RegionLeaderState, RegionRoleState};
use crate::request::{RegionEditKind, RegionEditRequest, WorkerRequest};
use crate::sst::file::{FileMeta, SHARED_LEVEL_SLOT};
use crate::sst::file::{FileMeta, LEVEL_SHARED, SHARED_LEVEL_SLOT};
/// A query-visible input snapshot. Callers may select a subset of `inputs` for a job.
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -70,6 +70,30 @@ pub fn is_table_compaction_metadata_compatible(
}
impl MitoEngine {
/// Installs shared ingestion references using the ingestion cache policy.
/// Keep import accounting: the same SST is referenced by multiple targets
/// and must not be counted as fresh writes at every target.
pub async fn ingest_shared_ssts(&self, region_id: RegionId, edit: RegionEdit) -> Result<()> {
ensure!(
edit.files_to_remove.is_empty()
&& edit
.files_to_add
.iter()
.all(|file| file.level == LEVEL_SHARED),
InvalidRequestSnafu {
region_id,
reason: "Shared ingestion requires shared files and cannot remove files"
}
);
self.edit_region_with_kind(
region_id,
edit,
RegionEditKind::Import,
*super::INGEST_PRELOAD_SST_CACHE,
)
.await
}
/// Reads committed inputs while an ordinary edit or ALTER is in progress.
pub fn table_compaction_snapshot(
&self,