Failure to load filters is now a configuration error

When a filter module is not found or the instance creation fails, this is considered
a fatal error and MaxScale will not start. If a failure occurs when the configuration
is being reloaded, the service will not use filters and an error will be logged.
This commit is contained in:
Markus Makela 2015-11-17 06:06:56 +02:00
parent 9c7118eb9a
commit 41d26b5b73
3 changed files with 69 additions and 40 deletions

View File

@ -1028,7 +1028,10 @@ process_config_context(CONFIG_CONTEXT *context)
if (filters && obj->element)
{
serviceSetFilters(obj->element, filters);
if (!serviceSetFilters(obj->element, filters))
{
error_count++;
}
}
}
else if (!strcmp(type, "listener"))
@ -2141,7 +2144,11 @@ process_config_update(CONFIG_CONTEXT *context)
}
if (filters && obj->element)
{
serviceSetFilters(obj->element, filters);
if (!serviceSetFilters(obj->element, filters))
{
MXS_ERROR("Failed to set service filters for '%s'. This "
"service will not use filters.", obj->object);
}
}
}
else if (!strcmp(type, "listener"))

View File

@ -1069,49 +1069,71 @@ char *ptr;
*
* @param service The service itself
* @param filters ASCII string of filters to use
* @return True if loading and creating all filters was successful. False if a
* filter module was not found or the instance creation failed.
*/
void
bool
serviceSetFilters(SERVICE *service, char *filters)
{
FILTER_DEF **flist;
char *ptr, *brkt;
int n = 0;
FILTER_DEF **flist;
char *ptr, *brkt;
int n = 0;
bool rval = true;
if ((flist = (FILTER_DEF **)malloc(sizeof(FILTER_DEF *))) == NULL)
{
MXS_ERROR("Out of memory adding filters to service.\n");
return;
}
ptr = strtok_r(filters, "|", &brkt);
while (ptr)
{
n++;
if ((flist = (FILTER_DEF **)realloc(flist,
(n + 1) * sizeof(FILTER_DEF *))) == NULL)
{
MXS_ERROR("Out of memory adding filters to service.");
return;
}
char *filter_name = trim(ptr);
if ((flist[n-1] = filter_find(filter_name)) == NULL)
{
MXS_WARNING("Unable to find filter '%s' for service '%s'\n",
filter_name, service->name);
n--;
}
else if (!filter_load(flist[n - 1]))
{
MXS_ERROR("Failed to load filter '%s' for service '%s'.",
filter_name, service->name);
n--;
}
if ((flist = (FILTER_DEF **) malloc(sizeof(FILTER_DEF *))) == NULL)
{
MXS_ERROR("Out of memory adding filters to service.\n");
return false;
}
ptr = strtok_r(filters, "|", &brkt);
while (ptr)
{
n++;
FILTER_DEF **tmp;
if ((tmp = (FILTER_DEF **) realloc(flist,
(n + 1) * sizeof(FILTER_DEF *))) == NULL)
{
MXS_ERROR("Out of memory adding filters to service.");
rval = false;
break;
}
flist[n] = NULL;
ptr = strtok_r(NULL, "|", &brkt);
}
flist = tmp;
char *filter_name = trim(ptr);
service->filters = flist;
service->n_filters = n;
if ((flist[n - 1] = filter_find(filter_name)))
{
if (!filter_load(flist[n - 1]))
{
MXS_ERROR("Failed to load filter '%s' for service '%s'.",
filter_name, service->name);
rval = false;
break;
}
}
else
{
MXS_WARNING("Unable to find filter '%s' for service '%s'\n",
filter_name, service->name);
rval = false;
break;
}
flist[n] = NULL;
ptr = strtok_r(NULL, "|", &brkt);
}
if (rval)
{
service->filters = flist;
service->n_filters = n;
}
else
{
free(flist);
}
return rval;
}
/**

View File

@ -219,7 +219,7 @@ extern int serviceStop(SERVICE *);
extern int serviceRestart(SERVICE *);
extern int serviceSetUser(SERVICE *, char *, char *);
extern int serviceGetUser(SERVICE *, char **, char **);
extern void serviceSetFilters(SERVICE *, char *);
extern bool serviceSetFilters(SERVICE *, char *);
extern int serviceSetSSL(SERVICE *service, char* action);
extern int serviceInitSSL(SERVICE* service);
extern int serviceSetSSLVersion(SERVICE *service, char* version);