From 62f5d484d994be08eaedd7b6627f194b91e7b93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arpad=20M=C3=BCller?= Date: Tue, 29 Oct 2024 01:36:05 +0100 Subject: [PATCH] Assert the tenant to be active in `unoffload_timeline` (#9539) Currently, all callers of `unoffload_timeline` ensure that the tenant the unoffload operation is called on is active. We rely on it being active as we activate the timeline below and don't want to race with the activation code of the tenant (in the worst case, activating a timeline twice). Therefore, add this assertion. Part of #8088 --- pageserver/src/tenant.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pageserver/src/tenant.rs b/pageserver/src/tenant.rs index 64e871cada..7011ae9e63 100644 --- a/pageserver/src/tenant.rs +++ b/pageserver/src/tenant.rs @@ -1830,6 +1830,18 @@ impl Tenant { ctx: RequestContext, ) -> Result, TimelineArchivalError> { info!("unoffloading timeline"); + + // We activate the timeline below manually, so this must be called on an active timeline. + // We expect callers of this function to ensure this. + match self.current_state() { + TenantState::Activating { .. } + | TenantState::Attaching + | TenantState::Broken { .. } => { + panic!("Timeline expected to be active") + } + TenantState::Stopping { .. } => return Err(TimelineArchivalError::Cancelled), + TenantState::Active => {} + } let cancel = self.cancel.clone(); // Protect against concurrent attempts to use this TimelineId