Skip to content

Commit

Permalink
* Execute all test cases with 'CLIENT_DEPRECATE_EOF' both enabled and…
Browse files Browse the repository at this point in the history
… disabled.

* Introduced 'ps_type' enum to differentiate between preparing a statement and executing a statement
* Fixed issue where the warning count fails to reset when the SET statement generates a warning.
* Resolved the issue where the 'server_status' and 'warning count' were not accurately represented in the statement.
* Replaced 'mysql_warning_count' with 'mysql_stmt_warning_count' for retrieving the warning count in statements.
* Added 'handle_warning' field in hostgroup_attributes TAP test
* Updated warnings TAP test
  • Loading branch information
rahim-kanji committed Nov 16, 2023
1 parent ffb6676 commit 045d6bc
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 166 deletions.
4 changes: 3 additions & 1 deletion deps/mariadb-client-library/client_deprecate_eof.patch
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ index 0aaaf1a..229023b 100644
{
/* allocate space for rows */
if (!(current= (MYSQL_ROWS *)ma_alloc_root(&result->alloc, sizeof(MYSQL_ROWS) + packet_len)))
@@ -276,10 +284,14 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt)
@@ -276,10 +284,16 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt)
{
*pprevious= 0;
/* sace status info */
Expand All @@ -664,6 +664,8 @@ index 0aaaf1a..229023b 100644
+
+ if (stmt->mysql->server_capabilities & CLIENT_DEPRECATE_EOF && !is_data_packet) {
+ ma_read_ok_packet(stmt->mysql, p + 1, packet_len);
+ stmt->upsert_status.warning_count= stmt->mysql->warning_count;
+ stmt->upsert_status.server_status= stmt->mysql->server_status;
+ } else {
+ stmt->upsert_status.warning_count= stmt->mysql->warning_count= uint2korr(p + 1);
+ stmt->upsert_status.server_status= stmt->mysql->server_status= uint2korr(p + 3);
Expand Down
8 changes: 7 additions & 1 deletion include/MySQL_Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ enum proxysql_session_type {
PROXYSQL_SESSION_NONE
};

enum ps_type : uint8_t {
ps_type_not_set = 0x0,
ps_type_prepare_stmt = 0x1,
ps_type_execute_stmt = 0x2
};

std::string proxysql_session_type_str(enum proxysql_session_type session_type);

// these structs will be used for various regex hardcoded
Expand Down Expand Up @@ -121,7 +127,7 @@ class MySQL_Session
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_SET_OPTION(PtrSize_t *);
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_STATISTICS(PtrSize_t *);
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_PROCESS_KILL(PtrSize_t *);
bool handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(PtrSize_t *, bool *lock_hostgroup, bool ps=false);
bool handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(PtrSize_t *, bool *lock_hostgroup, ps_type prepare_stmt_type=ps_type_not_set);

void handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED__get_connection();

Expand Down
15 changes: 7 additions & 8 deletions lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3289,7 +3289,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
}
assert(qpo); // GloQPro->process_mysql_query() should always return a qpo
// setting 'prepared' to prevent fetching results from the cache if the digest matches
rc_break=handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(&pkt, &lock_hostgroup, true);
rc_break=handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(&pkt, &lock_hostgroup, ps_type_prepare_stmt);
if (rc_break==true) {
return;
}
Expand Down Expand Up @@ -3457,7 +3457,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C

CurrentQuery.stmt_meta=stmt_meta;
//current_hostgroup=qpo->destination_hostgroup;
rc_break=handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(&pkt, &lock_hostgroup, true);
rc_break=handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(&pkt, &lock_hostgroup, ps_type_execute_stmt);
if (rc_break==true) {
return;
}
Expand Down Expand Up @@ -5992,7 +5992,7 @@ int MySQL_Session::handler_WCD_SS_MCQ_qpo_Parse_SQL_LOG_BIN(PtrSize_t *pkt, bool
}
*/

bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(PtrSize_t *pkt, bool *lock_hostgroup, bool prepared) {
bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(PtrSize_t *pkt, bool *lock_hostgroup, ps_type prepare_stmt_type) {
/*
lock_hostgroup:
If this variable is set to true, this session will get lock to a
Expand Down Expand Up @@ -6027,7 +6027,7 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
return true;
}

if (prepared) { // for prepared statement we exit here
if (prepare_stmt_type & ps_type_execute_stmt) { // for prepared statement execute we exit here
reset_warning_hostgroup_flag_and_release_connection();
goto __exit_set_destination_hostgroup;
}
Expand All @@ -6043,7 +6043,6 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
if (warning_in_hg > -1) {
proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Changing current_hostgroup to '%d'\n", warning_in_hg);
current_hostgroup = warning_in_hg;
//warning_in_hg = -1;
return false;
} else {
proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "No warnings were detected in the previous query. Sending an empty response.\n");
Expand Down Expand Up @@ -6951,12 +6950,12 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
}

// handle command KILL #860
if (prepared == false) {
//if (prepared == false) {
if (handle_command_query_kill(pkt)) {
return true;
}
}
if (qpo->cache_ttl>0) {
//}
if (qpo->cache_ttl>0 && ((prepare_stmt_type & ps_type_prepare_stmt) == 0)) {
bool deprecate_eof_active = client_myds->myconn->options.client_flag & CLIENT_DEPRECATE_EOF;
uint32_t resbuf=0;
unsigned char *aa=GloQC->get(
Expand Down
20 changes: 10 additions & 10 deletions lib/mysql_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,13 @@ void MySQL_Connection::update_warning_count_from_connection() {
// 'mysql_thread_query_digest' is set to false, fetching that statement from the cache may still contain the digest text.
// To prevent this, we will check the digest text in conjunction with 'mysql_thread_query_digest' to verify whether it
// is enabled or disabled.
if (myds && myds->sess && (myds->sess->CurrentQuery.QueryParserArgs.digest_text ||
(myds->sess->CurrentQuery.stmt_info && myds->sess->CurrentQuery.stmt_info->digest_text &&
mysql_thread___query_digests == true))) {
const bool handle_warnings_enabled = parent->myhgc->handle_warnings_enabled();
if (handle_warnings_enabled && mysql_errno(mysql) == 0 && mysql_warning_count(mysql) > 0) {
if (myds && myds->sess && myds->sess->CurrentQuery.QueryParserArgs.digest_text) {
const char* dig_text = myds->sess->CurrentQuery.QueryParserArgs.digest_text;
const size_t dig_len = strlen(dig_text);
// SHOW WARNINGS doesn't have any impact warning count,
// so we are replication same behaviour here
if (parent->myhgc->handle_warnings_enabled() &&
(dig_len != 13 || strncasecmp(dig_text, "SHOW WARNINGS", 13) != 0)) {
warning_count = mysql_warning_count(mysql);
}
}
Expand All @@ -571,8 +573,7 @@ void MySQL_Connection::update_warning_count_from_statement() {
// is enabled or disabled.
if (myds && myds->sess && myds->sess->CurrentQuery.stmt_info && myds->sess->CurrentQuery.stmt_info->digest_text &&
mysql_thread___query_digests == true) {
const bool handle_warnings_enabled = parent->myhgc->handle_warnings_enabled();
if (handle_warnings_enabled && mysql_stmt_warning_count(query.stmt) > 0) {
if (parent->myhgc->handle_warnings_enabled()) {
warning_count = mysql_stmt_warning_count(query.stmt);
}
}
Expand Down Expand Up @@ -1382,7 +1383,7 @@ MDB_ASYNC_ST MySQL_Connection::handler(short event) {
if (query.stmt_result==NULL) {
NEXT_IMMEDIATE(ASYNC_STMT_EXECUTE_END);
} else {
update_warning_count_from_connection(); //update_warning_count_from_statement();
update_warning_count_from_statement();
if (myds->sess->mirror==false) {
if (MyRS_reuse == NULL) {
MyRS = new MySQL_ResultSet();
Expand Down Expand Up @@ -1497,7 +1498,7 @@ MDB_ASYNC_ST MySQL_Connection::handler(short event) {
NEXT_IMMEDIATE(ASYNC_STMT_EXECUTE_SUCCESSFUL);
}
*/
update_warning_count_from_connection(); //update_warning_count_from_statement();
update_warning_count_from_statement();
break;
// case ASYNC_STMT_EXECUTE_SUCCESSFUL:
// break;
Expand Down Expand Up @@ -2615,7 +2616,6 @@ void MySQL_Connection::ProcessQueryAndSetStatusFlags(char *query_digest_text) {
// 'warning_in_hg' will be used if the next query is 'SHOW WARNINGS' or
// 'SHOW COUNT(*) WARNINGS'
myds->sess->warning_in_hg = myds->sess->current_hostgroup;
//warning_count = mysql_warning_count(this->mysql);
// enabling multiplexing
set_status(true, STATUS_MYSQL_CONNECTION_HAS_WARNINGS);
}
Expand Down
2 changes: 1 addition & 1 deletion test/tap/tests/test_cluster_sync-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ int main(int, char**) {
std::make_tuple(18, 2, -1, 20, "SET sql_mode = \"\"", 0, 0, 100, "", "", ""),
std::make_tuple(19, 2, -1, 20, "SET sql_mode = \"\"", 0, 0, 100, "{}", "{}", "{}"),
std::make_tuple(20, 0, 0, 30, "SET long_query_time = 0", 1, 0, 123, "{\"session_variables\":[\"tmp_table_size\",\"join_buffer_size\"]}", "", ""),
std::make_tuple(21, 2, -1, 50, "SET sql_mode = \"\"", 1, 0, 125, "{\"session_variables\":[\"tmp_table_size\",\"join_buffer_size\"]}", "{}", ""),
std::make_tuple(21, 2, -1, 50, "SET sql_mode = \"\"", 1, 0, 125, "{\"session_variables\":[\"tmp_table_size\",\"join_buffer_size\"]}", "{\"handle_warnings\":1}", ""),
std::make_tuple(22, 3, -1, 40, "SET sql_mode = \"\"", 1, 0, 124, "{\"session_variables\":[\"tmp_table_size\",\"join_buffer_size\"]}", "", "{\"weight\": 100, \"max_connections\": 1000}")
};
std::vector<std::string> insert_mysql_hostgroup_attributes_queries{};
Expand Down
Loading

0 comments on commit 045d6bc

Please sign in to comment.