Skip to content
Open
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
3 changes: 3 additions & 0 deletions include/MySQL_HostGroups_Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ class MySrvC { // MySQL Server Container
unsigned int connect_ERR_at_time_last_detected_error;
unsigned long long queries_sent;
unsigned long long queries_gtid_sync;
unsigned long long queries_ok;
unsigned long long queries_err;
unsigned long long queries_warnings;
Comment thread
adregner marked this conversation as resolved.
unsigned long long bytes_sent;
unsigned long long bytes_recv;
bool shunned_automatic;
Expand Down
4 changes: 2 additions & 2 deletions include/ProxySQL_Admin_Tables_Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@
#define STATS_SQLITE_TABLE_MYSQL_USERS "CREATE TABLE stats_mysql_users (username VARCHAR PRIMARY KEY , frontend_connections INT NOT NULL , frontend_max_connections INT NOT NULL)"
#define STATS_SQLITE_TABLE_MYSQL_COMMANDS_COUNTERS "CREATE TABLE stats_mysql_commands_counters (Command VARCHAR NOT NULL PRIMARY KEY , Total_Time_us INT NOT NULL , Total_cnt INT NOT NULL , cnt_100us INT NOT NULL , cnt_500us INT NOT NULL , cnt_1ms INT NOT NULL , cnt_5ms INT NOT NULL , cnt_10ms INT NOT NULL , cnt_50ms INT NOT NULL , cnt_100ms INT NOT NULL , cnt_500ms INT NOT NULL , cnt_1s INT NOT NULL , cnt_5s INT NOT NULL , cnt_10s INT NOT NULL , cnt_INFs)"
#define STATS_SQLITE_TABLE_MYSQL_PROCESSLIST "CREATE TABLE stats_mysql_processlist (ThreadID INT NOT NULL , SessionID INTEGER PRIMARY KEY , user VARCHAR , db VARCHAR , cli_host VARCHAR , cli_port INT , hostgroup INT , l_srv_host VARCHAR , l_srv_port INT , srv_host VARCHAR , srv_port INT , command VARCHAR , time_ms INT NOT NULL , info VARCHAR , status_flags INT , extended_info VARCHAR)"
#define STATS_SQLITE_TABLE_MYSQL_CONNECTION_POOL "CREATE TABLE stats_mysql_connection_pool (hostgroup INT , srv_host VARCHAR , srv_port INT , status VARCHAR , ConnUsed INT , ConnFree INT , ConnOK INT , ConnERR INT , MaxConnUsed INT , Queries INT , Queries_GTID_sync INT , Bytes_data_sent INT , Bytes_data_recv INT , Latency_us INT)"
#define STATS_SQLITE_TABLE_MYSQL_CONNECTION_POOL "CREATE TABLE stats_mysql_connection_pool (hostgroup INT , srv_host VARCHAR , srv_port INT , status VARCHAR , ConnUsed INT , ConnFree INT , ConnOK INT , ConnERR INT , MaxConnUsed INT , Queries INT , Queries_GTID_sync INT , Bytes_data_sent INT , Bytes_data_recv INT , Latency_us INT , Queries_OK INT , Queries_ERR INT , Queries_warnings INT)"

#define STATS_SQLITE_TABLE_MYSQL_CONNECTION_POOL_RESET "CREATE TABLE stats_mysql_connection_pool_reset (hostgroup INT , srv_host VARCHAR , srv_port INT , status VARCHAR , ConnUsed INT , ConnFree INT , ConnOK INT , ConnERR INT , MaxConnUsed INT , Queries INT , Queries_GTID_sync INT , Bytes_data_sent INT , Bytes_data_recv INT , Latency_us INT)"
#define STATS_SQLITE_TABLE_MYSQL_CONNECTION_POOL_RESET "CREATE TABLE stats_mysql_connection_pool_reset (hostgroup INT , srv_host VARCHAR , srv_port INT , status VARCHAR , ConnUsed INT , ConnFree INT , ConnOK INT , ConnERR INT , MaxConnUsed INT , Queries INT , Queries_GTID_sync INT , Bytes_data_sent INT , Bytes_data_recv INT , Latency_us INT , Queries_OK INT , Queries_ERR INT , Queries_warnings INT)"

#define STATS_SQLITE_TABLE_MYSQL_FREE_CONNECTIONS "CREATE TABLE stats_mysql_free_connections (fd INT NOT NULL , hostgroup INT NOT NULL , srv_host VARCHAR NOT NULL , srv_port INT NOT NULL , user VARCHAR NOT NULL , schema VARCHAR , init_connect VARCHAR , time_zone VARCHAR , sql_mode VARCHAR , autocommit VARCHAR , idle_ms INT , statistics VARCHAR , mysql_info VARCHAR)"

Expand Down
4 changes: 3 additions & 1 deletion include/ProxySQL_Statistics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

#define STATSDB_SQLITE_TABLE_HISTORY_STATS_MYSQL_CONNECTION_POOL_V2_0_10 "CREATE TABLE history_stats_mysql_connection_pool (timestamp INT NOT NULL , hostgroup INT , srv_host VARCHAR , srv_port INT , status VARCHAR , ConnUsed INT , ConnFree INT , ConnOK INT , ConnERR INT , MaxConnUsed INT , Queries INT , Queries_GTID_sync INT , Bytes_data_sent INT , Bytes_data_recv INT , Latency_us INT, PRIMARY KEY (timestamp, hostgroup , srv_host , srv_port))"

#define STATSDB_SQLITE_TABLE_HISTORY_STATS_MYSQL_CONNECTION_POOL STATSDB_SQLITE_TABLE_HISTORY_STATS_MYSQL_CONNECTION_POOL_V2_0_10
#define STATSDB_SQLITE_TABLE_HISTORY_STATS_MYSQL_CONNECTION_POOL_V3_0_10 "CREATE TABLE history_stats_mysql_connection_pool (timestamp INT NOT NULL , hostgroup INT , srv_host VARCHAR , srv_port INT , status VARCHAR , ConnUsed INT , ConnFree INT , ConnOK INT , ConnERR INT , MaxConnUsed INT , Queries INT , Queries_GTID_sync INT , Bytes_data_sent INT , Bytes_data_recv INT , Latency_us INT , Queries_OK INT , Queries_ERR INT , Queries_warnings INT, PRIMARY KEY (timestamp, hostgroup , srv_host , srv_port))"

Check failure on line 28 in include/ProxySQL_Statistics.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this macro by "const", "constexpr" or an "enum".

See more on https://sonarcloud.io/project/issues?id=sysown_proxysql&issues=AZ6qlOB8bYi6gGbjCJ_1&open=AZ6qlOB8bYi6gGbjCJ_1&pullRequest=5841

#define STATSDB_SQLITE_TABLE_HISTORY_STATS_MYSQL_CONNECTION_POOL STATSDB_SQLITE_TABLE_HISTORY_STATS_MYSQL_CONNECTION_POOL_V3_0_10

#define STATSDB_SQLITE_TABLE_MYHGM_CONNECTIONS_V2_0 "CREATE TABLE myhgm_connections (timestamp INT NOT NULL, MyHGM_myconnpoll_destroy INT NOT NULL, MyHGM_myconnpoll_get INT NOT NULL, MyHGM_myconnpoll_get_ok INT NOT NULL, MyHGM_myconnpoll_push INT NOT NULL, MyHGM_myconnpoll_reset INT NOT NULL, PRIMARY KEY (timestamp))"

Expand Down
20 changes: 19 additions & 1 deletion lib/Base_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3076,7 +3076,7 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
}

