Skip to content

Commit

Permalink
storcon: transform 404 to 503 on proxied GETs
Browse files Browse the repository at this point in the history
  • Loading branch information
jcsp committed Sep 19, 2024
1 parent 197a4aa commit 4323bdc
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions storage_controller/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@ async fn handle_tenant_timeline_passthrough(
let _timer = latency.start_timer(labels.clone());

let client = mgmt_api::Client::new(node.base_url(), service.get_config().jwt_token.as_deref());
let resp = client.get_raw(path).await.map_err(|_e|
// FIXME: give APiError a proper Unavailable variant. We return 503 here because
// if we can't successfully send a request to the pageserver, we aren't available.
ApiError::ShuttingDown)?;
let resp = client.get_raw(path).await.map_err(|e|
// We return 503 here because if we can't successfully send a request to the pageserver,
// either we aren't available or the pageserver is unavailable.
ApiError::ResourceUnavailable(format!("Error sending pageserver API request to {}: {e}", node).into()))?;

if !resp.status().is_success() {
let error_counter = &METRICS_REGISTRY
Expand All @@ -443,6 +443,19 @@ async fn handle_tenant_timeline_passthrough(
error_counter.inc(labels);
}

// Transform 404 into 503 if we raced with a migration
if resp.status() == reqwest::StatusCode::NOT_FOUND {
// Look up node again: if we migrated it will be different
let (new_node, _tenant_shard_id) = service.tenant_shard0_node(tenant_id).await?;
if new_node.get_id() != node.get_id() {
// Rather than retry here, send the client a 503 to prompt a retry: this matches
// the pageserver's use of 503, and all clients calling this API should retry on 503.
return Err(ApiError::ResourceUnavailable(
format!("Pageserver {node} returned 404, was migrated to {new_node}").into(),
));
}
}

// We have a reqest::Response, would like a http::Response
let mut builder = hyper::Response::builder().status(map_reqwest_hyper_status(resp.status())?);
for (k, v) in resp.headers() {
Expand Down

0 comments on commit 4323bdc

Please sign in to comment.