pub struct Api {
pub store: Store,
}Fields§
§store: StoreImplementations§
Source§impl Api
impl Api
pub fn new(store: Store) -> Self
Sourcepub async fn submit(
&self,
gid: &str,
trans_type: &str,
steps: &[SagaStep],
) -> Result<()>
pub async fn submit( &self, gid: &str, trans_type: &str, steps: &[SagaStep], ) -> Result<()>
提交。
重复提交同一个 gid 必须成功而不是报错 —— 客户端网络抖动重试时 返回错误会让它以为没受理,然后换个 gid 再来一次,就成了两笔。
Sourcepub async fn prepare(
&self,
gid: &str,
trans_type: &str,
actions: &[String],
query_prepared: &str,
grace_secs: Option<i64>,
) -> Result<()>
pub async fn prepare( &self, gid: &str, trans_type: &str, actions: &[String], query_prepared: &str, grace_secs: Option<i64>, ) -> Result<()>
第一阶段。msg 建 prepared 事务 + 正向分支;tcc / xa 只建空事务。
Sourcepub async fn register_branch(&self, r: &RegisterBranch) -> Result<()>
pub async fn register_branch(&self, r: &RegisterBranch) -> Result<()>
分支登记。必须先登记再做一阶段:反过来的话一阶段成功但登记失败, TC 就不知道有这个分支,回滚时不会处理它 —— TCC 是预留资源永久泄漏, XA 更糟,会留下一个永久持锁的 prepared 事务。
pub async fn query(&self, gid: &str) -> Result<TransView>
pub async fn list_recent(&self, limit: i64) -> Vec<TransView>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Api
impl !UnwindSafe for Api
impl Freeze for Api
impl Send for Api
impl Sync for Api
impl Unpin for Api
impl UnsafeUnpin for Api
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request