Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autocommit invalidly reported in several cases #4052

Merged
merged 3 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
53 changes: 47 additions & 6 deletions test/tap/tests/test_server_sess_status-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -133,18 +133,59 @@ 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
);

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");

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,
Expand Down