Skip to content

Commit

Permalink
Merge pull request #2944 from sysown/v2.1.0-2711
Browse files Browse the repository at this point in the history
Re-enable PXC node after pxc_maint_mode is DISABLED #2711
  • Loading branch information
renecannao authored Jul 10, 2020
2 parents 53dab4a + 16ef947 commit d722bbe
Showing 1 changed file with 44 additions and 13 deletions.
57 changes: 44 additions & 13 deletions lib/MySQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4567,7 +4567,7 @@ void MySQL_HostGroups_Manager::converge_group_replication_config(int _writer_hos
char *query=NULL;
char *q=NULL;
char *error=NULL;
q=(char *)"SELECT hostgroup_id,hostname,port FROM mysql_servers_incoming WHERE status=0 AND hostgroup_id IN (%d, %d, %d, %d) ORDER BY weight DESC, hostname DESC";
q=(char *)"SELECT hostgroup_id,hostname,port FROM mysql_servers_incoming WHERE status=0 AND hostgroup_id IN (%d, %d, %d, %d) ORDER BY weight DESC, hostname DESC, port DESC";
query=(char *)malloc(strlen(q)+256);
sprintf(query, q, info->writer_hostgroup, info->backup_writer_hostgroup, info->reader_hostgroup, info->offline_hostgroup);
mydb->execute_statement(query, &error, &cols , &affected_rows , &resultset);
Expand Down Expand Up @@ -4635,7 +4635,7 @@ void MySQL_HostGroups_Manager::converge_group_replication_config(int _writer_hos
resultset=NULL;
}
if (info->writer_is_also_reader==2) {
q=(char *)"SELECT hostgroup_id,hostname,port FROM mysql_servers_incoming WHERE status=0 AND hostgroup_id IN (%d, %d, %d, %d) ORDER BY weight DESC, hostname DESC";
q=(char *)"SELECT hostgroup_id,hostname,port FROM mysql_servers_incoming WHERE status=0 AND hostgroup_id IN (%d, %d, %d, %d) ORDER BY weight DESC, hostname DESC, port DESC";
query=(char *)malloc(strlen(q)+256);
sprintf(query, q, info->writer_hostgroup, info->backup_writer_hostgroup, info->reader_hostgroup, info->offline_hostgroup);
mydb->execute_statement(query, &error, &cols , &affected_rows , &resultset);
Expand Down Expand Up @@ -4764,7 +4764,7 @@ void MySQL_HostGroups_Manager::update_galera_set_offline(char *_hostname, int _p
char *query=NULL;
char *q=NULL;
char *error=NULL;
q=(char *)"SELECT hostgroup_id FROM mysql_servers JOIN mysql_galera_hostgroups ON hostgroup_id=writer_hostgroup OR hostgroup_id=backup_writer_hostgroup OR hostgroup_id=reader_hostgroup WHERE hostname='%s' AND port=%d";
q=(char *)"SELECT hostgroup_id FROM mysql_servers JOIN mysql_galera_hostgroups ON hostgroup_id=writer_hostgroup OR hostgroup_id=backup_writer_hostgroup OR hostgroup_id=reader_hostgroup WHERE hostname='%s' AND port=%d AND status=0";
query=(char *)malloc(strlen(q)+strlen(_hostname)+1024); // increased this buffer as it is used for other queries too
sprintf(query,q,_hostname,_port);
mydb->execute_statement(query, &error , &cols , &affected_rows , &resultset);
Expand Down Expand Up @@ -4815,7 +4815,13 @@ void MySQL_HostGroups_Manager::update_galera_set_offline(char *_hostname, int _p
mydb->execute(query);
//free(query);
} else {
q=(char *)"UPDATE mysql_servers_incoming SET status=1 WHERE hostname='%s' AND port=%d";
q=(char *)"INSERT OR IGNORE INTO mysql_servers_incoming SELECT %d, hostname, port, gtid_port, weight, status, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment FROM mysql_servers_incoming WHERE hostname='%s' AND port=%d AND hostgroup_id in (%d, %d, %d)";
sprintf(query,q,info->offline_hostgroup,_hostname,_port,_writer_hostgroup, info->backup_writer_hostgroup, info->reader_hostgroup);
mydb->execute(query);
q=(char *)"DELETE FROM mysql_servers_incoming WHERE hostname='%s' AND port=%d AND hostgroup_id in (%d, %d)";
sprintf(query,q,_hostname,_port, info->backup_writer_hostgroup, info->reader_hostgroup);
mydb->execute(query);
q=(char *)"UPDATE mysql_servers_incoming SET status=1 WHERE hostname='%s' AND port=%d AND hostgroup_id = %d";
sprintf(query,q,_hostname,_port,_writer_hostgroup);
mydb->execute(query);
}
Expand Down Expand Up @@ -4998,7 +5004,7 @@ void MySQL_HostGroups_Manager::update_galera_set_writer(char *_hostname, int _po
char *query=NULL;
char *q=NULL;
char *error=NULL;
q=(char *)"SELECT hostgroup_id FROM mysql_servers JOIN mysql_galera_hostgroups ON hostgroup_id=writer_hostgroup OR hostgroup_id=reader_hostgroup OR hostgroup_id=backup_writer_hostgroup OR hostgroup_id=offline_hostgroup WHERE hostname='%s' AND port=%d";
q=(char *)"SELECT hostgroup_id,status FROM mysql_servers JOIN mysql_galera_hostgroups ON hostgroup_id=writer_hostgroup OR hostgroup_id=reader_hostgroup OR hostgroup_id=backup_writer_hostgroup OR hostgroup_id=offline_hostgroup WHERE hostname='%s' AND port=%d";
query=(char *)malloc(strlen(q)+strlen(_hostname)+32);
sprintf(query,q,_hostname,_port);
mydb->execute_statement(query, &error, &cols , &affected_rows , &resultset);
Expand Down Expand Up @@ -5037,7 +5043,9 @@ void MySQL_HostGroups_Manager::update_galera_set_writer(char *_hostname, int _po
SQLite3_row *r=*it;
int hostgroup=atoi(r->fields[0]);
if (hostgroup==_writer_hostgroup) {
found_writer=true;
int status=atoi(r->fields[1]);
if (status==0)
found_writer=true;
}
if (read_HG>=0) {
if (hostgroup==read_HG) {
Expand Down Expand Up @@ -5217,7 +5225,7 @@ void MySQL_HostGroups_Manager::converge_galera_config(int _writer_hostgroup) {
char *query=NULL;
char *q=NULL;
char *error=NULL;
q=(char *)"SELECT hostgroup_id,hostname,port FROM mysql_servers_incoming WHERE status=0 AND hostgroup_id IN (%d, %d, %d, %d) ORDER BY weight DESC, hostname DESC";
q=(char *)"SELECT hostgroup_id,hostname,port FROM mysql_servers_incoming WHERE status=0 AND hostgroup_id IN (%d, %d, %d, %d) ORDER BY weight DESC, hostname DESC, port DESC";
query=(char *)malloc(strlen(q)+256);
sprintf(query, q, info->writer_hostgroup, info->backup_writer_hostgroup, info->reader_hostgroup, info->offline_hostgroup);
mydb->execute_statement(query, &error, &cols , &affected_rows , &resultset);
Expand All @@ -5239,15 +5247,35 @@ void MySQL_HostGroups_Manager::converge_galera_config(int _writer_hostgroup) {
}
if (num_writers > info->max_writers) { // there are more writers than allowed
int to_move=num_writers-info->max_writers;
int to_keep = info->max_writers;
if (GloMTH->variables.hostgroup_manager_verbose > 1) {
proxy_info("Galera: max_writers=%d , moving %d nodes from writer HG %d to backup HG %d\n", info->max_writers, to_move, info->writer_hostgroup, info->backup_writer_hostgroup);
}
for (std::vector<SQLite3_row *>::reverse_iterator it = resultset->rows.rbegin() ; it != resultset->rows.rend(); ++it) {
//for (std::vector<SQLite3_row *>::reverse_iterator it = resultset->rows.rbegin() ; it != resultset->rows.rend(); ++it) {
// note: we change the iterator from reverse_iterator to forward iterator
for (std::vector<SQLite3_row *>::iterator it = resultset->rows.begin() ; it != resultset->rows.end(); ++it) {
SQLite3_row *r=*it;
if (to_move) {
int hostgroup=atoi(r->fields[0]);
if (hostgroup==info->writer_hostgroup) {
q=(char *)"UPDATE OR REPLACE mysql_servers_incoming SET status=0, hostgroup_id=%d WHERE hostgroup_id=%d AND hostname='%s' AND port=%d";
int hostgroup=atoi(r->fields[0]);
if (hostgroup==info->writer_hostgroup) {
if (to_keep) {
q=(char *)"UPDATE OR REPLACE mysql_servers_incoming SET status=0 WHERE hostgroup_id=%d AND hostname='%s' AND port=%d";
query=(char *)malloc(strlen(q)+strlen(r->fields[1])+128);
sprintf(query,q,info->writer_hostgroup,r->fields[1],atoi(r->fields[2]));
mydb->execute(query);
free(query);
to_keep--;
continue;
}
if (to_move) {
// if the server is already in writer hostgroup, we set to shunned #2656
q=(char *)"UPDATE OR REPLACE mysql_servers_incoming SET status=1 WHERE hostgroup_id=%d AND hostname='%s' AND port=%d";
query=(char *)malloc(strlen(q)+strlen(r->fields[1])+128);
sprintf(query,q,info->writer_hostgroup,r->fields[1],atoi(r->fields[2]));
mydb->execute(query);
free(query);
//q=(char *)"UPDATE OR REPLACE mysql_servers_incoming SET status=0, hostgroup_id=%d WHERE hostgroup_id=%d AND hostname='%s' AND port=%d";
// we copy the server from the writer hostgroup in the backup writer hostgroup #2656
q=(char *)"INSERT OR IGNORE INTO mysql_servers_incoming SELECT %d, hostname, port, gtid_port, weight, 0, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment FROM mysql_servers_incoming WHERE hostgroup_id=%d AND hostname='%s' AND port=%d";
query=(char *)malloc(strlen(q)+strlen(r->fields[1])+128);
sprintf(query,q,info->backup_writer_hostgroup,info->writer_hostgroup,r->fields[1],atoi(r->fields[2]));
mydb->execute(query);
Expand All @@ -5270,6 +5298,9 @@ void MySQL_HostGroups_Manager::converge_galera_config(int _writer_hostgroup) {
q=(char *)"UPDATE OR REPLACE mysql_servers_incoming SET status=0, hostgroup_id=%d WHERE hostgroup_id=%d AND hostname='%s' AND port=%d";
query=(char *)malloc(strlen(q)+strlen(r->fields[1])+128);
sprintf(query,q,info->writer_hostgroup,info->backup_writer_hostgroup,r->fields[1],atoi(r->fields[2]));
if (GloMTH->variables.hostgroup_manager_verbose) {
proxy_info("Galera: %s\n", query);
}
mydb->execute(query);
free(query);
to_move--;
Expand Down Expand Up @@ -5346,7 +5377,7 @@ void MySQL_HostGroups_Manager::converge_galera_config(int _writer_hostgroup) {
resultset=NULL;
}
if (info->writer_is_also_reader==2) {
q=(char *)"SELECT hostgroup_id,hostname,port FROM mysql_servers_incoming WHERE status=0 AND hostgroup_id IN (%d, %d, %d, %d) ORDER BY weight DESC, hostname DESC";
q=(char *)"SELECT hostgroup_id,hostname,port FROM mysql_servers_incoming WHERE status=0 AND hostgroup_id IN (%d, %d, %d, %d) ORDER BY weight DESC, hostname DESC, port DESC";
query=(char *)malloc(strlen(q)+256);
sprintf(query, q, info->writer_hostgroup, info->backup_writer_hostgroup, info->reader_hostgroup, info->offline_hostgroup);
mydb->execute_statement(query, &error, &cols , &affected_rows , &resultset);
Expand Down

0 comments on commit d722bbe

Please sign in to comment.