mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-24 00:20:37 +00:00
## Problem Spun off from https://github.com/neondatabase/neon/pull/6394 -- this PR is just the persistence parts and the changes that enable it to work nicely ## Summary of changes - Revert #6444 and #6450 - In neon_local, start a vanilla postgres instance for the attachment service to use. - Adopt `diesel` crate for database access in attachment service. This uses raw SQL migrations as the source of truth for the schema, so it's a soft dependency: we can switch libraries pretty easily. - Rewrite persistence.rs to use postgres (via diesel) instead of JSON. - Preserve JSON read+write at startup and shutdown: this enables using the JSON format in compatibility tests, so that we don't have to commit to our DB schema yet. - In neon_local, run database creation + migrations before starting attachment service - Run the initial reconciliation in Service::spawn in the background, so that the pageserver + attachment service don't get stuck waiting for each other to start, when restarting both together in a test.
61 lines
1.2 KiB
Rust
61 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;
|
|
mod schema;
|
|
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)
|
|
}
|
|
}
|