fixup control_plane attach hook

This commit is contained in:
John Spray
2023-08-29 14:37:06 +01:00
parent 79f9f7c5f8
commit cd6367b5ae
4 changed files with 7 additions and 43 deletions

2
Cargo.lock generated
View File

@@ -1001,7 +1001,6 @@ dependencies = [
"comfy-table",
"compute_api",
"git-version",
"hex",
"hyper",
"nix 0.26.2",
"once_cell",
@@ -2687,6 +2686,7 @@ dependencies = [
"bytes",
"const_format",
"enum-map",
"hex",
"postgres_ffi",
"serde",
"serde_json",

View File

@@ -10,7 +10,6 @@ clap.workspace = true
comfy-table.workspace = true
git-version.workspace = true
nix.workspace = true
hex.workspace = true
once_cell.workspace = true
postgres.workspace = true
hyper.workspace = true

View File

@@ -1,5 +1,6 @@
use crate::{background_process, local_env::LocalEnv};
use anyhow::anyhow;
use pageserver_api::control_api::HexTenantId;
use serde::{Deserialize, Serialize};
use std::{path::PathBuf, process::Child};
use utils::id::{NodeId, TenantId};
@@ -14,7 +15,7 @@ const COMMAND: &str = "attachment_service";
#[derive(Serialize, Deserialize)]
pub struct AttachHookRequest {
pub tenant_id: TenantId,
pub tenant_id: HexTenantId,
pub pageserver_id: Option<NodeId>,
}
@@ -88,7 +89,7 @@ impl AttachmentService {
.expect("Failed to construct http client");
let request = AttachHookRequest {
tenant_id,
tenant_id: HexTenantId::new(tenant_id),
pageserver_id: Some(pageserver_id),
};

View File

@@ -6,7 +6,6 @@
///
use anyhow::anyhow;
use clap::Parser;
use hex::FromHex;
use hyper::StatusCode;
use hyper::{Body, Request, Response};
use pageserver_api::control_api::*;
@@ -76,41 +75,6 @@ where
Ok(hex_map.into_iter().map(|(k, v)| (k.take(), v)).collect())
}
#[derive(Eq, PartialEq, Clone, Hash)]
struct HexTenantId(TenantId);
impl HexTenantId {
fn new(t: TenantId) -> Self {
Self(t)
}
fn take(self) -> TenantId {
self.0
}
}
impl Serialize for HexTenantId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let hex = self.0.hex_encode();
serializer.collect_str(&hex)
}
}
impl<'de> Deserialize<'de> for HexTenantId {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let string = String::deserialize(deserializer)?;
TenantId::from_hex(string)
.map(|t| HexTenantId::new(t))
.map_err(|e| serde::de::Error::custom(format!("{e}")))
}
}
// Top level state available to all HTTP handlers
#[derive(Serialize, Deserialize)]
struct PersistentState {
@@ -189,7 +153,7 @@ async fn handle_re_attach(mut req: Request<Body>) -> Result<Response<Body>, ApiE
if state.pageserver == Some(reattach_req.node_id) {
state.generation += 1;
response.tenants.push(ReAttachResponseTenant {
id: t.clone(),
id: HexTenantId::new(t.clone()),
generation: state.generation,
});
}
@@ -216,7 +180,7 @@ async fn handle_validate(mut req: Request<Body>) -> Result<Response<Body>, ApiEr
};
for req_tenant in validate_req.tenants {
if let Some(tenant_state) = locked.tenants.get(&req_tenant.id) {
if let Some(tenant_state) = locked.tenants.get(req_tenant.id.as_ref()) {
let valid = tenant_state.generation == req_tenant.gen;
response.tenants.push(ValidateResponseTenant {
id: req_tenant.id,
@@ -238,7 +202,7 @@ async fn handle_attach_hook(mut req: Request<Body>) -> Result<Response<Body>, Ap
let tenant_state = locked
.tenants
.entry(attach_req.tenant_id)
.entry(attach_req.tenant_id.take())
.or_insert_with(|| TenantState {
pageserver: attach_req.pageserver_id,
generation: 0,