mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-21 07:00:38 +00:00
## Problem The API for detaching things wasn't implement yet, but one could hit this case indirectly from tests when using attach-hook, and find tenants unexpectedly attached again because their policy remained Single. ## Summary of changes Add PlacementPolicy::Detached, and: - add the behavior for it in schedule() - in tenant_migrate, refuse if the policy is detached - automatically set this policy in attach-hook if the caller has specified pageserver=null.
60 lines
1.2 KiB
Rust
60 lines
1.2 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use utils::seqwait::MonotonicCounter;
|
|
|
|
mod compute_hook;
|
|
pub mod http;
|
|
mod node;
|
|
pub mod persistence;
|
|
mod reconciler;
|
|
mod scheduler;
|
|
pub mod service;
|
|
mod tenant_state;
|
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
enum PlacementPolicy {
|
|
/// Cheapest way to attach a tenant: just one pageserver, no secondary
|
|
Single,
|
|
/// Production-ready way to attach a tenant: one attached pageserver and
|
|
/// some number of secondaries.
|
|
Double(usize),
|
|
/// Do not attach to any pageservers
|
|
Detached,
|
|
}
|
|
|
|
#[derive(Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
|
|
struct Sequence(u64);
|
|
|
|
impl Sequence {
|
|
fn initial() -> Self {
|
|
Self(0)
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for Sequence {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
write!(f, "{}", self.0)
|
|
}
|
|
}
|
|
|
|
impl MonotonicCounter<Sequence> for Sequence {
|
|
fn cnt_advance(&mut self, v: Sequence) {
|
|
assert!(*self <= v);
|
|
*self = v;
|
|
}
|
|
fn cnt_value(&self) -> Sequence {
|
|
*self
|
|
}
|
|
}
|
|
|
|
impl Sequence {
|
|
fn next(&self) -> Sequence {
|
|
Sequence(self.0 + 1)
|
|
}
|
|
}
|
|
|
|
impl Default for PlacementPolicy {
|
|
fn default() -> Self {
|
|
PlacementPolicy::Double(1)
|
|
}
|
|
}
|