diff --git a/storage_controller/src/persistence.rs b/storage_controller/src/persistence.rs index bb12583cea844..dfca756aef2e1 100644 --- a/storage_controller/src/persistence.rs +++ b/storage_controller/src/persistence.rs @@ -1292,6 +1292,33 @@ impl Persistence { Ok(Some(tl)) } + /// Marks all timelines referencing a tenant for deletion + pub(crate) async fn mark_timelines_for_deletion( + &self, + del_tenant_id: TenantId, + ) -> DatabaseResult<()> { + use crate::schema::timelines::dsl::*; + let count = self + .with_measured_conn( + DatabaseOperation::DeleteTenant, + move |conn| -> DatabaseResult { + Ok(diesel::update(timelines) + .filter(tenant_id.eq(del_tenant_id.to_string())) + .filter(status_kind.ne(String::from(TimelineStatusKind::Deleted))) + .set(( + status.eq(String::from("")), + status_kind.eq(String::from(TimelineStatusKind::Deleted)), + )) + .execute(conn)?) + }, + ) + .await?; + + tracing::info!("marked {count} timelines for deletion in timelines table"); + + Ok(()) + } + pub(crate) async fn timelines_to_be_reconciled( &self, ) -> DatabaseResult> { diff --git a/storage_controller/src/service.rs b/storage_controller/src/service.rs index 8af3fc58af75b..9bc9f1ef81bdb 100644 --- a/storage_controller/src/service.rs +++ b/storage_controller/src/service.rs @@ -3104,6 +3104,8 @@ impl Service { self.maybe_load_tenant(tenant_id, &_tenant_lock).await?; + self.persistence.mark_timelines_for_deletion(tenant_id).await?; + // Detach all shards. This also deletes local pageserver shard data. let (detach_waiters, node) = { let mut detach_waiters = Vec::new();