MySQL  8.0.19
Source Code Documentation
clone_protocol_service.h
Go to the documentation of this file.
1 /* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
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 MYSQL_CLONE_PROTOCOL_SERVICE
24 #define MYSQL_CLONE_PROTOCOL_SERVICE
25 
26 /**
27  @file
28  This service provides functions for clone plugin to
29  connect and interact with remote server's clone plugin
30  counterpart.
31 
32 */
33 
34 #ifdef __cplusplus
35 class THD;
36 #else
37 #define THD void
38 #endif
39 
40 struct MYSQL;
41 struct MYSQL_SOCKET;
42 
44 #include <stddef.h>
45 #include <stdint.h>
46 #include <string>
47 #include <vector>
48 
49 #include "mysql_com_server.h"
50 
51 /** Connection parameters including SSL */
53  /** Clone ssl mode. Same as mysql client --ssl-mode */
55  /** Clone ssl private key. Same as mysql client --ssl-key */
56  const char *m_ssl_key;
57  /** Clone ssl certificate. Same as mysql client --ssl-cert */
58  const char *m_ssl_cert;
59  /** Clone ssl certificate authority. Same as mysql client --ssl-ca */
60  const char *m_ssl_ca;
61 
62  /** Enable network compression. */
65 };
66 
67 /** Vector of sting Values */
68 using Mysql_Clone_Values = std::vector<std::string>;
69 
70 /** Vector of string Key-Value pairs. */
71 using Mysql_Clone_Key_Values = std::vector<std::pair<std::string, std::string>>;
72 
73 BEGIN_SERVICE_DEFINITION(clone_protocol)
74 
75 /**
76  Start and set session and statement key form current thread
77  @param[in,out] thd server session THD
78  @param[in] thread_key PSI key for thread
79  @param[in] statement_key PSI Key for statement
80 */
82  (THD * &thd, unsigned int thread_key,
83  unsigned int statement_key));
84 
85 /**
86  Finish statement and session
87  @param[in,out] thd server session THD
88 */
90 
91 /**
92  Get all character set and collations
93  @param[in,out] thd server session THD
94  @param[out] char_sets all character set collations
95  @return error code.
96 */
98  (THD * thd, Mysql_Clone_Values &char_sets));
99 
100 /**
101  Check if all characters sets are supported by server
102  @param[in,out] thd server session THD
103  @param[in] char_sets all character set collations to validate
104  @return error code.
105 */
107  (THD * thd, Mysql_Clone_Values &char_sets));
108 
109 /**
110  Get system configuration parameter values.
111  @param[in,out] thd server session THD
112  @param[in,out] configs a list of configuration key value pair
113  keys are input and values are output
114  @return error code.
115 */
117  (THD * thd, Mysql_Clone_Key_Values &configs));
118 
119 /**
120  Check if configuration parameter values match
121  @param[in,out] thd server session THD
122  @param[in] configs a list of configuration key value pair
123  @return error code.
124 */
126  (THD * thd, Mysql_Clone_Key_Values &configs));
127 
128 /**
129  Connect to a remote server and switch to clone protocol
130  @param[in,out] thd server session THD
131  @param[in] host host name to connect to
132  @param[in] port port number to connect to
133  @param[in] user user name on remote host
134  @param[in] passwd password for the user
135  @param[in] ssl_ctx client ssl context
136  @param[out] socket Network socket for the connection
137 
138  @return Connection object if successful.
139 */
141  (THD * thd, const char *host, uint32_t port, const char *user,
142  const char *passwd, mysql_clone_ssl_context *ssl_ctx,
143  MYSQL_SOCKET *socket));
144 
145 /**
146  Execute clone command on remote server
147  @param[in,out] thd local session THD
148  @param[in,out] connection connection object
149  @param[in] set_active set socket active for current THD
150  @param[in] command remote command
151  @param[in] com_buffer data following command
152  @param[in] buffer_length data length
153  @return error code.
154 */
156  (THD * thd, MYSQL *connection, bool set_active,
157  unsigned char command, unsigned char *com_buffer,
158  size_t buffer_length));
159 
160 /**
161  Get response from 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] timeout timeout in seconds
166  @param[out] packet response packet
167  @param[out] length packet length
168  @param[out] net_length network data length for compressed data
169  @return error code.
170 */
172  (THD * thd, MYSQL *connection, bool set_active, uint32_t timeout,
173  unsigned char **packet, size_t *length, size_t *net_length));
174 
175 /**
176  Kill a remote connection
177  @param[in,out] connection connection object
178  @param[in] kill_connection connection to kill
179  @return error code.
180 */
182  (MYSQL * connection, MYSQL *kill_connection));
183 
184 /**
185  Disconnect from a remote server
186  @param[in,out] thd local session THD
187  @param[in,out] connection connection object
188  @param[in] is_fatal if closing after fatal error
189  @param[in] clear_error clear any earlier error in session
190 */
192  (THD * thd, MYSQL *connection, bool is_fatal, bool clear_error));
193 /**
194  Get error number and message.
195  @param[in,out] thd local session THD
196  @param[out] err_num error number
197  @param[out] err_mesg error message text
198 */
200  (THD * thd, uint32_t *err_num, const char **err_mesg));
201 
202 /**
203  Get command from client
204  @param[in,out] thd server session THD
205  @param[out] command remote command
206  @param[out] com_buffer data following command
207  @param[out] buffer_length data length
208  @return error code.
209 */
211  (THD * thd, unsigned char *command, unsigned char **com_buffer,
212  size_t *buffer_length));
213 
214 /**
215  Send response to client.
216  @param[in,out] thd server session THD
217  @param[in] secure needs to be sent over secure connection
218  @param[in] packet response packet
219  @param[in] length packet length
220  @return error code.
221 */
223  (THD * thd, bool secure, unsigned char *packet, size_t length));
224 
225 /**
226  Send error to client
227  @param[in,out] thd server session THD
228  @param[in] err_cmd error response command
229  @param[in] is_fatal if fatal error
230  @return error code.
231 */
233  (THD * thd, unsigned char err_cmd, bool is_fatal));
234 
235 END_SERVICE_DEFINITION(clone_protocol)
236 
237 #endif /* MYSQL_CLONE_PROTOCOL_SERVICE */
THD
Definition: sql_class.h:764
mysql_clone_send_command
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:361
END_SERVICE_DEFINITION
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:90
mysql_clone_get_command
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:537
BEGIN_SERVICE_DEFINITION
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:85
service.h
DECLARE_METHOD
#define DECLARE_METHOD(retval, name, args)
Declares a method as a part of the Service definition.
Definition: service.h:102
mysql_clone_validate_configs
int mysql_clone_validate_configs(THD *thd, Mysql_Clone_Key_Values &configs) noexcept
Check if configuration parameter values match.
Definition: clone_protocol_service.cc:199
mysql_clone_get_error
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:517
mysql_clone_start_statement
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:48
host
const char * host
Definition: mysqladmin.cc:58
NET_SERVER
Definition: mysql_com_server.h:58
mysql_clone_ssl_context::m_ssl_ca
const char * m_ssl_ca
Clone ssl certificate authority.
Definition: clone_protocol_service.h:60
mysql_clone_ssl_context::m_server_extn
NET_SERVER * m_server_extn
Definition: clone_protocol_service.h:64
mysql_clone_finish_statement
void mysql_clone_finish_statement(THD *thd) noexcept
Finish statement and session.
Definition: clone_protocol_service.cc:86
Mysql_Clone_Key_Values
std::vector< std::pair< std::string, std::string > > Mysql_Clone_Key_Values
Vector of string Key-Value pairs.
Definition: clone_protocol_service.h:71
mysql_clone_connect
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:243
mysql_clone_ssl_context::m_ssl_mode
int m_ssl_mode
Clone ssl mode.
Definition: clone_protocol_service.h:54
port
static in_port_t port
Definition: testapp.c:33
mysql_clone_ssl_context
Connection parameters including SSL.
Definition: clone_protocol_service.h:52
mysql_clone_send_response
int mysql_clone_send_response(THD *thd, bool secure, uchar *packet, size_t length) noexcept
Send response to client.
Definition: clone_protocol_service.cc:579
mysql_clone_validate_charsets
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:121
mysql_clone_ssl_context::m_ssl_cert
const char * m_ssl_cert
Clone ssl certificate.
Definition: clone_protocol_service.h:58
mysql_clone_get_charsets
int mysql_clone_get_charsets(THD *thd, Mysql_Clone_Values &char_sets) noexcept
Get all character set and collations.
Definition: clone_protocol_service.cc:99
command
command
Definition: version_token.cc:278
user
char * user
Definition: mysqladmin.cc:59
Mysql_Clone_Values
std::vector< std::string > Mysql_Clone_Values
Vector of sting Values.
Definition: clone_protocol_service.h:68
mysql_clone_get_configs
int mysql_clone_get_configs(THD *thd, Mysql_Clone_Key_Values &configs) noexcept
Get system configuration parameter values.
Definition: clone_protocol_service.cc:180
mysql_clone_get_response
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:399
undo::set_active
void set_active(space_id_t space_id)
Set an undo tablespace active.
Definition: trx0purge.cc:1072
MYSQL
Definition: mysql.h:295
mysql_clone_ssl_context::m_enable_compression
bool m_enable_compression
Enable network compression.
Definition: clone_protocol_service.h:63
mysql_clone_ssl_context::m_ssl_key
const char * m_ssl_key
Clone ssl private key.
Definition: clone_protocol_service.h:56
gis::length
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:75
mysql_clone_send_error
int mysql_clone_send_error(THD *thd, uchar err_cmd, bool is_fatal) noexcept
Send error to client.
Definition: clone_protocol_service.cc:607
mysql_clone_disconnect
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:490
mysql_clone_kill
int mysql_clone_kill(MYSQL *connection, MYSQL *kill_connection) noexcept
Kill a remote connection.
Definition: clone_protocol_service.cc:475
mysql_com_server.h
MYSQL_SOCKET
An instrumented socket.
Definition: mysql_socket_bits.h:34