fix(mito2): report stale compaction execution instead of region closed

When a compaction finishes but its execution no longer matches the
current one, the region may have been reopened or truncated, or the
compaction was superseded. Reporting RegionClosed to waiters is
misleading; introduce a neutral StaleCompactionExecution error (same
Cancelled status code) for this case.

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>
This commit is contained in:
Lei, HUANG
2026-07-23 17:41:23 +08:00
parent fa0cf5ec4b
commit 11b80b9b44
2 changed files with 13 additions and 2 deletions
+11
View File
@@ -554,6 +554,16 @@ pub enum Error {
location: Location,
},
#[snafu(display(
"Stale compaction execution for region {}, the region may have been reopened, truncated or the compaction was superseded",
region_id
))]
StaleCompactionExecution {
region_id: RegionId,
#[snafu(implicit)]
location: Location,
},
#[snafu(display("Region {} is truncated", region_id))]
RegionTruncated {
region_id: RegionId,
@@ -1434,6 +1444,7 @@ impl ErrorExt for Error {
FlushRegion { source, .. } | BuildIndexAsync { source, .. } => source.status_code(),
RegionDropped { .. } => StatusCode::Cancelled,
RegionClosed { .. } => StatusCode::Cancelled,
StaleCompactionExecution { .. } => StatusCode::Cancelled,
RegionTruncated { .. } => StatusCode::Cancelled,
RejectWrite { .. } => StatusCode::StorageUnavailable,
CompactRegion { source, .. } => source.status_code(),
+2 -2
View File
@@ -20,7 +20,7 @@ use store_api::storage::RegionId;
use crate::compaction::{CompactionExecution, CompactionPickFinished};
use crate::config::IndexBuildMode;
use crate::error::{RegionClosedSnafu, RegionNotFoundSnafu};
use crate::error::{RegionNotFoundSnafu, StaleCompactionExecutionSnafu};
use crate::metrics::COMPACTION_REQUEST_COUNT;
use crate::region::MitoRegionRef;
use crate::request::{
@@ -116,7 +116,7 @@ impl<S> RegionWorkerLoop<S> {
}
};
if !self.is_current_compaction_execution(&region, &request.execution) {
request.on_failure(RegionClosedSnafu { region_id }.build());
request.on_failure(StaleCompactionExecutionSnafu { region_id }.build());
return;
}
let execution = request.execution.clone();