From 7b4251e9b5251c79c8d14510947d09a073a7d7e4 Mon Sep 17 00:00:00 2001 From: Alex Chi Z Date: Fri, 21 Jul 2023 16:18:00 -0400 Subject: [PATCH] use Tenant::shutdown Signed-off-by: Alex Chi Z --- pageserver/src/tenant/mgr.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pageserver/src/tenant/mgr.rs b/pageserver/src/tenant/mgr.rs index 280bcaeb4a..1993627b00 100644 --- a/pageserver/src/tenant/mgr.rs +++ b/pageserver/src/tenant/mgr.rs @@ -16,7 +16,7 @@ use tokio::task::JoinSet; use tracing::*; use remote_storage::GenericRemoteStorage; -use utils::crashsafe; +use utils::{completion, crashsafe}; use crate::config::PageServerConf; use crate::context::{DownloadBehavior, RequestContext}; @@ -385,9 +385,12 @@ pub async fn create_tenant( }; if let Err(e) = check() { - // schedule_local_tenant_processing eventually launches the tenant's background task - // We need to shut them down before bailing out. - created_tenant.set_broken("failed to create".into()).await; + // `schedule_local_tenant_processing` eventually launches the tenant's background task + // We need to shut them down before bailing out. Shutdown the tenant in the background. + tokio::spawn(async move { + let (_guard, shutdown_progress) = completion::channel(); + created_tenant.shutdown(shutdown_progress, false).await + }); return Err(e); } @@ -648,9 +651,12 @@ pub async fn attach_tenant( }; if let Err(e) = check() { - // schedule_local_tenant_processing eventually launches the tenant's background task - // We need to shut them down before bailing out. - attached_tenant.set_broken("failed to create".into()).await; + // `schedule_local_tenant_processing` eventually launches the tenant's background task + // We need to shut them down before bailing out. Shutdown the tenant in the background. + tokio::spawn(async move { + let (_guard, shutdown_progress) = completion::channel(); + attached_tenant.shutdown(shutdown_progress, false).await + }); return Err(e); }