fix(metric-engine): identify compaction pause failures during metadata sync

Signed-off-by: WenyXu <wenymedia@gmail.com>
This commit is contained in:
WenyXu
2026-11-20 04:52:12 +00:00
parent 78e040cb93
commit e9e54c50ef
2 changed files with 39 additions and 4 deletions
+29 -4
View File
@@ -24,7 +24,7 @@ use store_api::storage::RegionId;
use crate::engine::MetricEngineInner;
use crate::error::{
MissingFilesSnafu, MitoCopyRegionFromOperationSnafu, MitoEditRegionSnafu,
PhysicalRegionNotFoundSnafu, Result,
MitoPauseCompactionOperationSnafu, PhysicalRegionNotFoundSnafu, Result,
};
use crate::utils;
@@ -59,9 +59,8 @@ impl MetricEngineInner {
.pause_compaction(target_metadata_region_id)
.await
.map_err(BoxedError::new)
.context(MitoCopyRegionFromOperationSnafu {
source_region_id: source_metadata_region_id,
target_region_id: target_metadata_region_id,
.context(MitoPauseCompactionOperationSnafu {
region_id: target_metadata_region_id,
})?;
let res = self
.mito
@@ -218,6 +217,32 @@ mod tests {
assert_eq!(columns, expected_columns);
}
#[tokio::test]
async fn test_metadata_sync_pause_on_missing_target() {
let env = TestEnv::new().await;
let source = env.default_physical_region_id();
let target = RegionId::new(source.table_id(), source.region_number() + 1);
let target_metadata = crate::utils::to_metadata_region_id(target);
let err = env
.metric()
.inner
.sync_region_from_region(target, source, 1)
.await
.unwrap_err();
assert_eq!(StatusCode::RegionNotFound, err.status_code());
let crate::error::Error::MitoPauseCompactionOperation {
region_id, source, ..
} = err
else {
panic!("unexpected sync error: {err:?}");
};
assert_eq!(target_metadata, region_id);
assert!(matches!(
source.into_inner().as_any().downcast_ref::<mito2::error::Error>(),
Some(mito2::error::Error::RegionNotFound { region_id, .. }) if *region_id == target_metadata
));
}
#[tokio::test]
async fn test_metadata_sync_blocks_compaction_until_cleanup() {
let env = TestEnv::new().await;
+10
View File
@@ -149,6 +149,14 @@ pub enum Error {
target_region_id: RegionId,
},
#[snafu(display("Failed to pause compaction for region {}", region_id))]
MitoPauseCompactionOperation {
region_id: RegionId,
source: BoxedError,
#[snafu(implicit)]
location: Location,
},
#[snafu(display("Mito edit region operation fails, region id: {}", region_id))]
MitoEditRegion {
region_id: RegionId,
@@ -488,6 +496,7 @@ impl ErrorExt for Error {
| BatchOpenMitoRegion { source, .. }
| BatchCatchupMitoRegion { source, .. }
| MitoCopyRegionFromOperation { source, .. }
| MitoPauseCompactionOperation { source, .. }
| MitoEditRegion { source, .. } => source.status_code(),
EncodePrimaryKey { source, .. } => source.status_code(),
@@ -527,6 +536,7 @@ impl ErrorExt for Error {
| MitoSyncOperation { source, .. }
| MitoEnterStagingOperation { source, .. }
| MitoCopyRegionFromOperation { source, .. }
| MitoPauseCompactionOperation { source, .. }
| MitoEditRegion { source, .. } => source.retry_hint(),
EncodePrimaryKey { source, .. } => source.retry_hint(),