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