Line data Source code
1 : use pageserver_api::controller_api::{NodeAvailability, NodeSchedulingPolicy};
2 : use serde::Serialize;
3 : use utils::id::NodeId;
4 :
5 : use crate::persistence::NodePersistence;
6 :
7 : /// Represents the in-memory description of a Node.
8 : ///
9 : /// Scheduling statistics are maintened separately in [`crate::scheduler`].
10 : ///
11 : /// The persistent subset of the Node is defined in [`crate::persistence::NodePersistence`]: the
12 : /// implementation of serialization on this type is only for debug dumps.
13 0 : #[derive(Clone, Serialize)]
14 : pub(crate) struct Node {
15 : pub(crate) id: NodeId,
16 :
17 : pub(crate) availability: NodeAvailability,
18 : pub(crate) scheduling: NodeSchedulingPolicy,
19 :
20 : pub(crate) listen_http_addr: String,
21 : pub(crate) listen_http_port: u16,
22 :
23 : pub(crate) listen_pg_addr: String,
24 : pub(crate) listen_pg_port: u16,
25 : }
26 :
27 : impl Node {
28 0 : pub(crate) fn base_url(&self) -> String {
29 0 : format!("http://{}:{}", self.listen_http_addr, self.listen_http_port)
30 0 : }
31 :
32 : /// Is this node elegible to have work scheduled onto it?
33 12 : pub(crate) fn may_schedule(&self) -> bool {
34 12 : match self.availability {
35 10 : NodeAvailability::Active => {}
36 2 : NodeAvailability::Offline => return false,
37 : }
38 :
39 10 : match self.scheduling {
40 10 : NodeSchedulingPolicy::Active => true,
41 0 : NodeSchedulingPolicy::Draining => false,
42 0 : NodeSchedulingPolicy::Filling => true,
43 0 : NodeSchedulingPolicy::Pause => false,
44 : }
45 12 : }
46 :
47 0 : pub(crate) fn to_persistent(&self) -> NodePersistence {
48 0 : NodePersistence {
49 0 : node_id: self.id.0 as i64,
50 0 : scheduling_policy: self.scheduling.into(),
51 0 : listen_http_addr: self.listen_http_addr.clone(),
52 0 : listen_http_port: self.listen_http_port as i32,
53 0 : listen_pg_addr: self.listen_pg_addr.clone(),
54 0 : listen_pg_port: self.listen_pg_port as i32,
55 0 : }
56 0 : }
57 : }
|