diff options
author | Yuchen Wu <[email protected]> | 2024-06-20 15:32:37 -0700 |
---|---|---|
committer | Edward Wang <[email protected]> | 2024-06-28 12:34:25 -0700 |
commit | f9148430dbbbcf9d3658ba94eb434ae0e77f0be4 (patch) | |
tree | b15b934b0323c5f09128e9abba5beb44325dd07a | |
parent | 03bd29044e8367b9e44ac7b31e0c7aa152cf6b60 (diff) | |
download | pingora-f9148430dbbbcf9d3658ba94eb434ae0e77f0be4.tar.gz pingora-f9148430dbbbcf9d3658ba94eb434ae0e77f0be4.zip |
Report evction/invalidtion types
This helps the storage to log/track different type of cache deletions.
-rw-r--r-- | .bleep | 2 | ||||
-rw-r--r-- | pingora-cache/src/lib.rs | 12 | ||||
-rw-r--r-- | pingora-cache/src/memory.rs | 15 | ||||
-rw-r--r-- | pingora-cache/src/put.rs | 2 | ||||
-rw-r--r-- | pingora-cache/src/storage.rs | 16 |
5 files changed, 38 insertions, 9 deletions
@@ -1 +1 @@ -b8ac54b482f643f04533dcc04061b1575482c92d
\ No newline at end of file +27bf4df19b465281ddc2d348ed6f3f0402fa60cc
\ No newline at end of file diff --git a/pingora-cache/src/lib.rs b/pingora-cache/src/lib.rs index 563727c..6ba057e 100644 --- a/pingora-cache/src/lib.rs +++ b/pingora-cache/src/lib.rs @@ -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 diff --git a/pingora-cache/src/memory.rs b/pingora-cache/src/memory.rs index 3863b2b..dec8f1a 100644 --- a/pingora-cache/src/memory.rs +++ b/pingora-cache/src/memory.rs @@ -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)); diff --git a/pingora-cache/src/put.rs b/pingora-cache/src/put.rs index e29cfad..e1041e0 100644 --- a/pingora-cache/src/put.rs +++ b/pingora-cache/src/put.rs @@ -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; } } diff --git a/pingora-cache/src/storage.rs b/pingora-cache/src/storage.rs index c6365c7..0d4e104 100644 --- a/pingora-cache/src/storage.rs +++ b/pingora-cache/src/storage.rs @@ -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( |