-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
balancer: unload duplicate rooms #1131
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! Tests for how the balancer handles room state in the context of managing rooms on monoliths. | ||
|
||
use std::time::Duration; | ||
|
||
use harness::{Client, Monolith, TestRunner}; | ||
use ott_balancer_protocol::monolith::{B2MUnload, MsgB2M}; | ||
use test_context::test_context; | ||
|
||
#[test_context(TestRunner)] | ||
#[tokio::test] | ||
async fn should_unload_duplicate_rooms(ctx: &TestRunner) { | ||
let mut m1 = Monolith::new(ctx).await.unwrap(); | ||
let mut m2 = Monolith::new(ctx).await.unwrap(); | ||
|
||
m1.show().await; | ||
m2.show().await; | ||
|
||
m1.load_room("foo").await; | ||
m2.load_room("foo").await; | ||
|
||
m2.wait_recv().await; | ||
|
||
let recv = m2.collect_recv(); | ||
assert_eq!(recv.len(), 1); | ||
assert!(matches!(recv[0], MsgB2M::Unload(B2MUnload { .. }))); | ||
} | ||
|
||
#[test_context(TestRunner)] | ||
#[tokio::test] | ||
async fn should_unload_duplicate_rooms_and_route_correctly(ctx: &TestRunner) { | ||
let mut m1 = Monolith::new(ctx).await.unwrap(); | ||
let mut m2 = Monolith::new(ctx).await.unwrap(); | ||
|
||
m1.show().await; | ||
m2.show().await; | ||
|
||
m1.load_room("foo").await; | ||
m2.load_room("foo").await; | ||
|
||
tokio::time::timeout(Duration::from_millis(100), m2.wait_recv()) | ||
.await | ||
.expect("timed out waiting for unload"); | ||
|
||
let mut c = Client::new(ctx).unwrap(); | ||
c.join("foo").await; | ||
|
||
tokio::time::timeout(Duration::from_millis(100), m1.wait_recv()) | ||
.await | ||
.expect("timed out waiting for client join"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
use std::{collections::HashMap, sync::Arc}; | ||
|
||
use ott_balancer_protocol::monolith::{B2MClientMsg, B2MJoin, B2MLeave, MsgM2B, RoomMetadata}; | ||
use ott_balancer_protocol::monolith::{ | ||
B2MClientMsg, B2MJoin, B2MLeave, B2MUnload, MsgM2B, RoomMetadata, | ||
}; | ||
use ott_balancer_protocol::*; | ||
use rand::seq::IteratorRandom; | ||
use serde_json::value::RawValue; | ||
|
@@ -343,12 +345,15 @@ impl BalancerContext { | |
match locator.load_epoch().cmp(&load_epoch) { | ||
std::cmp::Ordering::Less => { | ||
// we already have an older version of this room | ||
self.unload_room(monolith_id, metadata.name.clone()).await?; | ||
return Err(anyhow::anyhow!("room already loaded")); | ||
} | ||
std::cmp::Ordering::Greater => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are rooms ordered by id? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this code compares the |
||
// we have an newer version of this room, remove it | ||
self.remove_room(&metadata.name, locator.monolith_id()) | ||
self.unload_room(locator.monolith_id(), metadata.name.clone()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. difference between unload_room() and remove_room()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.await?; | ||
// self.remove_room(&metadata.name, locator.monolith_id()) | ||
// .await?; | ||
} | ||
_ => {} | ||
} | ||
|
@@ -414,6 +419,12 @@ impl BalancerContext { | |
.ok_or(anyhow::anyhow!("no monoliths available"))?; | ||
Ok(selected) | ||
} | ||
|
||
pub async fn unload_room(&self, monolith: MonolithId, room: RoomName) -> anyhow::Result<()> { | ||
let monolith = self.monoliths.get(&monolith).unwrap(); | ||
monolith.send(B2MUnload { room }).await?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub async fn join_client( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in general what does the exclamation point after certain functions mean?
Couple questions for this line:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recv
is aVec<MsgB2M>
MsgB2M::Unload(B2MUnload { .. }))
is pattern matching syntax. https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html