Add error tolerance to "servers_no_promotion"
Previously, if the list contained servers that were not monitored by the monitor yet were valid servers, an error value would be returned and the monitor failed to start. With this update, the non-monitored servers are simply ignored when forming the final list. Also, added printing of the list to diagnostics.
This commit is contained in:
parent
faaf43ff39
commit
b8d3da4968
@ -385,14 +385,15 @@ void load_server_journal(MXS_MONITOR *monitor, MXS_MONITORED_SERVER **master);
|
||||
MXS_MONITORED_SERVER* mon_get_monitored_server(const MXS_MONITOR* mon, SERVER* search_server);
|
||||
|
||||
/**
|
||||
* Get an array of monitored servers. All the servers defined in the config setting must be monitored by
|
||||
* the given monitor.
|
||||
* Get an array of monitored servers. If a server defined in the config setting is not monitored by
|
||||
* the given monitor, that server is ignored and not inserted into the output array.
|
||||
*
|
||||
* @param params Config parameters
|
||||
* @param key Setting name
|
||||
* @param mon Monitor which should monitor the servers
|
||||
* @param monitored_servers_out Where to save output. The caller should free the array, but not the elements.
|
||||
* @return Output array size if successful, negative value otherwise
|
||||
* @param monitored_servers_out Where to save output array. The caller should free the array, but not the
|
||||
* elements. The output must contain NULL before calling this function.
|
||||
* @return Output array size.
|
||||
*/
|
||||
int mon_config_get_servers(const MXS_CONFIG_PARAMETER* params, const char* key, const MXS_MONITOR* mon,
|
||||
MXS_MONITORED_SERVER*** monitored_array_out);
|
||||
|
@ -2444,41 +2444,41 @@ MXS_MONITORED_SERVER* mon_get_monitored_server(const MXS_MONITOR* mon, SERVER* s
|
||||
int mon_config_get_servers(const MXS_CONFIG_PARAMETER* params, const char* key, const MXS_MONITOR* mon,
|
||||
MXS_MONITORED_SERVER*** monitored_servers_out)
|
||||
{
|
||||
ss_dassert(*monitored_servers_out == NULL);
|
||||
ss_dassert(monitored_servers_out != NULL && *monitored_servers_out == NULL);
|
||||
SERVER** servers = NULL;
|
||||
int servers_size = config_get_server_list(params, key, &servers);
|
||||
int rval = 0;
|
||||
int found = 0;
|
||||
// All servers in the array must be monitored by the given monitor.
|
||||
if (servers_size > 0)
|
||||
{
|
||||
MXS_MONITORED_SERVER** monitored_array =
|
||||
(MXS_MONITORED_SERVER**)MXS_CALLOC(servers_size, sizeof(MXS_MONITORED_SERVER*));
|
||||
bool error = false;
|
||||
for (int i = 0; i < servers_size && !error; i++)
|
||||
for (int i = 0; i < servers_size; i++)
|
||||
{
|
||||
MXS_MONITORED_SERVER* mon_serv = mon_get_monitored_server(mon, servers[i]);
|
||||
if (mon_serv != NULL)
|
||||
{
|
||||
monitored_array[i] = mon_serv;
|
||||
monitored_array[found++] = mon_serv;
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Server '%s' is not monitored by monitor '%s'.", servers[i]->unique_name, mon->name);
|
||||
error = true;
|
||||
MXS_WARNING("Server '%s' is not monitored by monitor '%s'.",
|
||||
servers[i]->unique_name, mon->name);
|
||||
}
|
||||
}
|
||||
MXS_FREE(servers);
|
||||
|
||||
if (error)
|
||||
ss_dassert(found <= servers_size);
|
||||
if (found == 0)
|
||||
{
|
||||
MXS_FREE(monitored_array);
|
||||
rval = -1;
|
||||
monitored_array = NULL;
|
||||
}
|
||||
else
|
||||
else if (found < servers_size)
|
||||
{
|
||||
*monitored_servers_out = monitored_array;
|
||||
rval = servers_size;
|
||||
monitored_array = (MXS_MONITORED_SERVER**)MXS_REALLOC(monitored_array, found);
|
||||
}
|
||||
*monitored_servers_out = monitored_array;
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
@ -1176,6 +1176,21 @@ static bool stop_monitor(MXS_MONITOR* mon)
|
||||
return actually_stopped;
|
||||
}
|
||||
|
||||
static string monitored_servers_to_string(MXS_MONITORED_SERVER** array, size_t array_size)
|
||||
{
|
||||
string rval;
|
||||
if (array_size > 0)
|
||||
{
|
||||
const char* separator = "";
|
||||
for (size_t i = 0; i < array_size; i++)
|
||||
{
|
||||
rval += separator;
|
||||
rval += array[i]->server->unique_name;
|
||||
separator = ",";
|
||||
}
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
/**
|
||||
* Daignostic interface
|
||||
*
|
||||
@ -1196,8 +1211,14 @@ static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
||||
"Enabled" : "Disabled");
|
||||
dcb_printf(dcb, "Detect stale master: %s\n", (handle->detectStaleMaster == 1) ?
|
||||
"Enabled" : "Disabled");
|
||||
dcb_printf(dcb, "\nServer information:\n-------------------\n\n");
|
||||
if (handle->n_excluded > 0)
|
||||
{
|
||||
dcb_printf(dcb, "Non-promotable servers (failover): ");
|
||||
dcb_printf(dcb, "%s\n",
|
||||
monitored_servers_to_string(handle->excluded_servers, handle->n_excluded).c_str());
|
||||
}
|
||||
|
||||
dcb_printf(dcb, "\nServer information:\n-------------------\n\n");
|
||||
for (MXS_MONITORED_SERVER *db = mon->monitored_servers; db; db = db->next)
|
||||
{
|
||||
MySqlServerInfo *serv_info = get_server_info(handle, db);
|
||||
@ -1265,7 +1286,11 @@ static json_t* diagnostics_json(const MXS_MONITOR *mon)
|
||||
{
|
||||
json_object_set_new(rval, "script", json_string(handle->script));
|
||||
}
|
||||
|
||||
if (handle->n_excluded > 0)
|
||||
{
|
||||
string list = monitored_servers_to_string(handle->excluded_servers, handle->n_excluded);
|
||||
json_object_set_new(rval, CN_NO_PROMOTE_SERVERS, json_string(list.c_str()));
|
||||
}
|
||||
if (mon->monitored_servers)
|
||||
{
|
||||
json_t* arr = json_array();
|
||||
|
Loading…
x
Reference in New Issue
Block a user