#![allow(dead_code)]
use std::sync::Arc;
use std::fmt::Debug;
use std::io::Result as IOResult;
use futures::future::BoxFuture;
use bytes::BufMut;
use pi_atom::Atom;
pub mod manager_2pc;
#[derive(Debug, Clone)]
pub enum ErrorLevel {
Normal, Fatal, }
pub trait TransactionError: Debug + Sized + 'static {
fn new_transaction_error<E>(level: ErrorLevel, reason: E) -> Self
where E: Debug + Sized + 'static;
}
pub trait TransactionLog: BufMut + AsRef<[u8]> + Send + Sized + 'static {}
pub trait AsyncTransaction: Send + Sync + 'static {
type Output: Default + Send + 'static;
type Error: TransactionError;
fn is_writable(&self) -> bool;
fn is_concurrent_commit(&self) -> bool;
fn is_concurrent_rollback(&self) -> bool;
fn get_source(&self) -> Atom;
fn init(&self) -> BoxFuture<Result<<Self as AsyncTransaction>::Output, <Self as AsyncTransaction>::Error>>;
fn rollback(&self) -> BoxFuture<Result<<Self as AsyncTransaction>::Output, <Self as AsyncTransaction>::Error>>;
}
pub trait Transaction2Pc: AsyncTransaction + Clone {
type Tid: Debug + Clone + Send + PartialEq + Eq + 'static;
type Pid: Debug + Clone + Send + PartialEq + Eq + 'static;
type Cid: Debug + Clone + Send + PartialEq + Eq + 'static;
type PrepareOutput: BufMut + AsRef<[u8]> + Send + Sized + 'static;
type PrepareError: TransactionError;
type ConfirmOutput: Send + 'static;
type ConfirmError: TransactionError;
type CommitConfirm: Fn(
<Self as Transaction2Pc>::Tid,
<Self as Transaction2Pc>::Cid,
Result<<Self as Transaction2Pc>::ConfirmOutput, <Self as Transaction2Pc>::ConfirmError>
) -> Result<(), <Self as Transaction2Pc>::ConfirmError> + Clone + Send + Sync + 'static;
fn is_require_persistence(&self) -> bool;
fn require_persistence(&self);
fn is_concurrent_prepare(&self) -> bool;
fn is_enable_inherit_uid(&self) -> bool;
fn get_transaction_uid(&self) -> Option<<Self as Transaction2Pc>::Tid>;
fn set_transaction_uid(&self, uid: <Self as Transaction2Pc>::Tid);
fn get_prepare_uid(&self) -> Option<<Self as Transaction2Pc>::Pid>;
fn set_prepare_uid(&self, uid: <Self as Transaction2Pc>::Pid);
fn get_commit_uid(&self) -> Option<<Self as Transaction2Pc>::Cid>;
fn set_commit_uid(&self, uid: <Self as Transaction2Pc>::Cid);
fn get_prepare_timeout(&self) -> u64;
fn get_commit_timeout(&self) -> u64;
fn prepare(&self) -> BoxFuture<Result<Option<<Self as Transaction2Pc>::PrepareOutput>, <Self as Transaction2Pc>::PrepareError>>;
fn prepare_conflicts(&self) -> BoxFuture<Result<Option<<Self as Transaction2Pc>::PrepareOutput>, <Self as Transaction2Pc>::PrepareError>>;
fn commit(&self, confirm: <Self as Transaction2Pc>::CommitConfirm)
-> BoxFuture<Result<<Self as AsyncTransaction>::Output, <Self as AsyncTransaction>::Error>>;
}
pub trait UnitTransaction: Transaction2Pc {
type Status: Debug + Clone + PartialEq + Eq + 'static;
type Qos: Debug + Default + Clone + PartialEq + Eq + 'static;
fn is_unit(&self) -> bool;
fn get_status(&self) -> <Self as UnitTransaction>::Status;
fn set_status(&self, status: <Self as UnitTransaction>::Status);
fn qos(&self) -> <Self as UnitTransaction>::Qos;
}
pub trait SequenceTransaction: UnitTransaction {
type Item: Transaction2Pc;
fn is_sequence(&self) -> bool;
fn prev_item(&self) -> Option<<Self as SequenceTransaction>::Item>;
fn next_item(&self) -> Option<<Self as SequenceTransaction>::Item>;
}
pub trait TransactionTree: UnitTransaction {
type Node: TransactionTree + SequenceTransaction;
type NodeInterator: Iterator<Item = <Self as TransactionTree>::Node> + 'static;
fn is_tree(&self) -> bool;
fn children_len(&self) -> usize;
fn to_children(&self) -> Self::NodeInterator;
}
pub trait AsyncCommitLog: Clone + Send + Sync + 'static {
type C: Clone + Send + 'static;
type Cid: Debug + Clone + Send + PartialEq + Eq + 'static;
fn append<B>(&self, commit_uid: Self::Cid, log: B) -> BoxFuture<'static, IOResult<Self::C>>
where B: BufMut + AsRef<[u8]> + Send + Sized + 'static;
fn flush(&self, log_handle: Self::C) -> BoxFuture<'static, IOResult<()>>;
fn confirm(&self, commit_uid: Self::Cid) -> BoxFuture<'static, IOResult<()>>;
fn start_replay<B, F>(&self, callback: Arc<F>) -> BoxFuture<'static, IOResult<(usize, usize)>>
where B: BufMut + AsRef<[u8]> + From<Vec<u8>> + Send + Sized + 'static,
F: Fn(Self::Cid, B) -> IOResult<()> + Send + Sync + 'static;
fn start_replay_by_file<B, F, G>(&self,
callback: Arc<F>,
file_finished: Arc<G>) -> BoxFuture<'static, IOResult<(usize, usize)>>
where B: BufMut + AsRef<[u8]> + From<Vec<u8>> + Send + Sized + 'static,
F: Fn(Self::Cid, B) -> IOResult<()> + Send + Sync + 'static,
G: Fn() -> IOResult<()> + Send + Sync + 'static;
fn append_replay<B>(&self, commit_uid: Self::Cid, log: B) -> BoxFuture<'static, IOResult<Self::C>>
where B: BufMut + AsRef<[u8]> + Send + Sized + 'static;
fn flush_replay(&self, log_handle: Self::C) -> BoxFuture<'static, IOResult<()>>;
fn confirm_replay(&self, commit_uid: Self::Cid) -> BoxFuture<'static, IOResult<()>>;
fn finish_replay(&self) -> BoxFuture<'static, IOResult<()>>;
fn advance_replay_check_point(&self) -> BoxFuture<'static, IOResult<()>>;
fn check_point_of(&self, commit_uid: Self::Cid) -> BoxFuture<'static, Option<usize>>;
fn current_check_point(&self) -> BoxFuture<'static, usize>;
fn append_check_point(&self) -> BoxFuture<'static, IOResult<usize>>;
fn waiting_confirm_count(&self) -> BoxFuture<'static, usize>;
fn append_total_count(&self) -> usize;
fn confirm_total_count(&self) -> usize;
}