Coverage Report

Created: 2026-02-06 12:16

/root/doris/be/src/olap/base_tablet.h
Line
Count
Source (jump to first uncovered line)
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 <memory>
21
#include <shared_mutex>
22
#include <string>
23
24
#include "common/status.h"
25
#include "olap/iterators.h"
26
#include "olap/olap_common.h"
27
#include "olap/tablet_fwd.h"
28
#include "olap/tablet_meta.h"
29
#include "util/metrics.h"
30
31
namespace doris {
32
struct RowSetSplits;
33
struct RowsetWriterContext;
34
class RowsetWriter;
35
36
enum class CompactionStage { NOT_SCHEDULED, PENDING, EXECUTING };
37
38
// Base class for all tablet classes
39
class BaseTablet {
40
public:
41
    explicit BaseTablet(TabletMetaSharedPtr tablet_meta);
42
    virtual ~BaseTablet();
43
    BaseTablet(const BaseTablet&) = delete;
44
    BaseTablet& operator=(const BaseTablet&) = delete;
45
46
11.8k
    const std::string& tablet_path() const { return _tablet_path; }
47
1.22k
    TabletState tablet_state() const { return _tablet_meta->tablet_state(); }
48
    Status set_tablet_state(TabletState state);
49
2
    int64_t table_id() const { return _tablet_meta->table_id(); }
50
892
    int64_t partition_id() const { return _tablet_meta->partition_id(); }
51
17.3k
    int64_t tablet_id() const { return _tablet_meta->tablet_id(); }
52
1.38k
    int32_t schema_hash() const { return _tablet_meta->schema_hash(); }
53
621
    KeysType keys_type() const { return _tablet_meta->tablet_schema()->keys_type(); }
54
128
    size_t num_key_columns() const { return _tablet_meta->tablet_schema()->num_key_columns(); }
55
821
    bool enable_unique_key_merge_on_write() const {
56
821
#ifdef BE_TEST
57
821
        if (_tablet_meta == nullptr) {
58
0
            return false;
59
0
        }
60
821
#endif
61
821
        return _tablet_meta->enable_unique_key_merge_on_write();
62
821
    }
63
64
    // Property encapsulated in TabletMeta
65
2.79k
    const TabletMetaSharedPtr& tablet_meta() { return _tablet_meta; }
66
67
    int32 max_version_config();
68
69
    // FIXME(plat1ko): It is not appropriate to expose this lock
70
0
    std::shared_mutex& get_header_lock() { return _meta_lock; }
71
72
    void update_max_version_schema(const TabletSchemaSPtr& tablet_schema);
73
74
    Status update_by_least_common_schema(const TabletSchemaSPtr& update_schema);
75
76
11.1k
    TabletSchemaSPtr tablet_schema() const {
77
11.1k
        std::shared_lock rlock(_meta_lock);
78
11.1k
        return _max_version_schema;
79
11.1k
    }
80
81
    virtual bool exceed_version_limit(int32_t limit) const = 0;
82
83
    virtual Result<std::unique_ptr<RowsetWriter>> create_rowset_writer(RowsetWriterContext& context,
84
                                                                       bool vertical) = 0;
85
86
    virtual Status capture_rs_readers(const Version& spec_version,
87
                                      std::vector<RowSetSplits>* rs_splits,
88
                                      bool skip_missing_version) const = 0;
89
90
    virtual size_t tablet_footprint() = 0;
91
92
    // this method just return the compaction sum on each rowset
93
    // note(tsy): we should unify the compaction score calculation finally
94
    uint32_t get_real_compaction_score() const;
95
96
protected:
97
    mutable std::shared_mutex _meta_lock;
98
    const TabletMetaSharedPtr _tablet_meta;
99
    TabletSchemaSPtr _max_version_schema;
100
101
    std::string _tablet_path;
102
103
    // metrics of this tablet
104
    std::shared_ptr<MetricEntity> _metric_entity;
105
106
public:
107
    IntCounter* query_scan_bytes = nullptr;
108
    IntCounter* query_scan_rows = nullptr;
109
    IntCounter* query_scan_count = nullptr;
110
    IntCounter* flush_bytes = nullptr;
111
    IntCounter* flush_finish_count = nullptr;
112
    std::atomic<int64_t> published_count = 0;
113
114
    std::mutex sample_info_lock;
115
    std::vector<CompactionSampleInfo> sample_infos;
116
    Status last_compaction_status = Status::OK();
117
118
    std::atomic<int64_t> read_block_count = 0;
119
    std::atomic<int64_t> write_count = 0;
120
    std::atomic<int64_t> compaction_count = 0;
121
122
    CompactionStage compaction_stage = CompactionStage::NOT_SCHEDULED;
123
};
124
125
} /* namespace doris */