blob: c21f330bd9da1cd3e7ed5be789f48dbe8a59b04a [file]
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#pragma once
#include "runtime/exec_env.h"
#include "runtime/memory/lru_cache_policy.h"
#include "storage/tablet/tablet_fwd.h"
#include "storage/tablet/tablet_schema.h"
namespace doris {
// TabletColumnObjectPool is a cache for TabletColumn/TabletIndex objects. It is used to reduce memory consumption
// when there are a large number of identical TabletColumns/TabletIndex in the cluster, which usually occurs
// when VARIANT type columns are modified and added, each Rowset has an individual TabletSchema.
// Excessive TabletSchemas can lead to significant memory overhead. Reusing memory for identical
// TabletColumns would greatly reduce this memory consumption.
class TabletColumnObjectPool : public LRUCachePolicy {
public:
TabletColumnObjectPool(size_t capacity)
: LRUCachePolicy(CachePolicy::CacheType::TABLET_COLUMN_OBJECT_POOL, capacity,
LRUCacheType::NUMBER, config::tablet_schema_cache_recycle_interval,
/*num_shards*/ 32,
/*element_count_capacity*/ 0, /*enable_prune*/ true,
/*is_lru_k*/ false) {}
static TabletColumnObjectPool* create_global_column_cache(size_t capacity) {
auto* res = new TabletColumnObjectPool(capacity);
return res;
}
static TabletColumnObjectPool* instance() {
return ExecEnv::GetInstance()->get_tablet_column_object_pool();
}
std::pair<Cache::Handle*, TabletColumnPtr> insert(const std::string& key);
std::pair<Cache::Handle*, TabletIndexPtr> insert_index(const std::string& key);
private:
template <typename T>
struct BaseCacheValue : public LRUCacheValueBase {
~BaseCacheValue() override;
std::shared_ptr<T> value;
};
using CacheValue = BaseCacheValue<TabletColumn>;
using IndexCacheValue = BaseCacheValue<TabletIndex>;
};
} // namespace doris