Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 9c1b781

Browse files
Jupyung Lee (JP)Herman Lee
authored andcommitted
Port mysql_change_user_nonblocking from 8.0.17 to 8.0.20
Summary: This diff will port client library change made to add mysql_change_user_nonblocking api in 8.0.17, to 8.0.20. In particular, these diffs are ported: D27452997 : [MySQL client] Add mysql_change_user_nonblocking D28080971 : [MySQL client](easy) add the declaration of mysql_change_user_nonblocking in mysql.h.pp D28564637 : [MySQL client] mysql_change_user_nonblocking has to keep calling state_function if it returns STATE_MACHINE_CONTINUE D28940396 : [MySQL Client] Fix memory leak in mysql_change_user_nonblocking, when the call is terminated abnormally Reviewed By: yichenshen Differential Revision: D29434855
1 parent cff91cc commit 9c1b781

8 files changed

Lines changed: 274 additions & 52 deletions

File tree

‎client/mysqltest.cc‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,22 @@ static int socket_event_listen(my_socket fd) {
761761
}
762762
#endif
763763

764+
static int async_mysql_change_user_wrapper(MYSQL *mysql, const char *user,
765+
const char *passwd, const char *db) {
766+
net_async_status status;
767+
AsyncTimer t(__func__);
768+
while ((status = mysql_change_user_nonblocking(mysql, user, passwd, db)) ==
769+
NET_ASYNC_NOT_READY) {
770+
t.check();
771+
int result = socket_event_listen(mysql_get_socket_descriptor(mysql));
772+
if (result == -1) return 1;
773+
}
774+
if (status == NET_ASYNC_ERROR) {
775+
return 1;
776+
}
777+
return 0;
778+
}
779+
764780
/*
765781
Below async_mysql_*_wrapper functions are used to measure how much time
766782
each nonblocking call spends before completing the operations.
@@ -1006,6 +1022,14 @@ static int mysql_reset_connection_wrapper(MYSQL *mysql) {
10061022
return mysql_reset_connection(mysql);
10071023
}
10081024

1025+
static int mysql_change_user_wrapper(MYSQL *mysql, const char *user,
1026+
const char *passwd, const char *db) {
1027+
if (enable_async_client)
1028+
return async_mysql_change_user_wrapper(mysql, user, passwd, db);
1029+
else
1030+
return mysql_change_user(mysql, user, passwd, db);
1031+
}
1032+
10091033
/* async client test code (end) */
10101034

10111035
void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val, size_t len);
@@ -5017,7 +5041,7 @@ static void do_change_user(struct st_command *command) {
50175041
("connection: '%s' user: '%s' password: '%s' database: '%s'",
50185042
cur_con->name, ds_user.str, ds_passwd.str, ds_db.str));
50195043

5020-
if (mysql_change_user(mysql, ds_user.str, ds_passwd.str, ds_db.str)) {
5044+
if (mysql_change_user_wrapper(mysql, ds_user.str, ds_passwd.str, ds_db.str)) {
50215045
handle_error(curr_command, mysql_errno(mysql), mysql_error(mysql),
50225046
mysql_sqlstate(mysql), &ds_res);
50235047
mysql->reconnect = true;

‎include/mysql.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ bool STDCALL mysql_free_ssl_session_data(MYSQL *mysql, void *data);
493493
void *STDCALL mysql_take_ssl_context_ownership(MYSQL *mysql);
494494
bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
495495
const char *passwd, const char *db);
496+
enum net_async_status STDCALL mysql_change_user_nonblocking(MYSQL *mysql,
497+
const char *user,
498+
const char *passwd,
499+
const char *db);
496500
MYSQL *STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
497501
const char *user, const char *passwd,
498502
const char *db, unsigned int port,

‎include/mysql.h.pp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@
683683
void * mysql_take_ssl_context_ownership(MYSQL *mysql);
684684
bool mysql_change_user(MYSQL *mysql, const char *user,
685685
const char *passwd, const char *db);
686+
enum net_async_status mysql_change_user_nonblocking(MYSQL *mysql,
687+
const char *user,
688+
const char *passwd,
689+
const char *db);
686690
MYSQL * mysql_real_connect(MYSQL *mysql, const char *host,
687691
const char *user, const char *passwd,
688692
const char *db, unsigned int port,

‎include/sql_common.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ struct MYSQL_PLUGIN_VIO_INFO;
325325
void mpvio_info(MYSQL_VIO vio, MYSQL_PLUGIN_VIO_INFO *info);
326326
int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
327327
const char *data_plugin, const char *db);
328+
enum net_async_status run_plugin_auth_nonblocking_wrapper(MYSQL *mysql,
329+
const char *user,
330+
const char *passwd,
331+
const char *db);
328332
int mysql_client_plugin_init();
329333
void mysql_client_plugin_deinit();
330334

‎libmysql/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ SET(CLIENT_API_NONBLOCKING_FUNCTIONS
191191
mysql_get_socket_descriptor
192192
mysql_get_connect_stage
193193
mysql_reset_connection_nonblocking
194+
mysql_change_user_nonblocking
194195
CACHE INTERNAL "Nonblocking functions exported by client API"
195196
)
196197

‎libmysql/libmysql.cc‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,24 @@ void STDCALL mysql_debug(const char *debug [[maybe_unused]]) {
259259
#endif
260260
}
261261

262+
/**************************************************************************
263+
Change user and database, nonblocking
264+
**************************************************************************/
265+
266+
net_async_status STDCALL mysql_change_user_nonblocking(MYSQL *mysql,
267+
const char *user,
268+
const char *passwd,
269+
const char *db) {
270+
net_async_status status =
271+
run_plugin_auth_nonblocking_wrapper(mysql, user, passwd, db);
272+
273+
if (status == NET_ASYNC_COMPLETE || status == NET_ASYNC_ERROR) {
274+
mysql_detach_stmt_list(&mysql->stmts, "mysql_change_user");
275+
}
276+
277+
return status;
278+
}
279+
262280
/**************************************************************************
263281
Change user and database
264282
**************************************************************************/

0 commit comments

Comments
 (0)