Skip to content

Commit 9ab89b3

Browse files
committed
wip
Signed-off-by: WenyXu <[email protected]>
1 parent bfe619f commit 9ab89b3

File tree

7 files changed

+687
-68
lines changed

7 files changed

+687
-68
lines changed

src/meta-srv/src/procedure/region_migration.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub(crate) mod open_candidate_region;
2424
pub mod test_util;
2525
pub(crate) mod update_metadata;
2626
pub(crate) mod upgrade_candidate_region;
27+
pub(crate) mod utils;
2728

2829
use std::any::Any;
2930
use std::collections::{HashMap, HashSet};
@@ -100,9 +101,14 @@ where
100101
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
101102
pub struct PersistentContext {
102103
/// The table catalog.
103-
pub(crate) catalog: String,
104+
#[serde(default, skip_serializing_if = "Option::is_none")]
105+
pub(crate) catalog: Option<String>,
104106
/// The table schema.
105-
pub(crate) schema: String,
107+
#[serde(default, skip_serializing_if = "Option::is_none")]
108+
pub(crate) schema: Option<String>,
109+
/// The catalog and schema of the regions.
110+
#[serde(default)]
111+
pub(crate) catalog_and_schema: Vec<(String, String)>,
106112
/// The [Peer] of migration source.
107113
pub(crate) from_peer: Peer,
108114
/// The [Peer] of migration destination.
@@ -124,9 +130,17 @@ fn default_timeout() -> Duration {
124130

125131
impl PersistentContext {
126132
pub fn lock_key(&self) -> Vec<StringKey> {
127-
let mut lock_keys = Vec::with_capacity(self.region_ids.len() + 2);
128-
lock_keys.push(CatalogLock::Read(&self.catalog).into());
129-
lock_keys.push(SchemaLock::read(&self.catalog, &self.schema).into());
133+
let mut lock_keys =
134+
Vec::with_capacity(self.region_ids.len() + 2 + self.catalog_and_schema.len() * 2);
135+
if let (Some(catalog), Some(schema)) = (&self.catalog, &self.schema) {
136+
lock_keys.push(CatalogLock::Read(catalog).into());
137+
lock_keys.push(SchemaLock::read(catalog, schema).into());
138+
}
139+
for (catalog, schema) in self.catalog_and_schema.iter() {
140+
lock_keys.push(CatalogLock::Read(catalog).into());
141+
lock_keys.push(SchemaLock::read(catalog, schema).into());
142+
}
143+
130144
// Sort the region ids to ensure the same order of region ids.
131145
let mut region_ids = self.region_ids.clone();
132146
region_ids.sort_unstable();

src/meta-srv/src/procedure/region_migration/downgrade_leader_region.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,9 @@ mod tests {
390390

391391
fn new_persistent_context() -> PersistentContext {
392392
PersistentContext {
393-
catalog: "greptime".into(),
394-
schema: "public".into(),
393+
catalog: Some("greptime".to_string()),
394+
schema: Some("public".to_string()),
395+
catalog_and_schema: vec![],
395396
from_peer: Peer::empty(1),
396397
to_peer: Peer::empty(2),
397398
region_ids: vec![RegionId::new(1024, 1)],

0 commit comments

Comments
 (0)