From 9a6b176d3144d10e0f497bfdc4a67af3f38172b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 26 Jan 2018 16:19:48 +0100 Subject: [PATCH] Expanding stats_mysql_connection_pool Added counters of queries using gtid sync Added PR #1343 for FR #1207 --- include/MySQL_HostGroups_Manager.h | 14 ++++++++++++++ include/MySQL_Session.h | 3 +++ lib/MySQL_HostGroups_Manager.cpp | 25 ++++++++++++++++++++----- lib/MySQL_Session.cpp | 4 +++- lib/ProxySQL_Admin.cpp | 10 +++++----- lib/mysql_connection.cpp | 3 +++ 6 files changed, 48 insertions(+), 11 deletions(-) diff --git a/include/MySQL_HostGroups_Manager.h b/include/MySQL_HostGroups_Manager.h index b319e3669..3aad02122 100644 --- a/include/MySQL_HostGroups_Manager.h +++ b/include/MySQL_HostGroups_Manager.h @@ -317,6 +317,7 @@ class MySrvC { // MySQL Server Container unsigned int compression; unsigned int max_connections; unsigned int max_replication_lag; + unsigned int max_connections_used; // The maximum number of connections that has been opened unsigned int connect_OK; unsigned int connect_ERR; // note that these variables are in microsecond, while user defines max lantency in millisecond @@ -325,6 +326,7 @@ class MySrvC { // MySQL Server Container time_t time_last_detected_error; unsigned int connect_ERR_at_time_last_detected_error; unsigned long long queries_sent; + unsigned long long queries_gtid_sync; unsigned long long bytes_sent; unsigned long long bytes_recv; bool shunned_automatic; @@ -337,6 +339,18 @@ class MySrvC { // MySQL Server Container ~MySrvC(); void connect_error(int); void shun_and_killall(); + /** + * Update the maximum number of used connections + * @return + * the maximum number of used connections + */ + unsigned int update_max_connections_used() + { + unsigned int connections_used = ConnectionsUsed->conns_length(); + if (max_connections_used < connections_used) + max_connections_used = connections_used; + return max_connections_used; + } }; class MySrvList { // MySQL Server List diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index 3d8f8a8b9..edcd4f5a4 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -172,6 +172,9 @@ class MySQL_Session bool session_fast_forward; bool started_sending_data_to_client; // this status variable tracks if some result set was sent to the client, of if proysql is still buffering everything + + bool with_gtid; + MySQL_STMTs_meta *sess_STMTs_meta; StmtLongDataHandler *SLDH; diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 731180d3c..edff48a18 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -652,6 +652,8 @@ MySrvC::MySrvC(char *add, uint16_t p, uint16_t gp, unsigned int _weight, enum My queries_sent=0; bytes_sent=0; bytes_recv=0; + max_connections_used=0; + queries_gtid_sync=0; time_last_detected_error=0; connect_ERR_at_time_last_detected_error=0; shunned_automatic=false; @@ -2030,6 +2032,7 @@ MySQL_Connection * MySQL_HostGroups_Manager::get_MyConn_from_pool(unsigned int _ if (conn) { mysrvc->ConnectionsUsed->add(conn); status.myconnpoll_get_ok++; + mysrvc->update_max_connections_used(); } } wrunlock(); @@ -2210,7 +2213,7 @@ void MySQL_HostGroups_Manager::set_incoming_group_replication_hostgroups(SQLite3 } SQLite3_result * MySQL_HostGroups_Manager::SQL3_Connection_Pool(bool _reset) { - const int colnum=12; + const int colnum=14; proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 4, "Dumping Connection Pool\n"); SQLite3_result *result=new SQLite3_result(colnum); result->add_column_definition(SQLITE_TEXT,"hostgroup"); @@ -2221,7 +2224,9 @@ SQLite3_result * MySQL_HostGroups_Manager::SQL3_Connection_Pool(bool _reset) { result->add_column_definition(SQLITE_TEXT,"ConnFree"); result->add_column_definition(SQLITE_TEXT,"ConnOK"); result->add_column_definition(SQLITE_TEXT,"ConnERR"); + result->add_column_definition(SQLITE_TEXT,"MaxConnUsed"); result->add_column_definition(SQLITE_TEXT,"Queries"); + result->add_column_definition(SQLITE_TEXT,"Queries_GTID_sync"); result->add_column_definition(SQLITE_TEXT,"Bytes_sent"); result->add_column_definition(SQLITE_TEXT,"Bytes_recv"); result->add_column_definition(SQLITE_TEXT,"Latency_us"); @@ -2284,23 +2289,33 @@ SQLite3_result * MySQL_HostGroups_Manager::SQL3_Connection_Pool(bool _reset) { if (_reset) { mysrvc->connect_ERR=0; } - sprintf(buf,"%llu", mysrvc->queries_sent); + sprintf(buf,"%u", mysrvc->max_connections_used); pta[8]=strdup(buf); + if (_reset) { + mysrvc->max_connections_used=0; + } + sprintf(buf,"%llu", mysrvc->queries_sent); + pta[9]=strdup(buf); if (_reset) { mysrvc->queries_sent=0; } + sprintf(buf,"%llu", mysrvc->queries_gtid_sync); + pta[10]=strdup(buf); + if (_reset) { + mysrvc->queries_gtid_sync=0; + } sprintf(buf,"%llu", mysrvc->bytes_sent); - pta[9]=strdup(buf); + pta[11]=strdup(buf); if (_reset) { mysrvc->bytes_sent=0; } sprintf(buf,"%llu", mysrvc->bytes_recv); - pta[10]=strdup(buf); + pta[12]=strdup(buf); if (_reset) { mysrvc->bytes_recv=0; } sprintf(buf,"%u", mysrvc->current_latency_us); - pta[11]=strdup(buf); + pta[13]=strdup(buf); result->add_row(pta); for (k=0; kexecute("BEGIN"); statsdb->execute("DELETE FROM stats_mysql_connection_pool"); - char *a=(char *)"INSERT INTO stats_mysql_connection_pool VALUES (\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\")"; + char *a=(char *)"INSERT INTO stats_mysql_connection_pool VALUES (\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\")"; for (std::vector::iterator it = resultset->rows.begin() ; it != resultset->rows.end(); ++it) { SQLite3_row *r=*it; int arg_len=0; - for (int i=0; i<12; i++) { + for (int i=0; i<14; i++) { arg_len+=strlen(r->fields[i]); } char *query=(char *)malloc(strlen(a)+arg_len+32); - sprintf(query,a,r->fields[0],r->fields[1],r->fields[2],r->fields[3],r->fields[4],r->fields[5],r->fields[6],r->fields[7],r->fields[8],r->fields[9],r->fields[10],r->fields[11]); + sprintf(query,a,r->fields[0],r->fields[1],r->fields[2],r->fields[3],r->fields[4],r->fields[5],r->fields[6],r->fields[7],r->fields[8],r->fields[9],r->fields[10],r->fields[11],r->fields[12],r->fields[13]); statsdb->execute(query); free(query); } diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 8810e0152..a42bc6ed4 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -710,6 +710,9 @@ handler_again: __sync_fetch_and_add(&parent->queries_sent,1); __sync_fetch_and_add(&parent->bytes_sent,query.length); myds->sess->thread->status_variables.queries_backends_bytes_sent+=query.length; + if (myds->sess->with_gtid == true) { + __sync_fetch_and_add(&parent->queries_gtid_sync,1); + } if (async_exit_status) { next_event(ASYNC_QUERY_CONT); } else {