From ffb71de738a22a32df99de13446a7070d027a3e8 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Sat, 9 Sep 2023 19:44:30 +0800 Subject: [PATCH] Fix an issue that the last modified time might be get a little too early if eviction listener is enabled --- src/future/base_cache.rs | 3 ++- src/sync_base/base_cache.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/future/base_cache.rs b/src/future/base_cache.rs index 2b5e5bf9..ccbfc982 100644 --- a/src/future/base_cache.rs +++ b/src/future/base_cache.rs @@ -479,7 +479,6 @@ where ) -> (WriteOp, Instant) { self.retry_interrupted_ops().await; - let ts = self.current_time_from_expiration_clock(); let weight = self.inner.weigh(&key, &value); let op_cnt1 = Arc::new(AtomicU8::new(0)); let op_cnt2 = Arc::clone(&op_cnt1); @@ -494,6 +493,8 @@ where None }; + let ts = self.current_time_from_expiration_clock(); + // Since the cache (cht::SegmentedHashMap) employs optimistic locking // strategy, insert_with_or_modify() may get an insert/modify operation // conflicted with other concurrent hash table operations. In that case, it diff --git a/src/sync_base/base_cache.rs b/src/sync_base/base_cache.rs index 5f39c43b..acfc7515 100644 --- a/src/sync_base/base_cache.rs +++ b/src/sync_base/base_cache.rs @@ -480,7 +480,6 @@ where hash: u64, value: V, ) -> (WriteOp, Instant) { - let ts = self.current_time_from_expiration_clock(); let weight = self.inner.weigh(&key, &value); let op_cnt1 = Rc::new(AtomicU8::new(0)); let op_cnt2 = Rc::clone(&op_cnt1); @@ -491,6 +490,8 @@ where let kl = self.maybe_key_lock(&key); let _klg = &kl.as_ref().map(|kl| kl.lock()); + let ts = self.current_time_from_expiration_clock(); + // Since the cache (cht::SegmentedHashMap) employs optimistic locking // strategy, insert_with_or_modify() may get an insert/modify operation // conflicted with other concurrent hash table operations. In that case, it