From 446c9ec0c814a6bc0a61cfa6d7d9fda0fee67cd3 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Tue, 14 Mar 2023 13:22:46 +0500 Subject: [PATCH] Added logging --- include/MySQL_HostGroups_Manager.h | 23 +++++++++++++++++++++++ lib/MySQL_HostGroups_Manager.cpp | 17 +++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/include/MySQL_HostGroups_Manager.h b/include/MySQL_HostGroups_Manager.h index f7cac8cc5..6f29b633c 100644 --- a/include/MySQL_HostGroups_Manager.h +++ b/include/MySQL_HostGroups_Manager.h @@ -424,8 +424,31 @@ class MySQL_HostGroups_Manager { ~HostGroup_Server_Mapping() = default; // Note: copy_if_not_exists, remove, clear method also makes changes to MyHostGroups + + /** + * @brief Copies all unique nodes from source vector to destination vector. + * @details Copies all unique nodes from source vector to destination vector. The source and destination vectors are identified by an input enumeration type, + * which can be either a reader or a writer. During the copying process, the function also adds servers to the HostGroup connection container. + * @param dest_type Input Can be reader or writer + * @param src_type Input Can be reader or writer + */ void copy_if_not_exists(Type dest_type, Type src_type); + + /** + * @brief Removes node located at the specified index. + * @details Node is removed from vector located at the specified index identified by an input enumeration type. + Node that was removed is marked as offline in the HostGroup connection container. + * @param dest_type Input Can be reader or writer + * @param index Input Index of node to be removed + */ void remove(Type type, size_t index); + + /** + * @brief Removes all nodes. + * @details All nodes are removed from vector, identified by an input enumeration type. + Nodes that are removed is marked as offline in the HostGroup connection container. + * @param type Input Can be reader or writer + */ void clear(Type type); // diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 8ec0db1f3..06803a923 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -1966,8 +1966,9 @@ bool MySQL_HostGroups_Manager::commit( if (hgsm_mysql_servers_checksum != table_resultset_checksum[HGM_TABLES::MYSQL_SERVERS] || hgsm_mysql_replication_hostgroups_checksum != table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS]) { - proxy_info("Checksum for table 'mysql_servers': old:0x%lX new:0x%lX\n", hgsm_mysql_servers_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_SERVERS]); - proxy_info("Checksum for table 'mysql_replication_hostgroups': old:0x%lX new:0x%lX\n", hgsm_mysql_replication_hostgroups_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS]); + proxy_info("Rebuilding 'Hostgroup_Manager_Mapping' due to checksums change - mysql_servers { old: 0x%lX, new: 0x%lX }, mysql_replication_hostgroups { old:0x%lX, new:0x%lX }\n", + hgsm_mysql_servers_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_SERVERS], + hgsm_mysql_replication_hostgroups_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS]); char* error = NULL; int cols = 0; @@ -4617,6 +4618,8 @@ void MySQL_HostGroups_Manager::read_only_action_v2(const std::listcopy_if_not_exists(HostGroup_Server_Mapping::Type::WRITER, HostGroup_Server_Mapping::Type::READER); if (mysql_thread___monitor_writer_is_also_reader) { @@ -4628,9 +4631,13 @@ void MySQL_HostGroups_Manager::read_only_action_v2(const std::listget_readonly_flag() != 0) { // it is the first time that we detect RO on this server @@ -4673,17 +4680,21 @@ void MySQL_HostGroups_Manager::read_only_action_v2(const std::listcopy_if_not_exists(HostGroup_Server_Mapping::Type::READER, HostGroup_Server_Mapping::Type::WRITER); // clearing all writer nodes host_server_mapping->clear(HostGroup_Server_Mapping::Type::WRITER); update_mysql_servers_table = true; + proxy_info("Regenerating table 'mysql_servers' due to actions on server '%s:%d'\n", hostname.c_str(), port); } } else { // LCOV_EXCL_START @@ -7637,6 +7648,8 @@ MySrvC* MySQL_HostGroups_Manager::find_server_in_hg(unsigned int _hid, const std void MySQL_HostGroups_Manager::HostGroup_Server_Mapping::copy_if_not_exists(Type dest_type, Type src_type) { + assert(dest_type != src_type); + const std::vector& src_nodes = mapping[src_type]; if (src_nodes.empty()) return;