diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 7b579a231..2a2a17167 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -5410,20 +5410,12 @@ void MySQL_HostGroups_Manager::update_galera_set_writer(char *_hostname, int _po } pthread_mutex_unlock(&Galera_Info_mutex); - if (resultset->rows_count) { - for (std::vector::iterator it = resultset->rows.begin() ; it != resultset->rows.end(); ++it) { - SQLite3_row *r=*it; - int hostgroup=atoi(r->fields[0]); - if (hostgroup==_writer_hostgroup) { - int status=atoi(r->fields[1]); - if (status==0) - found_writer=true; - } - if (read_HG>=0) { - if (hostgroup==read_HG) { - found_reader=true; - } - } + for (size_t i = 0, l = resultset->rows.size(); i < l; ++i) { + int status = atoi(resultset->rows[i]->fields[1]); + if (status == 0) { + int hostgroup = atoi(resultset->rows[i]->fields[0]); + found_writer |= hostgroup == _writer_hostgroup; + found_reader |= (read_HG >= 0) && (hostgroup == read_HG); } }