MySQL 9.1.0
Source Code Documentation
applier_metrics_interface.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_APPLIER_METRICS_AGGREGATOR_H
25#define CS_APPLIER_METRICS_AGGREGATOR_H
26
27#include <cstdint> // int64_t
28#include <string>
29
31
32namespace cs::apply::instruments {
33
34/// @brief This abstract class is an interface for classes that
35/// contain replication applier data as counters and wait times
37 public:
38 virtual ~Applier_metrics_interface() = default;
39
40 /// @brief Starts the timer when the applier metrics collection began.
41 /// Sets the state to running.
42 /// This can be queried later to know for how long time the stats have been
43 /// collected, i.e., the duration.
44 virtual void start_applier_timer() = 0;
45
46 /// @brief Calculates the total time the applier ran.
47 /// Sets the state to not running
48 /// Sums to time since start to the total running time
49 virtual void stop_applier_timer() = 0;
50
51 /// @brief Gets the time point when the metric timer started.
52 /// @return The time point since the collection of statistics started.
53 virtual int64_t get_last_applier_start_micros() const = 0;
54
55 /// @brief Returns the total time the applier was running
56 /// @return Amount of time the applier threads were running for this channel
57 virtual int64_t get_total_execution_time() const = 0;
58
59 /// @brief increment the number of transactions committed.
60 /// @param amount the amount of transactions to increment.
61 virtual void inc_transactions_committed_count(int64_t amount) = 0;
62
63 /// @brief Gets the number of transactions committed.
64 /// @return the number of transactions committed.
65 virtual int64_t get_transactions_committed_count() const = 0;
66
67 /// @brief increment the number of transactions received.
68 /// @param amount the amount of transactions to increment.
69 virtual void inc_transactions_received_count(int64_t amount) = 0;
70
71 /// @brief Gets the number of transactions received.
72 /// @return the number of transactions received.
73 virtual int64_t get_transactions_received_count() const = 0;
74
75 /// @brief increment the size of transactions committed.
76 /// @param amount the size amount to increment.
77 virtual void inc_transactions_committed_size_sum(int64_t amount) = 0;
78
79 /// @brief Gets the total sum of the size of committed transactions
80 /// @return the total size of committed transactions
81 virtual int64_t get_transactions_committed_size_sum() const = 0;
82
83 /// @brief increment the pending size of queued transactions.
84 /// @param amount the size amount to increment.
85 virtual void inc_transactions_received_size_sum(int64_t amount) = 0;
86
87 /// @brief Gets the pending size sum of queued transactions
88 /// @return the exectuted size of pending transactions
89 virtual int64_t get_transactions_received_size_sum() const = 0;
90
91 /// @brief increment the number of events scheduled by a given amount.
92 /// @param amount the amount of events to increment.
93 virtual void inc_events_committed_count(int64_t amount) = 0;
94
95 /// @brief Gets the number of events scheduled.
96 /// @return the number of events scheduled.
97 virtual int64_t get_events_committed_count() const = 0;
98
99 /// @brief Resets the statistics to zero.
100 virtual void reset() = 0;
101
102 /// @brief Query whether the size/count of received transactions has been
103 /// completely computed.
104 ///
105 /// Among other things, we track track the count and size of *pending*
106 /// transactions, i.e., the transactions that are received but not yet
107 /// committed. Internally, in this class, we track these metrics using two
108 /// sets of transactions: the size/count of *committed* transactions and the
109 /// size/count of *received* transactions. The size/count of pending
110 /// transactions can be computed as the difference between the two.
111 ///
112 /// The correct initial value for the received transactions would be the size
113 /// of all not yet applied transactions in the relay log. To get that metric
114 /// correct at the time the server starts (or the time the user enables
115 /// collecting metrics), we would have to scan the relay logs. But that can be
116 /// too expensive. So instead we just take a note that the metric is not yet
117 /// known. Until the metric is known, we display the value as NULL to the
118 /// user. Internally, we compute the initial value progressively, while
119 /// applying those transactions.
120 ///
121 /// We define the *metrics breakpoint* as the point in the relay log such that
122 /// when the point is reached we know that the size/count of received
123 /// transactions is completely computed. The metrics breakpoint is (the start
124 /// of) the first relay log the receiver writes to.
125 ///
126 /// Sizes/counts of transactions which appear before the metrics breakpoint
127 /// are incremented when those transactions commit. When the metrics
128 /// breakpoint is reached, the coordinator waits for preceding transactions to
129 /// commit, and then declares that the metrics have been computed.
130 /// Sizes/counts of transactions which appear after the metrics breakpoint are
131 /// incremented when those transactions are fully received and written to the
132 /// relay log.
133 ///
134 /// When the receiver starts, it uses @c set_metrics_breakpoint to set the
135 /// metric breakpoint to the relay log in which it writes the first event.
136 ///
137 /// It is guaranteed that the applier, when it reaches first relay log that
138 /// was received after the receiver thread started, waits for preceding
139 /// transactions to complete. It does this while applying the
140 /// Format_description_log_event from the source. Therefore, after any such
141 /// wait, it uses @c check_metrics_breakpoint to checks if the current relay
142 /// log is the metrics breakpoint. If that is the case, the internal flag @c
143 /// m_is_after_metrics_breakpoint is set to true, and this makes subsequent
144 /// calls to @c is_after_metrics_breakpoint return true.
145 ///
146 /// When the coordinator schedules an event to a worker, it propagates @c
147 /// is_after_metrics_breakpoint to the worker, through @c
148 /// Slave_job_item::m_is_after_metrics_breakpoint. When the worker commits the
149 /// transaction, it checks the flag. If the flag is false, it increments the
150 /// count/size of received transactions.
151 ///
152 /// This function may be called from many different threads.
153 ///
154 /// @return true if the size/count of received transactions is initialized,
155 /// false otherwise.
156 virtual bool is_after_metrics_breakpoint() const = 0;
157
158 /// @brief If the metrics breakpoint has not been set yet, set it to the given
159 /// filename.
160 ///
161 /// This function must only be called by the receiver thread.
162 ///
163 /// @see is_after_metrics_breakpoint.
164 virtual void set_metrics_breakpoint(const char *relay_log_filename) = 0;
165
166 /// @brief If the metrics breakpoint has been set and is equal to the given
167 /// filename, remember that we are now after the metrics breakpoint, so that
168 /// subsequent calls to @c is_after_metrics_breakpoint return true.
169 ///
170 /// This function must only be called by the coordinator thread.
171 ///
172 /// @see is_after_metrics_breakpoint.
173 virtual void check_metrics_breakpoint(const char *relay_log_filename) = 0;
174
175 /// @brief Returns time metrics for waits on work from the source
176 /// @return a Time_based_metric_interface object that contains metric
177 /// information on a wait
179
180 /// @brief Returns time metrics for waits on available workers
181 /// @return a Time_based_metric_interface object that contains metric
182 /// information on a wait
184
185 /// @brief Returns time metrics for waits on transaction dependecies on
186 /// workers
187 /// @return a Time_based_metric_interface object that contains metric
188 /// information on a wait
191
192 /// @brief Returns time metrics for waits when a worker queue exceeds max
193 /// memory
194 /// @return a Time_based_metric_interface object that contains metric
195 /// information on a wait
198
199 /// @brief Returns time metrics for waits when the worker queues are full
200 /// @return a Time_based_metric_interface object that contains metric
201 /// information on a wait
203
204 /// @brief Returns time metrics for relay log read wait times
205 /// @return a Time_based_metric_interface object that contains metric
206 /// information on a wait
209
210 /// @brief Increments the stored values for the commit order metrics.
211 /// @param count The count for commit order waits
212 /// @param time The time waited on commit order
214 int64_t time) = 0;
215
216 /// @brief Gets the stored number of times we waited on committed order
217 /// @return the stored number of commit order waits
218 virtual int64_t get_number_of_waits_on_commit_order() const = 0;
219
220 /// @brief Gets the stored summed time waited on commit order
221 /// @return the stored sum of the time waited on commit
222 virtual int64_t get_wait_time_on_commit_order() const = 0;
223};
224} // namespace cs::apply::instruments
225
226#endif /* CS_APPLIER_METRICS_AGGREGATOR_H */
Abstract class for time based metrics implementations.
Definition: time_based_metric_interface.h:30
This abstract class is an interface for classes that contain replication applier data as counters and...
Definition: applier_metrics_interface.h:36
virtual void inc_transactions_received_size_sum(int64_t amount)=0
increment the pending size of queued transactions.
virtual void inc_events_committed_count(int64_t amount)=0
increment the number of events scheduled by a given amount.
virtual int64_t get_transactions_committed_count() const =0
Gets the number of transactions committed.
virtual int64_t get_events_committed_count() const =0
Gets the number of events scheduled.
virtual void set_metrics_breakpoint(const char *relay_log_filename)=0
If the metrics breakpoint has not been set yet, set it to the given filename.
virtual void inc_transactions_committed_count(int64_t amount)=0
increment the number of transactions committed.
virtual void start_applier_timer()=0
Starts the timer when the applier metrics collection began.
virtual int64_t get_transactions_received_size_sum() const =0
Gets the pending size sum of queued transactions.
virtual Time_based_metric_interface & get_worker_queues_memory_exceeds_max_wait_metric()=0
Returns time metrics for waits when a worker queue exceeds max memory.
virtual void check_metrics_breakpoint(const char *relay_log_filename)=0
If the metrics breakpoint has been set and is equal to the given filename, remember that we are now a...
virtual int64_t get_number_of_waits_on_commit_order() const =0
Gets the stored number of times we waited on committed order.
virtual int64_t get_transactions_committed_size_sum() const =0
Gets the total sum of the size of committed transactions.
virtual void inc_transactions_received_count(int64_t amount)=0
increment the number of transactions received.
virtual int64_t get_wait_time_on_commit_order() const =0
Gets the stored summed time waited on commit order.
virtual bool is_after_metrics_breakpoint() const =0
Query whether the size/count of received transactions has been completely computed.
virtual void stop_applier_timer()=0
Calculates the total time the applier ran.
virtual Time_based_metric_interface & get_workers_available_wait_metric()=0
Returns time metrics for waits on available workers.
virtual void reset()=0
Resets the statistics to zero.
virtual Time_based_metric_interface & get_worker_queues_full_wait_metric()=0
Returns time metrics for waits when the worker queues are full.
virtual int64_t get_transactions_received_count() const =0
Gets the number of transactions received.
virtual Time_based_metric_interface & get_transaction_dependency_wait_metric()=0
Returns time metrics for waits on transaction dependecies on workers.
virtual void inc_commit_order_wait_stored_metrics(int64_t count, int64_t time)=0
Increments the stored values for the commit order metrics.
virtual Time_based_metric_interface & get_time_to_read_from_relay_log_metric()=0
Returns time metrics for relay log read wait times.
virtual Time_based_metric_interface & get_work_from_source_wait_metric()=0
Returns time metrics for waits on work from the source.
virtual int64_t get_total_execution_time() const =0
Returns the total time the applier was running.
virtual void inc_transactions_committed_size_sum(int64_t amount)=0
increment the size of transactions committed.
virtual int64_t get_last_applier_start_micros() const =0
Gets the time point when the metric timer started.
static int count
Definition: myisam_ftdump.cc:45
Definition: applier_metrics.cc:27