diff --git a/deps/Makefile b/deps/Makefile index f9761e033..cd2b938f2 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -96,6 +96,7 @@ cleanall: cd mariadb-client-library && rm -rf mariadb-connector-c-2.3.1 cd libconfig && rm -rf libconfig-1.4.9 cd re2 && rm -rf re2 + cd pcre && rm -rf pcre-8.39 cd sqlite3/sqlite3 && rm -rf * || true .PHONY: cleanall diff --git a/include/MySQL_Monitor.hpp b/include/MySQL_Monitor.hpp index 968e6008b..4fc514a0c 100644 --- a/include/MySQL_Monitor.hpp +++ b/include/MySQL_Monitor.hpp @@ -31,8 +31,8 @@ struct cmp_str { #define MyGR_Nentries 10 typedef struct _MyGR_status_entry_t { - char *address; - int port; +// char *address; +// int port; unsigned long long check_time; long long transactions_behind; bool primary_partition; @@ -73,6 +73,7 @@ class MySQL_Monitor_State_Data { int ST; char *hostname; int port; + int writer_hostgroup; // used only by group replication bool use_ssl; MYSQL *mysql; MYSQL_RES *result; diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 9cd85c498..1aa1392d1 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -847,7 +847,7 @@ void MySQL_HostGroups_Manager::generate_mysql_group_replication_hostgroups_table int cols=0; int affected_rows=0; SQLite3_result *resultset=NULL; - char *query=(char *)"SELECT hostname, port, MAX(use_ssl) use_ssl FROM mysql_servers JOIN mysql_group_replication_hostgroups ON hostgroup_id=writer_hostgroup OR hostgroup_id=backup_writer_hostgroup OR hostgroup_id=reader_hostgroup OR hostgroup_id=offline_hostgroup WHERE status NOT IN (2,3) GROUP BY hostname, port"; + char *query=(char *)"SELECT writer_hostgroup, hostname, port, MAX(use_ssl) use_ssl FROM mysql_servers JOIN mysql_group_replication_hostgroups ON hostgroup_id=writer_hostgroup OR hostgroup_id=backup_writer_hostgroup OR hostgroup_id=reader_hostgroup OR hostgroup_id=offline_hostgroup WHERE status NOT IN (2,3) GROUP BY hostname, port"; mydb->execute_statement(query, &error , &cols , &affected_rows , &resultset); if (resultset) { if (GloMyMon->Group_Replication_Hosts_resultset) { diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index e08bfa6c5..8735220ff 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -795,6 +795,7 @@ __exit_monitor_group_replication_thread: __end_process_group_replication_result: proxy_info("GR: %s:%d , viable=%s , ro=%s, trx=%ld, err=%s\n", mmsd->hostname, mmsd->port, (viable_candidate ? "YES": "NO") , (read_only ? "YES": "NO") , transactions_behind, ( mmsd->mysql_error_msg ? mmsd->mysql_error_msg : "") ); + unsigned long long time_now=realtime_time(); pthread_mutex_lock(&GloMyMon->group_replication_mutex); //auto it = // TODO : complete this @@ -803,11 +804,10 @@ __end_process_group_replication_result: MyGR_monitor_node *node=NULL; if (it2!=GloMyMon->Group_Replication_Hosts_Map.end()) { node=it2->second; - node->add_entry(0,transactions_behind,viable_candidate,read_only,NULL); + node->add_entry(time_now,transactions_behind,viable_candidate,read_only,NULL); } else { - // TODO: find writer - node = new MyGR_monitor_node(mmsd->hostname,mmsd->port,0); - node->add_entry(0,transactions_behind,viable_candidate,read_only,NULL); + node = new MyGR_monitor_node(mmsd->hostname,mmsd->port,mmsd->writer_hostgroup); + node->add_entry(time_now,transactions_behind,viable_candidate,read_only,NULL); GloMyMon->Group_Replication_Hosts_Map.insert(std::make_pair(s,node)); } pthread_mutex_unlock(&GloMyMon->group_replication_mutex); @@ -1553,7 +1553,8 @@ void * MySQL_Monitor::monitor_group_replication() { } for (std::vector::iterator it = Group_Replication_Hosts_resultset->rows.begin() ; it != Group_Replication_Hosts_resultset->rows.end(); ++it) { SQLite3_row *r=*it; - MySQL_Monitor_State_Data *mmsd=new MySQL_Monitor_State_Data(r->fields[0],atoi(r->fields[1]), NULL, atoi(r->fields[2])); + MySQL_Monitor_State_Data *mmsd=new MySQL_Monitor_State_Data(r->fields[1],atoi(r->fields[2]), NULL, atoi(r->fields[3])); + mmsd->writer_hostgroup=atoi(r->fields[1]); mmsd->mondb=monitordb; //pthread_t thr_; //if ( pthread_create(&thr_, &attr, monitor_read_only_thread, (void *)mmsd) != 0 ) {