/root/doris/cloud/src/common/bvars.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 <bthread/mutex.h> |
21 | | #include <bvar/bvar.h> |
22 | | #include <bvar/latency_recorder.h> |
23 | | |
24 | | #include <cstdint> |
25 | | #include <map> |
26 | | #include <memory> |
27 | | #include <mutex> |
28 | | #include <string> |
29 | | #include <type_traits> |
30 | | |
31 | | /** |
32 | | * Manage bvars that with similar names (identical prefix) |
33 | | * ${module}_${name}_${tag} |
34 | | * where `tag` is added automatically when calling `get` or `put` |
35 | | */ |
36 | | template <typename Bvar, bool is_status = false> |
37 | | class BvarWithTag { |
38 | | public: |
39 | | BvarWithTag(std::string module, std::string name) |
40 | 1.84k | : module_(std::move(module)), name_(std::move(name)) {} _ZN11BvarWithTagIN4bvar15LatencyRecorderELb0EEC2ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_ Line | Count | Source | 40 | 1.44k | : module_(std::move(module)), name_(std::move(name)) {} |
_ZN11BvarWithTagIN4bvar6StatusIlvEELb1EEC2ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES9_ Line | Count | Source | 40 | 391 | : module_(std::move(module)), name_(std::move(name)) {} |
|
41 | | |
42 | | template <typename ValType> |
43 | | requires std::is_integral_v<ValType> |
44 | 12.9k | void put(const std::string& tag, ValType value) { |
45 | 12.9k | std::shared_ptr<Bvar> instance = nullptr; |
46 | 12.9k | { |
47 | 12.9k | std::lock_guard<bthread::Mutex> l(mutex_); |
48 | 12.9k | auto it = bvar_map_.find(tag); |
49 | 12.9k | if (it == bvar_map_.end()) { |
50 | 932 | instance = std::make_shared<Bvar>(module_, name_ + "_" + tag, ValType()); |
51 | 932 | bvar_map_[tag] = instance; |
52 | 12.0k | } else { |
53 | 12.0k | instance = it->second; |
54 | 12.0k | } |
55 | 12.9k | } |
56 | | // FIXME(gavin): check bvar::Adder and more |
57 | 12.9k | if constexpr (std::is_same_v<Bvar, bvar::LatencyRecorder>) { |
58 | 94 | (*instance) << value; |
59 | 94 | } else if constexpr (is_status) { |
60 | 94 | instance->set_value(value); |
61 | 94 | } else { |
62 | | // This branch mean to be unreachable, add an assert(false) here to |
63 | | // prevent missing branch match. |
64 | | // Postpone deduction of static_assert by evaluating sizeof(T) |
65 | 12.9k | static_assert(!sizeof(Bvar), "all types must be matched with if constexpr"); |
66 | 12.9k | } |
67 | 12.9k | } _ZN11BvarWithTagIN4bvar15LatencyRecorderELb0EE3putIlEEvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_ Line | Count | Source | 44 | 12.8k | void put(const std::string& tag, ValType value) { | 45 | 12.8k | std::shared_ptr<Bvar> instance = nullptr; | 46 | 12.8k | { | 47 | 12.8k | std::lock_guard<bthread::Mutex> l(mutex_); | 48 | 12.8k | auto it = bvar_map_.find(tag); | 49 | 12.8k | if (it == bvar_map_.end()) { | 50 | 855 | instance = std::make_shared<Bvar>(module_, name_ + "_" + tag, ValType()); | 51 | 855 | bvar_map_[tag] = instance; | 52 | 12.0k | } else { | 53 | 12.0k | instance = it->second; | 54 | 12.0k | } | 55 | 12.8k | } | 56 | | // FIXME(gavin): check bvar::Adder and more | 57 | 12.8k | if constexpr (std::is_same_v<Bvar, bvar::LatencyRecorder>) { | 58 | 12.8k | (*instance) << value; | 59 | 12.8k | } else if constexpr (is_status) { | 60 | 12.8k | instance->set_value(value); | 61 | 12.8k | } else { | 62 | | // This branch mean to be unreachable, add an assert(false) here to | 63 | | // prevent missing branch match. | 64 | | // Postpone deduction of static_assert by evaluating sizeof(T) | 65 | 12.8k | static_assert(!sizeof(Bvar), "all types must be matched with if constexpr"); | 66 | 12.8k | } | 67 | 12.8k | } |
_ZN11BvarWithTagIN4bvar6StatusIlvEELb1EE3putIlEEvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_ Line | Count | Source | 44 | 94 | void put(const std::string& tag, ValType value) { | 45 | 94 | std::shared_ptr<Bvar> instance = nullptr; | 46 | 94 | { | 47 | 94 | std::lock_guard<bthread::Mutex> l(mutex_); | 48 | 94 | auto it = bvar_map_.find(tag); | 49 | 94 | if (it == bvar_map_.end()) { | 50 | 77 | instance = std::make_shared<Bvar>(module_, name_ + "_" + tag, ValType()); | 51 | 77 | bvar_map_[tag] = instance; | 52 | 77 | } else { | 53 | 17 | instance = it->second; | 54 | 17 | } | 55 | 94 | } | 56 | | // FIXME(gavin): check bvar::Adder and more | 57 | 94 | if constexpr (std::is_same_v<Bvar, bvar::LatencyRecorder>) { | 58 | 94 | (*instance) << value; | 59 | 94 | } else if constexpr (is_status) { | 60 | 94 | instance->set_value(value); | 61 | 94 | } else { | 62 | | // This branch mean to be unreachable, add an assert(false) here to | 63 | | // prevent missing branch match. | 64 | | // Postpone deduction of static_assert by evaluating sizeof(T) | 65 | 94 | static_assert(!sizeof(Bvar), "all types must be matched with if constexpr"); | 66 | 94 | } | 67 | 94 | } |
|
68 | | |
69 | 544 | std::shared_ptr<Bvar> get(const std::string& tag) { |
70 | 544 | std::shared_ptr<Bvar> instance = nullptr; |
71 | 544 | std::lock_guard<bthread::Mutex> l(mutex_); |
72 | | |
73 | 544 | auto it = bvar_map_.find(tag); |
74 | 544 | if (it == bvar_map_.end()) { |
75 | 1 | instance = std::make_shared<Bvar>(module_, name_ + "_" + tag); |
76 | 1 | bvar_map_[tag] = instance; |
77 | 1 | return instance; |
78 | 1 | } |
79 | 543 | return it->second; |
80 | 544 | } |
81 | | |
82 | | void remove(const std::string& tag) { |
83 | | std::lock_guard<bthread::Mutex> l(mutex_); |
84 | | bvar_map_.erase(tag); |
85 | | } |
86 | | |
87 | | private: |
88 | | bthread::Mutex mutex_; |
89 | | std::string module_; |
90 | | std::string name_; |
91 | | std::map<std::string, std::shared_ptr<Bvar>> bvar_map_; |
92 | | }; |
93 | | |
94 | | using BvarLatencyRecorderWithTag = BvarWithTag<bvar::LatencyRecorder>; |
95 | | |
96 | | template <typename T> |
97 | | requires std::is_integral_v<T> |
98 | | using BvarStatusWithTag = BvarWithTag<bvar::Status<T>, true>; |
99 | | |
100 | | // meta-service's bvars |
101 | | extern BvarLatencyRecorderWithTag g_bvar_ms_begin_txn; |
102 | | extern BvarLatencyRecorderWithTag g_bvar_ms_precommit_txn; |
103 | | extern BvarLatencyRecorderWithTag g_bvar_ms_commit_txn; |
104 | | extern BvarLatencyRecorderWithTag g_bvar_ms_commit_txn_eventually; |
105 | | extern BvarLatencyRecorderWithTag g_bvar_ms_abort_txn; |
106 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_txn; |
107 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_current_max_txn_id; |
108 | | extern BvarLatencyRecorderWithTag g_bvar_ms_check_txn_conflict; |
109 | | extern BvarLatencyRecorderWithTag g_bvar_ms_abort_txn_with_coordinator; |
110 | | extern BvarLatencyRecorderWithTag g_bvar_ms_begin_sub_txn; |
111 | | extern BvarLatencyRecorderWithTag g_bvar_ms_abort_sub_txn; |
112 | | extern BvarLatencyRecorderWithTag g_bvar_ms_clean_txn_label; |
113 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_version; |
114 | | extern BvarLatencyRecorderWithTag g_bvar_ms_batch_get_version; |
115 | | extern BvarLatencyRecorderWithTag g_bvar_ms_create_tablets; |
116 | | extern BvarLatencyRecorderWithTag g_bvar_ms_update_tablet; |
117 | | extern BvarLatencyRecorderWithTag g_bvar_ms_update_tablet_schema; |
118 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_tablet; |
119 | | extern BvarLatencyRecorderWithTag g_bvar_ms_prepare_rowset; |
120 | | extern BvarLatencyRecorderWithTag g_bvar_ms_commit_rowset; |
121 | | extern BvarLatencyRecorderWithTag g_bvar_ms_update_tmp_rowset; |
122 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_rowset; |
123 | | extern BvarLatencyRecorderWithTag g_bvar_ms_drop_index; |
124 | | extern BvarLatencyRecorderWithTag g_bvar_ms_prepare_index; |
125 | | extern BvarLatencyRecorderWithTag g_bvar_ms_commit_index; |
126 | | extern BvarLatencyRecorderWithTag g_bvar_ms_prepare_partition; |
127 | | extern BvarLatencyRecorderWithTag g_bvar_ms_commit_partition; |
128 | | extern BvarLatencyRecorderWithTag g_bvar_ms_drop_partition; |
129 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_tablet_stats; |
130 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_obj_store_info; |
131 | | extern BvarLatencyRecorderWithTag g_bvar_ms_alter_obj_store_info; |
132 | | extern BvarLatencyRecorderWithTag g_bvar_ms_alter_storage_vault; |
133 | | extern BvarLatencyRecorderWithTag g_bvar_ms_create_instance; |
134 | | extern BvarLatencyRecorderWithTag g_bvar_ms_alter_instance; |
135 | | extern BvarLatencyRecorderWithTag g_bvar_ms_alter_cluster; |
136 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_cluster; |
137 | | extern BvarLatencyRecorderWithTag g_bvar_ms_create_stage; |
138 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_stage; |
139 | | extern BvarLatencyRecorderWithTag g_bvar_ms_drop_stage; |
140 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_iam; |
141 | | extern BvarLatencyRecorderWithTag g_bvar_ms_update_ak_sk; |
142 | | extern BvarLatencyRecorderWithTag g_bvar_ms_alter_iam; |
143 | | extern BvarLatencyRecorderWithTag g_bvar_ms_alter_ram_user; |
144 | | extern BvarLatencyRecorderWithTag g_bvar_ms_begin_copy; |
145 | | extern BvarLatencyRecorderWithTag g_bvar_ms_finish_copy; |
146 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_copy_job; |
147 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_copy_files; |
148 | | extern BvarLatencyRecorderWithTag g_bvar_ms_filter_copy_files; |
149 | | extern BvarLatencyRecorderWithTag g_bvar_ms_start_tablet_job; |
150 | | extern BvarLatencyRecorderWithTag g_bvar_ms_finish_tablet_job; |
151 | | extern BvarLatencyRecorderWithTag g_bvar_ms_update_delete_bitmap; |
152 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_delete_bitmap; |
153 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_delete_bitmap_update_lock; |
154 | | extern BvarLatencyRecorderWithTag g_bvar_ms_remove_delete_bitmap; |
155 | | extern BvarLatencyRecorderWithTag g_bvar_ms_remove_delete_bitmap_update_lock; |
156 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_cluster_status; |
157 | | extern BvarLatencyRecorderWithTag g_bvar_ms_set_cluster_status; |
158 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_instance; |
159 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_rl_task_commit_attach; |
160 | | extern BvarLatencyRecorderWithTag g_bvar_ms_reset_rl_progress; |
161 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_txn_id; |
162 | | extern BvarLatencyRecorderWithTag g_bvar_ms_check_kv; |
163 | | extern BvarLatencyRecorderWithTag g_bvar_ms_get_schema_dict; |
164 | | extern bvar::Adder<int64_t> g_bvar_update_delete_bitmap_fail_counter; |
165 | | extern bvar::Adder<int64_t> g_bvar_get_delete_bitmap_fail_counter; |
166 | | |
167 | | // recycler's bvars |
168 | | extern BvarStatusWithTag<int64_t> g_bvar_recycler_recycle_index_earlest_ts; |
169 | | extern BvarStatusWithTag<int64_t> g_bvar_recycler_recycle_partition_earlest_ts; |
170 | | extern BvarStatusWithTag<int64_t> g_bvar_recycler_recycle_rowset_earlest_ts; |
171 | | extern BvarStatusWithTag<int64_t> g_bvar_recycler_recycle_tmp_rowset_earlest_ts; |
172 | | extern BvarStatusWithTag<int64_t> g_bvar_recycler_recycle_expired_txn_label_earlest_ts; |
173 | | |
174 | | // txn_kv's bvars |
175 | | extern bvar::LatencyRecorder g_bvar_txn_kv_get; |
176 | | extern bvar::LatencyRecorder g_bvar_txn_kv_range_get; |
177 | | extern bvar::LatencyRecorder g_bvar_txn_kv_put; |
178 | | extern bvar::LatencyRecorder g_bvar_txn_kv_commit; |
179 | | extern bvar::LatencyRecorder g_bvar_txn_kv_atomic_set_ver_key; |
180 | | extern bvar::LatencyRecorder g_bvar_txn_kv_atomic_set_ver_value; |
181 | | extern bvar::LatencyRecorder g_bvar_txn_kv_atomic_add; |
182 | | extern bvar::LatencyRecorder g_bvar_txn_kv_remove; |
183 | | extern bvar::LatencyRecorder g_bvar_txn_kv_range_remove; |
184 | | extern bvar::LatencyRecorder g_bvar_txn_kv_get_read_version; |
185 | | extern bvar::LatencyRecorder g_bvar_txn_kv_get_committed_version; |
186 | | extern bvar::LatencyRecorder g_bvar_txn_kv_batch_get; |
187 | | |
188 | | extern bvar::Adder<int64_t> g_bvar_txn_kv_commit_error_counter; |
189 | | extern bvar::Adder<int64_t> g_bvar_txn_kv_commit_conflict_counter; |
190 | | extern bvar::Adder<int64_t> g_bvar_txn_kv_get_count_normalized; |
191 | | |
192 | | extern bvar::Adder<int64_t> g_bvar_delete_bitmap_lock_txn_put_conflict_counter; |
193 | | extern bvar::Adder<int64_t> g_bvar_delete_bitmap_lock_txn_remove_conflict_by_fail_counter; |
194 | | extern bvar::Adder<int64_t> g_bvar_delete_bitmap_lock_txn_remove_conflict_by_load_counter; |
195 | | extern bvar::Adder<int64_t> |
196 | | g_bvar_delete_bitmap_lock_txn_remove_conflict_by_compaction_commit_counter; |
197 | | extern bvar::Adder<int64_t> |
198 | | g_bvar_delete_bitmap_lock_txn_remove_conflict_by_compaction_lease_counter; |
199 | | extern bvar::Adder<int64_t> |
200 | | g_bvar_delete_bitmap_lock_txn_remove_conflict_by_compaction_abort_counter; |
201 | | |
202 | | extern const int64_t BVAR_FDB_INVALID_VALUE; |
203 | | extern bvar::Status<int64_t> g_bvar_fdb_client_count; |
204 | | extern bvar::Status<int64_t> g_bvar_fdb_configuration_coordinators_count; |
205 | | extern bvar::Status<int64_t> g_bvar_fdb_configuration_usable_regions; |
206 | | extern bvar::Status<int64_t> g_bvar_fdb_coordinators_unreachable_count; |
207 | | extern bvar::Status<int64_t> g_bvar_fdb_fault_tolerance_count; |
208 | | extern bvar::Status<int64_t> g_bvar_fdb_data_average_partition_size_bytes; |
209 | | extern bvar::Status<int64_t> g_bvar_fdb_data_log_server_space_bytes; |
210 | | extern bvar::Status<int64_t> g_bvar_fdb_data_moving_data_highest_priority; |
211 | | extern bvar::Status<int64_t> g_bvar_fdb_data_moving_data_in_flight_bytes; |
212 | | extern bvar::Status<int64_t> g_bvar_fdb_data_moving_data_in_queue_bytes; |
213 | | extern bvar::Status<int64_t> g_bvar_fdb_data_moving_total_written_bytes; |
214 | | extern bvar::Status<int64_t> g_bvar_fdb_data_partition_count; |
215 | | extern bvar::Status<int64_t> g_bvar_fdb_data_storage_server_space_bytes; |
216 | | extern bvar::Status<int64_t> g_bvar_fdb_data_state_min_replicas_remaining; |
217 | | extern bvar::Status<int64_t> g_bvar_fdb_data_total_kv_size_bytes; |
218 | | extern bvar::Status<int64_t> g_bvar_fdb_data_total_disk_used_bytes; |
219 | | extern bvar::Status<int64_t> g_bvar_fdb_generation; |
220 | | extern bvar::Status<int64_t> g_bvar_fdb_incompatible_connections; |
221 | | extern bvar::Status<int64_t> g_bvar_fdb_latency_probe_transaction_start_ns; |
222 | | extern bvar::Status<int64_t> g_bvar_fdb_latency_probe_commit_ns; |
223 | | extern bvar::Status<int64_t> g_bvar_fdb_latency_probe_read_ns; |
224 | | extern bvar::Status<int64_t> g_bvar_fdb_machines_count; |
225 | | extern bvar::Status<int64_t> g_bvar_fdb_process_count; |
226 | | extern bvar::Status<int64_t> g_bvar_fdb_qos_worst_data_lag_storage_server_ns; |
227 | | extern bvar::Status<int64_t> g_bvar_fdb_qos_worst_durability_lag_storage_server_ns; |
228 | | extern bvar::Status<int64_t> g_bvar_fdb_qos_worst_log_server_queue_bytes; |
229 | | extern bvar::Status<int64_t> g_bvar_fdb_qos_worst_storage_server_queue_bytes; |
230 | | extern bvar::Status<int64_t> g_bvar_fdb_workload_conflict_rate_hz; |
231 | | extern bvar::Status<int64_t> g_bvar_fdb_workload_location_rate_hz; |
232 | | extern bvar::Status<int64_t> g_bvar_fdb_workload_keys_read_hz; |
233 | | extern bvar::Status<int64_t> g_bvar_fdb_workload_read_bytes_hz; |
234 | | extern bvar::Status<int64_t> g_bvar_fdb_workload_read_rate_hz; |
235 | | extern bvar::Status<int64_t> g_bvar_fdb_workload_write_rate_hz; |
236 | | extern bvar::Status<int64_t> g_bvar_fdb_workload_written_bytes_hz; |
237 | | extern bvar::Status<int64_t> g_bvar_fdb_workload_transactions_started_hz; |
238 | | extern bvar::Status<int64_t> g_bvar_fdb_workload_transactions_committed_hz; |
239 | | extern bvar::Status<int64_t> g_bvar_fdb_workload_transactions_rejected_hz; |
240 | | extern bvar::Status<int64_t> g_bvar_fdb_client_thread_busyness_percent; |
241 | | |
242 | | // checker |
243 | | extern BvarStatusWithTag<long> g_bvar_checker_num_scanned; |
244 | | extern BvarStatusWithTag<long> g_bvar_checker_num_scanned_with_segment; |
245 | | extern BvarStatusWithTag<long> g_bvar_checker_num_check_failed; |
246 | | extern BvarStatusWithTag<long> g_bvar_checker_check_cost_s; |
247 | | extern BvarStatusWithTag<long> g_bvar_checker_enqueue_cost_s; |
248 | | extern BvarStatusWithTag<long> g_bvar_checker_last_success_time_ms; |
249 | | extern BvarStatusWithTag<long> g_bvar_checker_instance_volume; |
250 | | extern BvarStatusWithTag<long> g_bvar_inverted_checker_num_scanned; |
251 | | extern BvarStatusWithTag<long> g_bvar_inverted_checker_num_check_failed; |
252 | | |
253 | | extern BvarStatusWithTag<int64_t> g_bvar_inverted_checker_leaked_delete_bitmaps; |
254 | | extern BvarStatusWithTag<int64_t> g_bvar_inverted_checker_abnormal_delete_bitmaps; |
255 | | extern BvarStatusWithTag<int64_t> g_bvar_inverted_checker_delete_bitmaps_scanned; |