From 697a9b600f98e684f27c28d73f232aade59fa268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20S=C3=A1nchez=20Parra?= Date: Tue, 13 Dec 2022 17:05:45 +0100 Subject: [PATCH 1/3] Fix autocommit invalidly reported in several cases Otherwise, autocommit status flag is always zero, instead of displaying its true value. OK responses were reporting an invalid autocommit during handshake, reset_connection and change_user petitions. --- lib/MySQL_Session.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 089db49f8..5138837ee 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -5397,7 +5397,7 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE( (strcmp(client_addr,(char *)"::1")==0) ) { // we are good! - client_myds->myprot.generate_pkt_OK(true,NULL,NULL, _pid, 0,0,0,0,NULL); + client_myds->myprot.generate_pkt_OK(true, NULL, NULL, _pid, 0, 0, 2, 0, NULL); handshake_err = false; GloMyLogger->log_audit_entry(PROXYSQL_MYSQL_AUTH_OK, this, NULL); status=WAITING_CLIENT_DATA; @@ -5443,7 +5443,7 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE( //client_myds->myprot.generate_pkt_OK(true,NULL,NULL, (is_encrypted ? 3 : 2), 0,0,0,0,NULL,false); proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION,8,"Session=%p , DS=%p . STATE_CLIENT_AUTH_OK\n", this, client_myds); GloMyLogger->log_audit_entry(PROXYSQL_MYSQL_AUTH_OK, this, NULL); - client_myds->myprot.generate_pkt_OK(true,NULL,NULL, _pid, 0,0,0,0,NULL); + client_myds->myprot.generate_pkt_OK(true, NULL, NULL, _pid, 0, 0, 2, 0, NULL); handshake_err = false; status=WAITING_CLIENT_DATA; client_myds->DSS=STATE_CLIENT_AUTH_OK; @@ -6710,7 +6710,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C client_authenticated=false; if (client_myds->myprot.process_pkt_COM_CHANGE_USER((unsigned char *)pkt->ptr, pkt->size)==true) { l_free(pkt->size,pkt->ptr); - client_myds->myprot.generate_pkt_OK(true,NULL,NULL,1,0,0,0,0,NULL); + client_myds->myprot.generate_pkt_OK(true, NULL, NULL, 1, 0, 0, 2, 0, NULL); client_myds->DSS=STATE_SLEEP; status=WAITING_CLIENT_DATA; *wrong_pass=false; @@ -6800,7 +6800,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C l_free(pkt->size,pkt->ptr); client_myds->setDSS_STATE_QUERY_SENT_NET(); - client_myds->myprot.generate_pkt_OK(true,NULL,NULL,1,0,0,0,0,NULL); + client_myds->myprot.generate_pkt_OK(true, NULL, NULL, 1, 0, 0, 2, 0, NULL); client_myds->DSS=STATE_SLEEP; status=WAITING_CLIENT_DATA; } else { From dfb3ef2cefc9b2fa5cbcd94804578c6e8b3b6f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20S=C3=A1nchez=20Parra?= Date: Wed, 14 Dec 2022 12:34:01 +0100 Subject: [PATCH 2/3] Fix test_server_sess_status-t to expect autocommit to be set Commit c319438484d918cc90d3cd3eb8dd3d4d0eecd5a1 fixed the bug that caused autocommit to be shown as disabled when it is truly enabled. --- test/tap/tests/test_server_sess_status-t.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/tap/tests/test_server_sess_status-t.cpp b/test/tap/tests/test_server_sess_status-t.cpp index 076481547..c7233600c 100644 --- a/test/tap/tests/test_server_sess_status-t.cpp +++ b/test/tap/tests/test_server_sess_status-t.cpp @@ -133,18 +133,18 @@ int main(int argc, char** argv) { exp_mysql_srv_st, mysql->server_status ); - // TODO-FIXME: We are setting here '0' as expecting to see 'SERVER_STATUS_AUTOCOMMIT' to be false. - // This is a bug that should be addressed, and this test revisited. + uint32_t exp_proxy_srv_st = SERVER_STATUS_AUTOCOMMIT; + ok( - proxy->server_status == 0, + exp_proxy_srv_st == proxy->server_status, "ProxySQL init server status should match expected - exp: '%d', act:'%d'", - 0, proxy->server_status + exp_proxy_srv_st, proxy->server_status ); mysql_query(proxy, "SET SESSION session_track_transaction_info=\"CHARACTERISTICS\""); mysql_query(proxy, "START TRANSACTION"); - uint32_t exp_proxy_srv_st = SERVER_STATUS_AUTOCOMMIT | SERVER_STATUS_IN_TRANS; + exp_proxy_srv_st = SERVER_STATUS_AUTOCOMMIT | SERVER_STATUS_IN_TRANS; ok( exp_proxy_srv_st == proxy->server_status, From 0e7afa3391e64353890a513eae612f01ef9fd45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20S=C3=A1nchez=20Parra?= Date: Wed, 14 Dec 2022 12:37:17 +0100 Subject: [PATCH 3/3] Add test to check autocommit is set during reset_connection and change_user Adds a test to check that ProxySQL OK responses to reset_connection and change_user petitions have autocommit flag set. --- test/tap/tests/test_server_sess_status-t.cpp | 43 +++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/test/tap/tests/test_server_sess_status-t.cpp b/test/tap/tests/test_server_sess_status-t.cpp index c7233600c..cf743b275 100644 --- a/test/tap/tests/test_server_sess_status-t.cpp +++ b/test/tap/tests/test_server_sess_status-t.cpp @@ -81,7 +81,7 @@ int main(int argc, char** argv) { CommandLine cl; // TODO: Harcoded for now, this is an initial version of the test. - plan(4); + plan(6); if (cl.getEnv()) { diag("Failed to get the required environmental variables."); @@ -141,6 +141,47 @@ int main(int argc, char** argv) { exp_proxy_srv_st, proxy->server_status ); + int err_code = mysql_reset_connection(proxy); + if (err_code != EXIT_SUCCESS) { + diag( + "'mysql_reset_connection' failed with error: (%d,'%s') at ('%s':'%d')", + mysql_errno(proxy), mysql_error(proxy), __FILE__, __LINE__ + ); + return EXIT_FAILURE; + } + + ok( + exp_proxy_srv_st == proxy->server_status, + "ProxySQL server status after reset connection should match expected - exp: '%d', act:'%d'", + exp_proxy_srv_st, proxy->server_status + ); + + const string username = { "sbtest_reset_conn_1" }; + const string password = { "sbtest_reset_conn_1" }; + const string attributes = { "" }; + err_code = create_proxysql_user(admin, username, password, attributes); + if (err_code) { + diag("'create_proxysql_user' failed at ('%s':'%d') with error '%d'", __FILE__, __LINE__, err_code); + return EXIT_FAILURE; + } + + MYSQL_QUERY(admin, "LOAD MYSQL USERS TO RUNTIME"); + + err_code = mysql_change_user(proxy, username.c_str(), password.c_str(), NULL); + if (err_code != EXIT_SUCCESS) { + diag( + "'mysql_change_user' failed with error: (%d,'%s') at ('%s':'%d')", + mysql_errno(proxy), mysql_error(proxy), __FILE__, __LINE__ + ); + return EXIT_FAILURE; + } + + ok( + exp_proxy_srv_st == proxy->server_status, + "ProxySQL server status after change user should match expected - exp: '%d', act:'%d'", + exp_proxy_srv_st, proxy->server_status + ); + mysql_query(proxy, "SET SESSION session_track_transaction_info=\"CHARACTERISTICS\""); mysql_query(proxy, "START TRANSACTION");