Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

存储层的统一入口。按 URL 前缀自动选后端:

sqlite:...     / postgres://...  / mysql://...   → SQL 后端
redis://...    / rediss://...                    → Redis 后端(要开 redis feature)

⚠ Redis 后端跟 SQL 后端有实打实的语义差异(持久性更弱、终态会过期), 用之前务必读 [redis_store] 的模块说明。

Implementations§

Source§

impl Store

Source

pub async fn open(url: &str) -> Result<Self>

按 URL 选后端并连上。

Source

pub fn is_redis(&self) -> bool

底层是不是 Redis

Source

pub fn pool(&self) -> Option<&AnyPool>

SQL 后端的连接池。Redis 后端返回 None —— 调用方(主要是测试和屏障)要自己处理这种情况

Source

pub fn backend(&self) -> Option<Backend>

SQL 方言。Redis 后端没有方言可言,返回 None

Source§

impl Store

Source

pub async fn migrate(&self) -> Result<()>

建表(Redis 后端是空操作)

Source

pub async fn create_global( &self, g: &GlobalRow, branches: &[BranchRow], ) -> Result<bool>

建全局事务 + 分支。已存在返回 false不覆盖

Source

pub async fn get_global(&self, gid: &str) -> Result<Option<GlobalRow>>

Source

pub async fn list_branches(&self, gid: &str) -> Result<Vec<BranchRow>>

Source

pub async fn lock_one_due( &self, owner: &str, lease: i64, ) -> Result<Option<GlobalRow>>

抢一个到期事务。多实例不重复推进就靠它的原子性

Source

pub async fn set_global_status( &self, gid: &str, status: GlobalStatus, reason: &str, ) -> Result<()>

Source

pub async fn set_branch_result( &self, gid: &str, branch_id: &str, op: BranchOp, status: BranchStatus, payload: &str, ) -> Result<()>

Source

pub async fn set_branch_status( &self, gid: &str, branch_id: &str, op: BranchOp, status: BranchStatus, ) -> Result<()>

Source

pub async fn schedule_retry(&self, gid: &str, interval: i64) -> Result<()>

Source

pub async fn schedule_now(&self, gid: &str) -> Result<()>

Source

pub async fn register_branch( &self, gid: &str, branch_id: &str, ops: &[(BranchOp, String)], ) -> Result<()>

Source

pub async fn list_recent(&self, limit: i64) -> Result<Vec<GlobalRow>>

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Store

§

impl !UnwindSafe for Store

§

impl Freeze for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more