Coverage Report

Created: 2026-11-02 08:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/active_tablet_stats.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 <memory>
22
#include <vector>
23
24
namespace doris {
25
class BaseTablet;
26
27
// One entry of a per-dimension top-N list. Kept thrift-free on purpose so this header
28
// does not drag gen_cpp into the storage layer; conversion lives in task_worker_pool.cpp.
29
struct ActiveTabletCandidate {
30
    int64_t tablet_id = 0;
31
    int64_t delta = 0;
32
    int64_t window_ms = 1;
33
    int64_t last_time_ms = 0;
34
35
    // Rate, not raw delta. Raw deltas are not comparable: a dropped report round commits
36
    // no baseline, so the next delta covers several intervals, and backends report on
37
    // independent phases.
38
178k
    double rate() const {
39
178k
        return static_cast<double>(delta) * 1000.0 / static_cast<double>(window_ms);
40
178k
    }
41
};
42
43
// Collected inside the EXISTING report-tablet walk (no extra traversal). Collection is
44
// strictly read-only on the tablet baselines; commit() is called only after
45
// handle_report() returned true, so a retried or dropped report loses nothing.
46
class ActiveTabletCollector {
47
public:
48
    // Called at the top of each build_all_report_tablets_info() pass.
49
    void start();
50
    // Clock-injecting overload, so tests get exact delta windows. now_ms is wall clock
51
    // (compared against the tablets' activity timestamps, and shipped to FE); now_mono_ms
52
    // is monotonic and feeds the delta window only.
53
    void start(int64_t now_ms, int64_t now_mono_ms);
54
    // Called once per tablet during the walk.
55
    void collect(const std::shared_ptr<BaseTablet>& tablet);
56
    // Per-dimension nth_element by rate. No cross-dimension merging or weighting here:
57
    // query and load counts differ by one to two orders of magnitude, so ranking them
58
    // against each other drops load-heavy tablets as a class. FE owns that trade-off,
59
    // where the split is a mutable config instead of a be.conf restart.
60
    void take_top_n();
61
    // Advance the baselines. ONLY after handle_report() succeeded.
62
    void commit();
63
    // Reset everything; called on each retry of the report loop.
64
    void clear();
65
66
118
    const std::vector<ActiveTabletCandidate>& query_candidates() const { return _query_cands; }
67
103
    const std::vector<ActiveTabletCandidate>& load_candidates() const { return _load_cands; }
68
96
    bool truncated() const { return _truncated; }
69
70
private:
71
    struct Pending {
72
        std::weak_ptr<BaseTablet> tablet;
73
        int64_t scan_count = 0;
74
        int64_t flush_count = 0;
75
    };
76
    std::vector<ActiveTabletCandidate> _query_cands;
77
    std::vector<ActiveTabletCandidate> _load_cands;
78
    std::vector<Pending> _pending;
79
    // Wall clock, compared against the tablets' last query / load timestamps and shipped
80
    // to FE. _now_mono_ms only ever feeds the delta window -- see
81
    // BaseTablet::last_reported_mono_ms.
82
    int64_t _now_ms = 0;
83
    int64_t _now_mono_ms = 0;
84
    bool _truncated = false;
85
};
86
87
} // namespace doris