use osproxy_spi::Placement;
use thiserror::Error;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Phase {
Draining,
Cutover,
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum PartitionState {
Active(Placement),
Migrating {
from: Placement,
to: Placement,
phase: Phase,
},
}
impl PartitionState {
#[must_use]
pub fn read_placement(&self) -> &Placement {
match self {
Self::Active(p) | Self::Migrating { from: p, .. } => p,
}
}
#[must_use]
pub fn write_placement(&self) -> Option<&Placement> {
match self {
Self::Active(p)
| Self::Migrating {
from: p,
phase: Phase::Draining,
..
} => Some(p),
Self::Migrating {
phase: Phase::Cutover,
..
} => None,
}
}
#[must_use]
pub fn is_migrating(&self) -> bool {
matches!(self, Self::Migrating { .. })
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum WriteAdmission {
Admit,
Reject,
}
#[non_exhaustive]
#[derive(Clone, PartialEq, Eq, Debug, Error)]
pub enum MigrationError {
#[error("partition has no placement")]
UnknownPartition,
#[error("partition is already migrating")]
AlreadyMigrating,
#[error("partition is not migrating")]
NotMigrating,
#[error("migration is not draining")]
NotDraining,
#[error("migration is not in cutover")]
NotCutover,
#[error("migration store backend failure: {reason}")]
Backend {
reason: &'static str,
},
}