From 000330054b49ebb0df77cd55a69754d734b19d35 Mon Sep 17 00:00:00 2001 From: John Spray Date: Fri, 25 Aug 2023 16:26:10 +0100 Subject: [PATCH] pageserver: require attachment generation if control plane API is set --- pageserver/src/http/routes.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pageserver/src/http/routes.rs b/pageserver/src/http/routes.rs index e8181fef27..babf047b0a 100644 --- a/pageserver/src/http/routes.rs +++ b/pageserver/src/http/routes.rs @@ -479,20 +479,27 @@ async fn tenant_attach_handler( None => TenantConfOpt::default(), }; - // TODO: make generation mandatory here once control plane supports it - let generation = maybe_body - .as_ref() - .map(|tar| tar.generation) - .flatten() - .map(|g| Generation::new(g)) - .unwrap_or(Generation::none()); - let ctx = RequestContext::new(TaskKind::MgmtRequest, DownloadBehavior::Warn); info!("Handling tenant attach {tenant_id}"); let state = get_state(&request); + let generation = if state.conf.control_plane_api.is_some() { + // If we have been configured with a control plane URI, then generations are + // mandatory, as we will attempt to re-attach on startup. + maybe_body + .as_ref() + .map(|tar| tar.generation) + .flatten() + .map(|g| Generation::new(g)) + .ok_or(ApiError::BadRequest(anyhow!( + "generation attribute missing" + )))? + } else { + Generation::placeholder() + }; + if let Some(remote_storage) = &state.remote_storage { mgr::attach_tenant( state.conf,