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

Closes #3327: Call 'ProcessQueryAndSetStatusFlags' check even if query failed #3328

Merged
merged 2 commits into from
Mar 3, 2021
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
10 changes: 5 additions & 5 deletions lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4345,11 +4345,6 @@ int MySQL_Session::handler() {

handler_rc0_Process_GTID(myconn);

// check if multiplexing needs to be disabled
char *qdt=CurrentQuery.get_digest_text();
if (qdt)
myconn->ProcessQueryAndSetStatusFlags(qdt);

if (mirror == false) {
// Support for LAST_INSERT_ID()
if (myconn->mysql->insert_id) {
Expand Down Expand Up @@ -6557,6 +6552,11 @@ void MySQL_Session::LogQuery(MySQL_Data_Stream *myds) {
// this should execute most of the commands executed when a request is finalized
// this should become the place to hook other functions
void MySQL_Session::RequestEnd(MySQL_Data_Stream *myds) {
// check if multiplexing needs to be disabled
char *qdt=CurrentQuery.get_digest_text();
if (qdt && myds && myds->myconn) {
myds->myconn->ProcessQueryAndSetStatusFlags(qdt);
}

switch (status) {
case PROCESSING_STMT_EXECUTE:
Expand Down
77 changes: 77 additions & 0 deletions test/tap/tests/reg_test_3327-process_query_set_status_flags-t.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* @file reg_test_3327-process_query_set_status_flags-t.cpp
* @brief This test is a regression test for issue #3327.
* @details The test performs a invalid query that according to the new introduced behavior in
* ProxySQL #3327 should be processed by 'ProcessQueryAndSetStatusFlags' and disable multiplexing.
* @date 2021-03-01
*/

#include <vector>
#include <string>
#include <stdio.h>
#include <mysql.h>

#include "tap.h"
#include "command_line.h"
#include "utils.h"
#include "json.hpp"

using std::string;
using namespace nlohmann;

void parse_result_json_column(MYSQL_RES *result, json& j) {
if(!result) return;
MYSQL_ROW row;

while ((row = mysql_fetch_row(result))) {
j = json::parse(row[0]);
}
}

int main(int argc, char** argv) {
CommandLine cl;

if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
return -1;
}

MYSQL* proxysql_mysql = mysql_init(NULL);

if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql));
return -1;
}

int query_err = mysql_query(proxysql_mysql, "SELECT SQL_CALC_FOUND_ROWS * FROM reg_test_3327_non_exist_table");
ok (query_err != 0, "Initial query failed as intended.");

MYSQL_QUERY(proxysql_mysql, "PROXYSQL INTERNAL SESSION");
json j_status {};
MYSQL_RES* int_session_res = mysql_store_result(proxysql_mysql);
parse_result_json_column(int_session_res, j_status);
mysql_free_result(int_session_res);

if (j_status.contains("backends")) {
bool found_backend = false;
for (auto& backend : j_status["backends"]) {
if (backend != nullptr && backend.contains("conn") && backend["conn"].contains("status")) {
found_backend = true;
bool multiplex_disabled = backend["conn"]["MultiplexDisabled"];
ok(
multiplex_disabled == true,
"Connection status should reflect that 'MultiplexDisabled' is enabled due to the invalid 'SELECT SQL_CALC_FOUND_ROWS'."
);
}
}
if (found_backend == false) {
ok(false, "'backends' doens't contains 'conn' objects with the relevant session information");
}
} else {
ok(false, "No backends detected for the current connection.");
}

mysql_close(proxysql_mysql);

return exit_status();
}