Compare commits

..

No commits in common. "7f16e697e6c24c7ab701aa08d79590d9d65d4cf6" and "a70f4bfdc3ac80e7e89cddd1802af00201fd7d73" have entirely different histories.

2 changed files with 18 additions and 28 deletions

23
src/cache/fs.rs vendored
View file

@ -91,21 +91,14 @@ pub(super) async fn read_file(
return None; return None;
} }
let header = if let Some(header) = Header::from_slice(&header_bytes) { Box::pin(EncryptedDiskReader::new(
header file,
} else { SecretStream::init_pull(
warn!("Found file, but encrypted header was invalid. Assuming corrupted!"); &Header::from_slice(&header_bytes).expect("failed to get header"),
return None; key,
}; )
.expect("Failed to initialize decryption kesy"),
let secret_stream = if let Ok(stream) = SecretStream::init_pull(&header, key) { ))
stream
} else {
warn!("Failed to init secret stream with key and header. Assuming corrupted!");
return None;
};
Box::pin(EncryptedDiskReader::new(file, secret_stream))
} else { } else {
Box::pin(file) Box::pin(file)
}; };

23
src/cache/mem.rs vendored
View file

@ -74,24 +74,22 @@ impl InternalMemoryCache for Lru {
/// Memory accelerated disk cache. Uses the internal cache implementation in /// Memory accelerated disk cache. Uses the internal cache implementation in
/// memory to speed up reads. /// memory to speed up reads.
pub struct MemoryCache<MemoryCacheImpl, ColdCache> { pub struct MemoryCache<InternalCacheImpl, InnerCache> {
inner: ColdCache, inner: InnerCache,
cur_mem_size: AtomicU64, cur_mem_size: AtomicU64,
mem_cache: Mutex<MemoryCacheImpl>, mem_cache: Mutex<InternalCacheImpl>,
master_sender: Sender<(CacheKey, Bytes, ImageMetadata, u64)>, master_sender: Sender<(CacheKey, Bytes, ImageMetadata, u64)>,
} }
impl<MemoryCacheImpl, ColdCache> MemoryCache<MemoryCacheImpl, ColdCache> impl<InternalCacheImpl: 'static + InternalMemoryCache, InnerCache: 'static + Cache>
where MemoryCache<InternalCacheImpl, InnerCache>
MemoryCacheImpl: 'static + InternalMemoryCache,
ColdCache: 'static + Cache,
{ {
pub async fn new(inner: ColdCache, max_mem_size: u64) -> Arc<Self> { pub async fn new(inner: InnerCache, max_mem_size: u64) -> Arc<Self> {
let (tx, mut rx) = channel(100); let (tx, mut rx) = channel(100);
let new_self = Arc::new(Self { let new_self = Arc::new(Self {
inner, inner,
cur_mem_size: AtomicU64::new(0), cur_mem_size: AtomicU64::new(0),
mem_cache: Mutex::new(MemoryCacheImpl::unbounded()), mem_cache: Mutex::new(InternalCacheImpl::unbounded()),
master_sender: tx, master_sender: tx,
}); });
@ -101,7 +99,6 @@ where
let max_mem_size = max_mem_size / 20 * 19; let max_mem_size = max_mem_size / 20 * 19;
while let Some((key, bytes, metadata, size)) = rx.recv().await { while let Some((key, bytes, metadata, size)) = rx.recv().await {
// Add to memory cache // Add to memory cache
// We can add first because we constrain our memory usage to 95%
new_self new_self
.cur_mem_size .cur_mem_size
.fetch_add(size as u64, Ordering::Release); .fetch_add(size as u64, Ordering::Release);
@ -135,10 +132,10 @@ where
} }
#[async_trait] #[async_trait]
impl<MemoryCacheImpl, ColdCache> Cache for MemoryCache<MemoryCacheImpl, ColdCache> impl<InternalCacheImpl, InnerCache> Cache for MemoryCache<InternalCacheImpl, InnerCache>
where where
MemoryCacheImpl: InternalMemoryCache, InternalCacheImpl: InternalMemoryCache,
ColdCache: CallbackCache, InnerCache: CallbackCache,
{ {
#[inline] #[inline]
async fn get( async fn get(