Skip to content

Commit

Permalink
Mark timelines for deletion during tenant deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
arpad-m committed Jan 21, 2025
1 parent f467ed0 commit 46ddaaa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions storage_controller/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize> {
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<Vec<TimelinePersistence>> {
Expand Down
2 changes: 2 additions & 0 deletions storage_controller/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 46ddaaa

Please sign in to comment.