From 41cd740701f9e304e9d1842a54a9018372f1326f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Thu, 18 Jan 2024 05:04:53 +0000 Subject: [PATCH] Added metric MultiplexDisabled_ext #4241 In the output of PROXYSQL INTERNAL SESSION and stats_mysql_processlist.extended_info , MultiplexDisabled was only returning the output of MySQL_Connection::MultiplexDisabled() . If there was a transaction, or an error, multiplexing was disabled but MultiplexDisabled() was still reporting false. Therefore it was necessary to also check server_status flag and last_errno. This commits intruduces MultiplexDisabled_ext , that reports the output of: MySQL_Connection::MultiplexDisabled() || MySQL_Connection::isActiveTransaction() This should make troubleshooting easier. Also, removed any reference to deprecated STATUS_MYSQL_CONNECTION_TRANSACTION . Closes #4241 --- include/mysql_connection.h | 2 +- lib/MySQL_Session.cpp | 14 ++++++++++++-- lib/mysql_connection.cpp | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/mysql_connection.h b/include/mysql_connection.h index 501ccd7610..5b90881517 100644 --- a/include/mysql_connection.h +++ b/include/mysql_connection.h @@ -7,7 +7,7 @@ #include "../deps/json/json.hpp" using json = nlohmann::json; -#define STATUS_MYSQL_CONNECTION_TRANSACTION 0x00000001 +//#define STATUS_MYSQL_CONNECTION_TRANSACTION 0x00000001 // DEPRECATED #define STATUS_MYSQL_CONNECTION_COMPRESSION 0x00000002 #define STATUS_MYSQL_CONNECTION_USER_VARIABLE 0x00000004 #define STATUS_MYSQL_CONNECTION_PREPARED_STATEMENT 0x00000008 diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 61ea7d08eb..7254cf1227 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -1191,7 +1191,6 @@ void MySQL_Session::generate_proxysql_internal_session_json(json &j) { j["conn"]["client_flag"]["client_deprecate_eof"] = (client_myds->myconn->options.client_flag & CLIENT_DEPRECATE_EOF ? 1 : 0); j["conn"]["no_backslash_escapes"] = client_myds->myconn->options.no_backslash_escapes; j["conn"]["status"]["compression"] = client_myds->myconn->get_status(STATUS_MYSQL_CONNECTION_COMPRESSION); - j["conn"]["status"]["transaction"] = client_myds->myconn->get_status(STATUS_MYSQL_CONNECTION_TRANSACTION); j["conn"]["ps"]["client_stmt_to_global_ids"] = client_myds->myconn->local_stmts->client_stmt_to_global_ids; } } @@ -1250,7 +1249,18 @@ void MySQL_Session::generate_proxysql_internal_session_json(json &j) { j["backends"][i]["conn"]["status"]["prepared_statement"] = _myconn->get_status(STATUS_MYSQL_CONNECTION_PREPARED_STATEMENT); j["backends"][i]["conn"]["status"]["has_warnings"] = _myconn->get_status(STATUS_MYSQL_CONNECTION_HAS_WARNINGS); j["backends"][i]["conn"]["warning_count"] = _myconn->warning_count; - j["backends"][i]["conn"]["MultiplexDisabled"] = _myconn->MultiplexDisabled(); + { + // MultiplexDisabled : status returned by MySQL_Connection::MultiplexDisabled(); + // MultiplexDisabled_ext : status returned by MySQL_Connection::MultiplexDisabled() || MySQL_Connection::isActiveTransaction() + bool multiplex_disabled = _myconn->MultiplexDisabled(); + j["backends"][i]["conn"]["MultiplexDisabled"] = multiplex_disabled; + if (multiplex_disabled == false) { + if (_myconn->IsActiveTransaction() == true) { + multiplex_disabled = true; + } + } + j["backends"][i]["conn"]["MultiplexDisabled_ext"] = multiplex_disabled; + } j["backends"][i]["conn"]["ps"]["backend_stmt_to_global_ids"] = _myconn->local_stmts->backend_stmt_to_global_ids; j["backends"][i]["conn"]["ps"]["global_stmt_to_backend_ids"] = _myconn->local_stmts->global_stmt_to_backend_ids; j["backends"][i]["conn"]["client_flag"]["value"] = _myconn->options.client_flag; diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 4400d7ec9b..458c581858 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -2492,7 +2492,7 @@ bool MySQL_Connection::MultiplexDisabled(bool check_delay_token) { // status_flags stores information about the status of the connection // can be used to determine if multiplexing can be enabled or not bool ret=false; - if (status_flags & (STATUS_MYSQL_CONNECTION_TRANSACTION | STATUS_MYSQL_CONNECTION_USER_VARIABLE | STATUS_MYSQL_CONNECTION_PREPARED_STATEMENT | + if (status_flags & (STATUS_MYSQL_CONNECTION_USER_VARIABLE | STATUS_MYSQL_CONNECTION_PREPARED_STATEMENT | STATUS_MYSQL_CONNECTION_LOCK_TABLES | STATUS_MYSQL_CONNECTION_TEMPORARY_TABLE | STATUS_MYSQL_CONNECTION_GET_LOCK | STATUS_MYSQL_CONNECTION_NO_MULTIPLEX | STATUS_MYSQL_CONNECTION_SQL_LOG_BIN0 | STATUS_MYSQL_CONNECTION_FOUND_ROWS | STATUS_MYSQL_CONNECTION_NO_MULTIPLEX_HG | STATUS_MYSQL_CONNECTION_HAS_SAVEPOINT | STATUS_MYSQL_CONNECTION_HAS_WARNINGS) ) {