From 5b42ea5dfbbb32058ec025d58748d62eac4c42b4 Mon Sep 17 00:00:00 2001 From: WenyXu Date: Wed, 15 Nov 2023 08:49:16 +0000 Subject: [PATCH] refactor: unify the lock key --- src/meta-srv/src/procedure/region_failover.rs | 6 ++---- src/meta-srv/src/procedure/region_migration.rs | 7 ++----- src/meta-srv/src/procedure/utils.rs | 6 ++++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/meta-srv/src/procedure/region_failover.rs b/src/meta-srv/src/procedure/region_failover.rs index a09bb1c2c0c4..b56b17e7058f 100644 --- a/src/meta-srv/src/procedure/region_failover.rs +++ b/src/meta-srv/src/procedure/region_failover.rs @@ -46,6 +46,7 @@ use table::metadata::TableId; use crate::error::{Error, RegisterProcedureLoaderSnafu, Result, TableMetadataManagerSnafu}; use crate::lock::DistLockRef; use crate::metasrv::{SelectorContext, SelectorRef}; +use crate::procedure::utils::region_lock_key; use crate::service::mailbox::MailboxRef; const OPEN_REGION_MESSAGE_TIMEOUT: Duration = Duration::from_secs(30); @@ -377,10 +378,7 @@ impl Procedure for RegionFailoverProcedure { fn lock_key(&self) -> LockKey { let region_ident = &self.node.failed_region; - let region_key = format!( - "{}/region-{}", - region_ident.table_id, region_ident.region_number - ); + let region_key = region_lock_key(region_ident.table_id, region_ident.region_number); LockKey::single(region_key) } } diff --git a/src/meta-srv/src/procedure/region_migration.rs b/src/meta-srv/src/procedure/region_migration.rs index 5ea08840647e..6bd13c65abde 100644 --- a/src/meta-srv/src/procedure/region_migration.rs +++ b/src/meta-srv/src/procedure/region_migration.rs @@ -28,6 +28,7 @@ use store_api::storage::RegionId; use self::migration_start::RegionMigrationStart; use crate::error::{Error, Result}; +use crate::procedure::utils::region_lock_key; /// It's shared in each step and available even after recovering. /// @@ -46,11 +47,7 @@ pub struct PersistentContext { impl PersistentContext { pub fn lock_key(&self) -> String { - format!( - "{}/{}", - self.region_id.table_id(), - self.region_id.region_number() - ) + region_lock_key(self.region_id.table_id(), self.region_id.region_number()) } } diff --git a/src/meta-srv/src/procedure/utils.rs b/src/meta-srv/src/procedure/utils.rs index c57925697dd7..6f36dc7f9d5b 100644 --- a/src/meta-srv/src/procedure/utils.rs +++ b/src/meta-srv/src/procedure/utils.rs @@ -12,6 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +use store_api::storage::{RegionNumber, TableId}; + +pub fn region_lock_key(table_id: TableId, region_number: RegionNumber) -> String { + format!("{}/region-{}", table_id, region_number) +} + #[cfg(test)] pub mod mock { use std::io::Error;