Skip to content

Commit

Permalink
feat: implement region migration manager (#3014)
Browse files Browse the repository at this point in the history
* feat: implement region migration manager

* Update src/meta-srv/src/procedure/region_migration/manager.rs

Co-authored-by: JeremyHi <[email protected]>

* chore: apply suggestions from CR

---------

Co-authored-by: JeremyHi <[email protected]>
  • Loading branch information
WenyXu and fengjiachun authored Dec 27, 2023
1 parent 840e946 commit abeb32e
Show file tree
Hide file tree
Showing 6 changed files with 483 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/common/meta/src/key/table_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ impl TableRouteValue {
.cloned()
}

/// Returns true if it's [TableRouteValue::Physical].
pub fn is_physical(&self) -> bool {
matches!(self, TableRouteValue::Physical(_))
}

/// Gets the [RegionRoute]s of this [TableRouteValue::Physical].
///
/// # Panics
Expand Down
9 changes: 8 additions & 1 deletion src/meta-srv/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ use crate::pubsub::Message;
#[snafu(visibility(pub))]
#[stack_trace_debug]
pub enum Error {
#[snafu(display("Another migration procedure is running for region: {}", region_id))]
MigrationRunning {
location: Location,
region_id: RegionId,
},

#[snafu(display("The region migration procedure aborted, reason: {}", reason))]
MigrationAbort { location: Location, reason: String },

Expand Down Expand Up @@ -675,7 +681,8 @@ impl ErrorExt for Error {
| Error::TableIdChanged { .. }
| Error::RegionOpeningRace { .. }
| Error::RegionRouteNotFound { .. }
| Error::MigrationAbort { .. } => StatusCode::Unexpected,
| Error::MigrationAbort { .. }
| Error::MigrationRunning { .. } => StatusCode::Unexpected,
Error::TableNotFound { .. } => StatusCode::TableNotFound,
Error::InvalidateTableCache { source, .. } => source.status_code(),
Error::RequestDatanode { source, .. } => source.status_code(),
Expand Down
4 changes: 4 additions & 0 deletions src/meta-srv/src/procedure/region_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.

pub(crate) mod downgrade_leader_region;
// TODO(weny): remove it.
#[allow(dead_code)]
pub(crate) mod manager;
pub(crate) mod migration_abort;
pub(crate) mod migration_end;
pub(crate) mod migration_start;
Expand Down Expand Up @@ -123,6 +126,7 @@ pub trait ContextFactory {
}

/// Default implementation.
#[derive(Clone)]
pub struct ContextFactoryImpl {
volatile_ctx: VolatileContext,
table_metadata_manager: TableMetadataManagerRef,
Expand Down
Loading

0 comments on commit abeb32e

Please sign in to comment.