mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-15 17:32:56 +00:00
Optional get_timeline result
This commit is contained in:
@@ -1258,11 +1258,12 @@ impl Persistence {
|
||||
.await
|
||||
}
|
||||
|
||||
/// Obtains the timeline, returns None if not present
|
||||
pub(crate) async fn get_timeline(
|
||||
&self,
|
||||
tenant_id: TenantId,
|
||||
timeline_id: TimelineId,
|
||||
) -> DatabaseResult<TimelinePersistence> {
|
||||
) -> DatabaseResult<Option<TimelinePersistence>> {
|
||||
use crate::schema::timelines;
|
||||
let mut timelines: Vec<TimelineFromDb> = self
|
||||
.with_measured_conn(
|
||||
@@ -1275,7 +1276,9 @@ impl Persistence {
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
if timelines.len() != 1 {
|
||||
if timelines.len() == 0 {
|
||||
return Ok(None);
|
||||
} else if timelines.len() > 1 {
|
||||
return Err(DatabaseError::Logical(format!(
|
||||
"incorrect number of returned timelines: ({})",
|
||||
timelines.len()
|
||||
@@ -1286,7 +1289,7 @@ impl Persistence {
|
||||
|
||||
tracing::info!("get_timeline: loaded timeline");
|
||||
|
||||
Ok(tl)
|
||||
Ok(Some(tl))
|
||||
}
|
||||
|
||||
pub(crate) async fn timelines_to_be_reconciled(
|
||||
|
||||
@@ -4270,6 +4270,10 @@ impl Service {
|
||||
.persistence
|
||||
.get_timeline(tenant_id, timeline_id)
|
||||
.await?;
|
||||
let Some(tl) = tl else {
|
||||
tracing::info!("timeline {tenant_id}/{timeline_id} doesn't exist in timelines table, no deletions on safekeepers needed");
|
||||
return Ok(());
|
||||
};
|
||||
let status_kind =
|
||||
TimelineStatusKind::from_str(&tl.status_kind).map_err(ApiError::InternalServerError)?;
|
||||
if status_kind != TimelineStatusKind::Deleting {
|
||||
|
||||
@@ -76,11 +76,7 @@ impl SafekeeperReconciler {
|
||||
tl: &TimelinePersistence,
|
||||
sk_persistences: &HashMap<i64, SafekeeperPersistence>,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
tracing::info!(
|
||||
"Reconciling timeline on safekeepers {}/{}",
|
||||
tl.tenant_id,
|
||||
tl.timeline_id,
|
||||
);
|
||||
tracing::info!("Reconciling timeline on safekeepers");
|
||||
let tenant_id = TenantId::from_slice(tl.tenant_id.as_bytes())?;
|
||||
let timeline_id = TimelineId::from_slice(tl.timeline_id.as_bytes())?;
|
||||
|
||||
@@ -98,6 +94,11 @@ impl SafekeeperReconciler {
|
||||
.persistence
|
||||
.get_timeline(tenant_id, timeline_id)
|
||||
.await?;
|
||||
let Some(tl) = tl else {
|
||||
// This can happen but is a bit unlikely, so print it on the warn level instead of info
|
||||
tracing::warn!("timeline row in database disappeared");
|
||||
return Ok(());
|
||||
};
|
||||
let status = TimelineStatusKind::from_str(&tl.status)?;
|
||||
match status {
|
||||
TimelineStatusKind::Created | TimelineStatusKind::Deleted => (),
|
||||
|
||||
Reference in New Issue
Block a user