yiguolei commented on code in PR #67670:
URL: https://github.com/apache/doris/pull/67670#discussion_r4120725126


##########
be/src/util/lru_cache.cpp:
##########
@@ -305,21 +312,39 @@ void LRUCache::_lru_append(LRUHandle* list, LRUHandle* e) 
{
 }
 
 Cache::Handle* LRUCache::lookup(const CacheKey& key, uint32_t hash) {
+    _lookup_count.fetch_add(1, std::memory_order_relaxed);
+    {
+        std::shared_lock l(_mutex);
+        LRUHandle* e = _table.lookup(key, hash);
+        if (e == nullptr) {
+            // LRU-K misses must update the visits list under the exclusive 
lock.
+            if (!_is_lru_k) {
+                _miss_count.fetch_add(1, std::memory_order_relaxed);
+                return nullptr;
+            }
+        } else {
+            DCHECK(e->in_cache);
+            if (e->refs.load(std::memory_order_relaxed) > 1) {

Review Comment:
   感觉这种relaxed 不靠谱啊
   比如你这里load 的时候 refs == 2,然后跑到328 行的时候,实际refs == 1 了或者0了,你继续去refs 实际没意义了。
   感觉合理的做法是用while compare and exchange 的方式搞, 确保compare 的时候refs 是一个大于等于2 
的值,然后同时还把refs + 1 了,这样再执行last_visit_time _hit_count 的修改就很容易



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to