From c8cf3b1677e40702f2e5dde152d89974814b3f6f Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" <6406592+v0y4g3r@users.noreply.github.com> Date: Fri, 19 Jul 2024 21:24:10 +0800 Subject: [PATCH] fix(wal): handle WAL deletion on region drop (#4400) Add LogStore trait bound to RegionWorkerLoop and handle WAL deletion on region drop. --- src/mito2/src/worker/handle_drop.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/mito2/src/worker/handle_drop.rs b/src/mito2/src/worker/handle_drop.rs index c307e437c502..06a439cc5ea8 100644 --- a/src/mito2/src/worker/handle_drop.rs +++ b/src/mito2/src/worker/handle_drop.rs @@ -22,6 +22,7 @@ use futures::TryStreamExt; use object_store::util::join_path; use object_store::{EntryMode, ObjectStore}; use snafu::ResultExt; +use store_api::logstore::LogStore; use store_api::region_request::AffectedRows; use store_api::storage::RegionId; use tokio::time::sleep; @@ -34,7 +35,10 @@ use crate::worker::{RegionWorkerLoop, DROPPING_MARKER_FILE}; const GC_TASK_INTERVAL_SEC: u64 = 5 * 60; // 5 minutes const MAX_RETRY_TIMES: u64 = 288; // 24 hours (5m * 288) -impl RegionWorkerLoop { +impl RegionWorkerLoop +where + S: LogStore, +{ pub(crate) async fn handle_drop_request( &mut self, region_id: RegionId, @@ -58,7 +62,7 @@ impl RegionWorkerLoop { error!(e; "Failed to write the drop marker file for region {}", region_id); // Sets the state back to writable. It's possible that the marker file has been written. - // We sets the state back to writable so we can retry the drop operation. + // We set the state back to writable so we can retry the drop operation. region.switch_state_to_writable(RegionState::Dropping); })?; @@ -66,6 +70,15 @@ impl RegionWorkerLoop { // Removes this region from region map to prevent other requests from accessing this region self.regions.remove_region(region_id); self.dropping_regions.insert_region(region.clone()); + + // Delete region data in WAL. + self.wal + .obsolete( + region_id, + region.version_control.current().last_entry_id, + ®ion.provider, + ) + .await?; // Notifies flush scheduler. self.flush_scheduler.on_region_dropped(region_id); // Notifies compaction scheduler.