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