Skip to main content

TransactionRetryPolicy

Trait TransactionRetryPolicy 

Source
pub trait TransactionRetryPolicy:
    Debug
    + Send
    + Sync {
    // Required method
    fn on_abort(
        &self,
        error: Error,
        attempts: u32,
        elapsed: Duration,
    ) -> RetryResult;
}
Expand description

Defines a policy for retrying a transaction when it is aborted by Spanner.

§Example

#[derive(Debug)]
struct LimitedRetryPolicy {
    max_attempts: u32,
}

impl TransactionRetryPolicy for LimitedRetryPolicy {
    fn on_abort(&self, error: Error, attempts: u32, _elapsed: Duration) -> RetryResult {
        if attempts < self.max_attempts {
            RetryResult::Continue(error)
        } else {
            RetryResult::Exhausted(error)
        }
    }
}

Spanner can abort any read/write transaction due to lock conflicts or other transient issues. In such cases, the client should retry the complete transaction.

By default, transaction runners use BasicTransactionRetryPolicy with no attempt count or timeout limits, retrying aborted transactions until completion or runner timeout.

Required Methods§

Source

fn on_abort( &self, error: Error, attempts: u32, elapsed: Duration, ) -> RetryResult

Evaluates whether an aborted transaction should be retried.

  • error the Aborted error that was raised. Note that this policy takes ownership of the error and returns it embedded in the retry result.
  • attempts is the number of attempts already made (1 for the first failure).
  • elapsed is the total time spent executing the transaction so far.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: ?Sized + TransactionRetryPolicy> TransactionRetryPolicy for Arc<T>

Source§

fn on_abort( &self, error: Error, attempts: u32, elapsed: Duration, ) -> RetryResult

Source§

impl<T: ?Sized + TransactionRetryPolicy> TransactionRetryPolicy for Box<T>

Source§

fn on_abort( &self, error: Error, attempts: u32, elapsed: Duration, ) -> RetryResult

Implementors§