mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-16 18:02:56 +00:00
deleted_at column instead of new_sk_set
This commit is contained in:
@@ -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);
|
||||
@@ -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(
|
||||
@@ -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,
|
||||
@@ -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 {
|
||||
@@ -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,
|
||||
|
||||
@@ -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>,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user