Coverage Report

Created: 2026-06-10 02:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/tablet/tablet_schema_cache.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <cstdint>
21
#include <string>
22
#include <utility>
23
24
#include "runtime/exec_env.h"
25
#include "runtime/memory/lru_cache_policy.h"
26
#include "storage/tablet/tablet_fwd.h"
27
28
namespace doris {
29
30
class OlapTableSchemaParam;
31
struct OlapTableIndexSchema;
32
33
class TabletSchemaCache : public LRUCachePolicy {
34
public:
35
    using LRUCachePolicy::insert;
36
37
    TabletSchemaCache(size_t capacity)
38
1
            : LRUCachePolicy(CachePolicy::CacheType::TABLET_SCHEMA_CACHE, capacity,
39
1
                             LRUCacheType::NUMBER, config::tablet_schema_cache_recycle_interval,
40
1
                             /*num_shards*/ 32,
41
1
                             /*element_count_capacity*/ 0, /*enable_prune*/ true,
42
1
                             /*is_lru_k*/ false) {}
43
44
1
    static TabletSchemaCache* create_global_schema_cache(size_t capacity) {
45
1
        auto* res = new TabletSchemaCache(capacity);
46
1
        return res;
47
1
    }
48
49
12.7k
    static TabletSchemaCache* instance() {
50
12.7k
        return ExecEnv::GetInstance()->get_tablet_schema_cache();
51
12.7k
    }
52
53
    std::pair<Cache::Handle*, TabletSchemaSPtr> insert(const std::string& key);
54
55
    std::pair<Cache::Handle*, TabletSchemaSPtr> insert(const std::string& key,
56
                                                       TabletSchemaSPtr tablet_schema);
57
58
    std::pair<Cache::Handle*, TabletSchemaSPtr> lookup_schema(const std::string& key);
59
60
    static std::string build_load_schema_cache_key(int64_t index_id,
61
                                                   const OlapTableSchemaParam* table_schema_param,
62
                                                   const TabletSchema& ori_tablet_schema,
63
                                                   const OlapTableIndexSchema* index_schema);
64
65
    void release(Cache::Handle*);
66
67
private:
68
    class CacheValue : public LRUCacheValueBase {
69
    public:
70
        ~CacheValue() override;
71
72
        TabletSchemaSPtr tablet_schema;
73
    };
74
};
75
76
} // namespace doris