File tree 3 files changed +9
-5
lines changed
3 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -386,9 +386,9 @@ impl BalancerContext {
386
386
self . monoliths . values ( ) . collect ( )
387
387
}
388
388
389
- pub fn select_monolith ( & self ) -> anyhow:: Result < & BalancerMonolith > {
389
+ pub fn select_monolith ( & self , room : & RoomName ) -> anyhow:: Result < & BalancerMonolith > {
390
390
let filtered = self . filter_monoliths ( ) ;
391
- return self . monolith_selection . select_monolith ( filtered) ;
391
+ return self . monolith_selection . select_monolith ( room , filtered) ;
392
392
}
393
393
394
394
pub fn random_monolith ( & self ) -> anyhow:: Result < & BalancerMonolith > {
@@ -453,7 +453,7 @@ pub async fn join_client(
453
453
}
454
454
None => {
455
455
// the room is not loaded, randomly select a monolith
456
- let selected = ctx_write. select_monolith ( ) ?;
456
+ let selected = ctx_write. select_monolith ( & new_client . room ) ?;
457
457
debug ! (
458
458
"room is not loaded, selected monolith: {:?} (region: {:?})" ,
459
459
selected. id( ) ,
Original file line number Diff line number Diff line change 1
1
use crate :: monolith:: BalancerMonolith ;
2
2
use enum_dispatch:: enum_dispatch;
3
+ use ott_balancer_protocol:: RoomName ;
3
4
use rand:: seq:: IteratorRandom ;
4
5
use serde:: Deserialize ;
5
6
6
7
#[ enum_dispatch( MonolithSelectionStrategy ) ]
7
8
pub trait MonolithSelection : std:: fmt:: Debug {
8
9
fn select_monolith < ' a > (
9
10
& ' a self ,
11
+ room : & RoomName ,
10
12
monoliths : Vec < & ' a BalancerMonolith > ,
11
13
) -> anyhow:: Result < & BalancerMonolith > ;
12
14
@@ -40,6 +42,7 @@ pub struct MinRoomsSelector;
40
42
impl MonolithSelection for MinRoomsSelector {
41
43
fn select_monolith < ' a > (
42
44
& ' a self ,
45
+ _room : & RoomName ,
43
46
monoliths : Vec < & ' a BalancerMonolith > ,
44
47
) -> anyhow:: Result < & BalancerMonolith > {
45
48
fn cmp ( x : & BalancerMonolith , y : & BalancerMonolith ) -> std:: cmp:: Ordering {
@@ -121,8 +124,9 @@ mod test {
121
124
122
125
let monoliths: Vec < & BalancerMonolith > = vec ! [ & monolith_one, & monolith_two] ;
123
126
127
+ let room: RoomName = "foo" . into ( ) ;
124
128
let selected = MinRoomsSelector
125
- . select_monolith ( monoliths)
129
+ . select_monolith ( & room , monoliths)
126
130
. expect ( "failed to select monolith" ) ;
127
131
128
132
assert_eq ! ( selected. id( ) , monolith_two. id( ) )
Original file line number Diff line number Diff line change @@ -242,7 +242,7 @@ impl Service<Request<IncomingBody>> for BalancerService {
242
242
) ;
243
243
ctx_read. monoliths . get ( & locator. monolith_id ( ) )
244
244
} else {
245
- ctx_read. select_monolith ( ) . ok ( )
245
+ ctx_read. select_monolith ( & room_name ) . ok ( )
246
246
} ;
247
247
if let Some ( monolith) = monolith {
248
248
info ! ( "proxying request to monolith {}" , monolith. id( ) ) ;
You can’t perform that action at this time.
0 commit comments