mirror of
https://github.com/cloudflare/pingora.git
synced 2024-09-20 02:31:35 +02:00
Report evction/invalidtion types
This helps the storage to log/track different type of cache deletions.
This commit is contained in:
parent
872d4e0295
commit
6ea5cde02e
5 changed files with 38 additions and 9 deletions
2
.bleep
2
.bleep
|
@ -1 +1 @@
|
|||
b8ac54b482f643f04533dcc04061b1575482c92d
|
||||
27bf4df19b465281ddc2d348ed6f3f0402fa60cc
|
|
@ -44,7 +44,7 @@ pub use key::CacheKey;
|
|||
use lock::{CacheLock, LockStatus, Locked};
|
||||
pub use memory::MemCache;
|
||||
pub use meta::{CacheMeta, CacheMetaDefaults};
|
||||
pub use storage::{HitHandler, MissHandler, Storage};
|
||||
pub use storage::{HitHandler, MissHandler, PurgeType, Storage};
|
||||
pub use variance::VarianceBuilder;
|
||||
|
||||
pub mod prelude {}
|
||||
|
@ -658,7 +658,10 @@ impl HttpCache {
|
|||
let handle = span.handle();
|
||||
for item in evicted {
|
||||
// TODO: warn/log the error
|
||||
let _ = inner.storage.purge(&item, &handle).await;
|
||||
let _ = inner
|
||||
.storage
|
||||
.purge(&item, PurgeType::Eviction, &handle)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
inner.traces.finish_miss_span();
|
||||
|
@ -1063,7 +1066,10 @@ impl HttpCache {
|
|||
let inner = self.inner_mut();
|
||||
let mut span = inner.traces.child("purge");
|
||||
let key = inner.key.as_ref().unwrap().to_compact();
|
||||
let result = inner.storage.purge(&key, &span.handle()).await;
|
||||
let result = inner
|
||||
.storage
|
||||
.purge(&key, PurgeType::Invalidation, &span.handle())
|
||||
.await;
|
||||
// FIXME: also need to remove from eviction manager
|
||||
span.set_tag(|| trace::Tag::new("purged", matches!(result, Ok(true))));
|
||||
result
|
||||
|
|
|
@ -306,7 +306,12 @@ impl Storage for MemCache {
|
|||
Ok(Box::new(miss_handler))
|
||||
}
|
||||
|
||||
async fn purge(&'static self, key: &CompactCacheKey, _trace: &SpanHandle) -> Result<bool> {
|
||||
async fn purge(
|
||||
&'static self,
|
||||
key: &CompactCacheKey,
|
||||
_type: PurgeType,
|
||||
_trace: &SpanHandle,
|
||||
) -> Result<bool> {
|
||||
// This usually purges the primary key because, without a lookup, the variance key is usually
|
||||
// empty
|
||||
let hash = key.combined();
|
||||
|
@ -525,7 +530,9 @@ mod test {
|
|||
|
||||
assert!(cache.temp.read().contains_key(&hash));
|
||||
|
||||
let result = cache.purge(&key, &Span::inactive().handle()).await;
|
||||
let result = cache
|
||||
.purge(&key, PurgeType::Invalidation, &Span::inactive().handle())
|
||||
.await;
|
||||
assert!(result.is_ok());
|
||||
|
||||
assert!(!cache.temp.read().contains_key(&hash));
|
||||
|
@ -551,7 +558,9 @@ mod test {
|
|||
|
||||
assert!(cache.cached.read().contains_key(&hash));
|
||||
|
||||
let result = cache.purge(&key, &Span::inactive().handle()).await;
|
||||
let result = cache
|
||||
.purge(&key, PurgeType::Invalidation, &Span::inactive().handle())
|
||||
.await;
|
||||
assert!(result.is_ok());
|
||||
|
||||
assert!(!cache.cached.read().contains_key(&hash));
|
||||
|
|
|
@ -119,7 +119,7 @@ impl<C: CachePut> CachePutCtx<C> {
|
|||
.handle();
|
||||
for item in evicted {
|
||||
// TODO: warn/log the error
|
||||
let _ = self.storage.purge(&item, &trace).await;
|
||||
let _ = self.storage.purge(&item, PurgeType::Eviction, &trace).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,15 @@ use async_trait::async_trait;
|
|||
use pingora_error::Result;
|
||||
use std::any::Any;
|
||||
|
||||
/// The reason a purge() is called
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum PurgeType {
|
||||
// For eviction because the cache storage is full
|
||||
Eviction,
|
||||
// For cache invalidation
|
||||
Invalidation,
|
||||
}
|
||||
|
||||
/// Cache storage interface
|
||||
#[async_trait]
|
||||
pub trait Storage {
|
||||
|
@ -45,7 +54,12 @@ pub trait Storage {
|
|||
/// Delete the cached asset for the given key
|
||||
///
|
||||
/// [CompactCacheKey] is used here because it is how eviction managers store the keys
|
||||
async fn purge(&'static self, key: &CompactCacheKey, trace: &SpanHandle) -> Result<bool>;
|
||||
async fn purge(
|
||||
&'static self,
|
||||
key: &CompactCacheKey,
|
||||
purge_type: PurgeType,
|
||||
trace: &SpanHandle,
|
||||
) -> Result<bool>;
|
||||
|
||||
/// Update cache header and metadata for the already stored asset.
|
||||
async fn update_meta(
|
||||
|
|
Loading…
Reference in a new issue