Skip to content

Commit

Permalink
background task consumers could be more consistent (#5935)
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco authored Jun 26, 2024
1 parent ff0c914 commit d52aad0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion nexus/src/app/background/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl Driver {
///
/// If the task is currently running, it will be activated again when it
/// finishes.
pub fn activate(&self, task: &TaskHandle) {
pub(super) fn activate(&self, task: &TaskHandle) {
self.task_required(task).notify.notify_one();
}

Expand Down
16 changes: 10 additions & 6 deletions nexus/src/app/background/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ pub struct BackgroundTasks {
Option<external_endpoints::ExternalEndpoints>,
>,
/// task handle for the ipv4 nat entry garbage collector
pub nat_cleanup: TaskHandle,
pub task_nat_cleanup: TaskHandle,

/// task handle for the switch bfd manager
pub bfd_manager: TaskHandle,
pub task_bfd_manager: TaskHandle,

/// task handle for the task that collects inventory
pub task_inventory_collection: TaskHandle,
Expand Down Expand Up @@ -195,7 +195,7 @@ impl BackgroundTasks {
(task, watcher_channel)
};

let nat_cleanup = {
let task_nat_cleanup = {
driver.register(
"nat_v4_garbage_collector".to_string(),
String::from(
Expand All @@ -212,7 +212,7 @@ impl BackgroundTasks {
)
};

let bfd_manager = {
let task_bfd_manager = {
driver.register(
"bfd_manager".to_string(),
String::from(
Expand Down Expand Up @@ -479,8 +479,8 @@ impl BackgroundTasks {
task_metrics_producer_gc,
task_external_endpoints,
external_endpoints,
nat_cleanup,
bfd_manager,
task_nat_cleanup,
task_bfd_manager,
task_inventory_collection,
task_physical_disk_adoption,
task_phantom_disks,
Expand All @@ -498,6 +498,10 @@ impl BackgroundTasks {
}
}

/// Activate the specified background task
///
/// If the task is currently running, it will be activated again when it
/// finishes.
pub fn activate(&self, task: &TaskHandle) {
self.driver.activate(task);
}
Expand Down
10 changes: 2 additions & 8 deletions nexus/src/app/bfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ impl super::Nexus {
// add the bfd session to the db and trigger the bfd manager to handle
// the reset
self.datastore().bfd_session_create(opctx, &session).await?;
self.background_tasks
.driver
.activate(&self.background_tasks.bfd_manager);
self.background_tasks.activate(&self.background_tasks.task_bfd_manager);
// for timely propagation to bootstore
self.background_tasks
.driver
.activate(&self.background_tasks.task_switch_port_settings_manager);
Ok(())
}
Expand All @@ -57,12 +54,9 @@ impl super::Nexus {
// remove the bfd session from the db and trigger the bfd manager to
// handle the reset
self.datastore().bfd_session_delete(opctx, &session).await?;
self.background_tasks
.driver
.activate(&self.background_tasks.bfd_manager);
self.background_tasks.activate(&self.background_tasks.task_bfd_manager);
// for timely propagation to bootstore
self.background_tasks
.driver
.activate(&self.background_tasks.task_switch_port_settings_manager);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ impl Nexus {
"populate complete; activating background tasks"
);
for task in task_nexus.background_tasks.driver.tasks() {
task_nexus.background_tasks.driver.activate(task);
task_nexus.background_tasks.activate(task);
}
}
Err(_) => {
Expand Down
2 changes: 0 additions & 2 deletions nexus/src/app/switch_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ impl super::Nexus {

// eagerly propagate changes via rpw
self.background_tasks
.driver
.activate(&self.background_tasks.task_switch_port_settings_manager);

Ok(value)
Expand Down Expand Up @@ -86,7 +85,6 @@ impl super::Nexus {

// eagerly propagate changes via rpw
self.background_tasks
.driver
.activate(&self.background_tasks.task_switch_port_settings_manager);

Ok(())
Expand Down
3 changes: 0 additions & 3 deletions nexus/src/app/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ impl super::Nexus {

// eagerly propagate changes via rpw
self.background_tasks
.driver
.activate(&self.background_tasks.task_switch_port_settings_manager);

Ok(result)
Expand Down Expand Up @@ -214,7 +213,6 @@ impl super::Nexus {

// eagerly propagate changes via rpw
self.background_tasks
.driver
.activate(&self.background_tasks.task_switch_port_settings_manager);

Ok(())
Expand Down Expand Up @@ -248,7 +246,6 @@ impl super::Nexus {

// eagerly propagate changes via rpw
self.background_tasks
.driver
.activate(&self.background_tasks.task_switch_port_settings_manager);

Ok(())
Expand Down

0 comments on commit d52aad0

Please sign in to comment.