meta_srv/procedure/region_migration/
migration_abort.rs1use std::any::Any;
16
17use common_procedure::{Context as ProcedureContext, Status};
18use common_telemetry::warn;
19use serde::{Deserialize, Serialize};
20
21use crate::error::{self, Result};
22use crate::procedure::region_migration::{Context, State};
23
24#[derive(Debug, Serialize, Deserialize)]
25pub struct RegionMigrationAbort {
26 reason: String,
27}
28
29impl RegionMigrationAbort {
30 pub fn new(reason: &str) -> Self {
32 Self {
33 reason: reason.to_string(),
34 }
35 }
36}
37
38#[async_trait::async_trait]
39#[typetag::serde]
40impl State for RegionMigrationAbort {
41 async fn next(
42 &mut self,
43 ctx: &mut Context,
44 _procedure_ctx: &ProcedureContext,
45 ) -> Result<(Box<dyn State>, Status)> {
46 warn!(
47 "Region migration is aborted: {}, region_id: {}, from_peer: {}, to_peer: {}, {}",
48 self.reason,
49 ctx.region_id(),
50 ctx.persistent_ctx.from_peer,
51 ctx.persistent_ctx.to_peer,
52 ctx.volatile_ctx.metrics,
53 );
54 error::MigrationAbortSnafu {
55 reason: &self.reason,
56 }
57 .fail()
58 }
59
60 fn as_any(&self) -> &dyn Any {
61 self
62 }
63}