use mz_repr::GlobalId;
use mz_storage_types::read_holds::ReadHoldError;
use thiserror::Error;
use crate::controller::{ComputeInstanceId, ReplicaId};
pub const ERROR_TARGET_REPLICA_FAILED: &str = "target replica failed or was dropped";
#[derive(Error, Debug)]
#[error("instance does not exist: {0}")]
pub struct InstanceMissing(pub ComputeInstanceId);
#[derive(Error, Debug)]
#[error("instance exists already: {0}")]
pub struct InstanceExists(pub ComputeInstanceId);
#[derive(Error, Debug)]
#[error("collection does not exist: {0}")]
pub struct CollectionMissing(pub GlobalId);
#[derive(Error, Debug)]
#[error("No replicas found in cluster for target list.")]
pub struct HydrationCheckBadTarget(pub Vec<ReplicaId>);
#[derive(Error, Debug)]
pub enum CollectionLookupError {
#[error("instance does not exist: {0}")]
InstanceMissing(ComputeInstanceId),
#[error("collection does not exist: {0}")]
CollectionMissing(GlobalId),
}
impl From<InstanceMissing> for CollectionLookupError {
fn from(error: InstanceMissing) -> Self {
Self::InstanceMissing(error.0)
}
}
impl From<CollectionMissing> for CollectionLookupError {
fn from(error: CollectionMissing) -> Self {
Self::CollectionMissing(error.0)
}
}
#[derive(Error, Debug)]
pub enum ReplicaCreationError {
#[error("instance does not exist: {0}")]
InstanceMissing(ComputeInstanceId),
#[error("replica exists already: {0}")]
ReplicaExists(ReplicaId),
}
impl From<InstanceMissing> for ReplicaCreationError {
fn from(error: InstanceMissing) -> Self {
Self::InstanceMissing(error.0)
}
}
#[derive(Error, Debug)]
pub enum ReplicaDropError {
#[error("instance does not exist: {0}")]
InstanceMissing(ComputeInstanceId),
#[error("replica does not exist: {0}")]
ReplicaMissing(ReplicaId),
}
impl From<InstanceMissing> for ReplicaDropError {
fn from(error: InstanceMissing) -> Self {
Self::InstanceMissing(error.0)
}
}
#[derive(Error, Debug)]
pub enum DataflowCreationError {
#[error("instance does not exist: {0}")]
InstanceMissing(ComputeInstanceId),
#[error("collection does not exist: {0}")]
CollectionMissing(GlobalId),
#[error("replica does not exist: {0}")]
ReplicaMissing(ReplicaId),
#[error("dataflow definition lacks an as_of value")]
MissingAsOf,
#[error("dataflow has an as_of not beyond the since of collection: {0}")]
SinceViolation(GlobalId),
#[error("subscribe dataflow has an empty as_of")]
EmptyAsOfForSubscribe,
#[error("copy to dataflow has an empty as_of")]
EmptyAsOfForCopyTo,
}
impl From<InstanceMissing> for DataflowCreationError {
fn from(error: InstanceMissing) -> Self {
Self::InstanceMissing(error.0)
}
}
impl From<CollectionMissing> for DataflowCreationError {
fn from(error: CollectionMissing) -> Self {
Self::CollectionMissing(error.0)
}
}
impl From<ReadHoldError> for DataflowCreationError {
fn from(error: ReadHoldError) -> Self {
match error {
ReadHoldError::CollectionMissing(id) => Self::CollectionMissing(id),
ReadHoldError::SinceViolation(id) => Self::SinceViolation(id),
}
}
}
#[derive(Error, Debug)]
pub enum PeekError {
#[error("instance does not exist: {0}")]
InstanceMissing(ComputeInstanceId),
#[error("collection does not exist: {0}")]
CollectionMissing(GlobalId),
#[error("replica does not exist: {0}")]
ReplicaMissing(ReplicaId),
#[error("peek timestamp is not beyond the since of collection: {0}")]
SinceViolation(GlobalId),
}
impl From<InstanceMissing> for PeekError {
fn from(error: InstanceMissing) -> Self {
Self::InstanceMissing(error.0)
}
}
impl From<CollectionMissing> for PeekError {
fn from(error: CollectionMissing) -> Self {
Self::CollectionMissing(error.0)
}
}
impl From<ReadHoldError> for PeekError {
fn from(error: ReadHoldError) -> Self {
match error {
ReadHoldError::CollectionMissing(id) => Self::CollectionMissing(id),
ReadHoldError::SinceViolation(id) => Self::SinceViolation(id),
}
}
}
#[derive(Error, Debug)]
pub enum CollectionUpdateError {
#[error("instance does not exist: {0}")]
InstanceMissing(ComputeInstanceId),
#[error("collection does not exist: {0}")]
CollectionMissing(GlobalId),
}
impl From<InstanceMissing> for CollectionUpdateError {
fn from(error: InstanceMissing) -> Self {
Self::InstanceMissing(error.0)
}
}
impl From<CollectionMissing> for CollectionUpdateError {
fn from(error: CollectionMissing) -> Self {
Self::CollectionMissing(error.0)
}
}
#[derive(Error, Debug)]
pub enum ReadPolicyError {
#[error("instance does not exist: {0}")]
InstanceMissing(ComputeInstanceId),
#[error("collection does not exist: {0}")]
CollectionMissing(GlobalId),
#[error("collection is write-only: {0}")]
WriteOnlyCollection(GlobalId),
}
impl From<InstanceMissing> for ReadPolicyError {
fn from(error: InstanceMissing) -> Self {
Self::InstanceMissing(error.0)
}
}
impl From<CollectionMissing> for ReadPolicyError {
fn from(error: CollectionMissing) -> Self {
Self::CollectionMissing(error.0)
}
}
#[derive(Error, Debug)]
pub enum RemoveOrphansError {
#[error("orchestrator error: {0}")]
OrchestratorError(anyhow::Error),
}
impl From<anyhow::Error> for RemoveOrphansError {
fn from(error: anyhow::Error) -> Self {
Self::OrchestratorError(error)
}
}