Skip to content

Commit 2038690

Browse files
committed
balancer: fix how double room loads are handled
1 parent 2f3f5da commit 2038690

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

crates/ott-balancer/src/balancer.rs

+25-5
Original file line numberDiff line numberDiff line change
@@ -303,25 +303,45 @@ impl BalancerContext {
303303
debug!(func = "add_or_sync_room");
304304
if let Some(locator) = self.rooms_to_monoliths.get(&metadata.name) {
305305
if locator.monolith_id() != monolith_id {
306+
warn!(
307+
monolith_id = %locator.monolith_id(),
308+
monolith_id_new = %monolith_id,
309+
room = %metadata.name,
310+
load_epoch = %locator.load_epoch(),
311+
load_epoch_new = %load_epoch,
312+
"room already loaded on a different monolith"
313+
);
306314
// this room is loaded on a different monolith than we were expecting
307315
match locator.load_epoch().cmp(&load_epoch) {
308316
std::cmp::Ordering::Less => {
309317
// we already have an older version of this room
318+
warn!(room = %metadata.name, "unloading room on new monolith because an older version is already loaded");
310319
self.unload_room(monolith_id, metadata.name.clone()).await?;
311320
return Err(anyhow::anyhow!("room already loaded"));
312321
}
313322
std::cmp::Ordering::Greater => {
314323
// we have an newer version of this room, remove it
315-
self.unload_room(locator.monolith_id(), metadata.name.clone())
324+
warn!(room = %metadata.name, "unloading room on old monolith because it's the newer version");
325+
if let Err(err) = self
326+
.unload_room(locator.monolith_id(), metadata.name.clone())
327+
.await
328+
{
329+
warn!(room = %metadata.name, "failed to unload room on old monolith: {:?}", err);
330+
}
331+
self.remove_room(&metadata.name, locator.monolith_id())
316332
.await?;
317-
// self.remove_room(&metadata.name, locator.monolith_id())
318-
// .await?;
319333
}
320-
_ => {}
334+
std::cmp::Ordering::Equal => {
335+
// this is really bad, and should never happen
336+
error!(room = %metadata.name, "room already loaded on the same version, but different monolith");
337+
return Err(anyhow::anyhow!("room already loaded"));
338+
}
321339
}
322340
}
323341
}
324-
let monolith = self.monoliths.get_mut(&monolith_id).unwrap();
342+
let Some(monolith) = self.monoliths.get_mut(&monolith_id) else {
343+
anyhow::bail!("monolith not found");
344+
};
325345

326346
self.rooms_to_monoliths.insert(
327347
metadata.name.clone(),

0 commit comments

Comments
 (0)