Skip to content

Commit

Permalink
deleted_at column instead of new_sk_set
Browse files Browse the repository at this point in the history
  • Loading branch information
arpad-m committed Jan 22, 2025
1 parent e56aa82 commit 7ec08ee
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ CREATE TABLE timelines (
PRIMARY KEY(tenant_id, timeline_id),
generation INTEGER NOT NULL,
sk_set BIGINT[] NOT NULL,
new_sk_set BIGINT[] NOT NULL,
cplane_notified_generation INTEGER NOT NULL,
status_kind VARCHAR NOT NULL,
status VARCHAR NOT NULL
status VARCHAR NOT NULL,
deleted_at timestamptz
);
CREATE INDEX timelines_idx ON timelines(status_kind, tenant_id, timeline_id);
CREATE INDEX timelines_idx ON timelines(status_kind, deleted_at, tenant_id, timeline_id);
39 changes: 36 additions & 3 deletions storage_controller/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,40 @@ impl Persistence {
)
.await
}
pub(crate) async fn update_timeline_status_deleted(
&self,
tenant_id: TenantId,
timeline_id: TimelineId,
) -> DatabaseResult<()> {
use crate::schema::timelines;

let now = chrono::offset::Utc::now();
self.with_measured_conn(
DatabaseOperation::InsertTimeline,
move |conn| -> DatabaseResult<()> {
let inserted_updated = diesel::update(timelines::table)
.filter(timelines::tenant_id.eq(tenant_id.to_string()))
.filter(timelines::timeline_id.eq(timeline_id.to_string()))
.filter(timelines::status_kind.eq(String::from(TimelineStatusKind::Deleting)))
.set((
timelines::status_kind.eq(String::from(TimelineStatusKind::Deleted)),
timelines::status.eq("{}"),
timelines::deleted_at.eq(now),
))
.execute(conn)?;

if inserted_updated != 1 {
return Err(DatabaseError::Logical(format!(
"unexpected number of rows ({})",
inserted_updated
)));
}

Ok(())
},
)
.await
}

/// Obtains the timeline, returns None if not present
pub(crate) async fn get_timeline(
Expand Down Expand Up @@ -1585,7 +1619,6 @@ pub(crate) struct TimelinePersistence {
pub(crate) timeline_id: String,
pub(crate) generation: i32,
pub(crate) sk_set: Vec<i64>,
pub(crate) new_sk_set: Vec<i64>,
pub(crate) cplane_notified_generation: i32,
pub(crate) status_kind: String,
pub(crate) status: String,
Expand All @@ -1598,10 +1631,11 @@ pub(crate) struct TimelineFromDb {
pub(crate) timeline_id: String,
pub(crate) generation: i32,
pub(crate) sk_set: Vec<Option<i64>>,
pub(crate) new_sk_set: Vec<Option<i64>>,
pub(crate) cplane_notified_generation: i32,
pub(crate) status_kind: String,
pub(crate) status: String,
#[allow(unused)]
pub(crate) deleted_at: Option<chrono::DateTime<chrono::Utc>>,
}

impl TimelineFromDb {
Expand All @@ -1611,7 +1645,6 @@ impl TimelineFromDb {
timeline_id: self.timeline_id,
generation: self.generation,
sk_set: self.sk_set.into_iter().flatten().collect(),
new_sk_set: self.new_sk_set.into_iter().flatten().collect(),
cplane_notified_generation: self.cplane_notified_generation,
status_kind: self.status_kind,
status: self.status,
Expand Down
2 changes: 1 addition & 1 deletion storage_controller/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ diesel::table! {
timeline_id -> Varchar,
generation -> Int4,
sk_set -> Array<Nullable<Int8>>,
new_sk_set -> Array<Nullable<Int8>>,
cplane_notified_generation -> Int4,
status_kind -> Varchar,
status -> Varchar,
deleted_at -> Nullable<Timestamptz>,
}
}

Expand Down
3 changes: 1 addition & 2 deletions storage_controller/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3592,7 +3592,6 @@ impl Service {
timeline_id: timeline_id.to_string(),
generation: 0,
sk_set: sks_persistence.clone(),
new_sk_set: sks_persistence.clone(),
cplane_notified_generation: 0,
status_kind: String::from(TimelineStatusKind::Creating),
status,
Expand Down Expand Up @@ -4260,7 +4259,7 @@ impl Service {

if new_status_kind == TimelineStatusKind::Deleted {
self.persistence
.update_timeline_status(tenant_id, timeline_id, new_status_kind, "{}".to_owned())
.update_timeline_status_deleted(tenant_id, timeline_id)
.await?;
}
Ok(())
Expand Down

0 comments on commit 7ec08ee

Please sign in to comment.