Skip to content

Commit

Permalink
fix(listener): fixed core acquire (#2247)
Browse files Browse the repository at this point in the history
  • Loading branch information
gurinderu authored May 16, 2024
1 parent 10079c1 commit 7f96659
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions crates/chain-listener/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,10 @@ impl ChainListener {
units.extend(&cu_groups.pending_units);
units.extend(&cu_groups.finished_units);

// Release all ccp units to allow the core manager to assign them again
// without that action availability count will be wrong
self.core_manager.release(&units);

let cores = self.core_manager.acquire_worker_core(AcquireRequest::new(
units.to_vec(),
WorkType::CapacityCommitment,
Expand Down Expand Up @@ -986,10 +990,8 @@ impl ChainListener {
available,
..
}) => {
tracing::warn!("Found {required} CUs in the Capacity Commitment, but Nox has only {available} Cores available for CC");
tracing::warn!(target: "chain-listener", "Found {required} CUs in the Capacity Commitment, but Nox has only {available} Cores available for CC");
let assign_units = units.iter().take(available).cloned().collect();
// Release all units to allow the core manager to assign them again
self.core_manager.release(units);
let assignment = self.core_manager.acquire_worker_core(AcquireRequest::new(
assign_units,
WorkType::CapacityCommitment,
Expand Down
6 changes: 3 additions & 3 deletions crates/core-manager/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,13 @@ impl CoreManagerFunctions for DevCoreManager {
})
}

fn release(&self, unit_ids: Vec<CUID>) {
fn release(&self, unit_ids: &[CUID]) {
let mut lock = self.state.write();
for unit_id in unit_ids {
if let Some(physical_core_id) = lock.unit_id_core_mapping.remove(&unit_id) {
let mapping = lock.core_unit_id_mapping.get_vec_mut(&physical_core_id);
if let Some(mapping) = mapping {
let index = mapping.iter().position(|x| *x == unit_id).unwrap();
let index = mapping.iter().position(|x| x == unit_id).unwrap();
mapping.remove(index);
if mapping.is_empty() {
lock.core_unit_id_mapping.remove(&physical_core_id);
Expand Down Expand Up @@ -462,7 +462,7 @@ mod tests {
assert_eq!(after_assignment_unit_id_mapping.len(), 2);
assert_eq!(after_assignment_type_mapping.len(), 2);

manager.release(unit_ids);
manager.release(&unit_ids);

let after_release_lock = manager.state.read();

Expand Down
2 changes: 1 addition & 1 deletion crates/core-manager/src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl CoreManagerFunctions for DummyCoreManager {
})
}

fn release(&self, _unit_ids: Vec<CUID>) {}
fn release(&self, _unit_ids: &[CUID]) {}

fn get_system_cpu_assignment(&self) -> Assignment {
self.all_cores()
Expand Down
2 changes: 1 addition & 1 deletion crates/core-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub trait CoreManagerFunctions {
assign_request: AcquireRequest,
) -> Result<Assignment, AcquireError>;

fn release(&self, unit_ids: Vec<CUID>);
fn release(&self, unit_ids: &[CUID]);

fn get_system_cpu_assignment(&self) -> Assignment;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/core-manager/src/strict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl CoreManagerFunctions for StrictCoreManager {
})
}

fn release(&self, unit_ids: Vec<CUID>) {
fn release(&self, unit_ids: &[CUID]) {
let mut lock = self.state.write();
for unit_id in unit_ids {
if let Some((physical_core_id, _)) = lock.unit_id_mapping.remove_by_right(&unit_id) {
Expand Down Expand Up @@ -468,7 +468,7 @@ mod tests {
assert_eq!(after_assignment_unit_id_mapping.len(), 2);
assert_eq!(after_assignment_type_mapping.len(), 2);