server_id for MySQL replication set for each node

server_id for MySQL replication is now set for each node and
dprintServer* routines can print it as well
This commit is contained in:
MassimilianoPinto
2014-05-28 10:43:01 +02:00
parent 78a02f5297
commit f985e1cac5
2 changed files with 21 additions and 2 deletions

View File

@ -334,6 +334,25 @@ char *server_string;
database->server->server_string = strdup(server_string);
}
/* get server_id form current node */
if (mysql_query(database->con, "SELECT @@server_id") == 0
&& (result = mysql_store_result(database->con)) != NULL)
{
long server_id = -1;
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
server_id = strtol(row[0], NULL, 10);
if ((errno == ERANGE && (server_id == LONG_MAX
|| server_id == LONG_MIN)) || (errno != 0 && server_id == 0))
{
server_id = -1;
}
database->server->node_id = server_id;
}
mysql_free_result(result);
}
/* Check SHOW SLAVE HOSTS - if we get rows then we are a master */
if (mysql_query(database->con, "SHOW SLAVE HOSTS"))
{