From c3d0ecd84f7f7ea8898d9e77d8008f9fb26cf96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Mon, 4 Oct 2021 15:12:58 +0200 Subject: [PATCH] Improved implementation of 'mysql-log_mysql_warnings_enabled' #3606 --- lib/MySQL_Session.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 82a14fb1c..be2382b02 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -4531,8 +4531,12 @@ handler_again: if (mysql_thread___log_mysql_warnings_enabled) { auto warn_no = mysql_warning_count(myconn->mysql); if (warn_no > 0) { + RequestEnd(myds); + writeout(); + myconn->async_state_machine=ASYNC_IDLE; myds->DSS=STATE_MARIADB_GENERIC; + NEXT_IMMEDIATE(SHOW_WARNINGS); } } @@ -4636,26 +4640,34 @@ handler_again: break; case SHOW_WARNINGS: + // Performs a 'SHOW WARNINGS' query over the current backend connection and returns the connection back + // to the connection pool when finished. Actual logging of received warnings is performed in + // 'MySQL_Connection' while processing 'ASYNC_USE_RESULT_CONT'. { MySQL_Data_Stream *myds=mybe->server_myds; MySQL_Connection *myconn=myds->myconn; - int pre_rc = myconn->async_query(mybe->server_myds->revents,(char *)"show warnings", strlen((char *)"show warnings")); - if (pre_rc==0) { - int myerr=mysql_errno(myconn->mysql); + int rc = myconn->async_query( + mybe->server_myds->revents,(char *)"SHOW WARNINGS", strlen((char *)"SHOW WARNINGS") + ); + if (rc == 0 || rc == -1) { + // Cleanup the connection resulset from 'SHOW WARNINGS' for the next query. + if (myconn->MyRS != NULL) { + delete myconn->MyRS; + myconn->MyRS = NULL; + } RequestEnd(myds); - writeout(); + finishQuery(myds,myconn,prepared_stmt_with_no_params); + + if (rc == -1) { + int myerr = mysql_errno(myconn->mysql); + proxy_error( + "'SHOW WARNINGS' failed to be executed over backend connection with error: '%d'\n", myerr + ); + } handler_ret = 0; return handler_ret; - if ( myerr > 0 ) { - char sqlstate[10]; - sprintf(sqlstate,"%s",mysql_sqlstate(mybe->server_myds->myconn->mysql)); - RequestEnd(mybe->server_myds); - break; - } - mybe->server_myds->myconn->async_free_result(); - NEXT_IMMEDIATE(PROCESSING_QUERY); } else { goto handler_again; }