MySQL 8.3.0
Source Code Documentation
sql_service_command.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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 SQL_SERVICE_COMMAND_INCLUDE
24#define SQL_SERVICE_COMMAND_INCLUDE
25
26#include <stddef.h>
27
28#include "my_inttypes.h"
31
32#define GR_PLUGIN_SESSION_THREAD_TIMEOUT 10
33
34/**
35 What is the policy when creation a new server session for SQL execution.
36*/
38 PSESSION_USE_THREAD, ///< Use the current thread
39 PSESSION_INIT_THREAD, ///< Use the current thread but initialize it
40 PSESSION_DEDICATED_THREAD ///< Use a dedicated thread to open a session
41};
42
44 public:
45 /**
46 Method to kill the session identified by the given session id in those
47 cases where the server hangs while executing the sql query.
48
49 @param sql_interface the server session interface for query execution
50 @param session_id id of the session to be killed.
51
52 @return the error value returned
53 @retval 0 - success
54 @retval >0 - Failure
55 */
57 void *session_id = nullptr);
58
59 /**
60 Method to remotely clone a server
61
62 @param[in] sql_interface The connection where to execute the query
63 @param[in] variable_args Tuple <string,string,string,string,bool,string>
64
65 @return the error value returned
66 @retval 0 OK
67 @retval !=0 Error on execution
68 */
70 void *variable_args = nullptr);
71
72 /**
73 Method to execute a given query
74
75 @param[in] sql_interface The connection where to execute the query
76 @param[in] variable_args Tuple <string, string>
77
78 @return the error value returned
79 @retval 0 OK
80 @retval !=0 Error on execution
81 */
83 void *variable_args = nullptr);
84
85 /**
86 Method to execute a given conditional query
87
88 @param[in] sql_interface The connection where to execute the query
89 @param[in] variable_args Tuple <string, bool, string>
90
91 @return the error value returned
92 @retval 0 OK
93 @retval !=0 Error on execution
94 */
96 void *variable_args = nullptr);
97};
98
102};
103
105 public:
107
109
110 /**
111 Launch a new thread that will create a new server session.
112
113 @param plugin_pointer_var the plugin pointer for session creation
114 @param user the user for the connection
115
116 @return the operation was successful
117 @retval 0 OK
118 @retval !=0 Error
119 */
120 int launch_session_thread(void *plugin_pointer_var, const char *user);
121
122 /**
123 Terminate the thread and close the session.
124
125 @return the operation was successful
126 @retval 0 OK
127 @retval !=0 Error
128 */
130
131 /**
132 Thread handler for session creation.
133 */
135
136 /**
137 Method to submit a new method into execution on the session thread
138 @param method method to executed
139 @param terminate termination flag to the class
140 */
142 long (Sql_service_commands::*method)(Sql_service_interface *, void *),
143 bool terminate = false);
144
145 /**
146 Wait for the queued method to return.
147 @return the return value of the submitted method
148 */
150
152
153 /**
154 Sets a pointer that the next queued method will use to return a value
155 @param pointer the pointer where the method will store some return value
156 */
157 void set_return_pointer(void *pointer) { return_object = pointer; }
158
159 private:
161
163
165
167
168 /** The value for returning on methods */
170
171 /** Session thread handle */
173 /* run conditions and locks */
176 /* method completion conditions and locks */
179
180 /**The user for the session connection*/
181 const char *session_user;
182 /** Session thread method completion flag */
184 /** The method return value */
186 /** Session thread state */
188 /** Session termination flag */
190 /** Session thread error flag */
192};
193
195 public:
198
199 /**
200 Establishes the connection to the server.
201
202 @param isolation_param session creation requirements: use current thread,
203 use thread but initialize it or create it in a
204 dedicated thread
205 @param user the user for the connection
206 @param plugin_pointer the plugin pointer for threaded connections
207
208 @return the connection was successful
209 @retval 0 OK
210 @retval !=0 Error
211 */
213 const char *user,
214 void *plugin_pointer = nullptr);
215
216 /**
217 Terminates the old connection and creates a new one to the server.
218
219 @param isolation_param session creation requirements: use current thread,
220 use thread but initialize it or create it in a
221 dedicated thread
222 @param user the user for the connection
223 @param plugin_pointer the plugin pointer for threaded connections
224
225 @return the connection was successful
226 @retval 0 OK
227 @retval !=0 Error
228 */
230 const char *user, void *plugin_pointer = nullptr);
231 /**
232 Was this session killed?
233
234 @retval true session was killed
235 @retval false session was not killed
236 */
237 bool is_session_killed();
238
239 /**
240 Stops and deletes all connection related structures
241 */
243
244 /**
245 Returns the SQL service interface associated to this class
246
247 @return the sql service interface field
248 */
250
251 /**
252 Sets the SQL API user to be used on security checks
253
254 @param user the user to be used
255
256 @return the operation was successful
257 @retval 0 OK
258 @retval !=0 Error
259 */
260 int set_interface_user(const char *user);
261
262 /**
263 Method to kill the session identified by the given session id in those
264 cases where the server hangs while executing the sql query.
265
266 @param session_id id of the session to be killed.
267
268 @return the error value returned
269 @retval 0 - success
270 @retval >0 - Failure
271 */
272 long kill_session(unsigned long session_id);
273
274 /**
275 Checks if there is an existing session
276
277 @return the error value returned
278 @retval true valid
279 @retval false some issue prob happened on connection
280 */
281 bool is_session_valid();
282
283 /**
284 Method to remotely clone a server
285
286 @param [in] host The host to clone
287 @param [in] port The host port
288 @param [in] username The username to authenticate in the remote server
289 @param [in] password The password to authenticate in the remote server
290 @param [in] use_ssl Is ssl configured for the clone process
291 @param [out] error The error message in case of error
292
293 @return the error value returned
294 @retval 0 OK
295 @retval !=0 Error on execution
296 */
297 long clone_server(std::string &host, std::string &port, std::string &username,
298 std::string &password, bool use_ssl, std::string &error);
299
300 /**
301 Execute a query passed as parameter.
302
303 @param [in] query The query to execute
304
305 @return the error value returned
306 @retval 0 OK
307 @retval !=0 Error on execution
308 */
309 long execute_query(std::string &query);
310
311 /**
312 Execute a query passed as parameter.
313
314 @param [in] query The query to execute
315 @param [out] error The error message in case of error
316
317 @return the error value returned
318 @retval 0 OK
319 @retval !=0 Error on execution
320 */
321 long execute_query(std::string &query, std::string &error);
322
323 /**
324 Execute a conditional query passed as parameter.
325
326 @param [in] query The query to execute
327 @param [in] result The result of the query
328
329 @return the error value returned
330 @retval 0 OK
331 @retval !=0 Error on execution
332 */
333 long execute_conditional_query(std::string &query, bool *result);
334
335 /**
336 Execute a conditional query passed as parameter.
337
338 @param [in] query The query to execute
339 @param [in] result The result of the query
340 @param [out] error The error message in case of error
341
342 @return the error value returned
343 @retval 0 OK
344 @retval !=0 Error on execution
345 */
346 long execute_conditional_query(std::string &query, bool *result,
347 std::string &error);
348
349 private:
351
353
354 /** The internal SQL session service interface to the server */
356
357 /* The thread where the connection leaves if isolation is needed*/
359};
360
361#endif // SQL_SERVICE_COMMAND_INCLUDE
Definition: sql_service_command.h:104
void * m_plugin_pointer
Definition: sql_service_command.h:166
mysql_cond_t m_method_cond
Definition: sql_service_command.h:178
bool m_session_thread_terminate
Session termination flag.
Definition: sql_service_command.h:189
Synchronized_queue< st_session_method * > * incoming_methods
Definition: sql_service_command.h:164
bool m_method_execution_completed
Session thread method completion flag.
Definition: sql_service_command.h:183
mysql_cond_t m_run_cond
Definition: sql_service_command.h:175
void queue_new_method_for_application(long(Sql_service_commands::*method)(Sql_service_interface *, void *), bool terminate=false)
Method to submit a new method into execution on the session thread.
Definition: sql_service_command.cc:424
int terminate_session_thread()
Terminate the thread and close the session.
Definition: sql_service_command.cc:483
long wait_for_method_execution()
Wait for the queued method to return.
Definition: sql_service_command.cc:436
~Session_plugin_thread()
Definition: sql_service_command.cc:408
int session_thread_handler()
Thread handler for session creation.
Definition: sql_service_command.cc:527
long m_method_execution_return_value
The method return value.
Definition: sql_service_command.h:185
Sql_service_interface * get_service_interface()
Definition: sql_service_command.cc:598
const char * session_user
The user for the session connection.
Definition: sql_service_command.h:181
Sql_service_interface * m_server_interface
Definition: sql_service_command.h:162
mysql_mutex_t m_method_lock
Definition: sql_service_command.h:177
Sql_service_commands * command_interface
Definition: sql_service_command.h:160
my_thread_handle m_plugin_session_pthd
Session thread handle.
Definition: sql_service_command.h:172
Session_plugin_thread(Sql_service_commands *command_interface)
Definition: sql_service_command.cc:387
void set_return_pointer(void *pointer)
Sets a pointer that the next queued method will use to return a value.
Definition: sql_service_command.h:157
thread_state m_session_thread_state
Session thread state.
Definition: sql_service_command.h:187
int launch_session_thread(void *plugin_pointer_var, const char *user)
Launch a new thread that will create a new server session.
Definition: sql_service_command.cc:453
mysql_mutex_t m_run_lock
Definition: sql_service_command.h:174
int m_session_thread_error
Session thread error flag.
Definition: sql_service_command.h:191
void * return_object
The value for returning on methods.
Definition: sql_service_command.h:169
Definition: sql_service_command.h:194
Sql_service_commands sql_service_commands
Definition: sql_service_command.h:352
bool is_session_killed()
Was this session killed?
Definition: sql_service_command.cc:100
long kill_session(unsigned long session_id)
Method to kill the session identified by the given session id in those cases where the server hangs w...
Definition: sql_service_command.cc:157
int set_interface_user(const char *user)
Sets the SQL API user to be used on security checks.
Definition: sql_service_command.cc:127
Sql_service_command_interface()
Definition: sql_service_command.cc:33
Sql_service_interface * get_sql_service_interface()
Returns the SQL service interface associated to this class.
Definition: sql_service_command.cc:123
long execute_query(std::string &query)
Execute a query passed as parameter.
Definition: sql_service_command.cc:264
void terminate_connection_fields()
Stops and deletes all connection related structures.
Definition: sql_service_command.cc:108
Sql_service_interface * m_server_interface
The internal SQL session service interface to the server.
Definition: sql_service_command.h:355
Session_plugin_thread * m_plugin_session_thread
Definition: sql_service_command.h:358
bool is_session_valid()
Checks if there is an existing session.
Definition: sql_service_command.cc:96
int reestablish_connection(enum_plugin_con_isolation isolation_param, const char *user, void *plugin_pointer=nullptr)
Terminates the old connection and creates a new one to the server.
Definition: sql_service_command.cc:89
long execute_conditional_query(std::string &query, bool *result)
Execute a conditional query passed as parameter.
Definition: sql_service_command.cc:321
~Sql_service_command_interface()
Definition: sql_service_command.cc:38
int establish_session_connection(enum_plugin_con_isolation isolation_param, const char *user, void *plugin_pointer=nullptr)
Establishes the connection to the server.
Definition: sql_service_command.cc:42
long clone_server(std::string &host, std::string &port, std::string &username, std::string &password, bool use_ssl, std::string &error)
Method to remotely clone a server.
Definition: sql_service_command.cc:174
enum_plugin_con_isolation connection_thread_isolation
Definition: sql_service_command.h:350
Definition: sql_service_command.h:43
long internal_clone_server(Sql_service_interface *sql_interface, void *variable_args=nullptr)
Method to remotely clone a server.
Definition: sql_service_command.cc:198
long internal_execute_query(Sql_service_interface *sql_interface, void *variable_args=nullptr)
Method to execute a given query.
Definition: sql_service_command.cc:291
long internal_execute_conditional_query(Sql_service_interface *sql_interface, void *variable_args=nullptr)
Method to execute a given conditional query.
Definition: sql_service_command.cc:350
long internal_kill_session(Sql_service_interface *sql_interface, void *session_id=nullptr)
Method to kill the session identified by the given session id in those cases where the server hangs w...
Definition: sql_service_command.cc:131
Definition: sql_service_interface.h:33
Definition: plugin_utils.h:181
Some integer typedefs for easier portability.
static char * query
Definition: myisam_ftdump.cc:46
static char * password
Definition: mysql_secure_installation.cc:57
char * user
Definition: mysqladmin.cc:64
const char * host
Definition: mysqladmin.cc:63
bool terminate(THD *thd)
Drop all DD tables in case there is an error while upgrading server.
Definition: upgrade.cc:685
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:32
enum_plugin_con_isolation
What is the policy when creation a new server session for SQL execution.
Definition: sql_service_command.h:37
@ PSESSION_DEDICATED_THREAD
Use a dedicated thread to open a session.
Definition: sql_service_command.h:40
@ PSESSION_INIT_THREAD
Use the current thread but initialize it.
Definition: sql_service_command.h:39
@ PSESSION_USE_THREAD
Use the current thread.
Definition: sql_service_command.h:38
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: result.h:29
Definition: sql_service_command.h:99
long(Sql_service_commands::* method)(Sql_service_interface *, void *)
Definition: sql_service_command.h:100
bool terminated
Definition: sql_service_command.h:101
Definition: plugin_utils.h:47