Coverage Report

Created: 2024-11-18 12:21

/root/doris/be/src/olap/base_tablet.cpp
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
#include "olap/base_tablet.h"
19
20
#include <fmt/format.h>
21
22
#include "olap/tablet_fwd.h"
23
#include "olap/tablet_schema_cache.h"
24
#include "util/doris_metrics.h"
25
#include "vec/common/schema_util.h"
26
27
namespace doris {
28
using namespace ErrorCode;
29
30
extern MetricPrototype METRIC_query_scan_bytes;
31
extern MetricPrototype METRIC_query_scan_rows;
32
extern MetricPrototype METRIC_query_scan_count;
33
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(flush_bytes, MetricUnit::BYTES);
34
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(flush_finish_count, MetricUnit::OPERATIONS);
35
36
static bvar::Adder<size_t> g_total_tablet_num("doris_total_tablet_num");
37
38
251
BaseTablet::BaseTablet(TabletMetaSharedPtr tablet_meta) : _tablet_meta(std::move(tablet_meta)) {
39
251
    _metric_entity = DorisMetrics::instance()->metric_registry()->register_entity(
40
251
            fmt::format("Tablet.{}", tablet_id()), {{"tablet_id", std::to_string(tablet_id())}},
41
251
            MetricEntityType::kTablet);
42
251
    INT_COUNTER_METRIC_REGISTER(_metric_entity, query_scan_bytes);
43
251
    INT_COUNTER_METRIC_REGISTER(_metric_entity, query_scan_rows);
44
251
    INT_COUNTER_METRIC_REGISTER(_metric_entity, query_scan_count);
45
251
    INT_COUNTER_METRIC_REGISTER(_metric_entity, flush_bytes);
46
251
    INT_COUNTER_METRIC_REGISTER(_metric_entity, flush_finish_count);
47
251
    g_total_tablet_num << 1;
48
251
}
49
50
250
BaseTablet::~BaseTablet() {
51
250
    DorisMetrics::instance()->metric_registry()->deregister_entity(_metric_entity);
52
250
    g_total_tablet_num << -1;
53
250
}
54
55
25
Status BaseTablet::set_tablet_state(TabletState state) {
56
25
    if (_tablet_meta->tablet_state() == TABLET_SHUTDOWN && state != TABLET_SHUTDOWN) {
57
0
        return Status::Error<META_INVALID_ARGUMENT>(
58
0
                "could not change tablet state from shutdown to {}", state);
59
0
    }
60
25
    _tablet_meta->set_tablet_state(state);
61
25
    return Status::OK();
62
25
}
63
64
0
void BaseTablet::update_max_version_schema(const TabletSchemaSPtr& tablet_schema) {
65
0
    std::lock_guard wrlock(_meta_lock);
66
    // Double Check for concurrent update
67
0
    if (!_max_version_schema ||
68
0
        tablet_schema->schema_version() > _max_version_schema->schema_version()) {
69
0
        _max_version_schema = tablet_schema;
70
0
    }
71
0
}
72
73
0
Status BaseTablet::update_by_least_common_schema(const TabletSchemaSPtr& update_schema) {
74
0
    std::lock_guard wrlock(_meta_lock);
75
0
    CHECK(_max_version_schema->schema_version() >= update_schema->schema_version());
76
0
    TabletSchemaSPtr final_schema;
77
0
    bool check_column_size = true;
78
0
    RETURN_IF_ERROR(vectorized::schema_util::get_least_common_schema(
79
0
            {_max_version_schema, update_schema}, _max_version_schema, final_schema,
80
0
            check_column_size));
81
0
    _max_version_schema = final_schema;
82
0
    VLOG_DEBUG << "dump updated tablet schema: " << final_schema->dump_full_schema();
83
0
    return Status::OK();
84
0
}
85
86
0
uint32_t BaseTablet::get_real_compaction_score() const {
87
0
    const auto& rs_metas = _tablet_meta->all_rs_metas();
88
0
    return std::accumulate(rs_metas.begin(), rs_metas.end(), 0,
89
0
                           [](uint32_t score, const RowsetMetaSharedPtr& rs_meta) {
90
0
                               return score + rs_meta->get_compaction_score();
91
0
                           });
92
0
}
93
94
} /* namespace doris */