diff --git a/nativelink-store/src/filesystem_store.rs b/nativelink-store/src/filesystem_store.rs index ce542b350..0c83a9f4f 100644 --- a/nativelink-store/src/filesystem_store.rs +++ b/nativelink-store/src/filesystem_store.rs @@ -769,14 +769,11 @@ impl StoreDriver for FilesystemStore { keys: &[StoreKey<'_>], results: &mut [Option], ) -> Result<(), Error> { - // TODO(allada) This is a bit of a hack to get around the lifetime issues with the - // existence_cache. We need to convert the digests to owned values to be able to - // insert them into the cache. In theory it should be able to elide this conversion - // but it seems to be a bit tricky to get right. - let keys: Vec> = keys.iter().map(|v| v.borrow().into_owned()).collect(); self.evicting_map - .sizes_for_keys::<&Vec>, StoreKey<'static>, &StoreKey<'_>>( - &keys, results, false, /* peek */ + .sizes_for_keys::<_, StoreKeyBorrow<'_>, &StoreKey<'_>>( + keys.iter(), + results, + false, /* peek */ ) .await; // We need to do a special pass to ensure our zero files exist. @@ -884,8 +881,8 @@ impl StoreDriver for FilesystemStore { return Ok(()); } - let key_borrow: StoreKeyBorrow<'_> = key.borrow().into(); - let entry = self.evicting_map.get(&key_borrow).await.ok_or_else(|| { + let key_borrow: &StoreKeyBorrow<'_> = std::borrow::Borrow::borrow(&key); + let entry = self.evicting_map.get(key_borrow).await.ok_or_else(|| { make_err!( Code::NotFound, "{} not found in filesystem store here", diff --git a/nativelink-store/src/memory_store.rs b/nativelink-store/src/memory_store.rs index 201fce8da..b8993be97 100644 --- a/nativelink-store/src/memory_store.rs +++ b/nativelink-store/src/memory_store.rs @@ -26,7 +26,7 @@ use nativelink_metric::MetricsComponent; use nativelink_util::buf_channel::{DropCloserReadHalf, DropCloserWriteHalf}; use nativelink_util::evicting_map::{EvictingMap, LenEntry}; use nativelink_util::health_utils::{default_health_status_indicator, HealthStatusIndicator}; -use nativelink_util::store_trait::{StoreDriver, StoreKey, UploadSizeInfo}; +use nativelink_util::store_trait::{StoreDriver, StoreKey, StoreKeyBorrow, UploadSizeInfo}; use crate::cas_utils::is_zero_digest; @@ -84,13 +84,11 @@ impl StoreDriver for MemoryStore { keys: &[StoreKey<'_>], results: &mut [Option], ) -> Result<(), Error> { - // TODO(allada): This is a dirty hack to get around the lifetime issues with the - // evicting map. - let digests: Vec> = - keys.iter().map(|key| key.borrow().into_owned()).collect(); self.evicting_map - .sizes_for_keys::>, StoreKey<'static>, StoreKey<'_>>( - digests, results, false, /* peek */ + .sizes_for_keys::<_, StoreKeyBorrow<'_>, &StoreKey<'_>>( + keys.iter(), + results, + false, /* peek */ ) .await; // We need to do a special pass to ensure our zero digest exist. diff --git a/nativelink-util/src/store_trait.rs b/nativelink-util/src/store_trait.rs index 54003d993..02869b583 100644 --- a/nativelink-util/src/store_trait.rs +++ b/nativelink-util/src/store_trait.rs @@ -187,6 +187,19 @@ where } } +impl<'a, 'b> Borrow> for &StoreKey<'b> +where + 'b: 'a, +{ + fn borrow(&self) -> &StoreKeyBorrow<'a> { + // similar to the auto impl impl Borrow for &T + // but instead impl impl Borrow for &T + // for our new type key wrapper U + let y = *self; + std::borrow::Borrow::borrow(y) + } +} + /// Holds something that can be converted into a key the /// store API can understand. Generally this is a digest /// but it can also be a string if the caller wishes to