MySQL 8.0.40
Source Code Documentation
remote_clone_handler.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 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 REMOTE_CLONE_HANDLER_INCLUDED
25#define REMOTE_CLONE_HANDLER_INCLUDED
26
30
31/**
32 Class that hold the logic to decide if we should or not execute a clone
33 operation and the logic to launch it.
34*/
36 public:
37 /** The possible results when checking what is the recovery strategy */
39 DO_CLONE = 0, // Do a remote clone
40 DO_RECOVERY = 1, // Don't clone, use distributed recovery
41 CHECK_ERROR = 2, // Error when checking
42 NO_RECOVERY_POSSIBLE = 3, // No available members for clone or recovery
43 CLONE_CHECKS_END = 4 // Enum end
44 };
45
46 /**
47 Constructor for the remote cloning handler
48
49 @param threshold The threshold for clone activation
50 @param components_stop_timeout The stop timeout in error cases
51 */
52 Remote_clone_handler(ulonglong threshold, ulong components_stop_timeout);
53
54 /**
55 The destructor
56 */
57 ~Remote_clone_handler() override;
58
59 /**
60 Set the class threshold for clone activation
61 @param threshold The threshold for clone activation
62 */
65 }
66
67 /*
68 Check what are the valid donors present and how many transactions
69 this member is missing related to them.this
70
71 @param donor_info a tuple that has the info. It contains
72 number of valid clone donors
73 number of valid recovery donors
74 number of valid recovering donors
75 whether clone activation threshold was breached or not
76
77 @return whether or not we managed to get the info
78 @retval 0 the info was retrieved
79 @retval != 0 some error occurred
80 */
81 int extract_donor_info(std::tuple<uint, uint, uint, bool> *donor_info);
82
83 /**
84 Check if clone or distributed recovery shall be used for provisioning
85 @return What is the clone strategy to follow or shall we error out
86 @retval DO_CLONE Do a remote clone
87 @retval DO_RECOVERY Don't clone, use distributed recovery
88 @retval CHECK_ERROR Error when choosing the strategy
89 @retval NO_RECOVERY_POSSIBLE No available members for clone or recovery
90 */
92
93 /**
94 Launch the clone process with some preliminary checks.
95
96 @param group_name The group name
97 @param view_id The view id when clone started
98
99 @note: the given parameters are used when falling back to
100 distributed recovery in case of a clone issue.
101
102 @return whether or not we managed to launch the clone thread.
103 @retval 0 the thread launched successfully
104 @retval != 0 for some reason we did not launch the thread
105 */
106 int clone_server(const std::string &group_name, const std::string &view_id);
107
108 /**
109 Terminate the clone process
110
111 @param rejoin Are we terminating or rejoining in the plugin
112
113 @note: the flag tells the method if the clone query should be killed or not
114 Usually on rejoins the clone query is not killed.
115 When stopping GR, then the query is terminated.
116 No guarantees are made about what the server state is after that
117 */
118 void terminate_clone_process(bool rejoin);
119
120 /**
121 Lock when trying to set the read mode and a clone might be running
122 */
125 }
126
127 /**
128 Unlock when trying to set the read mode and a clone might be running
129 */
132 }
133
134 private:
135 /** What is the result when we check if the clone plugin is present*/
137 CLONE_PLUGIN_NOT_PRESENT = 0, // the plugin is not there or not active
138 CLONE_PLUGIN_PRESENT = 1, // the plugin is there and active
139 CLONE_CHECK_QUERY_ERROR = 2, // error when checking
140 };
141
142 /** What are the states of the clone execution query */
144 CLONE_QUERY_NOT_EXECUTING = 0, // Not yet executed
145 CLONE_QUERY_EXECUTING = 1, // Executing query
146 CLONE_QUERY_EXECUTED = 2, // Executed already
147 };
148
149 // The listeners for group events
150
151 int after_view_change(const std::vector<Gcs_member_identifier> &joining,
152 const std::vector<Gcs_member_identifier> &leaving,
153 const std::vector<Gcs_member_identifier> &group,
154 bool is_leaving, bool *skip_election,
155 enum_primary_election_mode *election_mode,
156 std::string &suggested_primary) override;
158 std::string primary_uuid,
160 enum_primary_election_mode election_mode, int error) override;
162 const std::string &message_origin,
163 bool *skip_message) override;
164
165 /**
166 The thread callback passed onto mysql_thread_create.
167
168 @param[in] arg a pointer to a Remote_clone_handler instance.
169
170 @return Does not return.
171 */
172 static void *launch_thread(void *arg);
173
174 /**
175 The clone thread process.
176 */
177 [[noreturn]] void clone_thread_handle();
178
179 /**
180 Check if clone plugin is present
181 @return is the clone present or error
182 @retval CLONE_PLUGIN_NOT_PRESENT The plugin is not present or active
183 @retval CLONE_PLUGIN_PRESENT The plugin is present and active
184 @retval CLONE_CHECK_QUERY_ERROR There was an error when checking
185 */
187
188 /**
189 Get all the valid members for cloning
190
191 @param[out] suitable_donors the list of possible donors
192 */
193 void get_clone_donors(std::list<Group_member_info *> &suitable_donors);
194
195 /**
196 Configure the SSL options for the clone plugin
197
198 @param[in] sql_command_interface the connection to use
199 */
201 Sql_service_command_interface *sql_command_interface);
202
203 /**
204 In error fall back to recovery or error out
205
206 @param[in] critical_error the error prevent distributed recovery
207 */
208 int fallback_to_recovery_or_leave(bool critical_error = false);
209
210 /**
211 Executes the query to change the allowed donor list for clone
212
213 @param[in] sql_command_interface the connection to use
214 @param[in] hostname the hostname to set
215 @param[in] port the port to set
216
217 @return whether or not we managed to set the value
218 @retval 0 the value was set
219 @retval != 0 some error occurred
220 */
221 int update_donor_list(Sql_service_command_interface *sql_command_interface,
222 std::string &hostname, std::string &port);
223
224 /**
225 Checks if the server connection was not killed.
226 If so, establish a new one.
227
228 @param[in] sql_command_interface the server connection
229
230 @return did we manage to reconnect
231 @retval 0 yes
232 @retval != 0 some error occurred
233 */
235 Sql_service_command_interface *sql_command_interface);
236
237 /**
238 Executes the query to remotely clone a server
239
240 @param[in] sql_command_interface the connection to use
241 @param[in] hostname the hostname to use
242 @param[in] port the port to use
243 @param[in] username the username to use
244 @param[in] password the password to use
245 @param[in] use_ssl make clone use SSL
246
247 @return whether or not we managed to clone the server
248 @retval 0 the clone was successful
249 @retval != 0 some error occurred
250 */
251 int run_clone_query(Sql_service_command_interface *sql_command_interface,
252 std::string &hostname, std::string &port,
253 std::string &username, std::string &password,
254 bool use_ssl);
255
256 /**
257 Kill the current query executing a clone
258
259 @return whether or not we managed to kill the clone query
260 @retval 0 the kill query was successful
261 @retval != 0 some error occurred
262 */
263 int kill_clone_query();
264
265 /**
266 Given a error code it evaluates if the error is critical or not.
267 Basically it tells us if there is still data in the server.
268
269 @param[in] error_code the clone returned error
270
271 @retval true error is critical
272 @retval false error is not critical
273 */
274 bool evaluate_error_code(int error_code);
275
276#ifndef NDEBUG
277 /**
278 Function for debug points
279 @note this function can have a parameter for different debug points
280 */
282#endif /* NDEBUG */
283
284 // Settings to fall back to recovery
285 /** The group to which the recovering member belongs */
286 std::string m_group_name;
287 /** The view id when the clone started */
288 std::string m_view_id;
289
290 /** the THD handle. */
292 /** the state of the thread. */
294 /** the thread handle. */
296 /** the mutex for controlling access to the thread itself. */
298 /** the cond_var used to signal the thread. */
300 /** the mutex for the clone process query. */
302 /** the mutex for the clone external running status/read mode*/
304
305 /** Is the process being terminated*/
307 /** What is the status on the read only mode enabling query */
309 /** The session id for the clone query*/
311
312 /**The threshold after which the clone process is invoked*/
314
315 /** the mutex for donor list accesses. */
317
318 /** The list of available donors */
319 std::list<Group_member_info *> m_suitable_donors;
320
321 /** The current donor address*/
323
324 /** Timeout on shutdown */
326};
327
328#endif /* REMOTE_CLONE_HANDLER_INCLUDED */
It represents the identity of a group member within a certain group.
Definition: gcs_member_identifier.h:40
Class that others can extend to receive notifications about views and primary elections.
Definition: group_event_observer.h:40
This is the base GCS plugin message.
Definition: gcs_plugin_messages.h:64
Class that hold the logic to decide if we should or not execute a clone operation and the logic to la...
Definition: remote_clone_handler.h:35
mysql_cond_t m_run_cond
the cond_var used to signal the thread.
Definition: remote_clone_handler.h:299
ulonglong m_clone_activation_threshold
The threshold after which the clone process is invoked.
Definition: remote_clone_handler.h:313
bool evaluate_error_code(int error_code)
Given a error code it evaluates if the error is critical or not.
Definition: remote_clone_handler.cc:634
int extract_donor_info(std::tuple< uint, uint, uint, bool > *donor_info)
Definition: remote_clone_handler.cc:152
int run_clone_query(Sql_service_command_interface *sql_command_interface, std::string &hostname, std::string &port, std::string &username, std::string &password, bool use_ssl)
Executes the query to remotely clone a server.
Definition: remote_clone_handler.cc:474
enum_clone_check_result
The possible results when checking what is the recovery strategy.
Definition: remote_clone_handler.h:38
@ NO_RECOVERY_POSSIBLE
Definition: remote_clone_handler.h:42
@ DO_RECOVERY
Definition: remote_clone_handler.h:40
@ CLONE_CHECKS_END
Definition: remote_clone_handler.h:43
@ CHECK_ERROR
Definition: remote_clone_handler.h:41
@ DO_CLONE
Definition: remote_clone_handler.h:39
int evaluate_server_connection(Sql_service_command_interface *sql_command_interface)
Checks if the server connection was not killed.
Definition: remote_clone_handler.cc:548
enum_clone_query_status
What are the states of the clone execution query.
Definition: remote_clone_handler.h:143
@ CLONE_QUERY_EXECUTED
Definition: remote_clone_handler.h:146
@ CLONE_QUERY_EXECUTING
Definition: remote_clone_handler.h:145
@ CLONE_QUERY_NOT_EXECUTING
Definition: remote_clone_handler.h:144
int clone_server(const std::string &group_name, const std::string &view_id)
Launch the clone process with some preliminary checks.
Definition: remote_clone_handler.cc:582
bool m_being_terminated
Is the process being terminated.
Definition: remote_clone_handler.h:306
enum_clone_check_result check_clone_preconditions()
Check if clone or distributed recovery shall be used for provisioning.
Definition: remote_clone_handler.cc:270
std::string m_view_id
The view id when the clone started.
Definition: remote_clone_handler.h:288
int update_donor_list(Sql_service_command_interface *sql_command_interface, std::string &hostname, std::string &port)
Executes the query to change the allowed donor list for clone.
Definition: remote_clone_handler.cc:448
void clone_thread_handle()
The clone thread process.
Definition: remote_clone_handler.cc:657
mysql_mutex_t m_donor_list_lock
the mutex for donor list accesses.
Definition: remote_clone_handler.h:316
my_thread_handle m_thd_handle
the thread handle.
Definition: remote_clone_handler.h:295
void set_clone_threshold(ulonglong threshold)
Set the class threshold for clone activation.
Definition: remote_clone_handler.h:63
Remote_clone_handler(ulonglong threshold, ulong components_stop_timeout)
Constructor for the remote cloning handler.
Definition: remote_clone_handler.cc:34
void lock_gr_clone_read_mode_lock()
Lock when trying to set the read mode and a clone might be running.
Definition: remote_clone_handler.h:123
int kill_clone_query()
Kill the current query executing a clone.
Definition: remote_clone_handler.cc:515
int after_primary_election(std::string primary_uuid, enum_primary_election_primary_change_status primary_change_status, enum_primary_election_mode election_mode, int error) override
Executed after primary election.
Definition: remote_clone_handler.cc:104
~Remote_clone_handler() override
The destructor.
Definition: remote_clone_handler.cc:56
int after_view_change(const std::vector< Gcs_member_identifier > &joining, const std::vector< Gcs_member_identifier > &leaving, const std::vector< Gcs_member_identifier > &group, bool is_leaving, bool *skip_election, enum_primary_election_mode *election_mode, std::string &suggested_primary) override
Executed after view install and before primary election.
Definition: remote_clone_handler.cc:71
void get_clone_donors(std::list< Group_member_info * > &suitable_donors)
Get all the valid members for cloning.
Definition: remote_clone_handler.cc:340
std::string m_group_name
The group to which the recovering member belongs.
Definition: remote_clone_handler.h:286
enum_clone_query_status m_clone_query_status
What is the status on the read only mode enabling query.
Definition: remote_clone_handler.h:308
mysql_mutex_t m_run_lock
the mutex for controlling access to the thread itself.
Definition: remote_clone_handler.h:297
std::list< Group_member_info * > m_suitable_donors
The list of available donors.
Definition: remote_clone_handler.h:319
int set_clone_ssl_options(Sql_service_command_interface *sql_command_interface)
Configure the SSL options for the clone plugin.
Definition: remote_clone_handler.cc:367
void unlock_gr_clone_read_mode_lock()
Unlock when trying to set the read mode and a clone might be running.
Definition: remote_clone_handler.h:130
thread_state m_clone_process_thd_state
the state of the thread.
Definition: remote_clone_handler.h:293
ulong m_stop_wait_timeout
Timeout on shutdown.
Definition: remote_clone_handler.h:325
void terminate_clone_process(bool rejoin)
Terminate the clone process.
Definition: remote_clone_handler.cc:562
mysql_mutex_t m_clone_query_lock
the mutex for the clone process query.
Definition: remote_clone_handler.h:301
int fallback_to_recovery_or_leave(bool critical_error=false)
In error fall back to recovery or error out.
Definition: remote_clone_handler.cc:395
THD * m_clone_thd
the THD handle.
Definition: remote_clone_handler.h:291
mysql_mutex_t m_clone_read_mode_lock
the mutex for the clone external running status/read mode
Definition: remote_clone_handler.h:303
static void * launch_thread(void *arg)
The thread callback passed onto mysql_thread_create.
Definition: remote_clone_handler.cc:29
unsigned long m_clone_query_session_id
The session id for the clone query.
Definition: remote_clone_handler.h:310
enum_clone_presence_query_result check_clone_plugin_presence()
Check if clone plugin is present.
Definition: remote_clone_handler.cc:116
enum_clone_presence_query_result
What is the result when we check if the clone plugin is present.
Definition: remote_clone_handler.h:136
@ CLONE_CHECK_QUERY_ERROR
Definition: remote_clone_handler.h:139
@ CLONE_PLUGIN_NOT_PRESENT
Definition: remote_clone_handler.h:137
@ CLONE_PLUGIN_PRESENT
Definition: remote_clone_handler.h:138
Gcs_member_identifier * m_current_donor_address
The current donor address.
Definition: remote_clone_handler.h:322
void gr_clone_debug_point()
Function for debug points.
Definition: remote_clone_handler.cc:643
int before_message_handling(const Plugin_gcs_message &message, const std::string &message_origin, bool *skip_message) override
Executed before the message is processed.
Definition: remote_clone_handler.cc:110
Definition: sql_service_command.h:195
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
unsigned long long int ulonglong
Definition: my_inttypes.h:56
static char * password
Definition: mysql_secure_installation.cc:56
enum_primary_election_mode
Enum for election types.
Definition: primary_election_include.h:33
enum_primary_election_primary_change_status
Enum for primary change status.
Definition: primary_election_include.h:50
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
Definition: my_thread_bits.h:52
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: plugin_utils.h:47