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 | 168k | double rate() const { |
39 | 168k | return static_cast<double>(delta) * 1000.0 / static_cast<double>(window_ms); |
40 | 168k | } |
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 | | // Called once per tablet during the walk. |
51 | | void collect(const std::shared_ptr<BaseTablet>& tablet); |
52 | | // Per-dimension nth_element by rate. No cross-dimension merging or weighting here: |
53 | | // query and load counts differ by one to two orders of magnitude, so ranking them |
54 | | // against each other drops load-heavy tablets as a class. FE owns that trade-off, |
55 | | // where the split is a mutable config instead of a be.conf restart. |
56 | | void take_top_n(); |
57 | | // Advance the baselines. ONLY after handle_report() succeeded. |
58 | | void commit(); |
59 | | // Reset everything; called on each retry of the report loop. |
60 | | void clear(); |
61 | | |
62 | 101 | const std::vector<ActiveTabletCandidate>& query_candidates() const { return _query_cands; } |
63 | 88 | const std::vector<ActiveTabletCandidate>& load_candidates() const { return _load_cands; } |
64 | 81 | bool truncated() const { return _truncated; } |
65 | | |
66 | | private: |
67 | | struct Pending { |
68 | | std::weak_ptr<BaseTablet> tablet; |
69 | | int64_t scan_count = 0; |
70 | | int64_t flush_count = 0; |
71 | | }; |
72 | | std::vector<ActiveTabletCandidate> _query_cands; |
73 | | std::vector<ActiveTabletCandidate> _load_cands; |
74 | | std::vector<Pending> _pending; |
75 | | int64_t _now_ms = 0; |
76 | | bool _truncated = false; |
77 | | }; |
78 | | |
79 | | } // namespace doris |