MySQL 9.1.0
Source Code Documentation
applier_metrics.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
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 CS_MTA_METRICS_AGGREGATOR_H
25#define CS_MTA_METRICS_AGGREGATOR_H
26
27#include <atomic>
30
31namespace cs::apply::instruments {
32
33/// @brief This class contains metrics related to event and transaction
34/// scheduling activities in the replica MTA
36 public:
37 /// @brief Starts the timer when the applier metrics collection began.
38 /// Sets the state to running.
39 /// This can be queried later to know for how long time the stats have been
40 /// collected, i.e., the duration.
41 void start_applier_timer() override;
42
43 /// @brief Calculates the total time the applier ran.
44 /// Sets the state to not running
45 /// Sums to time since start to the total running time
46 void stop_applier_timer() override;
47
48 /// @brief Gets the time point when the metric timer started.
49 /// @return The time point since the collection of statistics started.
50 int64_t get_last_applier_start_micros() const override;
51
52 /// @brief Returns the total time the applier was running
53 /// @return Amount of time the applier threads were running for this channel
54 int64_t get_total_execution_time() const override;
55
56 /// @brief increment the number of transactions committed.
57 /// @param amount the amount of transactions to increment.
58 void inc_transactions_committed_count(int64_t amount) override;
59
60 /// @brief Gets the number of transactions committed.
61 /// @return the number of transactions committed.
62 int64_t get_transactions_committed_count() const override;
63
64 /// @brief increment the number of transactions pending.
65 /// @param amount the amount of transactions to increment.
66 void inc_transactions_received_count(int64_t amount) override;
67
68 /// @brief Gets the number of transactions pending.
69 /// @return the number of transactions waiting execution.
70 int64_t get_transactions_received_count() const override;
71
72 /// @brief increment the size of transactions committed.
73 /// @param amount the size amount to increment.
74 void inc_transactions_committed_size_sum(int64_t amount) override;
75
76 /// @brief Gets the total sum of the size of committed transactions
77 /// @return the total size of committed transactions
78 int64_t get_transactions_committed_size_sum() const override;
79
80 /// @brief increment the pending size of queued transactions.
81 /// @param amount the size amount to increment.
82 void inc_transactions_received_size_sum(int64_t amount) override;
83
84 /// @brief Gets the pending size sum of queued transactions
85 /// @return the exectuted size of pending transactions
86 int64_t get_transactions_received_size_sum() const override;
87
88 /// @brief increment the number of events scheduled by a given amount.
89 /// @param delta the amount of events to increment.
90 void inc_events_committed_count(int64_t delta) override;
91
92 /// @brief Gets the number of events scheduled.
93 /// @return the number of events scheduled.
94 int64_t get_events_committed_count() const override;
95
96 /// @brief Resets the statistics to zero.
97 void reset() override;
98
99 /// @brief Set the metrics breakpoint, if it has not already been set.
100 ///
101 /// @param relay_log_filename relay log name
102 void set_metrics_breakpoint(const char *relay_log_filename) override;
103
104 /// @return true if the coordinator has advanced past the metrics breakpoint.
105 bool is_after_metrics_breakpoint() const override;
106
107 /// If we are before the metrics breakpoint, and the metrics breakpoint is
108 /// equal to the given filename, remember that we are now after the metrics
109 /// breakpoint.
110 void check_metrics_breakpoint(const char *relay_log_filename) override;
111
112 /// @brief Returns time metrics for waits on work from the source
113 /// @return a Time_based_metric_interface object that contains metric
114 /// information on a wait
116
117 /// @brief Returns time metrics for waits on available workers
118 /// @return a Time_based_metric_interface object that contains metric
119 /// information on a wait
121
122 /// @brief Returns time metrics for waits on transaction dependecies on
123 /// workers
124 /// @return a Time_based_metric_interface object that contains metric
125 /// information on a wait
127 override;
128
129 /// @brief Returns time metrics for waits when a worker queue exceeds max
130 /// memory
131 /// @return a Time_based_metric_interface object that contains metric
132 /// information on a wait
135
136 /// @brief Returns time metrics for waits when the worker queues are full
137 /// @return a Time_based_metric_interface object that contains metric
138 /// information on a wait
140
141 /// @brief Returns time metrics for relay log read wait times
142 /// @return a Time_based_metric_interface object that contains metric
143 /// information on a wait
145 override;
146
147 /// @brief Increments the stored values for the commit order metrics.
148 /// @param count The count for commit order waits
149 /// @param time The time waited on commit order
151 int64_t time) override;
152
153 /// @brief Gets the stored number of times we waited on committed order
154 /// @return the stored number of commit order waits
155 int64_t get_number_of_waits_on_commit_order() const override;
156
157 /// @brief Gets the stored summed time waited on commit order
158 /// @return the stored sum of the time waited on commit
159 int64_t get_wait_time_on_commit_order() const override;
160
161 private:
162 /// @brief stats collection start timestamp
163 std::atomic<int64_t> m_last_applier_start_micros{};
164
165 /// @brief total applier execution time
167
168 /// @brief Holds the counter of transactions committed.
169 std::atomic_int64_t m_transactions_committed{0};
170
171 /// @brief Holds the counter of transactions currently pending.
172 std::atomic_int64_t m_transactions_received_count{0};
173
174 /// @brief The first (oldest) relay log that the receiver wrote to after
175 /// metric collection was enabled.
177
178 /// @brief State of the metrics breakpoint
180 /// Breakpoint not set yet (nothing received).
181 unset,
182 /// Breakpoint set by receiver; applier is positioned before it
183 before,
184 /// Breakpoint set by receiver; applier is positioned after it
185 after
186 };
187 /// @brief True if the receiver has initialized m_first_received_relay_log.
188 std::atomic<Metrics_breakpoint_state> m_metrics_breakpoint_state{
190
191 /// @brief Holds the total size of transactions committed till now.
192 std::atomic_int64_t m_transactions_committed_size_sum{0};
193
194 /// @brief Holds the executed event's size of transactions now ongoing
195 std::atomic_int64_t m_transactions_received_size_sum{0};
196
197 /// @brief Holds the counter of events scheduled.
198 std::atomic_int64_t m_events_committed_count{0};
199
200 // wait because there are no transactions to apply ---
201
202 /// @brief Tracks the number and time waited for transactions to apply
204
205 // wait because no workers available ---
206
207 /// @brief Tracks the number and time waited for transactions to apply
209
210 // waits for transaction dependency ---
211
212 /// @brief Tracks the number and time waited for transaction dependencies
214
215 // waits because worker queues memory exceeds max ---
216
217 /// @brief Tracks the number and time waited for transaction dependencies
219
220 // wait because worker queues are full ---
221
222 /// @brief Tracks the number and time waited for transaction dependencies
224
225 // Time spent reading from the relay log ---
226
227 /// @brief Tracks the number and time waited for transaction dependencies
229
230 /// @brief The stored number of time waited for commit order
231 std::atomic_int64_t m_order_commit_wait_count{0};
232
233 /// @brief The stored total amount of time waited for commit order
234 std::atomic_int64_t m_order_commit_waited_time{0};
235};
236} // namespace cs::apply::instruments
237
238#endif /* CS_MTA_METRICS_AGGREGATOR_H */
Abstract class for time based metrics implementations.
Definition: time_based_metric_interface.h:30
Class that encodes how much time we waited for something.
Definition: time_based_metric.h:31
This abstract class is an interface for classes that contain replication applier data as counters and...
Definition: applier_metrics_interface.h:36
This class contains metrics related to event and transaction scheduling activities in the replica MTA...
Definition: applier_metrics.h:35
Metrics_breakpoint_state
State of the metrics breakpoint.
Definition: applier_metrics.h:179
@ before
Breakpoint set by receiver; applier is positioned before it.
@ after
Breakpoint set by receiver; applier is positioned after it.
@ unset
Breakpoint not set yet (nothing received).
Time_based_metric_interface & get_work_from_source_wait_metric() override
Returns time metrics for waits on work from the source.
Definition: applier_metrics.cc:136
Time_based_metric m_wait_for_transaction_dependency
Tracks the number and time waited for transaction dependencies.
Definition: applier_metrics.h:213
std::atomic_int64_t m_order_commit_waited_time
The stored total amount of time waited for commit order.
Definition: applier_metrics.h:234
Time_based_metric m_wait_for_work_from_source
Tracks the number and time waited for transactions to apply.
Definition: applier_metrics.h:203
std::atomic_int64_t m_order_commit_wait_count
The stored number of time waited for commit order.
Definition: applier_metrics.h:231
void inc_events_committed_count(int64_t delta) override
increment the number of events scheduled by a given amount.
Definition: applier_metrics.cc:101
void inc_transactions_received_size_sum(int64_t amount) override
increment the pending size of queued transactions.
Definition: applier_metrics.cc:93
Time_based_metric m_wait_due_to_worker_queue_full
Tracks the number and time waited for transaction dependencies.
Definition: applier_metrics.h:223
std::atomic_int64_t m_transactions_committed
Holds the counter of transactions committed.
Definition: applier_metrics.h:169
void check_metrics_breakpoint(const char *relay_log_filename) override
If we are before the metrics breakpoint, and the metrics breakpoint is equal to the given filename,...
Definition: applier_metrics.cc:124
Time_based_metric_interface & get_worker_queues_full_wait_metric() override
Returns time metrics for waits when the worker queues are full.
Definition: applier_metrics.cc:156
std::atomic_int64_t m_transactions_received_size_sum
Holds the executed event's size of transactions now ongoing.
Definition: applier_metrics.h:195
Time_based_metric m_wait_for_worker_available
Tracks the number and time waited for transactions to apply.
Definition: applier_metrics.h:208
int64_t get_transactions_received_count() const override
Gets the number of transactions pending.
Definition: applier_metrics.cc:81
Time_based_metric_interface & get_transaction_dependency_wait_metric() override
Returns time metrics for waits on transaction dependecies on workers.
Definition: applier_metrics.cc:146
int64_t get_events_committed_count() const override
Gets the number of events scheduled.
Definition: applier_metrics.cc:105
int64_t get_wait_time_on_commit_order() const override
Gets the stored summed time waited on commit order.
Definition: applier_metrics.cc:175
std::atomic_int64_t m_transactions_committed_size_sum
Holds the total size of transactions committed till now.
Definition: applier_metrics.h:192
std::atomic< Metrics_breakpoint_state > m_metrics_breakpoint_state
True if the receiver has initialized m_first_received_relay_log.
Definition: applier_metrics.h:188
int64_t get_last_applier_start_micros() const override
Gets the time point when the metric timer started.
Definition: applier_metrics.cc:61
int64_t get_transactions_committed_size_sum() const override
Gets the total sum of the size of committed transactions.
Definition: applier_metrics.cc:89
int64_t get_transactions_received_size_sum() const override
Gets the pending size sum of queued transactions.
Definition: applier_metrics.cc:97
void set_metrics_breakpoint(const char *relay_log_filename) override
Set the metrics breakpoint, if it has not already been set.
Definition: applier_metrics.cc:109
Time_based_metric_interface & get_workers_available_wait_metric() override
Returns time metrics for waits on available workers.
Definition: applier_metrics.cc:141
void inc_transactions_committed_size_sum(int64_t amount) override
increment the size of transactions committed.
Definition: applier_metrics.cc:85
int64_t get_total_execution_time() const override
Returns the total time the applier was running.
Definition: applier_metrics.cc:65
void inc_transactions_committed_count(int64_t amount) override
increment the number of transactions committed.
Definition: applier_metrics.cc:69
void reset() override
Resets the statistics to zero.
Definition: applier_metrics.cc:29
Time_based_metric_interface & get_time_to_read_from_relay_log_metric() override
Returns time metrics for relay log read wait times.
Definition: applier_metrics.cc:161
void inc_commit_order_wait_stored_metrics(int64_t count, int64_t time) override
Increments the stored values for the commit order metrics.
Definition: applier_metrics.cc:165
int64_t get_transactions_committed_count() const override
Gets the number of transactions committed.
Definition: applier_metrics.cc:73
Time_based_metric_interface & get_worker_queues_memory_exceeds_max_wait_metric() override
Returns time metrics for waits when a worker queue exceeds max memory.
Definition: applier_metrics.cc:151
std::atomic_int64_t m_transactions_received_count
Holds the counter of transactions currently pending.
Definition: applier_metrics.h:172
void start_applier_timer() override
Starts the timer when the applier metrics collection began.
Definition: applier_metrics.cc:50
std::string m_first_received_relay_log
The first (oldest) relay log that the receiver wrote to after metric collection was enabled.
Definition: applier_metrics.h:176
Time_based_metric m_sum_applier_execution_time
total applier execution time
Definition: applier_metrics.h:166
void inc_transactions_received_count(int64_t amount) override
increment the number of transactions pending.
Definition: applier_metrics.cc:77
std::atomic_int64_t m_events_committed_count
Holds the counter of events scheduled.
Definition: applier_metrics.h:198
void stop_applier_timer() override
Calculates the total time the applier ran.
Definition: applier_metrics.cc:57
Time_based_metric m_wait_due_to_worker_queues_memory_exceeds_max
Tracks the number and time waited for transaction dependencies.
Definition: applier_metrics.h:218
bool is_after_metrics_breakpoint() const override
Definition: applier_metrics.cc:119
int64_t get_number_of_waits_on_commit_order() const override
Gets the stored number of times we waited on committed order.
Definition: applier_metrics.cc:171
Time_based_metric m_time_to_read_from_relay_log
Tracks the number and time waited for transaction dependencies.
Definition: applier_metrics.h:228
std::atomic< int64_t > m_last_applier_start_micros
stats collection start timestamp
Definition: applier_metrics.h:163
static int count
Definition: myisam_ftdump.cc:45
Definition: applier_metrics.cc:27