scylla 1.6.0

Async CQL driver for Rust, optimized for ScyllaDB, fully compatible with Apache Cassandraâ„¢
Documentation
//! Request retries configurations\
//! To decide when to retry a request the `Session` can use any object which implements
//! the `RetryPolicy` trait

use crate::errors::RequestAttemptError;
use crate::frame::types::Consistency;

/// Information about a failed request
#[non_exhaustive]
pub struct RequestInfo<'a> {
    /// The error with which the request failed
    pub error: &'a RequestAttemptError,
    /// A request is idempotent if it can be applied multiple times without changing the result of the initial application\
    /// If set to `true` we can be sure that it is idempotent\
    /// If set to `false` it is unknown whether it is idempotent
    pub is_idempotent: bool,
    /// Consistency with which the request failed
    pub consistency: Consistency,
}

/// Returned by implementations of RetryPolicy. Instructs the driver on what
/// to do about the request after it failed.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum RetryDecision {
    /// Request will be sent to the same shard on the same host.
    RetrySameTarget(Option<Consistency>), // None means that the same consistency should be used as before
    /// Request will be sent to the next target generated by load balancing policy.
    RetryNextTarget(Option<Consistency>), // ditto
    /// Fails the whole request.
    DontRetry,
    /// Will cause the driver to return an empty successful response.
    IgnoreWriteError,
}

/// Specifies a policy used to decide when to retry a request
pub trait RetryPolicy: std::fmt::Debug + Send + Sync {
    /// Called for each new request, starts a session of deciding about retries
    fn new_session(&self) -> Box<dyn RetrySession>;
}

/// Used throughout a single request to decide when to retry it
/// After this request is finished it is destroyed or reset
pub trait RetrySession: Send + Sync {
    /// Called after the request failed - decide what to do next
    fn decide_should_retry(&mut self, request_info: RequestInfo) -> RetryDecision;

    /// Reset before using for a new request
    fn reset(&mut self);
}