Skip to main content

cd_da_reader/
retry.rs

1/// Retry policy for idempotent read operations.
2///
3/// The policy is applied per failed read chunk/command and can combine
4/// capped exponential backoff with adaptive chunk-size reduction.
5#[derive(Debug, Clone)]
6pub struct RetryConfig {
7    /// Maximum attempts per operation, including the initial attempt.
8    /// By default the value is 4.
9    ///
10    /// Values below `1` are normalized by callers to at least one attempt.
11    pub max_attempts: u8,
12    /// Initial backoff delay in milliseconds before the second attempt.
13    /// First attempt is always immediate, so if there are no issues during
14    /// reading, we don't wait any time.
15    pub initial_backoff_ms: u64,
16    /// Upper bound for exponential backoff delay in milliseconds.
17    ///
18    /// Each retry typically doubles the previous delay until this cap is reached.
19    pub max_backoff_ms: u64,
20    /// Enable adaptive sector-count reduction on retry for `READ CD` operations.
21    ///
22    /// Current implementation reduces chunk size from large reads toward smaller
23    /// reads (for example `27 -> 8 -> 1`) to have a higher change of success.
24    pub reduce_chunk_on_retry: bool,
25    /// Minimum sectors per `READ CD` command when adaptive reduction is enabled.
26    /// Default value is 27 for 64KB per read.
27    ///
28    /// Use `1` for maximal fault isolation; larger values can improve throughput.
29    pub min_sectors_per_read: u32,
30}
31
32impl Default for RetryConfig {
33    fn default() -> Self {
34        Self {
35            max_attempts: 4,
36            initial_backoff_ms: 20,
37            max_backoff_ms: 300,
38            reduce_chunk_on_retry: true,
39            min_sectors_per_read: 1,
40        }
41    }
42}