SQLite3_result * MySQL_HostGroups_Manager::SQL3_Connection_Pool(bool _reset, int *hid) {
const int colnum=14;
const int colnum=17;
Comment thread
adregner marked this conversation as resolved.
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");
Expand All @@ -3093,6 +3093,9 @@ SQLite3_result * MySQL_HostGroups_Manager::SQL3_Connection_Pool(bool _reset, int
result->add_column_definition(SQLITE_TEXT,"Bytes_sent");
result->add_column_definition(SQLITE_TEXT,"Bytes_recv");
result->add_column_definition(SQLITE_TEXT,"Latency_us");
result->add_column_definition(SQLITE_TEXT,"Queries_OK");
result->add_column_definition(SQLITE_TEXT,"Queries_ERR");
result->add_column_definition(SQLITE_TEXT,"Queries_warnings");
wrlock();
int i,j, k;
for (i=0; i<(int)MyHostGroups->len; i++) {
Expand Down Expand Up @@ -3187,6 +3190,21 @@ SQLite3_result * MySQL_HostGroups_Manager::SQL3_Connection_Pool(bool _reset, int
}
sprintf(buf,"%u", mysrvc->current_latency_us);
pta[13]=strdup(buf);
sprintf(buf,"%llu", mysrvc->queries_ok);
pta[14]=strdup(buf);
if (_reset) {
mysrvc->queries_ok=0;
}
sprintf(buf,"%llu", mysrvc->queries_err);
pta[15]=strdup(buf);
if (_reset) {
mysrvc->queries_err=0;
}
sprintf(buf,"%llu", mysrvc->queries_warnings);
pta[16]=strdup(buf);
if (_reset) {
mysrvc->queries_warnings=0;
}
Comment thread
adregner marked this conversation as resolved.
result->add_row(pta);
for (k=0; k<colnum; k++) {
if (pta[k])
Expand Down
20 changes: 19 additions & 1 deletion lib/MySQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3424,7 +3424,7 @@
}

SQLite3_result * MySQL_HostGroups_Manager::SQL3_Connection_Pool(bool _reset, int *hid) {
const int colnum=14;
const int colnum=17;
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");
Expand All @@ -3441,6 +3441,9 @@
result->add_column_definition(SQLITE_TEXT,"Bytes_sent");
result->add_column_definition(SQLITE_TEXT,"Bytes_recv");
result->add_column_definition(SQLITE_TEXT,"Latency_us");
result->add_column_definition(SQLITE_TEXT,"Queries_OK");
result->add_column_definition(SQLITE_TEXT,"Queries_ERR");
result->add_column_definition(SQLITE_TEXT,"Queries_warnings");
wrlock();
int i,j, k;
for (i=0; i<(int)MyHostGroups->len; i++) {
Expand Down Expand Up @@ -3535,6 +3538,21 @@
}
sprintf(buf,"%u", mysrvc->current_latency_us);
pta[13]=strdup(buf);
sprintf(buf,"%llu", mysrvc->queries_ok);

Check failure on line 3541 in lib/MySQL_HostGroups_Manager.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make sure use of "sprintf" function is safe here or replace it with a call to "snprintf".

See more on https://sonarcloud.io/project/issues?id=sysown_proxysql&issues=AZ6qlOIabYi6gGbjCJ_2&open=AZ6qlOIabYi6gGbjCJ_2&pullRequest=5841
pta[14]=strdup(buf);
if (_reset) {
mysrvc->queries_ok=0;
}
sprintf(buf,"%llu", mysrvc->queries_err);

Check failure on line 3546 in lib/MySQL_HostGroups_Manager.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make sure use of "sprintf" function is safe here or replace it with a call to "snprintf".

See more on https://sonarcloud.io/project/issues?id=sysown_proxysql&issues=AZ6qlOIabYi6gGbjCJ_3&open=AZ6qlOIabYi6gGbjCJ_3&pullRequest=5841
pta[15]=strdup(buf);
if (_reset) {
mysrvc->queries_err=0;
}
sprintf(buf,"%llu", mysrvc->queries_warnings);

Check failure on line 3551 in lib/MySQL_HostGroups_Manager.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make sure use of "sprintf" function is safe here or replace it with a call to "snprintf".

See more on https://sonarcloud.io/project/issues?id=sysown_proxysql&issues=AZ6qlOIabYi6gGbjCJ_4&open=AZ6qlOIabYi6gGbjCJ_4&pullRequest=5841
pta[16]=strdup(buf);
if (_reset) {
mysrvc->queries_warnings=0;
}
Comment thread
adregner marked this conversation as resolved.
result->add_row(pta);
for (k=0; k<colnum; k++) {
if (pta[k])
Expand Down
3 changes: 3 additions & 0 deletions lib/MySrvC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ MySrvC::MySrvC(
connect_OK=0;
connect_ERR=0;
queries_sent=0;
queries_ok=0;
queries_err=0;
queries_warnings=0;
bytes_sent=0;
bytes_recv=0;
max_connections_used=0;
Expand Down
6 changes: 3 additions & 3 deletions lib/ProxySQL_Admin_Stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,15 +1180,15 @@ void ProxySQL_Admin::stats___mysql_connection_pool(bool _reset) {
if (resultset==NULL) return;
statsdb->execute("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\",\"%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\",\"%s\",\"%s\",\"%s\")";
Comment thread
adregner marked this conversation as resolved.
for (std::vector<SQLite3_row *>::iterator it = resultset->rows.begin() ; it != resultset->rows.end(); ++it) {
SQLite3_row *r=*it;
int arg_len=0;
for (int i=0; i<14; i++) {
for (int i=0; i<17; i++) {
arg_len+=strlen(r->fields[i]);
}
char *query=(char *)malloc(strlen(a)+arg_len+32);
snprintf(query, strlen(a)+arg_len+32, 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]);
snprintf(query, strlen(a)+arg_len+32, 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],r->fields[14],r->fields[15],r->fields[16]);
statsdb->execute(query);
Comment thread
adregner marked this conversation as resolved.
free(query);
}
Expand Down
15 changes: 13 additions & 2 deletions lib/mysql_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2258,9 +2258,13 @@ int MySQL_Connection::async_query(short event, char *stmt, unsigned long length,
if (async_state_machine==ASYNC_QUERY_END) {
PROXY_TRACE2();
compute_unknown_transaction_status();
if (mysql_errno(mysql)) {
int _myerrno = mysql_errno(mysql);
if (_myerrno) {
if (_myerrno < 2000) __sync_fetch_and_add(&parent->queries_err, 1);
return -1;
} else {
__sync_fetch_and_add(&parent->queries_ok, 1);
if (warning_count > 0) __sync_fetch_and_add(&parent->queries_warnings, warning_count);
return 0;
}
}
Expand All @@ -2269,19 +2273,26 @@ int MySQL_Connection::async_query(short event, char *stmt, unsigned long length,
query.stmt_meta=NULL;
async_state_machine=ASYNC_QUERY_END;
compute_unknown_transaction_status();
if (mysql_stmt_errno(query.stmt)) {
unsigned int _stmt_errno = mysql_stmt_errno(query.stmt);
if (_stmt_errno) {
if (_stmt_errno < 2000) __sync_fetch_and_add(&parent->queries_err, 1);
return -1;
} else {
__sync_fetch_and_add(&parent->queries_ok, 1);
if (warning_count > 0) __sync_fetch_and_add(&parent->queries_warnings, warning_count);
return 0;
}
}
if (async_state_machine==ASYNC_STMT_PREPARE_SUCCESSFUL || async_state_machine==ASYNC_STMT_PREPARE_FAILED) {
query.stmt_meta=NULL;
compute_unknown_transaction_status();
if (async_state_machine==ASYNC_STMT_PREPARE_FAILED) {
unsigned int _prep_errno = query.stmt ? mysql_stmt_errno(query.stmt) : mysql_errno(mysql);
if (_prep_errno < 2000) __sync_fetch_and_add(&parent->queries_err, 1);
return -1;
} else {
*_stmt=query.stmt;
__sync_fetch_and_add(&parent->queries_ok, 1);
return 0;
}
}
Expand Down
1 change: 1 addition & 0 deletions test/tap/groups/groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@
"test_ps_min_gtid_fc-t" : [ "legacy-binlog-g1" ],
"test_ps_no_store-t" : [ "legacy-g8","mysql-auto_increment_delay_multiplex=0-g3","mysql-multiplexing=false-g3","mysql-query_digests=0-g3","mysql-query_digests_keep_comment=1-g3","mysql84-g8","mysql90-g3","mysql95-g3" ],
"test_query_cache_soft_ttl_pct-t" : [ "legacy-g9","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g4","mysql90-g4","mysql95-g4" ],
"test_query_error_counters-t" : [ "legacy-g5","mysql84-g5","mysql90-g5","mysql95-g5" ],
"test_query_rules_fast_routing_algorithm-t" : [ "legacy-g9","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g4","mysql90-g4","mysql95-g4" ],
"test_query_rules_routing-t" : [ "legacy-g9","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g4","mysql90-g4","mysql95-g4" ],
"test_query_timeout-t" : [ "legacy-g9","mariadb10-galera-g9","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g9","mysql84-gr-g9","mysql90-g4","mysql95-g4" ],
Expand Down
Loading