Skip to content

Commit

Permalink
refactor: remove InactiveRegionManager
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Nov 10, 2023
1 parent 1a92ff1 commit 89be9c4
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 307 deletions.
2 changes: 1 addition & 1 deletion src/meta-srv/src/handler/node_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Stat {
pub fn regions(&self) -> Vec<(RegionId, RegionRole)> {
self.region_stats
.iter()
.map(|s| (RegionId::from(s.id), s.role.into()))
.map(|s| (RegionId::from(s.id), s.role))
.collect()
}

Expand Down
11 changes: 4 additions & 7 deletions src/meta-srv/src/handler/region_lease_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod test {
fn new_empty_region_stat(region_id: RegionId, role: RegionRole) -> RegionStat {
RegionStat {
id: region_id.as_u64(),
role: role.into(),
role,
rcus: 0,
wcus: 0,
approximate_bytes: 0,
Expand Down Expand Up @@ -209,10 +209,7 @@ mod test {

handler.handle(&req, ctx, acc).await.unwrap();

assert_region_lease(
&acc,
vec![GrantedRegion::new(region_id, RegionRole::Leader)],
);
assert_region_lease(acc, vec![GrantedRegion::new(region_id, RegionRole::Leader)]);

let acc = &mut HeartbeatAccumulator::default();

Expand All @@ -234,7 +231,7 @@ mod test {
);

assert_region_lease(
&acc,
acc,
vec![GrantedRegion::new(region_id, RegionRole::Follower)],
);
}
Expand Down Expand Up @@ -305,7 +302,7 @@ mod test {
handler.handle(&req, ctx, acc).await.unwrap();

assert_region_lease(
&acc,
acc,
vec![
GrantedRegion::new(region_id, RegionRole::Follower),
GrantedRegion::new(another_region_id, RegionRole::Leader),
Expand Down
156 changes: 0 additions & 156 deletions src/meta-srv/src/inactive_region_manager.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/meta-srv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ pub mod table_meta_alloc;

pub use crate::error::Result;

mod inactive_region_manager;

mod greptimedb_telemetry;

#[cfg(test)]
Expand Down
19 changes: 0 additions & 19 deletions src/meta-srv/src/procedure/region_failover/activate_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use crate::error::{
self, Error, Result, RetryLaterSnafu, SerializeToJsonSnafu, UnexpectedInstructionReplySnafu,
};
use crate::handler::HeartbeatMailbox;
use crate::inactive_region_manager::InactiveRegionManager;
use crate::procedure::region_failover::OPEN_REGION_MESSAGE_TIMEOUT;
use crate::service::mailbox::{Channel, MailboxReceiver};

Expand Down Expand Up @@ -104,17 +103,6 @@ impl ActivateRegion {
input: instruction.to_string(),
})?;

// Ensure that metasrv will renew the lease for this candidate node.
//
// This operation may not be redundant, imagine the following scenario:
// This candidate once had the current region, and because it did not respond to the `close`
// command in time, it was considered an inactive node by metasrv, then it replied, and the
// current region failed over again, and the node was selected as a candidate, so it needs
// to clear its previous state first.
InactiveRegionManager::new(&ctx.in_memory)
.deregister_inactive_region(&candidate_ident)
.await?;

let ch = Channel::Datanode(self.candidate.id);
ctx.mailbox.send(&ch, msg, timeout).await
}
Expand Down Expand Up @@ -182,13 +170,6 @@ impl State for ActivateRegion {
ctx: &RegionFailoverContext,
failed_region: &RegionIdent,
) -> Result<Box<dyn State>> {
if self.remark_inactive_region {
// Remark the fail region as inactive to prevent it from renewing the lease.
InactiveRegionManager::new(&ctx.in_memory)
.register_inactive_region(failed_region)
.await?;
}

let mailbox_receiver = self
.send_open_region_message(ctx, failed_region, OPEN_REGION_MESSAGE_TIMEOUT)
.await?;
Expand Down
16 changes: 1 addition & 15 deletions src/meta-srv/src/procedure/region_failover/deactivate_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use crate::error::{
self, Error, Result, RetryLaterSnafu, SerializeToJsonSnafu, UnexpectedInstructionReplySnafu,
};
use crate::handler::HeartbeatMailbox;
use crate::inactive_region_manager::InactiveRegionManager;
use crate::service::mailbox::{Channel, MailboxReceiver};

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -91,22 +90,13 @@ impl DeactivateRegion {
})?;

let ch = Channel::Datanode(failed_region.datanode_id);
// Mark the region as inactive
InactiveRegionManager::new(&ctx.in_memory)
.register_inactive_region(failed_region)
.await?;
// We first marked the region as inactive, which means that the failed region cannot
// be successfully renewed from now on, so after the lease time is exceeded, the region
// will be automatically closed.
// If the deadline is exceeded, we can proceed to the next step with confidence,
// as the expiration means that the region has been closed.
let timeout = Duration::from_secs(ctx.region_lease_secs);
ctx.mailbox.send(&ch, msg, timeout).await
}

async fn handle_response(
&self,
ctx: &RegionFailoverContext,
_ctx: &RegionFailoverContext,
mailbox_receiver: MailboxReceiver,
failed_region: &RegionIdent,
) -> Result<Box<dyn State>> {
Expand All @@ -123,10 +113,6 @@ impl DeactivateRegion {
.fail();
};
if result {
InactiveRegionManager::new(&ctx.in_memory)
.deregister_inactive_region(failed_region)
.await?;

Ok(Box::new(ActivateRegion::new(self.candidate.clone())))
} else {
// Under rare circumstances would a Datanode fail to close a Region.
Expand Down
15 changes: 0 additions & 15 deletions src/meta-srv/src/service/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

mod health;
mod heartbeat;
mod inactive_regions;
mod leader;
mod meta;
mod node_lease;
Expand Down Expand Up @@ -91,20 +90,6 @@ pub fn make_admin_service(meta_srv: MetaSrv) -> Admin {
.route("/route", handler.clone())
.route("/route/help", handler);

let router = router.route(
"/inactive-regions/view",
inactive_regions::ViewInactiveRegionsHandler {
store: meta_srv.in_memory().clone(),
},
);

let router = router.route(
"/inactive-regions/clear",
inactive_regions::ClearInactiveRegionsHandler {
store: meta_srv.in_memory().clone(),
},
);

let router = Router::nest("/admin", router);

Admin::new(router)
Expand Down
Loading

0 comments on commit 89be9c4

Please sign in to comment.