From 38886a67d45785fe8b0e5d73d2b3803da5120883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 22 Nov 2023 14:34:03 +0100 Subject: [PATCH] Only print warning about unknown allocation if a worker connects It isn't helpful to repeat it when it disconnects. --- .../src/server/autoalloc/process.rs | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/crates/hyperqueue/src/server/autoalloc/process.rs b/crates/hyperqueue/src/server/autoalloc/process.rs index a288eda01..aac009afd 100644 --- a/crates/hyperqueue/src/server/autoalloc/process.rs +++ b/crates/hyperqueue/src/server/autoalloc/process.rs @@ -406,19 +406,16 @@ async fn process_queue( fn get_data_from_worker<'a>( state: &'a mut AutoAllocState, - id: WorkerId, manager_info: &ManagerInfo, ) -> Option<(&'a mut AllocationQueue, QueueId, AllocationId)> { let allocation_id = &manager_info.allocation_id; - match state.get_queue_id_by_allocation(allocation_id) { - Some(queue_id) => state - .get_queue_mut(queue_id) - .map(|queue| (queue, queue_id, allocation_id.clone())), - None => { - log::warn!("Worker {id} belongs to an unknown allocation {allocation_id}"); - None - } - } + state + .get_queue_id_by_allocation(allocation_id) + .and_then(|queue_id| { + state + .get_queue_mut(queue_id) + .map(|queue| (queue, queue_id, allocation_id.clone())) + }) } /// Synchronize the state of allocations with the external job manager. @@ -494,8 +491,16 @@ fn on_worker_connected( worker_id: WorkerId, manager_info: &ManagerInfo, ) { - let (queue, queue_id, allocation_id) = - get_or_return!(get_data_from_worker(state, worker_id, manager_info)); + let (queue, queue_id, allocation_id) = match get_data_from_worker(state, manager_info) { + Some(ret) => ret, + None => { + log::warn!( + "Worker {worker_id} belongs to an unknown allocation {}", + manager_info.allocation_id + ); + return; + } + }; log::debug!("Worker {worker_id} connected to allocation {allocation_id}"); let allocation = get_or_return!(queue.get_allocation_mut(&allocation_id));