Skip to content

Commit

Permalink
Change to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
arpad-m committed Jan 9, 2025
1 parent e2d432c commit 15ce3c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
18 changes: 10 additions & 8 deletions pageserver/src/tenant/timeline/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,10 @@ impl DeleteTimelineFlow {
) -> Result<(), DeleteTimelineError> {
super::debug_assert_current_span_has_tenant_and_timeline_id();

let allow_offloaded_children = false;
let set_stopping = true;
let (timeline, mut guard) = make_timeline_delete_guard(
tenant,
timeline_id,
allow_offloaded_children,
set_stopping,
TimelineDeleteGuardKind::Delete,
)?;

guard.mark_in_progress()?;
Expand Down Expand Up @@ -417,11 +414,16 @@ impl DeleteTimelineFlow {
}
}

#[derive(Copy, Clone, PartialEq, Eq)]
pub(super) enum TimelineDeleteGuardKind {
Offload,
Delete,
}

pub(super) fn make_timeline_delete_guard(
tenant: &Tenant,
timeline_id: TimelineId,
allow_offloaded_children: bool,
set_stopping: bool,
guard_kind: TimelineDeleteGuardKind,
) -> Result<(TimelineOrOffloaded, DeletionGuard), DeleteTimelineError> {
// Note the interaction between this guard and deletion guard.
// Here we attempt to lock deletion guard when we're holding a lock on timelines.
Expand All @@ -447,7 +449,7 @@ pub(super) fn make_timeline_delete_guard(
// Ensure that there are no child timelines, because we are about to remove files,
// which will break child branches
let mut children = Vec::new();
if !allow_offloaded_children {
if guard_kind == TimelineDeleteGuardKind::Delete {
children.extend(timelines_offloaded.iter().filter_map(|(id, entry)| {
(entry.ancestor_timeline_id == Some(timeline_id)).then_some(*id)
}));
Expand Down Expand Up @@ -477,7 +479,7 @@ pub(super) fn make_timeline_delete_guard(
}
};

if set_stopping {
if guard_kind == TimelineDeleteGuardKind::Delete {
if let TimelineOrOffloaded::Timeline(timeline) = &timeline {
timeline.set_state(TimelineState::Stopping);
}
Expand Down
7 changes: 2 additions & 5 deletions pageserver/src/tenant/timeline/offload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::delete::{delete_local_timeline_directory, DeletionGuard};
use super::Timeline;
use crate::span::debug_assert_current_span_has_tenant_and_timeline_id;
use crate::tenant::remote_timeline_client::ShutdownIfArchivedError;
use crate::tenant::timeline::delete::make_timeline_delete_guard;
use crate::tenant::timeline::delete::{make_timeline_delete_guard, TimelineDeleteGuardKind};
use crate::tenant::{OffloadedTimeline, Tenant, TenantManifestError, TimelineOrOffloaded};

#[derive(thiserror::Error, Debug)]
Expand Down Expand Up @@ -37,13 +37,10 @@ pub(crate) async fn offload_timeline(
debug_assert_current_span_has_tenant_and_timeline_id();
tracing::info!("offloading archived timeline");

let allow_offloaded_children = true;
let set_stopping = false;
let (timeline, guard) = make_timeline_delete_guard(
tenant,
timeline.timeline_id,
allow_offloaded_children,
set_stopping,
TimelineDeleteGuardKind::Offload,
)
.map_err(|e| OffloadError::Other(anyhow::anyhow!(e)))?;

Expand Down

0 comments on commit 15ce3c7

Please sign in to comment.