diff options
-rw-r--r-- | .bleep | 2 | ||||
-rw-r--r-- | pingora-cache/src/key.rs | 11 | ||||
-rw-r--r-- | pingora-cache/src/lib.rs | 19 | ||||
-rw-r--r-- | pingora-cache/src/put.rs | 15 |
4 files changed, 33 insertions, 14 deletions
@@ -1 +1 @@ -f664d443d0b1b709e2276e8ea74cc1c26659a372
\ No newline at end of file +624b1bc2959636de01cbb6f9da86df12784fa812
\ No newline at end of file diff --git a/pingora-cache/src/key.rs b/pingora-cache/src/key.rs index 73053cd..ea506f6 100644 --- a/pingora-cache/src/key.rs +++ b/pingora-cache/src/key.rs @@ -18,6 +18,7 @@ use super::*; use blake2::{Blake2b, Digest}; use serde::{Deserialize, Serialize}; +use std::fmt::{Display, Formatter, Result as FmtResult}; // 16-byte / 128-bit key: large enough to avoid collision const KEY_SIZE: usize = 16; @@ -138,6 +139,16 @@ pub struct CompactCacheKey { pub user_tag: Box<str>, // the len should be small to keep memory usage bounded } +impl Display for CompactCacheKey { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!(f, "{}", hex2str(&self.primary))?; + if let Some(var) = &self.variance { + write!(f, ", variance: {}", hex2str(var.as_ref()))?; + } + write!(f, ", user_tag: {}", self.user_tag) + } +} + impl CacheHashKey for CompactCacheKey { fn primary_bin(&self) -> HashBinary { self.primary diff --git a/pingora-cache/src/lib.rs b/pingora-cache/src/lib.rs index c65f602..f747672 100644 --- a/pingora-cache/src/lib.rs +++ b/pingora-cache/src/lib.rs @@ -19,6 +19,7 @@ use http::{method::Method, request::Parts as ReqHeader, response::Parts as RespHeader}; use key::{CacheHashKey, HashBinary}; use lock::WritePermit; +use log::warn; use pingora_error::Result; use pingora_http::ResponseHeader; use rustracing::tag::Tag; @@ -751,16 +752,18 @@ impl HttpCache { let cache_key = key.to_compact(); let meta = inner.meta.as_ref().unwrap(); let evicted = eviction.admit(cache_key, size, meta.0.internal.fresh_until); - // TODO: make this async + // actual eviction can be done async let span = inner.traces.child("eviction"); let handle = span.handle(); - for item in evicted { - // TODO: warn/log the error - let _ = inner - .storage - .purge(&item, PurgeType::Eviction, &handle) - .await; - } + let storage = inner.storage; + tokio::task::spawn(async move { + for item in evicted { + if let Err(e) = storage.purge(&item, PurgeType::Eviction, &handle).await + { + warn!("Failed to purge {item} during eviction for finish miss handler: {e}"); + } + } + }); } inner.traces.finish_miss_span(); Ok(()) diff --git a/pingora-cache/src/put.rs b/pingora-cache/src/put.rs index 851bb4c..9a3a37e 100644 --- a/pingora-cache/src/put.rs +++ b/pingora-cache/src/put.rs @@ -17,6 +17,7 @@ use crate::*; use bytes::Bytes; use http::header; +use log::warn; use pingora_core::protocols::http::{ v1::common::header_value_content_length, HttpTask, ServerSession, }; @@ -112,15 +113,19 @@ impl<C: CachePut> CachePutCtx<C> { let cache_key = self.key.to_compact(); let meta = self.meta.as_ref().unwrap(); let evicted = eviction.admit(cache_key, size, meta.0.internal.fresh_until); - // TODO: make this async + // actual eviction can be done async let trace = self .trace .child("cache put eviction", |o| o.start()) .handle(); - for item in evicted { - // TODO: warn/log the error - let _ = self.storage.purge(&item, PurgeType::Eviction, &trace).await; - } + let storage = self.storage; + tokio::task::spawn(async move { + for item in evicted { + if let Err(e) = storage.purge(&item, PurgeType::Eviction, &trace).await { + warn!("Failed to purge {item} during eviction for cache put: {e}"); + } + } + }); } Ok(()) |