// if any server has gtid_port enabled, use_gtid is set to true
// and then has_gtid_port is set too
booluse_gtid=false;
mydb->execute("DELETE FROM mysql_servers");
generate_mysql_servers_table();
constchar*query="SELECT mem_pointer, t1.hostgroup_id, t1.hostname, t1.port FROM mysql_servers t1 LEFT OUTER JOIN mysql_servers_incoming t2 ON (t1.hostgroup_id=t2.hostgroup_id AND t1.hostname=t2.hostname AND t1.port=t2.port) WHERE t2.hostgroup_id IS NULL";
proxy_warning("Removed server at address %lld, hostgroup %s, address %s port %s. Setting status OFFLINE HARD and immediately dropping all free connections. Used connections will be dropped when trying to use them\n",ptr,r->fields[1],r->fields[2],r->fields[3]);
MySrvC*mysrvc=(MySrvC*)ptr;
mysrvc->status=MYSQL_SERVER_STATUS_OFFLINE_HARD;
mysrvc->ConnectionsFree->drop_all_connections();
char*q1=(char*)"DELETE FROM mysql_servers WHERE mem_pointer=%lld";
// SELECT FROM mysql_servers whatever is not identical in mysql_servers_incoming, or where mem_pointer=0 (where there is no pointer yet)
query=(char*)"SELECT t1.*, t2.gtid_port, t2.weight, t2.status, t2.compression, t2.max_connections, t2.max_replication_lag, t2.use_ssl, t2.max_latency_ms, t2.comment FROM mysql_servers t1 JOIN mysql_servers_incoming t2 ON (t1.hostgroup_id=t2.hostgroup_id AND t1.hostname=t2.hostname AND t1.port=t2.port) WHERE mem_pointer=0 OR t1.gtid_port<>t2.gtid_port OR t1.weight<>t2.weight OR t1.status<>t2.status OR t1.compression<>t2.compression OR t1.max_connections<>t2.max_connections OR t1.max_replication_lag<>t2.max_replication_lag OR t1.use_ssl<>t2.use_ssl OR t1.max_latency_ms<>t2.max_latency_ms or t1.comment<>t2.comment";
proxy_info("Creating new server in HG %d : %s:%d , gtid_port=%d, weight=%d, status=%d\n",atoi(r->fields[0]),r->fields[1],atoi(r->fields[2]),atoi(r->fields[3]),atoi(r->fields[4]),(MySerStatus)atoi(r->fields[5]));
}
MySrvC*mysrvc=newMySrvC(r->fields[1],atoi(r->fields[2]),atoi(r->fields[3]),atoi(r->fields[4]),(MySerStatus)atoi(r->fields[5]),atoi(r->fields[6]),atoi(r->fields[7]),atoi(r->fields[8]),atoi(r->fields[9]),atoi(r->fields[10]),r->fields[11]);// add new fields here if adding more columns in mysql_servers
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Adding new server %s:%d , weight=%d, status=%d, mem_ptr=%p into hostgroup=%d\n",r->fields[1],atoi(r->fields[2]),atoi(r->fields[4]),(MySerStatus)atoi(r->fields[5]),mysrvc,atoi(r->fields[0]));
// this server has gtid_port configured, we set use_gtid
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,6,"Server %u:%s:%d has gtid_port enabled, setting use_gitd=true if not already set\n",mysrvc->myhgc->hid,mysrvc->address,mysrvc->port);
use_gtid=true;
}
}else{
boolrun_update=false;
MySrvC*mysrvc=(MySrvC*)ptr;
// carefully increase the 2nd index by 1 for every new column added
if(atoi(r->fields[3])!=atoi(r->fields[13])){
if(GloMTH->variables.hostgroup_manager_verbose)
proxy_info("Changing gtid_port for server %u:%s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->myhgc->hid,mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),atoi(r->fields[3]),mysrvc->gtid_port,atoi(r->fields[13]));
mysrvc->gtid_port=atoi(r->fields[13]);
}
if(atoi(r->fields[4])!=atoi(r->fields[14])){
if(GloMTH->variables.hostgroup_manager_verbose)
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Changing weight for server %d:%s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->myhgc->hid,mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),atoi(r->fields[4]),mysrvc->weight,atoi(r->fields[14]));
mysrvc->weight=atoi(r->fields[14]);
}
if(atoi(r->fields[5])!=atoi(r->fields[15])){
if(GloMTH->variables.hostgroup_manager_verbose)
proxy_info("Changing status for server %d:%s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->myhgc->hid,mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),atoi(r->fields[5]),mysrvc->status,atoi(r->fields[15]));
mysrvc->status=(MySerStatus)atoi(r->fields[15]);
if(mysrvc->status==MYSQL_SERVER_STATUS_SHUNNED){
mysrvc->shunned_automatic=false;
}
}
if(atoi(r->fields[6])!=atoi(r->fields[16])){
if(GloMTH->variables.hostgroup_manager_verbose)
proxy_info("Changing compression for server %d:%s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->myhgc->hid,mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),atoi(r->fields[6]),mysrvc->compression,atoi(r->fields[16]));
mysrvc->compression=atoi(r->fields[16]);
}
if(atoi(r->fields[7])!=atoi(r->fields[17])){
if(GloMTH->variables.hostgroup_manager_verbose)
proxy_info("Changing max_connections for server %d:%s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->myhgc->hid,mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),atoi(r->fields[7]),mysrvc->max_connections,atoi(r->fields[17]));
mysrvc->max_connections=atoi(r->fields[17]);
}
if(atoi(r->fields[8])!=atoi(r->fields[18])){
if(GloMTH->variables.hostgroup_manager_verbose)
proxy_info("Changing max_replication_lag for server %u:%s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->myhgc->hid,mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),atoi(r->fields[8]),mysrvc->max_replication_lag,atoi(r->fields[18]));
mysrvc->max_replication_lag=atoi(r->fields[18]);
if(mysrvc->max_replication_lag==0){// we just changed it to 0
// the server is currently shunned due to replication lag
// but we reset max_replication_lag to 0
// therefore we immediately reset the status too
mysrvc->status=MYSQL_SERVER_STATUS_ONLINE;
}
}
}
if(atoi(r->fields[9])!=atoi(r->fields[19])){
if(GloMTH->variables.hostgroup_manager_verbose)
proxy_info("Changing use_ssl for server %d:%s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->myhgc->hid,mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),atoi(r->fields[9]),mysrvc->use_ssl,atoi(r->fields[19]));
mysrvc->use_ssl=atoi(r->fields[19]);
}
if(atoi(r->fields[10])!=atoi(r->fields[20])){
if(GloMTH->variables.hostgroup_manager_verbose)
proxy_info("Changing max_latency_ms for server %d:%s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->myhgc->hid,mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),atoi(r->fields[10]),mysrvc->max_latency_us/1000,atoi(r->fields[20]));
mysrvc->max_latency_us=1000*atoi(r->fields[20]);
}
if(strcmp(r->fields[11],r->fields[21])){
if(GloMTH->variables.hostgroup_manager_verbose)
proxy_info("Changing comment for server %d:%s:%d (%s:%d) from '%s' to '%s'\n",mysrvc->myhgc->hid,mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),r->fields[11],r->fields[21]);
// this server has gtid_port configured, we set use_gtid
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,6,"Server %u:%s:%d has gtid_port enabled, setting use_gitd=true if not already set\n",mysrvc->myhgc->hid,mysrvc->address,mysrvc->port);
use_gtid=true;
}
}
}
(*proxy_sqlite3_finalize)(statement1);
(*proxy_sqlite3_finalize)(statement2);
}
if(use_gtid){
has_gtid_port=true;
}else{
has_gtid_port=false;
}
if(resultset){deleteresultset;resultset=NULL;}
purge_mysql_servers_table();
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,4,"DELETE FROM mysql_servers\n");
// // if any server has gtid_port enabled, use_gtid is set to true
// // and then has_gtid_port is set too
// bool use_gtid = false;
//
// mydb->execute("DELETE FROM mysql_servers");
// generate_mysql_servers_table();
//
// const char* query = "SELECT mem_pointer, t1.hostgroup_id, t1.hostname, t1.port FROM mysql_servers t1 LEFT OUTER JOIN mysql_servers_incoming t2 ON (t1.hostgroup_id=t2.hostgroup_id AND t1.hostname=t2.hostname AND t1.port=t2.port) WHERE t2.hostgroup_id IS NULL";
// proxy_error("Error on %s : %s\n", query, error);
// } else {
// if (GloMTH->variables.hostgroup_manager_verbose) {
// proxy_info("Dumping mysql_servers LEFT JOIN mysql_servers_incoming\n");
// resultset->dump_to_stderr();
// }
//
// for (std::vector<SQLite3_row*>::iterator it = resultset->rows.begin(); it != resultset->rows.end(); ++it) {
// SQLite3_row* r = *it;
// long long ptr = atoll(r->fields[0]);
// proxy_warning("Removed server at address %lld, hostgroup %s, address %s port %s. Setting status OFFLINE HARD and immediately dropping all free connections. Used connections will be dropped when trying to use them\n", ptr, r->fields[1], r->fields[2], r->fields[3]);
// // SELECT FROM mysql_servers whatever is not identical in mysql_servers_incoming, or where mem_pointer=0 (where there is no pointer yet)
// query = (char*)"SELECT t1.*, t2.gtid_port, t2.weight, t2.status, t2.compression, t2.max_connections, t2.max_replication_lag, t2.use_ssl, t2.max_latency_ms, t2.comment FROM mysql_servers t1 JOIN mysql_servers_incoming t2 ON (t1.hostgroup_id=t2.hostgroup_id AND t1.hostname=t2.hostname AND t1.port=t2.port) WHERE mem_pointer=0 OR t1.gtid_port<>t2.gtid_port OR t1.weight<>t2.weight OR t1.status<>t2.status OR t1.compression<>t2.compression OR t1.max_connections<>t2.max_connections OR t1.max_replication_lag<>t2.max_replication_lag OR t1.use_ssl<>t2.use_ssl OR t1.max_latency_ms<>t2.max_latency_ms or t1.comment<>t2.comment";
// if (GloMTH->variables.hostgroup_manager_verbose) {
// proxy_info("Creating new server in HG %d : %s:%d , gtid_port=%d, weight=%d, status=%d\n", atoi(r->fields[0]), r->fields[1], atoi(r->fields[2]), atoi(r->fields[3]), atoi(r->fields[4]), (MySerStatus)atoi(r->fields[5]));
// }
// MySrvC* mysrvc = new MySrvC(r->fields[1], atoi(r->fields[2]), atoi(r->fields[3]), atoi(r->fields[4]), (MySerStatus)atoi(r->fields[5]), atoi(r->fields[6]), atoi(r->fields[7]), atoi(r->fields[8]), atoi(r->fields[9]), atoi(r->fields[10]), r->fields[11]); // add new fields here if adding more columns in mysql_servers
// proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 5, "Adding new server %s:%d , weight=%d, status=%d, mem_ptr=%p into hostgroup=%d\n", r->fields[1], atoi(r->fields[2]), atoi(r->fields[4]), (MySerStatus)atoi(r->fields[5]), mysrvc, atoi(r->fields[0]));
// // this server has gtid_port configured, we set use_gtid
// proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 6, "Server %u:%s:%d has gtid_port enabled, setting use_gitd=true if not already set\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port);
// use_gtid = true;
// }
// } else {
// bool run_update = false;
// MySrvC* mysrvc = (MySrvC*)ptr;
// // carefully increase the 2nd index by 1 for every new column added
// if (atoi(r->fields[3]) != atoi(r->fields[13])) {
// if (GloMTH->variables.hostgroup_manager_verbose)
// proxy_info("Changing gtid_port for server %u:%s:%d (%s:%d) from %d (%d) to %d\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, r->fields[1], atoi(r->fields[2]), atoi(r->fields[3]), mysrvc->gtid_port, atoi(r->fields[13]));
// mysrvc->gtid_port = atoi(r->fields[13]);
// }
//
// if (atoi(r->fields[4]) != atoi(r->fields[14])) {
// if (GloMTH->variables.hostgroup_manager_verbose)
// proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 5, "Changing weight for server %d:%s:%d (%s:%d) from %d (%d) to %d\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, r->fields[1], atoi(r->fields[2]), atoi(r->fields[4]), mysrvc->weight, atoi(r->fields[14]));
// mysrvc->weight = atoi(r->fields[14]);
// }
// if (atoi(r->fields[5]) != atoi(r->fields[15])) {
// if (GloMTH->variables.hostgroup_manager_verbose)
// proxy_info("Changing status for server %d:%s:%d (%s:%d) from %d (%d) to %d\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, r->fields[1], atoi(r->fields[2]), atoi(r->fields[5]), mysrvc->status, atoi(r->fields[15]));
// if (mysrvc->status == MYSQL_SERVER_STATUS_SHUNNED) {
// mysrvc->shunned_automatic = false;
// }
// }
// if (atoi(r->fields[6]) != atoi(r->fields[16])) {
// if (GloMTH->variables.hostgroup_manager_verbose)
// proxy_info("Changing compression for server %d:%s:%d (%s:%d) from %d (%d) to %d\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, r->fields[1], atoi(r->fields[2]), atoi(r->fields[6]), mysrvc->compression, atoi(r->fields[16]));
// mysrvc->compression = atoi(r->fields[16]);
// }
// if (atoi(r->fields[7]) != atoi(r->fields[17])) {
// if (GloMTH->variables.hostgroup_manager_verbose)
// proxy_info("Changing max_connections for server %d:%s:%d (%s:%d) from %d (%d) to %d\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, r->fields[1], atoi(r->fields[2]), atoi(r->fields[7]), mysrvc->max_connections, atoi(r->fields[17]));
// mysrvc->max_connections = atoi(r->fields[17]);
// }
// if (atoi(r->fields[8]) != atoi(r->fields[18])) {
// if (GloMTH->variables.hostgroup_manager_verbose)
// proxy_info("Changing max_replication_lag for server %u:%s:%d (%s:%d) from %d (%d) to %d\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, r->fields[1], atoi(r->fields[2]), atoi(r->fields[8]), mysrvc->max_replication_lag, atoi(r->fields[18]));
// if (mysrvc->max_replication_lag == 0) { // we just changed it to 0
// if (mysrvc->status == MYSQL_SERVER_STATUS_SHUNNED_REPLICATION_LAG) {
// // the server is currently shunned due to replication lag
// // but we reset max_replication_lag to 0
// // therefore we immediately reset the status too
// mysrvc->status = MYSQL_SERVER_STATUS_ONLINE;
// }
// }
// }
// if (atoi(r->fields[9]) != atoi(r->fields[19])) {
// if (GloMTH->variables.hostgroup_manager_verbose)
// proxy_info("Changing use_ssl for server %d:%s:%d (%s:%d) from %d (%d) to %d\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, r->fields[1], atoi(r->fields[2]), atoi(r->fields[9]), mysrvc->use_ssl, atoi(r->fields[19]));
// mysrvc->use_ssl = atoi(r->fields[19]);
// }
// if (atoi(r->fields[10]) != atoi(r->fields[20])) {
// if (GloMTH->variables.hostgroup_manager_verbose)
// proxy_info("Changing max_latency_ms for server %d:%s:%d (%s:%d) from %d (%d) to %d\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, r->fields[1], atoi(r->fields[2]), atoi(r->fields[10]), mysrvc->max_latency_us / 1000, atoi(r->fields[20]));
// if (GloMTH->variables.hostgroup_manager_verbose)
// proxy_info("Changing comment for server %d:%s:%d (%s:%d) from '%s' to '%s'\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, r->fields[1], atoi(r->fields[2]), r->fields[11], r->fields[21]);
query=(char*)"SELECT mem_pointer, t1.hostgroup_id, t1.hostname, t1.port FROM mysql_servers t1 LEFT OUTER JOIN mysql_servers_incoming t2 ON (t1.hostgroup_id=t2.hostgroup_id AND t1.hostname=t2.hostname AND t1.port=t2.port) WHERE t2.hostgroup_id IS NULL";
// SELECT FROM mysql_servers whatever is not identical in mysql_servers_incoming, or where mem_pointer=0 (where there is no pointer yet)
query=(char*)"SELECT t1.*, t2.gtid_port, t2.weight, t2.status, t2.compression, t2.max_connections, t2.max_replication_lag, t2.use_ssl, t2.max_latency_ms, t2.comment FROM mysql_servers t1 JOIN mysql_servers_incoming t2 ON (t1.hostgroup_id=t2.hostgroup_id AND t1.hostname=t2.hostname AND t1.port=t2.port) WHERE mem_pointer=0 OR t1.gtid_port<>t2.gtid_port OR t1.weight<>t2.weight OR t1.status<>t2.status OR t1.compression<>t2.compression OR t1.max_connections<>t2.max_connections OR t1.max_replication_lag<>t2.max_replication_lag OR t1.use_ssl<>t2.use_ssl OR t1.max_latency_ms<>t2.max_latency_ms or t1.comment<>t2.comment";
char*query=(char*)"SELECT hostgroup_id, hostname, port, gtid_port, CASE status WHEN 0 OR 1 OR 4 THEN 0 ELSE status END status, weight, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment FROM mysql_servers WHERE status<>3 ORDER BY hostgroup_id, hostname, port";
proxy_info("Checksum for table %s is 0x%lX\n","mysql_servers",table_resultset_checksum[HGM_TABLES::MYSQL_SERVERS]);
//char* error = NULL;
//int cols = 0;
//int affected_rows = 0;
//SQLite3_result* resultset = NULL;
//char* query = (char*)"SELECT hostgroup_id, hostname, port, gtid_port, CASE status WHEN 0 OR 1 OR 4 THEN 0 ELSE status END status, weight, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment FROM mysql_servers WHERE status<>3 ORDER BY hostgroup_id, hostname, port";
proxy_debug(PROXY_DEBUG_CLUSTER,5,"Global checksum 0x%llX for peer %s:%d matches\n",v,node->get_hostname(),node->get_port());
ret=false;
}else{
proxy_debug(PROXY_DEBUG_CLUSTER,5,"Global checksum for peer %s:%d is different from fetched one. Local checksum:[0x%llX] Fetched checksum:[0x%llX]\n",node->get_hostname(),node->get_port(),node->global_checksum,v);
proxy_debug(PROXY_DEBUG_CLUSTER,5,"Global checksum for peer %s:%d is different from fetched one. Local checksum:[0x%lX] Fetched checksum:[0x%lX]\n",node->get_hostname(),node->get_port(),node->global_checksum,v);