Skip to content

Commit 904f005

Browse files
committed
chore: apply suggestions from CR
Signed-off-by: WenyXu <[email protected]>
1 parent bb51c1d commit 904f005

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/mito2/src/engine/staging_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ async fn test_staging_exit_success_with_manifests_with_format(flat_format: bool)
468468
let normal_count_before = normal_files_before.len();
469469
assert_eq!(
470470
// One file for table creation
471-
// One files for flush operation
471+
// One file for flush operation
472472
normal_count_before,
473473
2,
474474
"Normal manifest directory should initially contain 2 file"

src/mito2/src/region.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,19 @@ impl MitoRegion {
344344
)
345345
}
346346

347+
/// Exits the entering staging state back to writable.
348+
pub(crate) fn exit_entering_staging(&self) -> Result<()> {
349+
self.compare_exchange_state(
350+
RegionLeaderState::EnteringStaging,
351+
RegionRoleState::Leader(RegionLeaderState::Writable),
352+
)
353+
}
354+
347355
/// Exits the staging state back to writable.
348356
///
349357
/// You should call this method in the worker loop.
350358
/// Transitions from Staging to Writable state.
351-
fn exit_staging(&self) -> Result<()> {
359+
pub fn exit_staging(&self) -> Result<()> {
352360
self.compare_exchange_state(
353361
RegionLeaderState::Staging,
354362
RegionRoleState::Leader(RegionLeaderState::Writable),

src/mito2/src/worker/handle_enter_staging.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<S: LogStore> RegionWorkerLoop<S> {
6161

6262
let version = region.version();
6363
if !version.memtables.is_empty() {
64-
// If memtable is empty, we can't enter staging directly and need to flush
64+
// If memtable is not empty, we can't enter staging directly and need to flush
6565
// all memtables first.
6666
info!("Flush region: {} before entering staging", region_id);
6767
debug_assert!(!region.is_staging());
@@ -127,6 +127,9 @@ impl<S: LogStore> RegionWorkerLoop<S> {
127127
"Failed to clear staging manifest files for region {}",
128128
region.region_id
129129
);
130+
if let Err(e) = region.exit_entering_staging() {
131+
error!(e; "Failed to exit entering staging after failed to clear staging manifest files");
132+
}
130133
sender.send(Err(e));
131134
return;
132135
}
@@ -202,13 +205,13 @@ impl<S: LogStore> RegionWorkerLoop<S> {
202205
common_runtime::spawn_global(async move {
203206
let mut manager = region.manifest_ctx.manifest_manager.write().await;
204207
if let Err(e) = manager.clear_staging_manifests().await {
205-
error!(e; "Failed to clear staging manifests after failed to switch region state to entering staging");
208+
error!(e; "Failed to clear staging manifests after failed to switch region state to staging");
206209
}
207210
});
208211
};
209212

210213
if let Err(e) = region.switch_state_to_staging(RegionLeaderState::EnteringStaging) {
211-
error!(e; "Failed to switch region state to entering staging");
214+
error!(e; "Failed to switch region state to staging");
212215
enter_staging_result.sender.send(Err(e));
213216
clean_staging_manifests(region);
214217
return;

0 commit comments

Comments
 (0)