Do hangups only after server states have been updated

The hangup code was refactored into a common function which should only be
used after the server states have been updated. This will remove erroneus
connections to already failed servers.
This commit is contained in:
Markus Makela
2016-11-09 13:46:02 +02:00
parent b12a87ef04
commit 7ef8b187b5
6 changed files with 30 additions and 32 deletions

View File

@ -1055,3 +1055,16 @@ void mon_log_state_change(MONITOR_SERVERS *ptr)
free(prev);
free(next);
}
void mon_hangup_failed_servers(MONITOR *monitor)
{
for (MONITOR_SERVERS *ptr = monitor->databases; ptr; ptr = ptr->next)
{
if (mon_status_changed(ptr) &&
(!(SERVER_IS_RUNNING(ptr->server)) ||
!(SERVER_IS_IN_CLUSTER(ptr->server))))
{
dcb_hangup_foreach(ptr->server);
}
}
}

View File

@ -222,4 +222,13 @@ connect_result_t mon_connect_to_db(MONITOR* mon, MONITOR_SERVERS *database);
void mon_log_connect_error(MONITOR_SERVERS* database, connect_result_t rval);
void mon_log_state_change(MONITOR_SERVERS *ptr);
/**
* @brief Hangup connections to failed servers
*
* Injects hangup events for DCB that are connected to servers that are down.
*
* @param monitor Monitor object
*/
void mon_hangup_failed_servers(MONITOR *monitor);
#endif

View File

@ -538,16 +538,9 @@ monitorMain(void *arg)
STRSRVSTATUS(ptr->server));
}
if (!(SERVER_IS_RUNNING(ptr->server)) ||
!(SERVER_IS_IN_CLUSTER(ptr->server)))
{
dcb_hangup_foreach(ptr->server);
}
if (SERVER_IS_DOWN(ptr->server))
{
/** Increase this server'e error count */
dcb_hangup_foreach(ptr->server);
ptr->mon_err_count += 1;
}
@ -653,6 +646,8 @@ monitorMain(void *arg)
}
ptr = ptr->next;
}
mon_hangup_failed_servers(mon);
}
}

View File

@ -599,15 +599,6 @@ monitorMain(void *arg)
/* monitor current node */
monitorDatabase(mon, ptr);
if (mon_status_changed(ptr))
{
if (!(SERVER_IS_RUNNING(ptr->server)) ||
!(SERVER_IS_IN_CLUSTER(ptr->server)))
{
dcb_hangup_foreach(ptr->server);
}
}
if (mon_status_changed(ptr) ||
mon_print_fail_status(ptr))
{
@ -679,6 +670,8 @@ monitorMain(void *arg)
}
ptr = ptr->next;
}
mon_hangup_failed_servers(mon);
}
}

View File

@ -860,22 +860,6 @@ monitorMain(void *arg)
ptr->server->name,
ptr->server->port);
}
/**
* Here we say: If the server's state changed
* so that it isn't running or some other way
* lost cluster membership, call call-back function
* of every DCB for which such callback was
* registered for this kind of issue (DCB_REASON_...)
*/
if (!(SERVER_IS_RUNNING(ptr->server)) ||
!(SERVER_IS_IN_CLUSTER(ptr->server)))
{
dcb_hangup_foreach(ptr->server);
}
}
if (mon_status_changed(ptr))
@ -1090,6 +1074,8 @@ monitorMain(void *arg)
ptr = ptr->next;
}
}
mon_hangup_failed_servers(mon);
} /*< while (1) */
}

View File

@ -447,6 +447,8 @@ monitorMain(void *arg)
}
ptr = ptr->next;
}
mon_hangup_failed_servers(mon);
}
}