Skip to content

Commit

Permalink
task_mgr: baggage idea
Browse files Browse the repository at this point in the history
  • Loading branch information
problame committed Mar 26, 2024
1 parent d81e85e commit 55cb2ea
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions pageserver/src/task_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,46 @@ struct PageServerTask {
timeline_id: Option<TimelineId>,

mutable: Mutex<MutableTaskState>,

baggage: Option<Box<dyn Any>>,
}

/// Launch a new task
/// Launch a new task.
///
/// Note: if shutdown_process_on_error is set to true failure
/// of the task will lead to shutdown of entire process
pub fn spawn<F>(
#[inline(always)]
pub fn spawn(
kind: TaskKind,
tenant_shard_id: Option<TenantShardId>,
timeline_id: Option<TimelineId>,
name: &str,
shutdown_process_on_error: bool,
baggage: Box<dyn Any>,
future: F,
) -> PageserverTaskId
where
F: Future<Output = anyhow::Result<()>> + Send + 'static,
{
spawnw_with_baggage(
kind,
tenant_shard_id,
timeline_id,
name,
shutdown_process_on_error,
None,
future,
)
}

/// Like [`spawn`], but additionally the task structure carries a piece of "baggage".
pub fn spawnw_with_baggage<F>(
kind: TaskKind,
tenant_shard_id: Option<TenantShardId>,
timeline_id: Option<TimelineId>,
name: &str,
shutdown_process_on_error: bool,
baggage: Option<Box<dyn Any>>,
future: F,
) -> PageserverTaskId
where
Expand All @@ -325,6 +354,7 @@ where
tenant_shard_id,
timeline_id,
mutable: Mutex::new(MutableTaskState { join_handle: None }),
baggage,
});

TASKS.lock().unwrap().insert(task_id, Arc::clone(&task));
Expand Down

0 comments on commit 55cb2ea

Please sign in to comment.