MySQL 8.0.32
Source Code Documentation
clone0monitor.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2017, 2022, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/clone0monitor.h
28 Performance Schema stage instrumentation to monitor clone progress.
29
30 ****************************************************************************/
31
32#ifndef CLONE_MONITOR_H
33#define CLONE_MONITOR_H
34
35/* mysql_stage_inc_work_completed */
37#include "univ.i"
38#include "ut0dbg.h"
39
40/** Function to alert caller for long wait.
41@return error code */
42using Clone_Alert_Func = std::function<int()>;
43
44/** Class used to report CLONE progress via Performance Schema. */
46 public:
47 /** Constructor */
49 : m_estimate(),
51 m_progress(),
56 }
57
58 /** Destructor. */
60 if (m_progress == nullptr) {
61 return;
62 }
63
65 }
66
67 /** Initialize all monitoring data.
68 @param[in] key PFS key to register stage event
69 @param[in] enable if true, enable PFS trackig. */
70 void init_state(PSI_stage_key key, bool enable) {
72 m_progress = nullptr;
73 m_estimate = 0;
74 m_work_done = 0;
77
78 if (enable && key != PSI_NOT_INSTRUMENTED) {
80 }
81
82 if (m_progress == nullptr) {
84 return;
85 }
86
88 }
89
90 /** @return true if in estimation phase */
91 bool is_estimation_phase() const { return (m_cur_phase == ESTIMATE_WORK); }
92
93 /** @return estimated work in bytes */
94 uint64_t get_estimate() {
95 uint64_t ret_estimate = 0;
96 if (m_estimate > 0) {
97 ret_estimate = m_estimate << PFS_DATA_CHUNK_SIZE_POW2;
98 }
99 ret_estimate += m_estimate_bytes_left;
100 return (ret_estimate);
101 }
102
103 /** Update the work estimated for the clone operation.
104 @param[in] size size in bytes that needs to transferred
105 across. */
106 void add_estimate(uint64_t size) {
107 m_estimate += convert_bytes_to_work(size, true);
108
109 if (m_cur_phase == NOT_STARTED) {
110 return;
111 }
112
114 ut_ad(m_progress != nullptr);
115
117 }
118
119 /** Update the progress of the clone operation.
120 param[in] size size in bytes that is being transferred
121 across. */
122 void update_work(uint size) {
123 if (m_cur_phase == NOT_STARTED) {
124 return;
125 }
126
127 ut_ad(m_progress != nullptr);
129
130 m_work_done += convert_bytes_to_work(size, false);
132 }
133
134 /** Change from one phase to the other. */
136 switch (m_cur_phase) {
137 case NOT_STARTED:
138 return;
139
140 case ESTIMATE_WORK:
141 if (m_estimate_bytes_left != 0) {
143 }
144
146 break;
147
148 case COMPLETE_WORK:
149 if (m_work_bytes_left != 0) {
150 uint64_t rounded_estimate = m_estimate;
151 if (m_estimate_bytes_left != 0) {
152 ++rounded_estimate;
153 }
154 if (m_work_done < rounded_estimate) {
155 m_work_done++;
156 }
158 }
159
161 break;
162 }
163 }
164
165 private:
166 /** Translate bytes to work unit.
167 @param[in] size size in bytes that needs to be converted to the
168 @param[in] is_estimate if called during estimation
169 corresponding work unit.
170 @return the number of PFS chunks that the size constitutes. */
171 uint64_t convert_bytes_to_work(uint64_t size, bool is_estimate) {
172 auto &bytes_left = is_estimate ? m_estimate_bytes_left : m_work_bytes_left;
173 size += bytes_left;
174
175 auto aligned_size = ut_uint64_align_down(size, m_pfs_data_chunk_size);
176 bytes_left = size - aligned_size;
177
178 return (aligned_size >> PFS_DATA_CHUNK_SIZE_POW2);
179 }
180
181 /* Number of PFS chunks which needs to be transferred across. */
182 uint64_t m_estimate;
183
184 /* Number of PFS chunks already transferred. */
185 uint64_t m_work_done;
186
187 /* Performance schema accounting object. */
189
190 /* Size in bytes which couldn't fit the chunk during estimation. */
192
193 /* Size in bytes which couldn't fit the chunk during transfer. */
195
196 /* Current phase. */
198
199 /* PFS Chunk size in power of 2 in unit of bytes. */
200 static const int PFS_DATA_CHUNK_SIZE_POW2 = 20;
201
202 /* PFS chunk size. */
204};
205
206#endif /* CLONE_MONITOR_H */
Class used to report CLONE progress via Performance Schema.
Definition: clone0monitor.h:45
@ NOT_STARTED
Definition: clone0monitor.h:197
@ COMPLETE_WORK
Definition: clone0monitor.h:197
@ ESTIMATE_WORK
Definition: clone0monitor.h:197
void change_phase()
Change from one phase to the other.
Definition: clone0monitor.h:135
~Clone_Monitor()
Destructor.
Definition: clone0monitor.h:59
enum Clone_Monitor::@187 m_cur_phase
void update_work(uint size)
Update the progress of the clone operation.
Definition: clone0monitor.h:122
uint64_t m_estimate_bytes_left
Definition: clone0monitor.h:191
void add_estimate(uint64_t size)
Update the work estimated for the clone operation.
Definition: clone0monitor.h:106
uint64_t m_work_done
Definition: clone0monitor.h:185
bool is_estimation_phase() const
Definition: clone0monitor.h:91
void init_state(PSI_stage_key key, bool enable)
Initialize all monitoring data.
Definition: clone0monitor.h:70
uint64_t m_estimate
Definition: clone0monitor.h:182
uint64_t m_work_bytes_left
Definition: clone0monitor.h:194
PSI_stage_progress * m_progress
Definition: clone0monitor.h:188
uint64_t get_estimate()
Definition: clone0monitor.h:94
Clone_Monitor()
Constructor.
Definition: clone0monitor.h:48
uint64_t convert_bytes_to_work(uint64_t size, bool is_estimate)
Translate bytes to work unit.
Definition: clone0monitor.h:171
static const int PFS_DATA_CHUNK_SIZE_POW2
Definition: clone0monitor.h:200
uint m_pfs_data_chunk_size
Definition: clone0monitor.h:203
std::function< int()> Clone_Alert_Func
Function to alert caller for long wait.
Definition: clone0monitor.h:42
unsigned int PSI_stage_key
Instrumented stage key.
Definition: psi_stage_bits.h:42
#define mysql_set_stage(K)
Set the current stage.
Definition: mysql_stage.h:79
#define mysql_end_stage
End the last stage.
Definition: mysql_stage.h:85
#define mysql_stage_set_work_completed(P1, P2)
Definition: mysql_stage.h:114
#define mysql_stage_set_work_estimated(P1, P2)
Definition: mysql_stage.h:139
Instrumentation helpers for stages.
required string key
Definition: replication_asynchronous_connection_failover.proto:59
Interface for an instrumented stage progress.
Definition: psi_stage_bits.h:62
unsigned int uint
Definition: uca-dump.cc:29
Version control for database, common definitions, and include files.
static uint64_t ut_uint64_align_down(uint64_t n, ulint align_no)
Rounds a 64-bit integer downward to a multiple of a power of 2.
Debug utilities for Innobase.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:68
static uint32_t ut_2_exp(uint32_t n)
Calculates 2 to power n.
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:39