xinyiZzz commented on code in PR #22041:
URL: https://github.com/apache/doris/pull/22041#discussion_r1274564679


##########
be/src/service/point_query_executor.h:
##########
@@ -186,76 +189,59 @@ class RowCache {
 
 // A cache used for prepare stmt.
 // One connection per stmt perf uuid
-// Use DoublyBufferedData to wrap Cache for performance and thread safe,
-// since it's barely modified
-class LookupCache {
+class LookupConnectionCache : public LRUCachePolicy {
 public:
-    // uuid to reusable
-    using Cache = phmap::flat_hash_map<uint128, std::shared_ptr<Reusable>>;
-    using CacheIter = Cache::iterator;
-
-    LookupCache() = default;
-    static LookupCache& instance() {
-        static LookupCache ins;
-        return ins;
-    }
+    static LookupConnectionCache* instance() { return _s_instance; }
 
-    void add(uint128 cache_id, std::shared_ptr<Reusable> item) {
-        assert(item != nullptr);
-        _double_buffer_cache.Modify(update_cache, std::make_pair(cache_id, 
item));
-    }
+    static void create_global_instance(size_t capacity);
 
-    // find an item, return null if not exist
-    std::shared_ptr<Reusable> get(uint128 cache_id) {
-        butil::DoublyBufferedData<Cache>::ScopedPtr s;
-        if (_double_buffer_cache.Read(&s) != 0) {
-            LOG(WARNING) << "failed to get cache from double buffer data";
-            return nullptr;
-        }
-        auto it = s->find(cache_id);
-        if (it != s->end()) {
-            return it->second;
-        }
-        return nullptr;
+private:
+    friend class PointQueryExecutor;
+    LookupConnectionCache(size_t capacity)
+            : LRUCachePolicy("LookupConnectionCache", capacity, 
LRUCacheType::SIZE,
+                             config::tablet_lookup_cache_clean_interval) {}
+
+    std::string encode_key(__int128_t cache_id) {
+        fmt::memory_buffer buffer;
+        fmt::format_to(buffer, "{}", cache_id);
+        return std::string(buffer.data(), buffer.size());
     }
 
-private:
-    butil::DoublyBufferedData<Cache> _double_buffer_cache;
-    // 30 seconds for expiring an item
-    int32_t _expir_seconds = config::tablet_lookup_cache_clean_interval;
-
-    static size_t update_cache(Cache& old_cache,
-                               const std::pair<uint128, 
std::shared_ptr<Reusable>>& p) {
-        old_cache.emplace(p);
-        return 1;
+    void add(__int128_t cache_id, std::shared_ptr<Reusable> item) {
+        std::string key = encode_key(cache_id);
+        CacheValue* value = new CacheValue;
+        value->last_visit_time = UnixMillis();
+        value->item = item;
+        auto deleter = [](const doris::CacheKey& key, void* value) {
+            CacheValue* cache_value = (CacheValue*)value;
+            delete cache_value;
+        };
+        LOG(INFO) << "Add item mem size " << item->mem_size()

Review Comment:
   Could this log be too frequent
   Maybe add metrics to `add` and `get`



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to