Coverage Report

Created: 2024-11-18 12:21

/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
492
    const std::string& tablet_path() const { return _tablet_path; }
47
970
    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
198
    int64_t partition_id() const { return _tablet_meta->partition_id(); }
51
3.68k
    int64_t tablet_id() const { return _tablet_meta->tablet_id(); }
52
228
    int32_t schema_hash() const { return _tablet_meta->schema_hash(); }
53
608
    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
577
    bool enable_unique_key_merge_on_write() const {
56
577
#ifdef BE_TEST
57
577
        if (_tablet_meta == nullptr) {
58
0
            return false;
59
0
        }
60
577
#endif
61
577
        return _tablet_meta->enable_unique_key_merge_on_write();
62
577
    }
63
64
    // Property encapsulated in TabletMeta
65
487
    const TabletMetaSharedPtr& tablet_meta() { return _tablet_meta; }
66
67
    // FIXME(plat1ko): It is not appropriate to expose this lock
68
0
    std::shared_mutex& get_header_lock() { return _meta_lock; }
69
70
    void update_max_version_schema(const TabletSchemaSPtr& tablet_schema);
71
72
    Status update_by_least_common_schema(const TabletSchemaSPtr& update_schema);
73
74
646
    TabletSchemaSPtr tablet_schema() const {
75
646
        std::shared_lock rlock(_meta_lock);
76
646
        return _max_version_schema;
77
646
    }
78
79
    virtual bool exceed_version_limit(int32_t limit) const = 0;
80
81
    virtual Result<std::unique_ptr<RowsetWriter>> create_rowset_writer(RowsetWriterContext& context,
82
                                                                       bool vertical) = 0;
83
84
    virtual Status capture_rs_readers(const Version& spec_version,
85
                                      std::vector<RowSetSplits>* rs_splits,
86
                                      bool skip_missing_version) const = 0;
87
88
    virtual size_t tablet_footprint() = 0;
89
90
    // this method just return the compaction sum on each rowset
91
    // note(tsy): we should unify the compaction score calculation finally
92
    uint32_t get_real_compaction_score() const;
93
94
protected:
95
    mutable std::shared_mutex _meta_lock;
96
    const TabletMetaSharedPtr _tablet_meta;
97
    TabletSchemaSPtr _max_version_schema;
98
99
    std::string _tablet_path;
100
101
    // metrics of this tablet
102
    std::shared_ptr<MetricEntity> _metric_entity;
103
104
public:
105
    IntCounter* query_scan_bytes = nullptr;
106
    IntCounter* query_scan_rows = nullptr;
107
    IntCounter* query_scan_count = nullptr;
108
    IntCounter* flush_bytes = nullptr;
109
    IntCounter* flush_finish_count = nullptr;
110
    std::atomic<int64_t> published_count = 0;
111
112
    std::mutex sample_info_lock;
113
    std::vector<CompactionSampleInfo> sample_infos;
114
    Status last_compaction_status = Status::OK();
115
116
    std::atomic<int64_t> read_block_count = 0;
117
    std::atomic<int64_t> write_count = 0;
118
    std::atomic<int64_t> compaction_count = 0;
119
120
    CompactionStage compaction_stage = CompactionStage::NOT_SCHEDULED;
121
};
122
123
} /* namespace doris */