LCOV - code coverage report
Current view: top level - libs/pageserver_api/src - controller_api.rs (source / functions) Coverage Total Hit
Test: 322b88762cba8ea666f63cda880cccab6936bf37.info Lines: 0.0 % 33 0
Test Date: 2024-02-29 11:57:12 Functions: 0.0 % 170 0

            Line data    Source code
       1              : use std::str::FromStr;
       2              : 
       3              : /// Request/response types for the storage controller
       4              : /// API (`/control/v1` prefix).  Implemented by the server
       5              : /// in [`attachment_service::http`]
       6              : use serde::{Deserialize, Serialize};
       7              : use utils::id::NodeId;
       8              : 
       9              : use crate::{models::ShardParameters, shard::TenantShardId};
      10              : 
      11            0 : #[derive(Serialize, Deserialize)]
      12              : pub struct TenantCreateResponseShard {
      13              :     pub shard_id: TenantShardId,
      14              :     pub node_id: NodeId,
      15              :     pub generation: u32,
      16              : }
      17              : 
      18            0 : #[derive(Serialize, Deserialize)]
      19              : pub struct TenantCreateResponse {
      20              :     pub shards: Vec<TenantCreateResponseShard>,
      21              : }
      22              : 
      23            0 : #[derive(Serialize, Deserialize)]
      24              : pub struct NodeRegisterRequest {
      25              :     pub node_id: NodeId,
      26              : 
      27              :     pub listen_pg_addr: String,
      28              :     pub listen_pg_port: u16,
      29              : 
      30              :     pub listen_http_addr: String,
      31              :     pub listen_http_port: u16,
      32              : }
      33              : 
      34            0 : #[derive(Serialize, Deserialize)]
      35              : pub struct NodeConfigureRequest {
      36              :     pub node_id: NodeId,
      37              : 
      38              :     pub availability: Option<NodeAvailability>,
      39              :     pub scheduling: Option<NodeSchedulingPolicy>,
      40              : }
      41              : 
      42            0 : #[derive(Serialize, Deserialize, Debug)]
      43              : pub struct TenantLocateResponseShard {
      44              :     pub shard_id: TenantShardId,
      45              :     pub node_id: NodeId,
      46              : 
      47              :     pub listen_pg_addr: String,
      48              :     pub listen_pg_port: u16,
      49              : 
      50              :     pub listen_http_addr: String,
      51              :     pub listen_http_port: u16,
      52              : }
      53              : 
      54            0 : #[derive(Serialize, Deserialize)]
      55              : pub struct TenantLocateResponse {
      56              :     pub shards: Vec<TenantLocateResponseShard>,
      57              :     pub shard_params: ShardParameters,
      58              : }
      59              : 
      60              : /// Explicitly migrating a particular shard is a low level operation
      61              : /// TODO: higher level "Reschedule tenant" operation where the request
      62              : /// specifies some constraints, e.g. asking it to get off particular node(s)
      63            0 : #[derive(Serialize, Deserialize, Debug)]
      64              : pub struct TenantShardMigrateRequest {
      65              :     pub tenant_shard_id: TenantShardId,
      66              :     pub node_id: NodeId,
      67              : }
      68              : 
      69            0 : #[derive(Serialize, Deserialize, Clone, Copy, Eq, PartialEq)]
      70              : pub enum NodeAvailability {
      71              :     // Normal, happy state
      72              :     Active,
      73              :     // Offline: Tenants shouldn't try to attach here, but they may assume that their
      74              :     // secondary locations on this node still exist.  Newly added nodes are in this
      75              :     // state until we successfully contact them.
      76              :     Offline,
      77              : }
      78              : 
      79              : impl FromStr for NodeAvailability {
      80              :     type Err = anyhow::Error;
      81              : 
      82            0 :     fn from_str(s: &str) -> Result<Self, Self::Err> {
      83            0 :         match s {
      84            0 :             "active" => Ok(Self::Active),
      85            0 :             "offline" => Ok(Self::Offline),
      86            0 :             _ => Err(anyhow::anyhow!("Unknown availability state '{s}'")),
      87              :         }
      88            0 :     }
      89              : }
      90              : 
      91              : /// FIXME: this is a duplicate of the type in the attachment_service crate, because the
      92              : /// type needs to be defined with diesel traits in there.
      93            0 : #[derive(Serialize, Deserialize, Clone, Copy, Eq, PartialEq)]
      94              : pub enum NodeSchedulingPolicy {
      95              :     Active,
      96              :     Filling,
      97              :     Pause,
      98              :     Draining,
      99              : }
     100              : 
     101              : impl FromStr for NodeSchedulingPolicy {
     102              :     type Err = anyhow::Error;
     103              : 
     104            0 :     fn from_str(s: &str) -> Result<Self, Self::Err> {
     105            0 :         match s {
     106            0 :             "active" => Ok(Self::Active),
     107            0 :             "filling" => Ok(Self::Filling),
     108            0 :             "pause" => Ok(Self::Pause),
     109            0 :             "draining" => Ok(Self::Draining),
     110            0 :             _ => Err(anyhow::anyhow!("Unknown scheduling state '{s}'")),
     111              :         }
     112            0 :     }
     113              : }
     114              : 
     115              : impl From<NodeSchedulingPolicy> for String {
     116            0 :     fn from(value: NodeSchedulingPolicy) -> String {
     117            0 :         use NodeSchedulingPolicy::*;
     118            0 :         match value {
     119            0 :             Active => "active",
     120            0 :             Filling => "filling",
     121            0 :             Pause => "pause",
     122            0 :             Draining => "draining",
     123              :         }
     124            0 :         .to_string()
     125            0 :     }
     126              : }
     127              : 
     128            0 : #[derive(Serialize, Deserialize, Debug)]
     129              : pub struct TenantShardMigrateResponse {}
        

Generated by: LCOV version 2.1-beta