use uuid::Uuid;
use crate::meta_storage::MetaResult;
use crate::schema::{
DimensionMetadata, Job, Resolution, RunFootprint, TableShape, TaskMetadata, Ticket,
TicketStatus,
};
pub trait MetaBackend: Clone + std::fmt::Debug + Send + Sync + Sized + 'static {
type Error: std::error::Error + Send + Sync + 'static;
type Conn<'a>: MetaConnApi<Self> + Send
where
Self: 'a;
type Tx<'a>: MetaTxApi<Self> + Send
where
Self: 'a;
type Client<'a>: MetaClientApi<Self> + Copy + Send + Sync
where
Self: 'a;
type Ticket<'a, const N: usize>: MetaTicketApi<N, Error = Self::Error> + Send
where
Self: 'a;
type Resolution<'a, const N: usize>: MetaResolutionApi<N, Error = Self::Error> + Send
where
Self: 'a;
fn worker_conn(&self) -> impl Future<Output = MetaResult<Self::Conn<'_>, Self::Error>> + Send;
fn scheduler_conn(
&self,
) -> impl Future<Output = MetaResult<Self::Conn<'static>, Self::Error>> + Send;
fn ensure_lock(&self) -> impl Future<Output = MetaResult<(), Self::Error>> + Send;
fn check_lock(&self) -> impl Future<Output = MetaResult<(), Self::Error>> + Send;
}
pub trait MetaConnApi<MSto: MetaBackend>: Send {
fn transaction(&mut self)
-> impl Future<Output = MetaResult<MSto::Tx<'_>, MSto::Error>> + Send;
fn as_client(&self) -> MSto::Client<'_>;
}
pub trait MetaTxApi<MSto: MetaBackend>: Send {
fn commit(self) -> impl Future<Output = MetaResult<(), MSto::Error>> + Send;
fn rollback(self) -> impl Future<Output = MetaResult<(), MSto::Error>> + Send;
fn as_client(&self) -> MSto::Client<'_>;
}
pub trait MetaClientApi<MSto: MetaBackend>: Copy + Send + Sync {
fn ticket<const N: usize>(&self, task_meta: TaskMetadata<N>) -> MSto::Ticket<'_, N>;
fn resolution<const N: usize>(&self, dim_meta: DimensionMetadata<N>)
-> MSto::Resolution<'_, N>;
fn init_schema(&self) -> impl Future<Output = MetaResult<(), MSto::Error>> + Send;
fn init_ticket_hash(&self) -> impl Future<Output = MetaResult<(), MSto::Error>> + Send;
fn init_dimension_hash(&self) -> impl Future<Output = MetaResult<(), MSto::Error>> + Send;
fn init_ticket_status_type(&self) -> impl Future<Output = MetaResult<(), MSto::Error>> + Send;
fn init_ticket_summary(&self) -> impl Future<Output = MetaResult<(), MSto::Error>> + Send;
fn init_footprint(&self) -> impl Future<Output = MetaResult<TableShape, MSto::Error>> + Send;
fn clear_footprint(&self) -> impl Future<Output = MetaResult<(), MSto::Error>> + Send;
fn get_footprint(
&self,
) -> impl Future<Output = MetaResult<Option<RunFootprint>, MSto::Error>> + Send;
fn upsert_run(
&self,
footprint: &RunFootprint,
) -> impl Future<Output = MetaResult<(), MSto::Error>> + Send;
fn put_execution(
&self,
run_id: Uuid,
execution_id: Uuid,
) -> impl Future<Output = MetaResult<(), MSto::Error>> + Send;
fn update_execution_on_finish(
&self,
footprint: &RunFootprint,
execution_id: Uuid,
) -> impl Future<Output = MetaResult<(), MSto::Error>> + Send;
}
pub trait MetaTicketApi<const N: usize> {
type Error: std::error::Error + Send + Sync + 'static;
fn init(&self) -> impl Future<Output = MetaResult<TableShape, Self::Error>> + Send;
fn clear(&self) -> impl Future<Output = MetaResult<(), Self::Error>> + Send;
fn get_all(
&self,
status: TicketStatus,
) -> impl Future<Output = MetaResult<Vec<Ticket<N>>, Self::Error>> + Send;
fn put(&self, ticket: Ticket<N>) -> impl Future<Output = MetaResult<(), Self::Error>> + Send;
fn dump(&self) -> impl Future<Output = MetaResult<Vec<Ticket<N>>, Self::Error>> + Send;
fn hydrate(
&self,
tickets: Vec<Ticket<N>>,
) -> impl Future<Output = MetaResult<(), Self::Error>> + Send;
fn raise_deps_done<const M: usize>(
&self,
upstream_meta: TaskMetadata<M>,
upstream_job: Job<M>,
aggregate_dims: &[&'static str],
) -> impl Future<Output = MetaResult<Vec<Ticket<N>>, Self::Error>> + Send;
fn raise_deps_quota<const M: usize>(
&self,
upstream_meta: TaskMetadata<M>,
upstream_ticket: Ticket<M>,
aggregate_dims: &[&'static str],
ub: usize,
) -> impl Future<Output = MetaResult<Vec<Ticket<N>>, Self::Error>> + Send;
fn explode<const M: usize, const IDX: usize>(
&self,
res_meta: DimensionMetadata<M>,
res: Resolution<M>,
) -> impl Future<Output = MetaResult<Vec<Ticket<N>>, Self::Error>> + Send;
fn mark_done(&self, job: Job<N>) -> impl Future<Output = MetaResult<(), Self::Error>> + Send;
fn get_status(&self) -> impl Future<Output = MetaResult<(i64, i64, i64), Self::Error>> + Send;
}
pub trait MetaResolutionApi<const N: usize> {
type Error: std::error::Error + Send + Sync + 'static;
fn init(&self) -> impl Future<Output = MetaResult<TableShape, Self::Error>> + Send;
fn clear(&self) -> impl Future<Output = MetaResult<(), Self::Error>> + Send;
fn get(
&self,
coordinate: [usize; N],
) -> impl Future<Output = MetaResult<Option<Resolution<N>>, Self::Error>> + Send;
fn put(
&self,
resolution: Resolution<N>,
) -> impl Future<Output = MetaResult<(), Self::Error>> + Send;
fn dump(&self) -> impl Future<Output = MetaResult<Vec<Resolution<N>>, Self::Error>> + Send;
fn hydrate(
&self,
resolutions: Vec<Resolution<N>>,
) -> impl Future<Output = MetaResult<(), Self::Error>> + Send;
}