xinyiZzz commented on code in PR #29668: URL: https://github.com/apache/doris/pull/29668#discussion_r1444291781
########## be/src/olap/tablet_schema_cache.cpp: ########## @@ -17,71 +17,39 @@ #include "olap/tablet_schema_cache.h" -#include "bvar/bvar.h" +#include <gen_cpp/olap_file.pb.h> -namespace doris { +#include "olap/tablet_schema.h" -bvar::Adder<int64_t> g_tablet_schema_cache_count("tablet_schema_cache_count"); -bvar::Adder<int64_t> g_tablet_schema_cache_columns_count("tablet_schema_cache_columns_count"); +namespace doris { -TabletSchemaSPtr TabletSchemaCache::insert(const std::string& key) { - std::lock_guard guard(_mtx); - auto iter = _cache.find(key); - if (iter == _cache.end()) { - TabletSchemaSPtr tablet_schema_ptr = std::make_shared<TabletSchema>(); +std::pair<Cache::Handle*, TabletSchemaSPtr> TabletSchemaCache::insert(const std::string& key) { + auto* lru_handle = cache()->lookup(key); + TabletSchemaSPtr tablet_schema_ptr; + if (lru_handle) { + auto* value = (CacheValue*)cache()->value(lru_handle); + value->last_visit_time = UnixMillis(); + tablet_schema_ptr = value->tablet_schema; + } else { + auto* value = new CacheValue; + value->last_visit_time = UnixMillis(); + tablet_schema_ptr = std::make_shared<TabletSchema>(); TabletSchemaPB pb; pb.ParseFromString(key); tablet_schema_ptr->init_from_pb(pb); - _cache[key] = tablet_schema_ptr; - g_tablet_schema_cache_count << 1; - g_tablet_schema_cache_columns_count << tablet_schema_ptr->num_columns(); - return tablet_schema_ptr; + value->tablet_schema = tablet_schema_ptr; + auto deleter = [](const doris::CacheKey& key, void* value) { + auto* cache_value = (CacheValue*)value; + delete cache_value; + }; + lru_handle = cache()->insert(key, value, tablet_schema_ptr->num_columns(), deleter, CachePriority::NORMAL); } - return iter->second; + DCHECK(lru_handle != nullptr); + return std::make_pair(lru_handle, tablet_schema_ptr); Review Comment: can release handle after return tablet_schema_ptr ########## be/src/olap/tablet_schema_cache.cpp: ########## @@ -17,71 +17,39 @@ #include "olap/tablet_schema_cache.h" -#include "bvar/bvar.h" +#include <gen_cpp/olap_file.pb.h> -namespace doris { +#include "olap/tablet_schema.h" -bvar::Adder<int64_t> g_tablet_schema_cache_count("tablet_schema_cache_count"); Review Comment: bvar can be retained -- 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