Skip to content

Commit

Permalink
chore: apply suggestions from CR
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Aug 30, 2023
1 parent 3619c47 commit c576021
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
5 changes: 1 addition & 4 deletions src/meta-srv/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ use crate::pubsub::Message;
#[derive(Debug, Snafu)]
#[snafu(visibility(pub))]
pub enum Error {
#[snafu(display(
"Failed to found failed region: {} in route, it may be already failover by another procedure",
region
))]
#[snafu(display("Failed to find the failed region: {} in table route", region))]
FailedRegionNotFound { location: Location, region: String },

#[snafu(display("Failed to list catalogs: {}", source))]
Expand Down
41 changes: 17 additions & 24 deletions src/meta-srv/src/procedure/region_failover/failover_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
// limitations under the License.

use async_trait::async_trait;
use common_catalog::format_full_table_name;
use common_error::ext::ErrorExt;
use common_error::status_code::StatusCode;
use common_meta::ident::TableIdent;
use common_meta::key::datanode_table::DatanodeTableKey;
use common_meta::peer::Peer;
use common_meta::RegionIdent;
use common_telemetry::info;
use serde::{Deserialize, Serialize};
use snafu::{ensure, OptionExt, ResultExt};
use snafu::{ensure, ResultExt};

use super::deactivate_region::DeactivateRegion;
use super::{RegionFailoverContext, State};
Expand All @@ -45,30 +45,23 @@ impl RegionFailoverStart {
failed_region: &RegionIdent,
) -> Result<bool> {
let table_id = failed_region.table_ident.table_id;
let route = ctx
let datanode_id = failed_region.datanode_id;

let value = ctx
.table_metadata_manager
.table_route_manager()
.get(table_id)
.datanode_table_manager()
.get(&DatanodeTableKey::new(datanode_id, table_id))
.await
.context(error::TableMetadataManagerSnafu)?
.with_context(|| error::TableRouteNotFoundSnafu {
table_name: format_full_table_name(
&failed_region.table_ident.catalog,
&failed_region.table_ident.schema,
&failed_region.table_ident.table,
),
})?;

let failed_region = route.region_routes.iter().any(|route| {
route.region.id.region_number() == failed_region.region_number
&& route
.leader_peer
.as_ref()
.map(|route| route.id == failed_region.datanode_id)
.unwrap_or_default()
});

Ok(failed_region)
.context(error::TableMetadataManagerSnafu)?;

Ok(value
.map(|value| {
value
.regions
.iter()
.any(|region| *region == failed_region.region_number)
})
.unwrap_or_default())
}

async fn choose_candidate(
Expand Down

0 comments on commit c576021

Please sign in to comment.