pub trait SerializableRetry {
// Required method
fn serializable_retry<'life0, 'async_trait, T, E, F, Fut>(
&'life0 self,
op: &'static str,
f: F,
) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'async_trait>>
where T: Send + 'async_trait,
E: Display + Send + 'async_trait,
F: Fn() -> Fut + Send + Sync + 'async_trait,
Fut: Future<Output = Result<T, E>> + Send + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Retry a fallible storage operation whenever it fails due to a transient serialization conflict.
Under PostgreSQL SERIALIZABLE isolation, concurrent transactions can abort with SQLSTATE
40001 (“could not serialize access”). These aborts are expected and safe to retry from
scratch, so every read or write should run inside this harness rather than calling
read / write directly.
f is re-invoked from scratch on each attempt, so it must (re)open its own transaction.
Backends that cannot produce serialization conflicts (e.g. the file system) implement this as a
single pass-through call.
The operation is generic over its error type E (e.g. [QueryError], anyhow::Error, or an
explorer error); conflicts are detected from the error’s Display output.
Required Methods§
Sourcefn serializable_retry<'life0, 'async_trait, T, E, F, Fut>(
&'life0 self,
op: &'static str,
f: F,
) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'async_trait>>
fn serializable_retry<'life0, 'async_trait, T, E, F, Fut>( &'life0 self, op: &'static str, f: F, ) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'async_trait>>
Run f, retrying on serialization conflicts according to the backend’s retry policy.
op is a short, static label for the operation (used in diagnostic logging); the
serializable_retry! macro fills it in automatically with the
name of the enclosing function.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.