mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-28 18:40:38 +00:00
Init Timeline in Stopping state in create_timeline_struct when Cause::Delete (#4780)
See https://github.com/neondatabase/neon/pull/4552#discussion_r1258368127 for context. TLDR: use CreateTimelineCause to infer desired state instead of using .set_stopping after initialization
This commit is contained in:
@@ -2012,19 +2012,24 @@ impl Tenant {
|
||||
init_order: Option<&InitializationOrder>,
|
||||
cause: CreateTimelineCause,
|
||||
) -> anyhow::Result<Arc<Timeline>> {
|
||||
if matches!(cause, CreateTimelineCause::Load) {
|
||||
let ancestor_id = new_metadata.ancestor_timeline();
|
||||
anyhow::ensure!(
|
||||
ancestor_id == ancestor.as_ref().map(|t| t.timeline_id),
|
||||
"Timeline's {new_timeline_id} ancestor {ancestor_id:?} was not found"
|
||||
);
|
||||
}
|
||||
let state = match cause {
|
||||
CreateTimelineCause::Load => {
|
||||
let ancestor_id = new_metadata.ancestor_timeline();
|
||||
anyhow::ensure!(
|
||||
ancestor_id == ancestor.as_ref().map(|t| t.timeline_id),
|
||||
"Timeline's {new_timeline_id} ancestor {ancestor_id:?} was not found"
|
||||
);
|
||||
TimelineState::Loading
|
||||
}
|
||||
CreateTimelineCause::Delete => TimelineState::Stopping,
|
||||
};
|
||||
|
||||
let initial_logical_size_can_start = init_order.map(|x| &x.initial_logical_size_can_start);
|
||||
let initial_logical_size_attempt = init_order.map(|x| &x.initial_logical_size_attempt);
|
||||
|
||||
let pg_version = new_metadata.pg_version();
|
||||
Ok(Timeline::new(
|
||||
|
||||
let timeline = Timeline::new(
|
||||
self.conf,
|
||||
Arc::clone(&self.tenant_conf),
|
||||
new_metadata,
|
||||
@@ -2036,7 +2041,10 @@ impl Tenant {
|
||||
pg_version,
|
||||
initial_logical_size_can_start.cloned(),
|
||||
initial_logical_size_attempt.cloned(),
|
||||
))
|
||||
state,
|
||||
);
|
||||
|
||||
Ok(timeline)
|
||||
}
|
||||
|
||||
fn new(
|
||||
|
||||
@@ -403,6 +403,8 @@ impl DeleteTimelineFlow {
|
||||
remote_client: Option<RemoteTimelineClient>,
|
||||
init_order: Option<&InitializationOrder>,
|
||||
) -> anyhow::Result<()> {
|
||||
// Note: here we even skip populating layer map. Timeline is essentially uninitialized.
|
||||
// RemoteTimelineClient is the only functioning part.
|
||||
let timeline = tenant
|
||||
.create_timeline_struct(
|
||||
timeline_id,
|
||||
@@ -422,9 +424,6 @@ impl DeleteTimelineFlow {
|
||||
.expect("cannot happen because we're the only owner"),
|
||||
);
|
||||
|
||||
// Note: here we even skip populating layer map. Timeline is essentially uninitialized.
|
||||
// RemoteTimelineClient is the only functioning part.
|
||||
timeline.set_state(TimelineState::Stopping);
|
||||
// We meed to do this because when console retries delete request we shouldnt answer with 404
|
||||
// because 404 means successful deletion.
|
||||
{
|
||||
|
||||
@@ -1360,9 +1360,10 @@ impl Timeline {
|
||||
pg_version: u32,
|
||||
initial_logical_size_can_start: Option<completion::Barrier>,
|
||||
initial_logical_size_attempt: Option<completion::Completion>,
|
||||
state: TimelineState,
|
||||
) -> Arc<Self> {
|
||||
let disk_consistent_lsn = metadata.disk_consistent_lsn();
|
||||
let (state, _) = watch::channel(TimelineState::Loading);
|
||||
let (state, _) = watch::channel(state);
|
||||
|
||||
let (layer_flush_start_tx, _) = tokio::sync::watch::channel(0);
|
||||
let (layer_flush_done_tx, _) = tokio::sync::watch::channel((0, Ok(())));
|
||||
|
||||
Reference in New Issue
Block a user