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§
Sourcefn on_abort(
&self,
error: Error,
attempts: u32,
elapsed: Duration,
) -> RetryResult
fn on_abort( &self, error: Error, attempts: u32, elapsed: Duration, ) -> RetryResult
Evaluates whether an aborted transaction should be retried.
errortheAbortederror that was raised. Note that this policy takes ownership of the error and returns it embedded in the retry result.attemptsis the number of attempts already made (1 for the first failure).elapsedis 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".