diff --git a/nativelink-scheduler/src/scheduler_state/awaited_action.rs b/nativelink-scheduler/src/scheduler_state/awaited_action.rs index 111cfafb3..d1de8fb00 100644 --- a/nativelink-scheduler/src/scheduler_state/awaited_action.rs +++ b/nativelink-scheduler/src/scheduler_state/awaited_action.rs @@ -145,7 +145,7 @@ impl AwaitedAction { .store(SystemTime::now().unix_timestamp(), Ordering::Release); } - /// Sets the priority of the action. + /// Upgrades the priority of the action if new priority is higher. /// /// If the priority was already set to `new_priority`, this function will /// return `None`. If the priority was different, it will return a @@ -153,9 +153,9 @@ impl AwaitedAction { /// will hold a lock preventing anyone else from reading or modifying the /// sort key until the result is dropped. #[must_use] - pub fn set_priority(&self, new_priority: i32) -> Option { + pub fn upgrade_priority(&self, new_priority: i32) -> Option { let sort_info_lock = self.sort_info.upgradable_read(); - if sort_info_lock.priority == new_priority { + if sort_info_lock.priority >= new_priority { return None; } let mut sort_info_lock = RwLockUpgradableReadGuard::upgrade(sort_info_lock); diff --git a/nativelink-scheduler/src/scheduler_state/state_manager.rs b/nativelink-scheduler/src/scheduler_state/state_manager.rs index c30fa9575..6f4a99985 100644 --- a/nativelink-scheduler/src/scheduler_state/state_manager.rs +++ b/nativelink-scheduler/src/scheduler_state/state_manager.rs @@ -287,7 +287,7 @@ impl AwaitedActionDb { )); } let awaited_action = awaited_action.clone(); - if let Some(sort_info_lock) = awaited_action.set_priority(priority) { + if let Some(sort_info_lock) = awaited_action.upgrade_priority(priority) { let state = awaited_action.get_current_state(); let maybe_sorted_awaited_action = self.get_sort_map_for_state(&state.stage)