Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add region migration procedure skeleton #2743

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/meta-srv/src/procedure/region_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub(crate) mod migration_start;
use std::fmt::Debug;

use common_meta::peer::Peer;
use common_meta::table_name::TableName;
use common_procedure::error::{
Error as ProcedureError, FromJsonSnafu, Result as ProcedureResult, ToJsonSnafu,
};
Expand All @@ -38,25 +37,21 @@ use crate::error::{Error, Result};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PersistentContext {
/// The [Peer] of migration source.
src_peer: Peer,
from_peer: Peer,
/// The [Peer] of migration destination.
dst_peer: Option<Peer>,
/// Closes the migrated region on the `src_peer`.
to_peer: Option<Peer>,
/// Closes the migrated region on the `from_peer`.
close_migrated_region: bool,
WenyXu marked this conversation as resolved.
Show resolved Hide resolved
/// The [TableName] of migration region.
table_name: TableName,
/// The [RegionId] of migration region.
region_id: RegionId,
}

impl PersistentContext {
pub fn lock_key(&self) -> String {
let table_name = &self.table_name;

common_catalog::format_full_table_name(
&table_name.catalog_name,
&table_name.schema_name,
&table_name.table_name,
format!(
"{}/{}",
self.region_id.table_id(),
self.region_id.region_number()
WenyXu marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
Expand Down Expand Up @@ -187,10 +182,9 @@ mod tests {

fn persistent_context_factory() -> PersistentContext {
PersistentContext {
src_peer: Peer::empty(1),
dst_peer: None,
from_peer: Peer::empty(1),
to_peer: None,
close_migrated_region: false,
table_name: TableName::new("foo", "bar", "name"),
region_id: RegionId::new(1024, 1),
}
}
Expand Down Expand Up @@ -231,7 +225,7 @@ mod tests {

let serialized = procedure.dump().unwrap();

let expected = r#"{"context":{"src_peer":{"id":1,"addr":""},"dst_peer":null,"close_migrated_region":false,"table_name":{"catalog_name":"foo","schema_name":"bar","table_name":"name"},"region_id":4398046511105},"state":{"region_migration_state":"RegionMigrationStart"}}"#;
let expected = r#"{"context":{"from_peer":{"id":1,"addr":""},"to_peer":null,"close_migrated_region":false,"region_id":4398046511105},"state":{"region_migration_state":"RegionMigrationStart"}}"#;
assert_eq!(expected, serialized);
}

Expand Down
Loading