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