MySQL 8.4.2
Source Code Documentation
metrics_handler.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef METRICS_HANDLER_INCLUDED
25#define METRICS_HANDLER_INCLUDED
26
27#include <atomic>
28#include "my_systime.h"
29
30/*
31 Forward declarations
32*/
33class Gcs_message;
34
35/**
36 @class Metrics
37
38 Handle metrics captured on Group Replication.
39*/
41 public:
42 enum class enum_message_type {
43 CONTROL, // Control messages.
44 DATA // Messages that contain transaction data.
45 };
46
47 Metrics_handler() = default;
48
49 virtual ~Metrics_handler() = default;
50
51 /**
52 Return time in microseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)
53
54 @return time in microseconds.
55 */
56 inline static uint64_t get_current_time() { return my_micro_time(); }
57
58 /**
59 Reset the metrics.
60 */
61 void reset();
62
63 /**
64 Number of control messages sent by this member.
65
66 @return number of messages.
67 */
68 uint64_t get_control_messages_sent_count() const;
69
70 /**
71 Number of messages that contain transaction data sent by this member.
72
73 @return number of messages.
74 */
75 uint64_t get_data_messages_sent_count() const;
76
77 /**
78 Sum of bytes of control messages sent by this member.
79 The size is the over the wire size.
80
81 @return sum of bytes.
82 */
84
85 /**
86 Sum of bytes of messages that contain transaction data sent by this member.
87 The size is the over the wire size.
88
89 @return sum of bytes.
90 */
91 uint64_t get_data_messages_sent_bytes_sum() const;
92
93 /**
94 Sum of the roundtrip time in micro-seconds of control messages sent by this
95 member. The time is measured between the send and the delivery of
96 the message on the sender member.
97 @see Metrics_handler::get_current_time()
98
99 @return sum of the roundtrip time.
100 */
102
103 /**
104 Sum of the roundtrip time in micro-seconds of messages that contain
105 transaction data sent by this member. The time is measured between the send
106 and the delivery of the message on the sender member.
107 @see Metrics_handler::get_current_time()
108
109 @return sum of the roundtrip time.
110 */
112
113 /**
114 Number of transactions executed with group_replication_consistency=BEFORE or
115 BEFORE_AND_AFTER.
116
117 @return number of transactions.
118 */
120
121 /**
122 Sum of the time that the member waited until its `group_replication_applier`
123 channel was consumed before execute the transaction with
124 group_replication_consistency=BEFORE or BEFORE_AND_AFTER.
125 @see Metrics_handler::get_current_time()
126
127 @return sum of the wait time.
128 */
130
131 /**
132 Number of transactions executed with group_replication_consistency=AFTER or
133 BEFORE_AND_AFTER.
134
135 @return number of transactions.
136 */
138
139 /**
140 Sum of the time spent between the delivery of the transaction executed with
141 group_replication_consistency= AFTER or BEFORE_AND_AFTER, and the
142 acknowledge of the other group members that the transaction is prepared.
143 @see Metrics_handler::get_current_time()
144
145 @return sum of the wait time.
146 */
148
149 /**
150 Number of transactions executed with group_replication_consistency=AFTER or
151 BEFORE_AND_AFTER.
152
153 @return number of transactions.
154 */
156
157 /**
158 Sum of the time that transactions on secondaries waited to start, while
159 waiting for transactions from the primary with
160 group_replication_consistency=AFTER or BEFORE_AND_AFTER to be committed.
161 @see Metrics_handler::get_current_time()
162
163 @return sum of the wait time.
164 */
166
167 /**
168 Number of times certification garbage collection did run.
169
170 @return number of transactions.
171 */
173
174 /**
175 Sum of the time that garbage collection runs took.
176 @see Metrics_handler::get_current_time()
177
178 @return sum of the time.
179 */
181
182 /**
183 Account message sent.
184
185 @param message the message to be accounted.
186 */
187 void add_message_sent(const Gcs_message &message);
188
189 /**
190 Account transaction that waited until its `group_replication_applier`
191 channel was consumed before execute the transaction with
192 group_replication_consistency=BEFORE or BEFORE_AND_AFTER.
193 @see Metrics_handler::get_current_time()
194
195 @param begin_timestamp time on which the wait began.
196 @param end_timestamp time on which the wait ended.
197 */
198 void add_transaction_consistency_before_begin(const uint64_t begin_timestamp,
199 const uint64_t end_timestamp);
200
201 /**
202 Account transaction executed with group_replication_consistency=AFTER or
203 BEFORE_AND_AFTER that waited for the acknowledge of the other group members
204 that the transaction is prepared.
205 @see Metrics_handler::get_current_time()
206
207 @param begin_timestamp time on which the wait began.
208 @param end_timestamp time on which the wait ended.
209 */
211 const uint64_t begin_timestamp, const uint64_t end_timestamp);
212
213 /**
214 Account transaction that waited for transactions from the primary with
215 group_replication_consistency=AFTER or BEFORE_AND_AFTER to be committed.
216 @see Metrics_handler::get_current_time()
217
218 @param begin_timestamp time on which the wait began.
219 @param end_timestamp time on which the wait ended.
220 */
221 void add_transaction_consistency_after_sync(const uint64_t begin_timestamp,
222 const uint64_t end_timestamp);
223
224 /**
225 Account a certification garbage collection run.
226 @see Metrics_handler::get_current_time()
227
228 @param begin_timestamp time on which the operation began.
229 @param end_timestamp time on which the operation ended.
230 */
231 void add_garbage_collection_run(const uint64_t begin_timestamp,
232 const uint64_t end_timestamp);
233
234 private:
235 /**
236 Account message sent.
237 @see Metrics_handler::get_current_time()
238
239 @param type message type.
240 @param bytes message length.
241 @param sent_timestamp time on which the message was sent.
242 @param received_timestamp time on which the message was received.
243 */
245 const uint64_t bytes,
246 const uint64_t sent_timestamp,
247 const uint64_t received_timestamp);
248
249 std::atomic<uint64_t> m_control_messages_sent_count{0};
250 std::atomic<uint64_t> m_data_messages_sent_count{0};
251
252 std::atomic<uint64_t> m_control_messages_sent_bytes_sum{0};
253 std::atomic<uint64_t> m_data_messages_sent_bytes_sum{0};
254
257
260
263 0};
264
267
270};
271
272#endif /* METRICS_HANDLER_INCLUDED */
Class that represents the data that is exchanged within a group.
Definition: gcs_message.h:357
Definition: metrics_handler.h:40
uint64_t get_data_messages_sent_bytes_sum() const
Sum of bytes of messages that contain transaction data sent by this member.
Definition: metrics_handler.cc:70
Metrics_handler()=default
std::atomic< uint64_t > m_certification_garbage_collector_time_sum
Definition: metrics_handler.h:269
std::atomic< uint64_t > m_data_messages_sent_bytes_sum
Definition: metrics_handler.h:253
std::atomic< uint64_t > m_data_messages_sent_count
Definition: metrics_handler.h:250
void add_transaction_consistency_after_sync(const uint64_t begin_timestamp, const uint64_t end_timestamp)
Account transaction that waited for transactions from the primary with group_replication_consistency=...
Definition: metrics_handler.cc:279
uint64_t get_transactions_consistency_after_termination_time_sum() const
Sum of the time spent between the delivery of the transaction executed with group_replication_consist...
Definition: metrics_handler.cc:98
std::atomic< uint64_t > m_data_messages_sent_roundtrip_time_sum
Definition: metrics_handler.h:256
uint64_t get_control_messages_sent_count() const
Number of control messages sent by this member.
Definition: metrics_handler.cc:58
enum_message_type
Definition: metrics_handler.h:42
uint64_t get_control_messages_sent_bytes_sum() const
Sum of bytes of control messages sent by this member.
Definition: metrics_handler.cc:66
void add_transaction_consistency_after_termination(const uint64_t begin_timestamp, const uint64_t end_timestamp)
Account transaction executed with group_replication_consistency=AFTER or BEFORE_AND_AFTER that waited...
Definition: metrics_handler.cc:268
void reset()
Reset the metrics.
Definition: metrics_handler.cc:41
std::atomic< uint64_t > m_transactions_consistency_after_sync_time_sum
Definition: metrics_handler.h:266
uint64_t get_transactions_consistency_before_begin_time_sum() const
Sum of the time that the member waited until its group_replication_applier channel was consumed befor...
Definition: metrics_handler.cc:87
uint64_t get_transactions_consistency_after_sync_count() const
Number of transactions executed with group_replication_consistency=AFTER or BEFORE_AND_AFTER.
Definition: metrics_handler.cc:103
uint64_t get_transactions_consistency_before_begin_count() const
Number of transactions executed with group_replication_consistency=BEFORE or BEFORE_AND_AFTER.
Definition: metrics_handler.cc:82
uint64_t get_certification_garbage_collector_time_sum() const
Sum of the time that garbage collection runs took.
Definition: metrics_handler.cc:117
std::atomic< uint64_t > m_transactions_consistency_after_sync_count
Definition: metrics_handler.h:265
std::atomic< uint64_t > m_transactions_consistency_after_termination_time_sum
Definition: metrics_handler.h:262
uint64_t get_certification_garbage_collector_count() const
Number of times certification garbage collection did run.
Definition: metrics_handler.cc:113
void add_message_sent_internal(const enum_message_type type, const uint64_t bytes, const uint64_t sent_timestamp, const uint64_t received_timestamp)
Account message sent.
Definition: metrics_handler.cc:227
void add_garbage_collection_run(const uint64_t begin_timestamp, const uint64_t end_timestamp)
Account a certification garbage collection run.
Definition: metrics_handler.cc:290
uint64_t get_transactions_consistency_after_sync_time_sum() const
Sum of the time that transactions on secondaries waited to start, while waiting for transactions from...
Definition: metrics_handler.cc:108
virtual ~Metrics_handler()=default
std::atomic< uint64_t > m_control_messages_sent_roundtrip_time_sum
Definition: metrics_handler.h:255
void add_message_sent(const Gcs_message &message)
Account message sent.
Definition: metrics_handler.cc:121
std::atomic< uint64_t > m_transactions_consistency_before_begin_count
Definition: metrics_handler.h:258
std::atomic< uint64_t > m_transactions_consistency_after_termination_count
Definition: metrics_handler.h:261
std::atomic< uint64_t > m_control_messages_sent_count
Definition: metrics_handler.h:249
uint64_t get_data_messages_sent_roundtrip_time_sum() const
Sum of the roundtrip time in micro-seconds of messages that contain transaction data sent by this mem...
Definition: metrics_handler.cc:78
uint64_t get_control_messages_sent_roundtrip_time_sum() const
Sum of the roundtrip time in micro-seconds of control messages sent by this member.
Definition: metrics_handler.cc:74
static uint64_t get_current_time()
Return time in microseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)
Definition: metrics_handler.h:56
std::atomic< uint64_t > m_certification_garbage_collector_count
Definition: metrics_handler.h:268
std::atomic< uint64_t > m_transactions_consistency_before_begin_time_sum
Definition: metrics_handler.h:259
uint64_t get_transactions_consistency_after_termination_count() const
Number of transactions executed with group_replication_consistency=AFTER or BEFORE_AND_AFTER.
Definition: metrics_handler.cc:92
uint64_t get_data_messages_sent_count() const
Number of messages that contain transaction data sent by this member.
Definition: metrics_handler.cc:62
std::atomic< uint64_t > m_control_messages_sent_bytes_sum
Definition: metrics_handler.h:252
void add_transaction_consistency_before_begin(const uint64_t begin_timestamp, const uint64_t end_timestamp)
Account transaction that waited until its group_replication_applier channel was consumed before execu...
Definition: metrics_handler.cc:257
Defines for getting and processing the current system type programmatically.
unsigned long long int my_micro_time()
Return time in microseconds.
Definition: my_systime.h:182
required string type
Definition: replication_group_member_actions.proto:34