* Added comments

* Few issues fixed
v2.x_refactor_cluster_mysql_servers
Rahim Kanji 3 years ago
parent 09f76511b1
commit 3821f562a8

@ -1842,6 +1842,13 @@ void MySQL_HostGroups_Manager::commit_update_checksums_from_tables() {
CUCFT1("mysql_hostgroup_attributes","hostgroup_id", table_resultset_checksum[HGM_TABLES::MYSQL_HOSTGROUP_ATTRIBUTES]);
}
/**
* @brief This code updates the 'hostgroup_server_mapping' table with the most recent mysql_servers and mysql_replication_hostgroups
* records while utilizing checksums to prevent unnecessary updates.
*
* IMPORTANT: Make sure wrlock() is called before calling this method.
*
*/
void MySQL_HostGroups_Manager::update_hostgroup_manager_mappings() {
if (hgsm_mysql_servers_checksum != table_resultset_checksum[HGM_TABLES::MYSQL_SERVERS] ||
@ -1912,6 +1919,11 @@ bool MySQL_HostGroups_Manager::commit(
bool only_commit_runtime_mysql_servers
) {
// if only_commit_runtime_mysql_servers is true, mysql_servers_incoming resultset will not be entertained and will cause memory leak.
if (only_commit_runtime_mysql_servers) {
proxy_info("Generating runtime mysql servers records only");
} else {
proxy_info("Generating runtime mysql servers and mysql servers incoming records");
}
unsigned long long curtime1=monotonic_time();
wrlock();
@ -2120,9 +2132,6 @@ bool MySQL_HostGroups_Manager::commit(
has_gtid_port = false;
}
if (resultset) { delete resultset; resultset=NULL; }
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 4, "DELETE FROM mysql_servers_incoming\n");
mydb->execute("DELETE FROM mysql_servers_incoming");
uint64_t mysql_servers_incoming_checksum = 0;
@ -2165,6 +2174,10 @@ bool MySQL_HostGroups_Manager::commit(
mysql_servers_incoming_checksum = get_mysql_servers_incoming_checksum(mysql_servers_incoming, false);
}
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 4, "DELETE FROM mysql_servers_incoming\n");
mydb->execute("DELETE FROM mysql_servers_incoming");
// regenerating mysql_servers records
mydb->execute("DELETE FROM mysql_servers");
generate_mysql_servers_table();

@ -3705,7 +3705,22 @@ void admin_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *pkt) {
GloAdmin->mysql_servers_wrunlock();
if (resultset == nullptr) {
resultset=MyHGM->dump_table_mysql(tn);
// fetching mysql_servers records from admin table as HGM mysql_servers records might be different.
if (tn == "mysql_servers_incoming") {
char *error=NULL;
int cols=0;
int affected_rows=0;
const char* query = "SELECT hostgroup_id,hostname,port,gtid_port,status,weight,compression,max_connections,max_replication_lag,use_ssl,max_latency_ms,comment FROM main.mysql_servers ORDER BY hostgroup_id, hostname, port";
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 4, "%s\n", query);
GloAdmin->mysql_servers_wrlock();
GloAdmin->admindb->execute_statement(query, &error , &cols , &affected_rows , &resultset);
GloAdmin->mysql_servers_wrunlock();
} else {
resultset = MyHGM->dump_table_mysql(tn);
}
if (resultset) {
sess->SQLite3_to_MySQL(resultset, error, affected_rows, &sess->client_myds->myprot);
delete resultset;

@ -1731,13 +1731,13 @@ void ProxySQL_Cluster::pull_runtime_mysql_servers_from_peer(const runtime_mysql_
proxy_info("Cluster: Computed checksum for MySQL Servers from peer %s:%d : %s\n", hostname, port, computed_checksum.c_str());
if (computed_checksum == peer_checksum) {
MyHGM->wrlock();
GloAdmin->mysql_servers_wrlock();
std::unique_ptr<SQLite3_result> runtime_mysql_servers_resultset = get_SQLite3_resulset(result);
proxy_debug(PROXY_DEBUG_CLUSTER, 5, "Loading runtime_mysql_servers from peer %s:%d into mysql_servers_incoming", hostname, port);
MyHGM->servers_add(runtime_mysql_servers_resultset.get());
proxy_debug(PROXY_DEBUG_CLUSTER, 5, "Updating runtime_mysql_servers from peer %s:%d", hostname, port);
MyHGM->commit(runtime_mysql_servers_resultset.release(), peer_runtime_mysql_server, nullptr, {}, true);
MyHGM->wrunlock();
GloAdmin->mysql_servers_wrunlock();
// free result
mysql_free_result(result);

Loading…
Cancel
Save