Move pageserver control plane API types into libs/

This commit is contained in:
John Spray
2023-08-25 13:02:53 +01:00
parent 034bebcfcd
commit 5b7d3e39d6
3 changed files with 43 additions and 38 deletions

View File

@@ -8,6 +8,7 @@ use anyhow::anyhow;
use clap::Parser;
use hyper::StatusCode;
use hyper::{Body, Request, Response};
use pageserver_api::control_api::*;
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use std::{collections::HashMap, sync::Arc};
@@ -108,22 +109,6 @@ fn get_state(request: &Request<Body>) -> &State {
.as_ref()
}
#[derive(Serialize, Deserialize)]
struct ReAttachRequest {
node_id: NodeId,
}
#[derive(Serialize, Deserialize)]
struct ReAttachResponseTenant {
id: TenantId,
generation: u32,
}
#[derive(Serialize, Deserialize)]
struct ReAttachResponse {
tenants: Vec<ReAttachResponseTenant>,
}
/// Pageserver calls into this on startup, to learn which tenants it should attach
async fn handle_re_attach(mut req: Request<Body>) -> Result<Response<Body>, ApiError> {
let reattach_req = json_request::<ReAttachRequest>(&mut req).await?;
@@ -152,28 +137,6 @@ async fn handle_re_attach(mut req: Request<Body>) -> Result<Response<Body>, ApiE
json_response(StatusCode::OK, response)
}
#[derive(Serialize, Deserialize)]
struct ValidateRequestTenant {
id: TenantId,
gen: u32,
}
#[derive(Serialize, Deserialize)]
struct ValidateRequest {
tenants: Vec<ValidateRequestTenant>,
}
#[derive(Serialize, Deserialize)]
struct ValidateResponse {
tenants: Vec<ValidateResponseTenant>,
}
#[derive(Serialize, Deserialize)]
struct ValidateResponseTenant {
id: TenantId,
valid: bool,
}
/// Pageserver calls into this before doing deletions, to confirm that it still
/// holds the latest generation for the tenants with deletions enqueued
async fn handle_validate(mut req: Request<Body>) -> Result<Response<Body>, ApiError> {

View File

@@ -0,0 +1,41 @@
/// Types in this file are for pageserver's upward-facing API calls to the control plane
use serde::{Deserialize, Serialize};
use utils::id::{NodeId, TenantId};
#[derive(Serialize, Deserialize)]
struct ReAttachRequest {
node_id: NodeId,
}
#[derive(Serialize, Deserialize)]
struct ReAttachResponseTenant {
id: TenantId,
generation: u32,
}
#[derive(Serialize, Deserialize)]
struct ReAttachResponse {
tenants: Vec<ReAttachResponseTenant>,
}
#[derive(Serialize, Deserialize)]
struct ValidateRequestTenant {
id: TenantId,
gen: u32,
}
#[derive(Serialize, Deserialize)]
struct ValidateRequest {
tenants: Vec<ValidateRequestTenant>,
}
#[derive(Serialize, Deserialize)]
struct ValidateResponse {
tenants: Vec<ValidateResponseTenant>,
}
#[derive(Serialize, Deserialize)]
struct ValidateResponseTenant {
id: TenantId,
valid: bool,
}

View File

@@ -1,6 +1,7 @@
use const_format::formatcp;
/// Public API types
pub mod control_api;
pub mod models;
pub mod reltag;