MySQL 26.7.0
Source Code Documentation
clone_protocol_service.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 2026, 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 MYSQL_CLONE_PROTOCOL_SERVICE
25#define MYSQL_CLONE_PROTOCOL_SERVICE
26
27/**
28 @file
29 This service provides functions for clone plugin to
30 connect and interact with remote server's clone plugin
31 counterpart.
32
33*/
34
35#ifdef __cplusplus
36class THD;
37#else
38#define THD void
39#endif
40
41struct MYSQL;
42struct MYSQL_SOCKET;
43
45#include <stddef.h>
46#include <stdint.h>
47#include <string>
48#include <vector>
49
50#include "mysql_com_server.h"
51
52/** Connection parameters including SSL */
54 /** Clone ssl mode. Same as mysql client --ssl-mode */
56 /** Clone ssl private key. Same as mysql client --ssl-key */
57 const char *m_ssl_key;
58 /** Clone ssl certificate. Same as mysql client --ssl-cert */
59 const char *m_ssl_cert;
60 /** Clone ssl certificate authority. Same as mysql client --ssl-ca */
61 const char *m_ssl_ca;
62
63 /** Enable network compression. */
66};
67
68/** Vector of string values */
69using Mysql_Clone_Values = std::vector<std::string>;
70
71/** Vector of string Key-Value pairs. */
72using Mysql_Clone_Key_Values = std::vector<std::pair<std::string, std::string>>;
73
75
76/**
77 Start and set session and statement key form current thread
78 @param[in,out] thd server session THD
79 @param[in] thread_key PSI key for thread
80 @param[in] statement_key PSI Key for statement
81*/
83 (THD * &thd, unsigned int thread_key,
84 unsigned int statement_key));
85
86/**
87 Finish statement and session
88 @param[in,out] thd server session THD
89*/
91
92/**
93 Get all character set and collations
94 @param[in,out] thd server session THD
95 @param[out] char_sets all character set collations
96 @return error code.
97*/
99 (THD * thd, Mysql_Clone_Values &char_sets));
100
101/**
102 Check if all characters sets are supported by server
103 @param[in,out] thd server session THD
104 @param[in] char_sets all character set collations to validate
105 @return error code.
106*/
108 (THD * thd, Mysql_Clone_Values &char_sets));
109
110/**
111 Get system configuration parameter values.
112 @param[in,out] thd server session THD
113 @param[in,out] configs a list of configuration key value pair
114 keys are input and values are output
115 @return error code.
116*/
118 (THD * thd, Mysql_Clone_Key_Values &configs));
119
120/**
121 Check if configuration parameter values match
122 @param[in,out] thd server session THD
123 @param[in] configs a list of configuration key value pair
124 @return error code.
125*/
127 (THD * thd, Mysql_Clone_Key_Values &configs));
128
129/**
130 Check if Clone is allowed from donor to recipient
131 @param[in] recipient recipient's version string
132 @param[in] donor donor's version string
133 @param[in] is_recipient_lts true if recipient is LTS, false otherwise
134 @param[in] is_donor_lts true if donor is LTS, false otherwise
135 @param[in] recipient_prev_lts previous LTS lineage of recipient
136 @return 0 on success, error code otherwise
137*/
139 (const std::string &recipient, const std::string &donor,
140 const bool is_recipient_lts, const bool is_donor_lts,
141 const std::string &recipient_prev_lts));
142
143/**
144 Connect to a remote server and switch to clone protocol
145 @param[in,out] thd server session THD
146 @param[in] host host name to connect to
147 @param[in] port port number to connect to
148 @param[in] user user name on remote host
149 @param[in] passwd password for the user
150 @param[in] ssl_ctx client ssl context
151 @param[out] socket Network socket for the connection
152
153 @return Connection object if successful.
154*/
156 (THD * thd, const char *host, uint32_t port, const char *user,
157 const char *passwd, mysql_clone_ssl_context *ssl_ctx,
159
160/**
161 Execute clone command on remote server
162 @param[in,out] thd local session THD
163 @param[in,out] connection connection object
164 @param[in] set_active set socket active for current THD
165 @param[in] command remote command
166 @param[in] com_buffer data following command
167 @param[in] buffer_length data length
168 @return error code.
169*/
171 (THD * thd, MYSQL *connection, bool set_active,
172 unsigned char command, unsigned char *com_buffer,
173 size_t buffer_length));
174
175/**
176 Get response from remote server
177 @param[in,out] thd local session THD
178 @param[in,out] connection connection object
179 @param[in] set_active set socket active for current THD
180 @param[in] timeout timeout in seconds
181 @param[out] packet response packet
182 @param[out] length packet length
183 @param[out] net_length network data length for compressed data
184 @return error code.
185*/
187 (THD * thd, MYSQL *connection, bool set_active, uint32_t timeout,
188 unsigned char **packet, size_t *length, size_t *net_length));
189
190/**
191 Kill a remote connection
192 @param[in,out] connection connection object
193 @param[in] kill_connection connection to kill
194 @return error code.
195*/
197 (MYSQL * connection, MYSQL *kill_connection));
198
199/**
200 Disconnect from a remote server
201 @param[in,out] thd local session THD
202 @param[in,out] connection connection object
203 @param[in] is_fatal if closing after fatal error
204 @param[in] clear_error clear any earlier error in session
205*/
207 (THD * thd, MYSQL *connection, bool is_fatal, bool clear_error));
208/**
209 Get error number and message.
210 @param[in,out] thd local session THD
211 @param[out] err_num error number
212 @param[out] err_mesg error message text
213*/
215 (THD * thd, uint32_t *err_num, const char **err_mesg));
216
217/**
218 Get command from client
219 @param[in,out] thd server session THD
220 @param[out] command remote command
221 @param[out] com_buffer data following command
222 @param[out] buffer_length data length
223 @return error code.
224*/
226 (THD * thd, unsigned char *command, unsigned char **com_buffer,
227 size_t *buffer_length));
228
229/**
230 Send response to client.
231 @param[in,out] thd server session THD
232 @param[in] secure needs to be sent over secure connection
233 @param[in] packet response packet
234 @param[in] length packet length
235 @return error code.
236*/
238 (THD * thd, bool secure, unsigned char *packet, size_t length));
239
240/**
241 Send error to client
242 @param[in,out] thd server session THD
243 @param[in] err_cmd error response command
244 @param[in] is_fatal if fatal error
245 @return error code.
246*/
248 (THD * thd, unsigned char err_cmd, bool is_fatal));
249
251
252#endif /* MYSQL_CLONE_PROTOCOL_SERVICE */
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
int mysql_clone_send_response(THD *thd, bool secure, uchar *packet, size_t length) noexcept
Send response to client.
Definition: clone_protocol_service.cc:676
int mysql_clone_send_command(THD *thd, MYSQL *connection, bool set_active, uchar command, uchar *com_buffer, size_t buffer_length) noexcept
Execute clone command on remote server.
Definition: clone_protocol_service.cc:440
int mysql_clone_kill(MYSQL *connection, MYSQL *kill_connection) noexcept
Kill a remote connection.
Definition: clone_protocol_service.cc:568
void mysql_clone_finish_statement(THD *thd) noexcept
Finish statement and session.
Definition: clone_protocol_service.cc:132
int mysql_clone_validate_version(const std::string &recipient, const std::string &donor, const bool is_recipient_lts, const bool is_donor_lts, const std::string &recipient_prev_lts) noexcept
Definition: clone_protocol_service.cc:302
void mysql_clone_disconnect(THD *thd, MYSQL *mysql, bool is_fatal, bool clear_error) noexcept
Disconnect from a remote server.
Definition: clone_protocol_service.cc:583
int mysql_clone_get_response(THD *thd, MYSQL *connection, bool set_active, uint32_t timeout, uchar **packet, size_t *length, size_t *net_length) noexcept
Get response from remote server.
Definition: clone_protocol_service.cc:478
int mysql_clone_send_error(THD *thd, uchar err_cmd, bool is_fatal) noexcept
Send error to client.
Definition: clone_protocol_service.cc:704
int mysql_clone_get_charsets(THD *thd, Mysql_Clone_Values &char_sets) noexcept
Get all character set and collations.
Definition: clone_protocol_service.cc:146
void mysql_clone_get_error(THD *thd, uint32_t *err_num, const char **err_mesg) noexcept
Get error number and message.
Definition: clone_protocol_service.cc:611
void mysql_clone_start_statement(THD *&thd, PSI_thread_key thread_key, PSI_statement_key statement_key) noexcept
Start and set session and statement key form current thread.
Definition: clone_protocol_service.cc:91
int mysql_clone_get_configs(THD *thd, Mysql_Clone_Key_Values &configs) noexcept
Get system configuration parameter values.
Definition: clone_protocol_service.cc:230
int mysql_clone_validate_charsets(THD *thd, Mysql_Clone_Values &char_sets) noexcept
Check if all characters sets are supported by server.
Definition: clone_protocol_service.cc:168
MYSQL * mysql_clone_connect(THD *thd, const char *host, uint32_t port, const char *user, const char *passwd, mysql_clone_ssl_context *ssl_ctx, MYSQL_SOCKET *socket) noexcept
Connect to a remote server and switch to clone protocol.
Definition: clone_protocol_service.cc:319
int mysql_clone_get_command(THD *thd, uchar *command, uchar **com_buffer, size_t *buffer_length) noexcept
Get command from client.
Definition: clone_protocol_service.cc:631
int mysql_clone_validate_configs(THD *thd, Mysql_Clone_Key_Values &configs) noexcept
Check if configuration parameter values match.
Definition: clone_protocol_service.cc:249
std::vector< std::pair< std::string, std::string > > Mysql_Clone_Key_Values
Vector of string Key-Value pairs.
Definition: clone_protocol_service.h:72
std::vector< std::string > Mysql_Clone_Values
Vector of string values.
Definition: clone_protocol_service.h:69
Definitions private to the server, used in the networking layer to notify specific events.
char * user
Definition: mysqladmin.cc:67
const char * host
Definition: mysqladmin.cc:66
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:499
stdx::expected< native_handle_type, error_type > socket(int family, int sock_type, int protocol)
Definition: socket.h:63
void set_active(space_id_t space_id)
Set an undo tablespace active.
Definition: trx0undo_trunc.cc:378
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
#define DECLARE_METHOD(retval, name, args)
Declares a method as a part of the Service definition.
Definition: service.h:103
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:91
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:86
An instrumented socket.
Definition: mysql_socket_bits.h:35
Definition: mysql.h:303
Definition: mysql_com_server.h:59
Connection parameters including SSL.
Definition: clone_protocol_service.h:53
int m_ssl_mode
Clone ssl mode.
Definition: clone_protocol_service.h:55
NET_SERVER * m_server_extn
Definition: clone_protocol_service.h:65
const char * m_ssl_key
Clone ssl private key.
Definition: clone_protocol_service.h:57
bool m_enable_compression
Enable network compression.
Definition: clone_protocol_service.h:64
const char * m_ssl_ca
Clone ssl certificate authority.
Definition: clone_protocol_service.h:61
const char * m_ssl_cert
Clone ssl certificate.
Definition: clone_protocol_service.h:59