pageserver: require attachment generation if control plane API is set

This commit is contained in:
John Spray
2023-08-25 16:26:10 +01:00
parent ddb6453f56
commit 000330054b

View File

@@ -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,