Skip to content

Commit 525e84b

Browse files
committed
archive-index: make wait-time for cache download configurable
1 parent 5eed146 commit 525e84b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ pub struct Config {
102102
// So we can preallocate the DashMap with this number to avoid resizes.
103103
pub(crate) local_archive_cache_expected_count: usize,
104104

105+
pub(crate) local_archive_cache_download_wait_ms: u64,
106+
105107
// Where to collect metrics for the metrics initiative.
106108
// When empty, we won't collect metrics.
107109
pub(crate) compiler_metrics_collection_path: Option<PathBuf>,
@@ -233,6 +235,10 @@ impl Config {
233235
"DOCSRS_ARCHIVE_INDEX_EXPECTED_COUNT",
234236
100_000usize,
235237
)?)
238+
.local_archive_cache_download_wait_ms(env(
239+
"DOCSRS_ARCHIVE_INDEX_DOWNLOAD_WAIT_MS",
240+
1000,
241+
)?)
236242
.compiler_metrics_collection_path(maybe_env("DOCSRS_COMPILER_METRICS_PATH")?)
237243
.temp_dir(temp_dir)
238244
.rustwide_workspace(env(

src/storage/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,12 +582,11 @@ impl AsyncStorage {
582582
// Someone else is already downloading/repairing. Don't queue on write(); just wait
583583
// a bit and poll the fast path until it becomes readable or we give up.
584584
const STEP_MS: u64 = 10;
585-
const ATTEMPTS: u64 = 50; // = 500ms total wait
586-
const TOTAL_WAIT_MS: u64 = STEP_MS * ATTEMPTS;
585+
let attempts = self.config.local_archive_cache_download_wait_ms / STEP_MS;
587586

588587
let mut last_err = None;
589588

590-
for _ in 0..ATTEMPTS {
589+
for _ in 0..attempts {
591590
sleep(Duration::from_millis(STEP_MS)).await;
592591

593592
match archive_index::find_in_file(local_index_path.clone(), path_in_archive).await {
@@ -603,7 +602,8 @@ impl AsyncStorage {
603602
Err(last_err
604603
.unwrap_or_else(|| anyhow!("archive index unavailable after repair wait"))
605604
.context(format!(
606-
"no archive index after waiting for {TOTAL_WAIT_MS}ms"
605+
"no archive index after waiting for {} ms",
606+
self.config.local_archive_cache_download_wait_ms
607607
)))
608608
}
609609

0 commit comments

Comments
 (0)