Skip to content

Commit

Permalink
balancer: refactor remove_monolith to not be async (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 authored Apr 11, 2024
1 parent bddbbde commit 2f3f5da
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions crates/ott-balancer/src/balancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl BalancerContext {
self.monoliths_by_region.entry(region).or_default().push(id);
}

pub async fn remove_monolith(&mut self, monolith_id: MonolithId) -> anyhow::Result<()> {
pub fn remove_monolith(&mut self, monolith_id: MonolithId) -> anyhow::Result<()> {
let m = self.monoliths.remove(&monolith_id);
if let Some(m) = m {
let region = m.region().to_string();
Expand All @@ -251,24 +251,6 @@ impl BalancerContext {
self.rooms_to_monoliths
.retain(|_, v| v.monolith_id() != monolith_id);

self.clients
.retain(|_, v| self.rooms_to_monoliths.contains_key(&v.room));

for client in self.clients.values() {
match client
.send(Message::Close(Some(CloseFrame {
code: CloseCode::Away,
reason: "Monolith disconnect".into(),
})))
.await
{
Ok(()) => {}
Err(err) => {
error!("failed to disconnect client: {:?}", err)
}
};
}

Ok(())
}

Expand Down Expand Up @@ -592,7 +574,7 @@ pub async fn leave_monolith(
) -> anyhow::Result<()> {
info!("monolith left");
let mut ctx_write = ctx.write().await;
ctx_write.remove_monolith(id).await?;
ctx_write.remove_monolith(id)?;
Ok(())
}

Expand Down

0 comments on commit 2f3f5da

Please sign in to comment.