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