Skip to content

Commit 8fcc62f

Browse files
emmaling27Convex, Inc.
authored andcommitted
Fix searchlight running locally by creating directory if doesn't exist (#26892)
Make it easier to debug archive cache and fix bug where extracting archive onto disk would fail if the directory did not exist. GitOrigin-RevId: 3adc4ee12dd9e19d6152f7fa271a2596ae816954
1 parent 381d26d commit 8fcc62f

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

crates/async_lru/src/async_lru.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,16 @@ enum Status<Value> {
185185
),
186186
}
187187

188+
impl<Value> std::fmt::Display for Status<Value> {
189+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
190+
match self {
191+
Status::Ready(_) => write!(f, "Ready"),
192+
Status::Waiting(_) => write!(f, "Waiting"),
193+
Status::Kickoff(..) => write!(f, "Kickoff"),
194+
}
195+
}
196+
}
197+
188198
impl<
189199
RT: Runtime,
190200
Key: Hash + Eq + Debug + Clone + Send + Sync + 'static,
@@ -370,7 +380,9 @@ impl<
370380
key: &Key,
371381
value_generator: ValueGenerator<Key, Value>,
372382
) -> anyhow::Result<Arc<Value>> {
373-
match self.get_sync(key, value_generator)? {
383+
let status = self.get_sync(key, value_generator)?;
384+
tracing::debug!("Getting key {key:?} with status {status}");
385+
match status {
374386
Status::Ready(value) => Ok(value),
375387
Status::Waiting(rx) => Ok(Self::wait_for_value(key, rx).await?),
376388
Status::Kickoff(rx, timer) => {

crates/search/src/archive/cache.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,13 @@ impl<RT: Runtime> ArchiveCacheManager<RT> {
379379
.get(
380380
cache_key.clone(),
381381
archive_fetcher
382-
.generate_value(search_storage, key.clone(), search_file_type)
382+
.generate_value(search_storage.clone(), key.clone(), search_file_type)
383383
.boxed(),
384384
)
385-
.await?;
385+
.await
386+
.with_context(|| {
387+
format!("Failed to get cache_key {cache_key:?} in {search_storage:?}")
388+
})?;
386389

387390
let path = result.path.clone();
388391
let current_size = self.cache.size();

crates/search/src/archive/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ use tokio::io::AsyncRead;
1818
pub mod cache;
1919
mod metrics;
2020

21-
/// Extract the archive stream to the specified output directory, which must not
22-
/// exist or this method will return an Error. This function should only be used
21+
/// Extract the archive stream to the specified output directory, which will be
22+
/// created if it doesn't already exist. This function should only be used
2323
/// for trusted ZIP archives; we don't make any attempt to guard against
2424
/// directory traversal attacks nor do we sanitize paths.
2525
pub(crate) async fn extract_zip<P: AsRef<Path>>(
2626
output_directory: P,
2727
archive: impl AsyncRead,
2828
) -> anyhow::Result<u64> {
29-
std::fs::create_dir(&output_directory)?;
29+
std::fs::create_dir_all(&output_directory)?;
3030
pin_mut!(archive);
3131
let mut reader = ZipFileReader::new(archive);
3232
let mut created_paths: HashSet<PathBuf> = HashSet::new();

0 commit comments

Comments
 (0)