From c9d3d03f320fe76619acc51ce7005af943b4625c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 8 Sep 2017 05:35:21 +0200 Subject: [PATCH] Cluster: better handling of mysql_servers.status --- lib/MySQL_HostGroups_Manager.cpp | 2 +- lib/ProxySQL_Cluster.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 0b601506c..4c12392f6 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -760,7 +760,7 @@ bool MySQL_HostGroups_Manager::commit() { int cols=0; int affected_rows=0; SQLite3_result *resultset=NULL; - char *query=(char *)"SELECT * FROM mysql_servers ORDER BY hostgroup_id, hostname, port"; + char *query=(char *)"SELECT hostgroup_id, hostname, port, CASE status WHEN 0 OR 1 OR 4 THEN 0 ELSE status END status, weight, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment FROM mysql_servers WHERE status<>3 ORDER BY hostgroup_id, hostname, port"; mydb->execute_statement(query, &error , &cols , &affected_rows , &resultset); if (resultset) { if (resultset->rows_count) { diff --git a/lib/ProxySQL_Cluster.cpp b/lib/ProxySQL_Cluster.cpp index b71d421f7..3a907ad9e 100644 --- a/lib/ProxySQL_Cluster.cpp +++ b/lib/ProxySQL_Cluster.cpp @@ -751,7 +751,8 @@ void ProxySQL_Cluster::pull_mysql_servers_from_peer() { proxy_info("Cluster: Fetching MySQL Servers from peer %s:%d started\n", hostname, port); rc_conn = mysql_real_connect(conn, hostname, username, password, NULL, port, NULL, 0); if (rc_conn) { - rc_query = mysql_query(conn,"SELECT hostgroup_id, hostname, port, status, weight, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment FROM runtime_mysql_servers"); + GloAdmin->mysql_servers_wrlock(); + rc_query = mysql_query(conn,"SELECT hostgroup_id, hostname, port, status, weight, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment FROM runtime_mysql_servers WHERE status<>'OFFLINE_HARD'"); if ( rc_query == 0 ) { MYSQL_RES *result = mysql_store_result(conn); GloAdmin->admindb->execute("DELETE FROM mysql_servers"); @@ -811,6 +812,7 @@ void ProxySQL_Cluster::pull_mysql_servers_from_peer() { } else { proxy_info("Cluster: Fetching MySQL Servers from peer %s:%d failed: %s\n", hostname, port, mysql_error(conn)); } + GloAdmin->mysql_servers_wrunlock(); } else { proxy_info("Cluster: Fetching MySQL Servers from peer %s:%d failed: %s\n", hostname, port, mysql_error(conn)); }