From 9f264fcf1dd78eddf90d2debb9c9e7fb2de2d8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sat, 8 Jan 2022 17:18:57 +0100 Subject: [PATCH] In Cluster pull_mysql_servers_from_peer() lock mysql_servers only if mysql servers tables are going to be written. Before this commit we were calling GloAdmin->mysql_servers_wrlock() at the beginning of the synchronization. This was not ideal as we should call GloAdmin->mysql_servers_wrlock() only if we are really going to write the tables. In other words, only if the resultsets are fetched from the remote peer, and if their checksums didn't change in the meantime. --- lib/ProxySQL_Cluster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ProxySQL_Cluster.cpp b/lib/ProxySQL_Cluster.cpp index d9ebee639..70c116fbe 100644 --- a/lib/ProxySQL_Cluster.cpp +++ b/lib/ProxySQL_Cluster.cpp @@ -1194,7 +1194,6 @@ void ProxySQL_Cluster::pull_mysql_servers_from_peer() { proxy_info("Cluster: Fetching MySQL Servers from peer %s:%d started. Expected checksum %s\n", hostname, port, peer_checksum); rc_conn = mysql_real_connect(conn, hostname, username, password, NULL, port, NULL, 0); if (rc_conn) { - GloAdmin->mysql_servers_wrlock(); std::vector results {}; // Server query messages @@ -1306,6 +1305,7 @@ void ProxySQL_Cluster::pull_mysql_servers_from_peer() { proxy_info("Cluster: Fetching checksum for MySQL Servers from peer %s:%d successful. Checksum: %s\n", hostname, port, checks); // sync mysql_servers proxy_info("Cluster: Writing mysql_servers table\n"); + GloAdmin->mysql_servers_wrlock(); GloAdmin->admindb->execute("DELETE FROM mysql_servers"); MYSQL_ROW row; char *q=(char *)"INSERT INTO mysql_servers (hostgroup_id, hostname, port, gtid_port, weight, status, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment) VALUES (%s, \"%s\", %s, %s, %s, \"%s\", %s, %s, %s, %s, %s, '%s')"; @@ -1481,6 +1481,7 @@ void ProxySQL_Cluster::pull_mysql_servers_from_peer() { } else { proxy_info("Cluster: Not saving to disk MySQL Servers from peer %s:%d failed.\n", hostname, port); } + GloAdmin->mysql_servers_wrunlock(); } // free results @@ -1490,7 +1491,6 @@ void ProxySQL_Cluster::pull_mysql_servers_from_peer() { metrics.p_counter_array[p_cluster_counter::pulled_mysql_servers_success]->Increment(); } - GloAdmin->mysql_servers_wrunlock(); } else { proxy_info("Cluster: Fetching MySQL Servers from peer %s:%d failed: %s\n", hostname, port, mysql_error(conn)); metrics.p_counter_array[p_cluster_counter::pulled_mysql_servers_failure]->Increment();