Make the instance name available to filters

The section name of a filter in the MaxScale configuration
file is unique for each filter. Hence, by providing that name
to the filter instance creation function, it is possible to
act differently depending on which particular instance is
being created.

Case in point.

There can be multiple cache filters defined in the MaxScale
configuration file, each with a different set of rules, ttl
and even backing store.

Each cache will be backed by a separate storage that e.g.
in the case of RocksDB will correspond to a particular path.

In other words, for each cache instance corresponding to a
particular cache definition in the MaxScale configuration file,
we need to be able to create a unique path.

If the filter section name (in the MaxScale configuration file)
that anyways needs to be unique, is provided to the filter, then
that name can be used when forming the unique path.

The alternative is to require the DBA to provide some unique
parameter for each cache definition, which adds configuration
overhead and is errorprone.

Furthermore, by providing the name to filters, also error
messages can be customized for a particular section when
appropriate.
This commit is contained in:
Johan Wikman
2016-08-23 14:08:11 +03:00
parent e782344115
commit 85b3d7c465
14 changed files with 47 additions and 29 deletions

View File

@ -405,7 +405,8 @@ bool filter_load(FILTER_DEF* filter)
{
ss_dassert(!filter->filter);
if ((filter->filter = (filter->obj->createInstance)(filter->options,
if ((filter->filter = (filter->obj->createInstance)(filter->name,
filter->options,
filter->parameters)))
{
rval = true;

View File

@ -67,7 +67,9 @@ typedef struct
*/
typedef struct filter_object
{
FILTER *(*createInstance)(char **options, FILTER_PARAMETER **);
FILTER *(*createInstance)(const char *name,
char **options,
FILTER_PARAMETER **params);
void *(*newSession)(FILTER *instance, SESSION *session);
void (*closeSession)(FILTER *instance, void *fsession);
void (*freeSession)(FILTER *instance, void *fsession);
@ -83,7 +85,7 @@ typedef struct filter_object
* is changed these values must be updated in line with the rules in the
* file modinfo.h.
*/
#define FILTER_VERSION {1, 1, 0}
#define FILTER_VERSION {2, 1, 0}
/**
* The definition of a filter from the configuration file.
* This is basically the link between a plugin to load and the

View File

@ -17,7 +17,7 @@
static char VERSION_STRING[] = "V1.0.0";
static FILTER *createInstance(char **options, FILTER_PARAMETER **);
static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *sdata);
static void freeSession(FILTER *instance, void *sdata);
@ -93,12 +93,13 @@ typedef struct cache_session_data
* Create an instance of the cache filter for a particular service
* within MaxScale.
*
* @param name The name of the instance (as defined in the config file).
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER *createInstance(char **options, FILTER_PARAMETER **params)
static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
CACHE_INSTANCE *cinstance;

View File

@ -57,7 +57,7 @@ MODULE_INFO info =
static char *version_str = "V1.1.0";
static FILTER *createInstance(char **options, FILTER_PARAMETER **params);
static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **params);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *session);
static void freeSession(FILTER *instance, void *session);
@ -156,13 +156,14 @@ GetModuleObject()
* Create an instance of the filter for a particular service
* within MaxScale.
*
* @param name The name of the instance (as defined in the config file).
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
CCR_INSTANCE *my_instance;
int i;

View File

@ -99,7 +99,7 @@ static char *version_str = "V1.2.0";
/*
* The filter entry points
*/
static FILTER *createInstance(char **options, FILTER_PARAMETER **);
static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *session);
static void freeSession(FILTER *instance, void *session);
@ -1357,12 +1357,14 @@ static bool process_rule_file(const char* filename, FW_INSTANCE* instance)
* Create an instance of the filter for a particular service
* within MaxScale.
*
* @param name The name of the instance (as defined in the config file).
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
FW_INSTANCE *my_instance;
int i;

View File

@ -82,7 +82,7 @@ static const char* datafile_name = "gatekeeper.data";
* return a non-NULL value when a hash hit is made */
static bool trueval = true;
static FILTER *createInstance(char **options, FILTER_PARAMETER **params);
static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **params);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *session);
static void freeSession(FILTER *instance, void *session);
@ -140,12 +140,13 @@ FILTER_OBJECT* GetModuleObject()
* Create an instance of the filter for a particular service
* within MaxScale.
*
* @param name The name of the instance (as defined in the config file).
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER* createInstance(char **options, FILTER_PARAMETER **params)
static FILTER* createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
GK_INSTANCE *inst = MXS_CALLOC(1, sizeof(GK_INSTANCE));

View File

@ -33,7 +33,7 @@ MODULE_INFO info =
static char *version_str = "V1.0.0";
static FILTER *createInstance(char **options, FILTER_PARAMETER **params);
static FILTER *createInstance(const char* name, char **options, FILTER_PARAMETER **params);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *session);
static void freeSession(FILTER *instance, void *session);
@ -97,12 +97,14 @@ GetModuleObject()
* Create an instance of the filter for a particular service
* within MaxScale.
*
* @param name The name of the instance (as defined in the config file).
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
HINT_INSTANCE *my_instance;

View File

@ -92,7 +92,7 @@ static int hktask_id = 0;
/*
* The filter entry points
*/
static FILTER *createInstance(char **options, FILTER_PARAMETER **);
static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *session);
static void freeSession(FILTER *instance, void *session);
@ -497,12 +497,14 @@ char** parse_optstr(char* str, char* tok, int* szstore)
* Create an instance of the filter for a particular service
* within MaxScale.
*
* @param name The name of the instance (as defined in the config file).
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
MQ_INSTANCE *my_instance;
int paramcount = 0, parammax = 64, i = 0, x = 0, arrsize = 0;

View File

@ -51,7 +51,7 @@ MODULE_INFO info =
static char *version_str = "V1.1.0";
static FILTER *createInstance(char **options, FILTER_PARAMETER **params);
static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **params);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *session);
static void freeSession(FILTER *instance, void *session);
@ -137,13 +137,14 @@ GetModuleObject()
* Create an instance of the filter for a particular service
* within MaxScale.
*
* @param params The array of name/value pair parameters for the filter
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE*)MXS_MALLOC(sizeof(REGEXHINT_INSTANCE));

