use async_trait::async_trait;
use reduct_base::error::ReductError;
use reduct_base::io::RecordMeta;
use reduct_base::msg::replication_api::{
FullReplicationInfo, ReplicationInfo, ReplicationMode, ReplicationSettings,
};
mod diagnostics;
pub mod proto;
mod remote_bucket;
mod replication_aggregator;
mod replication_event_payload;
mod replication_repository;
mod replication_sender;
mod replication_task;
mod transaction_filter;
mod transaction_log;
#[derive(Debug, Clone, PartialEq)]
pub enum Transaction {
WriteRecord(u64),
UpdateRecord(u64),
}
impl From<Transaction> for u8 {
fn from(val: Transaction) -> Self {
match val {
Transaction::WriteRecord(_) => 0,
Transaction::UpdateRecord(_) => 1,
}
}
}
impl Transaction {
pub fn timestamp(&self) -> &u64 {
match self {
Transaction::WriteRecord(ts) => ts,
Transaction::UpdateRecord(ts) => ts,
}
}
pub fn into_timestamp(self) -> u64 {
match self {
Transaction::WriteRecord(ts) => ts,
Transaction::UpdateRecord(ts) => ts,
}
}
}
impl TryFrom<u8> for Transaction {
type Error = ReductError;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(Transaction::WriteRecord(0)),
1 => Ok(Transaction::UpdateRecord(0)),
_ => Err(ReductError::internal_server_error(
"Invalid transaction type",
)),
}
}
}
#[derive(Debug, Clone)]
pub struct TransactionNotification {
pub bucket: String,
pub entry: String,
pub meta: RecordMeta,
pub event: Transaction,
}
#[async_trait]
pub trait ManageReplications {
async fn create_replication(
&mut self,
name: &str,
settings: ReplicationSettings,
) -> Result<(), ReductError>;
async fn update_replication(
&mut self,
name: &str,
settings: ReplicationSettings,
) -> Result<(), ReductError>;
async fn replications(&self) -> Result<Vec<ReplicationInfo>, ReductError>;
async fn get_info(&self, name: &str) -> Result<FullReplicationInfo, ReductError>;
async fn get_replication_settings(
&self,
name: &str,
) -> Result<ReplicationSettings, ReductError>;
async fn is_replication_running(&self, name: &str) -> Result<bool, ReductError>;
async fn set_replication_provisioned(
&mut self,
name: &str,
provisioned: bool,
) -> Result<(), ReductError>;
async fn remove_replication(&mut self, name: &str) -> Result<(), ReductError>;
async fn set_mode(&mut self, name: &str, mode: ReplicationMode) -> Result<(), ReductError>;
async fn notify(&mut self, notification: TransactionNotification) -> Result<(), ReductError>;
fn start(&mut self);
async fn stop(&mut self);
}
pub(crate) use replication_repository::ReplicationRepoBuilder;