Skip to content

Commit

Permalink
refactor: unify the lock key
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Nov 15, 2023
1 parent f4112f2 commit 5b42ea5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/meta-srv/src/procedure/region_failover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/meta-srv/src/procedure/region_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -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())
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/meta-srv/src/procedure/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5b42ea5

Please sign in to comment.