View File

@ -65,7 +65,7 @@ static char *version_str = "V1.1.1";
/*
* The filter entry points
*/
static FILTER *createInstance(char **options, FILTER_PARAMETER **);
static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *session);
static void freeSession(FILTER *instance, void *session);
@ -166,13 +166,14 @@ GetModuleObject()
* Create an instance of the filter for a particular service
* within MaxScale.
*
* @param name The name of the instance (as defined in the config file).
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
QLA_INSTANCE *my_instance = (QLA_INSTANCE*) MXS_MALLOC(sizeof(QLA_INSTANCE));

View File

@ -51,7 +51,7 @@ MODULE_INFO info =
static char *version_str = "V1.1.0";
static FILTER *createInstance(char **options, FILTER_PARAMETER **params);
static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **params);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *session);
static void freeSession(FILTER *instance, void *session);
@ -172,13 +172,14 @@ void free_instance(REGEX_INSTANCE *instance)
* Create an instance of the filter for a particular service
* within MaxScale.
*
* @param name The name of the instance (as defined in the config file).
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
REGEX_INSTANCE *my_instance;
int i, errnumber, cflags = PCRE2_CASELESS;

View File

@ -108,7 +108,7 @@ static char *version_str = "V1.0.0";
/*
* The filter entry points
*/
static FILTER *createInstance(char **options, FILTER_PARAMETER **);
static FILTER *createInstance(const char* name, char **options, FILTER_PARAMETER **);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *session);
static void freeSession(FILTER *instance, void *session);
@ -351,13 +351,14 @@ GetModuleObject()
* Create an instance of the filter for a particular service
* within MaxScale.
*
* @param name The name of the instance (as defined in the config file).
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
TEE_INSTANCE *my_instance;
int i;

View File

@ -39,7 +39,7 @@ MODULE_INFO info =
static char *version_str = "V1.0.0";
static FILTER *createInstance(char **options, FILTER_PARAMETER **params);
static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **params);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *session);
static void freeSession(FILTER *instance, void *session);
@ -119,13 +119,14 @@ GetModuleObject()
* Create an instance of the filter for a particular service
* within MaxScale.
*
* @param name The name of the instance (as defined in the config file).
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
TEST_INSTANCE *my_instance;

View File

@ -59,7 +59,7 @@ static char *version_str = "V1.0.1";
/*
* The filter entry points
*/
static FILTER *createInstance(char **options, FILTER_PARAMETER **);
static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **);
static void *newSession(FILTER *instance, SESSION *session);
static void closeSession(FILTER *instance, void *session);
static void freeSession(FILTER *instance, void *session);
@ -179,13 +179,14 @@ GetModuleObject()
* Create an instance of the filter for a particular service
* within MaxScale.
*
* @param name The name of the instance (as defined in the config file).
* @param options The options for this filter
* @param params The array of name/value pair parameters for the filter
*
* @return The instance data for this new instance
*/
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
createInstance(const char *name, char **options, FILTER_PARAMETER **params)
{
TOPN_INSTANCE *my_instance = (TOPN_INSTANCE*)MXS_MALLOC(sizeof(TOPN_INSTANCE));