MySQL 9.2.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
applier_metrics.h
Go to the documentation of this file.
1// Copyright (c) 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 CHANGESTREAMS_APPLY_METRICS_APPLIER_METRICS_H
25#define CHANGESTREAMS_APPLY_METRICS_APPLIER_METRICS_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 Remember "now" as the last applier start time.
38 void store_last_applier_start() override;
39
40 /// @brief Return time metric for total applier execution time.
41 /// @return a Time_based_metric_interface object that contains metric
42 /// information on a wait
44
45 /// @brief Gets the time point when the metric timer started.
46 /// @return The time point since the collection of statistics started.
47 int64_t get_last_applier_start_micros() const override;
48
49 /// @brief Returns the total time the applier was running
50 /// @return Amount of time the applier threads were running for this channel
51 int64_t get_total_execution_time() const override;
52
53 /// @brief increment the number of transactions committed.
54 /// @param amount the amount of transactions to increment.
55 void inc_transactions_committed_count(int64_t amount) override;
56
57 /// @brief Gets the number of transactions committed.
58 /// @return the number of transactions committed.
59 int64_t get_transactions_committed_count() const override;
60
61 /// @brief increment the number of transactions pending.
62 /// @param amount the amount of transactions to increment.
63 void inc_transactions_received_count(int64_t amount) override;
64
65 /// @brief Gets the number of transactions pending.
66 /// @return the number of transactions waiting execution.
67 int64_t get_transactions_received_count() const override;
68
69 /// @brief increment the size of transactions committed.
70 /// @param amount the size amount to increment.
71 void inc_transactions_committed_size_sum(int64_t amount) override;
72
73 /// @brief Gets the total sum of the size of committed transactions
74 /// @return the total size of committed transactions
75 int64_t get_transactions_committed_size_sum() const override;
76
77 /// @brief increment the pending size of queued transactions.
78 /// @param amount the size amount to increment.
79 void inc_transactions_received_size_sum(int64_t amount) override;
80
81 /// @brief Gets the pending size sum of queued transactions
82 /// @return the exectuted size of pending transactions
83 int64_t get_transactions_received_size_sum() const override;
84
85 /// @brief increment the number of events scheduled by a given amount.
86 /// @param delta the amount of events to increment.
87 void inc_events_committed_count(int64_t delta) override;
88
89 /// @brief Gets the number of events scheduled.
90 /// @return the number of events scheduled.
91 int64_t get_events_committed_count() const override;
92
93 /// @brief Resets the statistics to zero.
94 void reset() override;
95
96 /// @brief Set the metrics breakpoint, if it has not already been set.
97 ///
98 /// @param relay_log_filename relay log name
99 void set_metrics_breakpoint(const char *relay_log_filename) override;
100
101 /// @return true if the coordinator has advanced past the metrics breakpoint.
102 bool is_after_metrics_breakpoint() const override;
103
104 /// If we are before the metrics breakpoint, and the metrics breakpoint is
105 /// equal to the given filename, remember that we are now after the metrics
106 /// breakpoint.
107 void check_metrics_breakpoint(const char *relay_log_filename) override;
108
109 /// @brief Returns time metrics for waits on work from the source
110 /// @return a Time_based_metric_interface object that contains metric
111 /// information on a wait
113
114 /// @brief Returns time metrics for waits on available workers
115 /// @return a Time_based_metric_interface object that contains metric
116 /// information on a wait
118
119 /// @brief Returns time metrics for waits on transaction dependecies on
120 /// workers
121 /// @return a Time_based_metric_interface object that contains metric
122 /// information on a wait
124 override;
125
126 /// @brief Returns time metrics for waits when a worker queue exceeds max
127 /// memory
128 /// @return a Time_based_metric_interface object that contains metric
129 /// information on a wait
132
133 /// @brief Returns time metrics for waits when the worker queues are full
134 /// @return a Time_based_metric_interface object that contains metric
135 /// information on a wait
137
138 /// @brief Returns time metrics for relay log read wait times
139 /// @return a Time_based_metric_interface object that contains metric
140 /// information on a wait
142 override;
143
144 /// @brief Increments the stored values for the commit order metrics.
145 /// @param count The count for commit order waits
146 /// @param time The time waited on commit order
148 int64_t time) override;
149
150 /// @brief Gets the stored number of times we waited on committed order
151 /// @return the stored number of commit order waits
152 int64_t get_number_of_waits_on_commit_order() const override;
153
154 /// @brief Gets the stored summed time waited on commit order
155 /// @return the stored sum of the time waited on commit
156 int64_t get_wait_time_on_commit_order() const override;
157
158 private:
159 /// @brief stats collection start timestamp
160 std::atomic<int64_t> m_last_applier_start_micros{};
161
162 /// @brief total applier execution time
164
165 /// @brief Holds the counter of transactions committed.
166 std::atomic_int64_t m_transactions_committed{0};
167
168 /// @brief Holds the counter of transactions currently pending.
169 std::atomic_int64_t m_transactions_received_count{0};
170
171 /// @brief The first (oldest) relay log that the receiver wrote to after
172 /// metric collection was enabled.
174
175 /// @brief State of the metrics breakpoint
177 /// Breakpoint not set yet (nothing received).
178 unset,
179 /// Breakpoint set by receiver; applier is positioned before it
180 before,
181 /// Breakpoint set by receiver; applier is positioned after it
182 after
183 };
184 /// @brief True if the receiver has initialized m_first_received_relay_log.
185 std::atomic<Metrics_breakpoint_state> m_metrics_breakpoint_state{
187
188 /// @brief Holds the total size of transactions committed till now.
189 std::atomic_int64_t m_transactions_committed_size_sum{0};
190
191 /// @brief Holds the executed event's size of transactions now ongoing
192 std::atomic_int64_t m_transactions_received_size_sum{0};
193
194 /// @brief Holds the counter of events scheduled.
195 std::atomic_int64_t m_events_committed_count{0};
196
197 // wait because there are no transactions to apply ---
198
199 /// @brief Tracks the number and time waited for transactions to apply
201
202 // wait because no workers available ---
203
204 /// @brief Tracks the number and time waited for transactions to apply
206
207 // waits for transaction dependency ---
208
209 /// @brief Tracks the number and time waited for transaction dependencies
211
212 // waits because worker queues memory exceeds max ---
213
214 /// @brief Tracks the number and time waited for transaction dependencies
216
217 // wait because worker queues are full ---
218
219 /// @brief Tracks the number and time waited for transaction dependencies
221
222 // Time spent reading from the relay log ---
223
224 /// @brief Tracks the number and time waited for transaction dependencies
226
227 /// @brief The stored number of time waited for commit order
228 std::atomic_int64_t m_order_commit_wait_count{0};
229
230 /// @brief The stored total amount of time waited for commit order
231 std::atomic_int64_t m_order_commit_waited_time{0};
232};
233} // namespace cs::apply::instruments
234
235#endif /* CHANGESTREAMS_APPLY_METRICS_APPLIER_METRICS_H */
Abstract class for time based metrics implementations.
Definition: time_based_metric_interface.h:32
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:176
@ 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:135
Time_based_metric m_wait_for_transaction_dependency
Tracks the number and time waited for transaction dependencies.
Definition: applier_metrics.h:210
std::atomic_int64_t m_order_commit_waited_time
The stored total amount of time waited for commit order.
Definition: applier_metrics.h:231
Time_based_metric m_wait_for_work_from_source
Tracks the number and time waited for transactions to apply.
Definition: applier_metrics.h:200
std::atomic_int64_t m_order_commit_wait_count
The stored number of time waited for commit order.
Definition: applier_metrics.h:228
void inc_events_committed_count(int64_t delta) override
increment the number of events scheduled by a given amount.
Definition: applier_metrics.cc:100
void inc_transactions_received_size_sum(int64_t amount) override
increment the pending size of queued transactions.
Definition: applier_metrics.cc:92
Time_based_metric m_wait_due_to_worker_queue_full
Tracks the number and time waited for transaction dependencies.
Definition: applier_metrics.h:220
std::atomic_int64_t m_transactions_committed
Holds the counter of transactions committed.
Definition: applier_metrics.h:166
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:123
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:155
std::atomic_int64_t m_transactions_received_size_sum
Holds the executed event's size of transactions now ongoing.
Definition: applier_metrics.h:192
Time_based_metric m_wait_for_worker_available
Tracks the number and time waited for transactions to apply.
Definition: applier_metrics.h:205
int64_t get_transactions_received_count() const override
Gets the number of transactions pending.
Definition: applier_metrics.cc:80
Time_based_metric_interface & get_transaction_dependency_wait_metric() override
Returns time metrics for waits on transaction dependecies on workers.
Definition: applier_metrics.cc:145
int64_t get_events_committed_count() const override
Gets the number of events scheduled.
Definition: applier_metrics.cc:104
int64_t get_wait_time_on_commit_order() const override
Gets the stored summed time waited on commit order.
Definition: applier_metrics.cc:174
std::atomic_int64_t m_transactions_committed_size_sum
Holds the total size of transactions committed till now.
Definition: applier_metrics.h:189
std::atomic< Metrics_breakpoint_state > m_metrics_breakpoint_state
True if the receiver has initialized m_first_received_relay_log.
Definition: applier_metrics.h:185
int64_t get_last_applier_start_micros() const override
Gets the time point when the metric timer started.
Definition: applier_metrics.cc:60
void store_last_applier_start() override
Remember "now" as the last applier start time.
Definition: applier_metrics.cc:50
int64_t get_transactions_committed_size_sum() const override
Gets the total sum of the size of committed transactions.
Definition: applier_metrics.cc:88
int64_t get_transactions_received_size_sum() const override
Gets the pending size sum of queued transactions.
Definition: applier_metrics.cc:96
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:108
Time_based_metric_interface & get_workers_available_wait_metric() override
Returns time metrics for waits on available workers.
Definition: applier_metrics.cc:140
void inc_transactions_committed_size_sum(int64_t amount) override
increment the size of transactions committed.
Definition: applier_metrics.cc:84
int64_t get_total_execution_time() const override
Returns the total time the applier was running.
Definition: applier_metrics.cc:64
void inc_transactions_committed_count(int64_t amount) override
increment the number of transactions committed.
Definition: applier_metrics.cc:68
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:160
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:164
int64_t get_transactions_committed_count() const override
Gets the number of transactions committed.
Definition: applier_metrics.cc:72
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:150
std::atomic_int64_t m_transactions_received_count
Holds the counter of transactions currently pending.
Definition: applier_metrics.h:169
Time_based_metric_interface & get_sum_applier_execution_time() override
Return time metric for total applier execution time.
Definition: applier_metrics.cc:56
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:173
Time_based_metric m_sum_applier_execution_time
total applier execution time
Definition: applier_metrics.h:163
void inc_transactions_received_count(int64_t amount) override
increment the number of transactions pending.
Definition: applier_metrics.cc:76
std::atomic_int64_t m_events_committed_count
Holds the counter of events scheduled.
Definition: applier_metrics.h:195
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:215
bool is_after_metrics_breakpoint() const override
Definition: applier_metrics.cc:118
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:170
Time_based_metric m_time_to_read_from_relay_log
Tracks the number and time waited for transaction dependencies.
Definition: applier_metrics.h:225
std::atomic< int64_t > m_last_applier_start_micros
stats collection start timestamp
Definition: applier_metrics.h:160
static int count
Definition: myisam_ftdump.cc:45
Definition: applier_metrics.cc:27