pub struct Transaction { /* private fields */ }Expand description
A buffered, commit-or-rollback transaction over AmateRSClient.
All writes are staged locally in a Vec<TransactionOp> until commit() is
called. commit() issues a single execute_batch RPC so the writes are
applied atomically. rollback() discards the local buffer with no network
call.
§Reading inside a transaction
Transaction::get first inspects the local buffer using last-write-wins
semantics (reverse scan). A buffered Delete for the queried key returns
Ok(None). If the key has not been written in this transaction the call
falls through to the server.
§Drop behaviour
Dropping a transaction that is still Active and has un-committed
operations emits a tracing::warn! message. The buffer is silently
discarded (no rollback RPC is issued — rollback is always local).
§Construction
Prefer the factory method AmateRSClient::transaction over constructing
directly.
Implementations§
Source§impl Transaction
impl Transaction
Sourcepub fn new(client: Arc<AmateRSClient>, collection: impl Into<String>) -> Self
pub fn new(client: Arc<AmateRSClient>, collection: impl Into<String>) -> Self
Create a new transaction bound to collection.
Use AmateRSClient::transaction instead of calling this directly.
Sourcepub fn set(&mut self, key: Key, value: CipherBlob) -> Result<()>
pub fn set(&mut self, key: Key, value: CipherBlob) -> Result<()>
Stage a SET operation into the local buffer.
The write is not applied to the server until Self::commit is called.
§Errors
Returns SdkError::InvalidState if the transaction is no longer
active (already committed or rolled back).
Sourcepub fn delete(&mut self, key: Key) -> Result<()>
pub fn delete(&mut self, key: Key) -> Result<()>
Stage a DELETE operation into the local buffer.
The delete is not applied to the server until Self::commit is called.
§Errors
Returns SdkError::InvalidState if the transaction is no longer active.
Sourcepub async fn get(&self, key: &Key) -> Result<Option<CipherBlob>>
pub async fn get(&self, key: &Key) -> Result<Option<CipherBlob>>
Read a key, consulting the local buffer first (last-write-wins), then the server.
- A buffered
SETreturns the in-flight value without a server round-trip. - A buffered
DELETEreturnsOk(None)without a server round-trip. - If the key has not been touched in this transaction, the call falls
through to
client.get().
§Errors
Returns SdkError::InvalidState if the transaction is no longer active,
or any error returned by the server fall-through.
Sourcepub async fn commit(&mut self) -> Result<()>
pub async fn commit(&mut self) -> Result<()>
Commit all buffered operations atomically via execute_batch.
On success the transaction transitions to the Committed state.
If the batch RPC fails, the state remains Active so the caller can
retry or roll back.
An empty transaction commits instantly without a network round-trip.
§Errors
SdkError::InvalidState— already committed or rolled back.- Any
SdkErrorreturned by the underlyingexecute_batchRPC.
Sourcepub fn rollback(&mut self) -> Result<()>
pub fn rollback(&mut self) -> Result<()>
Rollback by discarding the local buffer — no network call is made.
§Errors
Returns SdkError::InvalidState if the transaction is already
committed or rolled back.
Sourcepub fn pending_ops(&self) -> usize
pub fn pending_ops(&self) -> usize
Number of operations currently staged in the local buffer.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Returns true if the transaction is still active (not yet committed or
rolled back).
Sourcepub fn collection(&self) -> &str
pub fn collection(&self) -> &str
Returns the collection name this transaction is bound to.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Transaction
impl !RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnsafeUnpin for Transaction
impl !UnwindSafe for Transaction
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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>
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>
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>
T in a tonic::RequestSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.