cambyzju commented on code in PR #29818: URL: https://github.com/apache/doris/pull/29818#discussion_r1449760593
########## be/src/olap/storage_engine.h: ########## @@ -492,7 +496,65 @@ class StorageEngine { std::atomic<bool> _need_clean_trash {false}; + std::unique_ptr<CreateTabletIdxCache> _create_tablet_idx_lru_cache; + DISALLOW_COPY_AND_ASSIGN(StorageEngine); }; +// lru cache for create tabelt round robin in disks +// key: partitionId_medium +// value: index +class CreateTabletIdxCache : public LRUCachePolicy { +public: + // get key, delimiter with DELIMITER '-' + static std::string get_key(int64_t partition_id, TStorageMedium::type medium) { + return fmt::format("{}-{}", partition_id, medium); + } + + // -1 not found key in lru + int64 get_index(const std::string& key) { + if (key.empty()) { + return {}; + } + auto lru_handle = cache()->lookup(key); + if (lru_handle) { + Defer release([cache = cache(), lru_handle] { cache->release(lru_handle); }); + auto value = (CacheValue*)cache()->value(lru_handle); + value->last_visit_time = UnixMillis(); + VLOG_DEBUG << "use create tablet idx cache key=" << key << " value=" << value->idx; + return value->idx; + } + return -1; + } + + void set_index(const std::string& key, int next_idx) { + assert(next_idx >= 0); + if (key.empty()) { + return; + } + CacheValue* value = new CacheValue; + value->last_visit_time = UnixMillis(); + value->idx = next_idx; + auto deleter = [](const doris::CacheKey& key, void* value) { + CacheValue* cache_value = (CacheValue*)value; + delete cache_value; + }; + auto lru_handle = + cache()->insert(key, value, 1, deleter, CachePriority::NORMAL, sizeof(int64)); + cache()->release(lru_handle); + } + + struct CacheValue : public LRUCacheValueBase { + int64 idx = 0; + }; + + CreateTabletIdxCache(size_t capacity) + : LRUCachePolicy(CachePolicy::CacheType::CREATE_TABLET_RR_IDX_CACHE, capacity, + LRUCacheType::NUMBER, + /*stale_sweep_time_s*/ 30 * 60) {} + +private: + static constexpr char DELIMITER = '-'; Review Comment: unused variable `DELIMITER` -- 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