Fix to MXS-429: Missing parameter no longer causes a crash
If a server is missing a weighting parameter the default weight will be used.
This commit is contained in:
@ -248,46 +248,71 @@ char *weightby;
|
|||||||
}
|
}
|
||||||
inst->servers[n] = NULL;
|
inst->servers[n] = NULL;
|
||||||
|
|
||||||
if ((weightby = serviceGetWeightingParameter(service)) != NULL)
|
if ((weightby = serviceGetWeightingParameter(service)) != NULL)
|
||||||
{
|
{
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (n = 0; inst->servers[n]; n++)
|
|
||||||
{
|
for (int n = 0; inst->servers[n]; n++)
|
||||||
backend = inst->servers[n];
|
{
|
||||||
total += atoi(serverGetParameter(backend->server,
|
BACKEND *backend = inst->servers[n];
|
||||||
weightby));
|
char *param = serverGetParameter(backend->server, weightby);
|
||||||
}
|
if (param)
|
||||||
if (total == 0)
|
{
|
||||||
{
|
total += atoi(param);
|
||||||
MXS_WARNING("Weighting Parameter for service '%s' "
|
}
|
||||||
"will be ignored as no servers have values "
|
}
|
||||||
"for the parameter '%s'.\n",
|
if (total == 0)
|
||||||
service->name, weightby);
|
{
|
||||||
}
|
MXS_WARNING("Weighting Parameter for service '%s' "
|
||||||
else
|
"will be ignored as no servers have values "
|
||||||
{
|
"for the parameter '%s'.",
|
||||||
for (n = 0; inst->servers[n]; n++)
|
service->name, weightby);
|
||||||
{
|
}
|
||||||
int perc, wght;
|
else if (total < 0)
|
||||||
backend = inst->servers[n];
|
{
|
||||||
perc = ((wght = atoi(serverGetParameter(backend->server,
|
MXS_ERROR("Sum of weighting parameter '%s' for service '%s' exceeds "
|
||||||
weightby))) * 1000) / total;
|
"maximum value of %d. Weighting will be ignored.",
|
||||||
if (perc == 0 && wght != 0)
|
weightby, service->name, INT_MAX);
|
||||||
perc = 1;
|
}
|
||||||
backend->weight = perc;
|
else
|
||||||
if (perc == 0)
|
{
|
||||||
{
|
for (int n = 0; inst->servers[n]; n++)
|
||||||
MXS_ERROR("Server '%s' has no value "
|
{
|
||||||
"for weighting parameter '%s', "
|
BACKEND *backend = inst->servers[n];
|
||||||
"no queries will be routed to "
|
char *param = serverGetParameter(backend->server, weightby);
|
||||||
"this server.\n",
|
if (param)
|
||||||
inst->servers[n]->server->unique_name,
|
{
|
||||||
weightby);
|
int wght = atoi(param);
|
||||||
}
|
int perc = (wght * 1000) / total;
|
||||||
|
|
||||||
}
|
if (perc == 0)
|
||||||
}
|
{
|
||||||
}
|
perc = 1;
|
||||||
|
MXS_ERROR("Weighting parameter '%s' with a value of %d for"
|
||||||
|
" server '%s' rounds down to zero with total weight"
|
||||||
|
" of %d for service '%s'. No queries will be "
|
||||||
|
"routed to this server.", weightby, wght,
|
||||||
|
backend->server->unique_name, total,
|
||||||
|
service->name);
|
||||||
|
}
|
||||||
|
else if (perc < 0)
|
||||||
|
{
|
||||||
|
MXS_ERROR("Weighting parameter '%s' for server '%s' is too large, "
|
||||||
|
"maximum value is %d. No weighting will be used for this server.",
|
||||||
|
weightby, backend->server->unique_name, INT_MAX / 1000);
|
||||||
|
perc = 1000;
|
||||||
|
}
|
||||||
|
backend->weight = perc;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MXS_WARNING("Server '%s' has no parameter '%s' used for weighting"
|
||||||
|
" for service '%s'.", backend->server->unique_name,
|
||||||
|
weightby, service->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Process the options
|
* Process the options
|
||||||
|
|||||||
Reference in New Issue
Block a user