pub struct RetryConfig { /* private fields */ }Expand description
Retry policy for failed drive reads.
Track and sector-range reads are split into chunks, and this policy is applied independently to each chunk. If a chunk read fails, the next attempt starts at the same LBA. Retry delays use capped exponential backoff. When adaptive chunk reduction is enabled, retries request fewer sectors from that LBA, down to the configured minimum. Chunks that were already read successfully are not repeated.
The default values are suitable for most drives. Unless you have specific
requirements, using RetryConfig::default is recommended.
The default policy uses:
- 4 attempts, including the initial read;
- a 20 ms initial backoff;
- a 300 ms maximum backoff;
- adaptive chunk reduction;
- a minimum chunk size of 1 sector.
Implementations§
Source§impl RetryConfig
impl RetryConfig
Sourcepub fn with_max_attempts(self, attempts: u8) -> Self
pub fn with_max_attempts(self, attempts: u8) -> Self
Set the maximum attempts per chunk, including the initial read.
A value of zero is normalized to one attempt.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let output_dir = common::fresh_output_dir("custom_retry")?;
14 let reader = CdReader::open_default()?;
15 let toc = reader.read_toc()?;
16
17 let first_audio = toc
18 .tracks
19 .iter()
20 .find(|t| t.is_audio)
21 .ok_or("no audio tracks found")?;
22
23 // More attempts, longer backoff, and sector reduction down to 1
24 // for maximum resilience on scratched media.
25 let retry = RetryConfig::default()
26 .with_max_attempts(8)
27 .with_initial_backoff(Duration::from_millis(50))
28 .with_max_backoff(Duration::from_secs(1))
29 .with_chunk_reduction(true)
30 .with_min_sectors_per_read(1);
31 let options = ReadOptions::default().with_retry(retry);
32
33 println!(
34 "Reading track {} with aggressive retry...",
35 first_audio.number
36 );
37 let data = reader.read_track_with_options(&toc, first_audio.number, &options)?;
38
39 let wav = create_wav(data);
40 let output_path = output_dir.join(format!("track{:02}.wav", first_audio.number));
41 std::fs::write(&output_path, wav)?;
42 println!("Saved {}", output_path.display());
43
44 Ok(())
45}Sourcepub fn with_initial_backoff(self, backoff: Duration) -> Self
pub fn with_initial_backoff(self, backoff: Duration) -> Self
Set the delay before the second attempt.
The first attempt is always immediate.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let output_dir = common::fresh_output_dir("custom_retry")?;
14 let reader = CdReader::open_default()?;
15 let toc = reader.read_toc()?;
16
17 let first_audio = toc
18 .tracks
19 .iter()
20 .find(|t| t.is_audio)
21 .ok_or("no audio tracks found")?;
22
23 // More attempts, longer backoff, and sector reduction down to 1
24 // for maximum resilience on scratched media.
25 let retry = RetryConfig::default()
26 .with_max_attempts(8)
27 .with_initial_backoff(Duration::from_millis(50))
28 .with_max_backoff(Duration::from_secs(1))
29 .with_chunk_reduction(true)
30 .with_min_sectors_per_read(1);
31 let options = ReadOptions::default().with_retry(retry);
32
33 println!(
34 "Reading track {} with aggressive retry...",
35 first_audio.number
36 );
37 let data = reader.read_track_with_options(&toc, first_audio.number, &options)?;
38
39 let wav = create_wav(data);
40 let output_path = output_dir.join(format!("track{:02}.wav", first_audio.number));
41 std::fs::write(&output_path, wav)?;
42 println!("Saved {}", output_path.display());
43
44 Ok(())
45}Sourcepub fn with_max_backoff(self, backoff: Duration) -> Self
pub fn with_max_backoff(self, backoff: Duration) -> Self
Set the upper bound for exponential backoff delays.
A duration of zero disables retry delays.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let output_dir = common::fresh_output_dir("custom_retry")?;
14 let reader = CdReader::open_default()?;
15 let toc = reader.read_toc()?;
16
17 let first_audio = toc
18 .tracks
19 .iter()
20 .find(|t| t.is_audio)
21 .ok_or("no audio tracks found")?;
22
23 // More attempts, longer backoff, and sector reduction down to 1
24 // for maximum resilience on scratched media.
25 let retry = RetryConfig::default()
26 .with_max_attempts(8)
27 .with_initial_backoff(Duration::from_millis(50))
28 .with_max_backoff(Duration::from_secs(1))
29 .with_chunk_reduction(true)
30 .with_min_sectors_per_read(1);
31 let options = ReadOptions::default().with_retry(retry);
32
33 println!(
34 "Reading track {} with aggressive retry...",
35 first_audio.number
36 );
37 let data = reader.read_track_with_options(&toc, first_audio.number, &options)?;
38
39 let wav = create_wav(data);
40 let output_path = output_dir.join(format!("track{:02}.wav", first_audio.number));
41 std::fs::write(&output_path, wav)?;
42 println!("Saved {}", output_path.display());
43
44 Ok(())
45}Sourcepub fn with_chunk_reduction(self, enabled: bool) -> Self
pub fn with_chunk_reduction(self, enabled: bool) -> Self
Enable or disable requesting fewer sectors after a failed chunk read.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let output_dir = common::fresh_output_dir("custom_retry")?;
14 let reader = CdReader::open_default()?;
15 let toc = reader.read_toc()?;
16
17 let first_audio = toc
18 .tracks
19 .iter()
20 .find(|t| t.is_audio)
21 .ok_or("no audio tracks found")?;
22
23 // More attempts, longer backoff, and sector reduction down to 1
24 // for maximum resilience on scratched media.
25 let retry = RetryConfig::default()
26 .with_max_attempts(8)
27 .with_initial_backoff(Duration::from_millis(50))
28 .with_max_backoff(Duration::from_secs(1))
29 .with_chunk_reduction(true)
30 .with_min_sectors_per_read(1);
31 let options = ReadOptions::default().with_retry(retry);
32
33 println!(
34 "Reading track {} with aggressive retry...",
35 first_audio.number
36 );
37 let data = reader.read_track_with_options(&toc, first_audio.number, &options)?;
38
39 let wav = create_wav(data);
40 let output_path = output_dir.join(format!("track{:02}.wav", first_audio.number));
41 std::fs::write(&output_path, wav)?;
42 println!("Saved {}", output_path.display());
43
44 Ok(())
45}Sourcepub fn with_min_sectors_per_read(self, sectors: u32) -> Self
pub fn with_min_sectors_per_read(self, sectors: u32) -> Self
Set the minimum sectors per command when adaptive reduction is enabled.
A value of zero is normalized to one sector.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let output_dir = common::fresh_output_dir("custom_retry")?;
14 let reader = CdReader::open_default()?;
15 let toc = reader.read_toc()?;
16
17 let first_audio = toc
18 .tracks
19 .iter()
20 .find(|t| t.is_audio)
21 .ok_or("no audio tracks found")?;
22
23 // More attempts, longer backoff, and sector reduction down to 1
24 // for maximum resilience on scratched media.
25 let retry = RetryConfig::default()
26 .with_max_attempts(8)
27 .with_initial_backoff(Duration::from_millis(50))
28 .with_max_backoff(Duration::from_secs(1))
29 .with_chunk_reduction(true)
30 .with_min_sectors_per_read(1);
31 let options = ReadOptions::default().with_retry(retry);
32
33 println!(
34 "Reading track {} with aggressive retry...",
35 first_audio.number
36 );
37 let data = reader.read_track_with_options(&toc, first_audio.number, &options)?;
38
39 let wav = create_wav(data);
40 let output_path = output_dir.join(format!("track{:02}.wav", first_audio.number));
41 std::fs::write(&output_path, wav)?;
42 println!("Saved {}", output_path.display());
43
44 Ok(())
45}Trait Implementations§
Source§impl Clone for RetryConfig
impl Clone for RetryConfig
Source§fn clone(&self) -> RetryConfig
fn clone(&self) -> RetryConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more