Cleanup slavelag.c
Untabification, indentation, Allman, etc.
This commit is contained in:
@ -41,13 +41,17 @@
|
|||||||
* match=<regex> Regex for matching
|
* match=<regex> Regex for matching
|
||||||
* ignore=<regex> Regex for ignoring
|
* ignore=<regex> Regex for ignoring
|
||||||
*
|
*
|
||||||
* The filter also has two options: @c case, which makes the regex case-sensitive, and @c ignorecase, which does the opposite.
|
* The filter also has two options:
|
||||||
|
* @c case, which makes the regex case-sensitive, and
|
||||||
|
* @c ignorecase, which does the opposite.
|
||||||
|
*
|
||||||
* Date Who Description
|
* Date Who Description
|
||||||
* 03/03/2015 Markus Mäkelä Written for demonstrative purposes
|
* 03/03/2015 Markus Mäkelä Written for demonstrative purposes
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MODULE_INFO info = {
|
MODULE_INFO info =
|
||||||
|
{
|
||||||
MODULE_API_FILTER,
|
MODULE_API_FILTER,
|
||||||
MODULE_GA,
|
MODULE_GA,
|
||||||
FILTER_VERSION,
|
FILTER_VERSION,
|
||||||
@ -65,7 +69,8 @@ static int routeQuery(FILTER *instance, void *fsession, GWBUF *queue);
|
|||||||
static void diagnostic(FILTER *instance, void *fsession, DCB *dcb);
|
static void diagnostic(FILTER *instance, void *fsession, DCB *dcb);
|
||||||
|
|
||||||
|
|
||||||
static FILTER_OBJECT MyObject = {
|
static FILTER_OBJECT MyObject =
|
||||||
|
{
|
||||||
createInstance,
|
createInstance,
|
||||||
newSession,
|
newSession,
|
||||||
closeSession,
|
closeSession,
|
||||||
@ -77,15 +82,18 @@ static FILTER_OBJECT MyObject = {
|
|||||||
diagnostic,
|
diagnostic,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LAGSTATS{
|
typedef struct lagstats
|
||||||
|
{
|
||||||
int n_add_count; /*< No. of statements diverted based on count */
|
int n_add_count; /*< No. of statements diverted based on count */
|
||||||
int n_add_time; /*< No. of statements diverted based on time */
|
int n_add_time; /*< No. of statements diverted based on time */
|
||||||
int n_modified; /*< No. of statements not diverted */
|
int n_modified; /*< No. of statements not diverted */
|
||||||
};
|
} LAGSTATS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance structure
|
* Instance structure
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
char *match; /* Regular expression to match */
|
char *match; /* Regular expression to match */
|
||||||
char *nomatch; /* Regular expression to ignore */
|
char *nomatch; /* Regular expression to ignore */
|
||||||
int time; /*< The number of seconds to wait before routing queries
|
int time; /*< The number of seconds to wait before routing queries
|
||||||
@ -93,7 +101,7 @@ typedef struct {
|
|||||||
* is done. */
|
* is done. */
|
||||||
int count; /*< Number of hints to add after each operation
|
int count; /*< Number of hints to add after each operation
|
||||||
* that modifies data. */
|
* that modifies data. */
|
||||||
struct LAGSTATS stats;
|
LAGSTATS stats;
|
||||||
regex_t re; /* Compiled regex text of match */
|
regex_t re; /* Compiled regex text of match */
|
||||||
regex_t nore; /* Compiled regex text of ignore */
|
regex_t nore; /* Compiled regex text of ignore */
|
||||||
} LAG_INSTANCE;
|
} LAG_INSTANCE;
|
||||||
@ -101,7 +109,8 @@ typedef struct {
|
|||||||
/**
|
/**
|
||||||
* The session structure for this filter
|
* The session structure for this filter
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
DOWNSTREAM down; /*< The downstream filter */
|
DOWNSTREAM down; /*< The downstream filter */
|
||||||
int hints_left; /*< Number of hints left to add to queries*/
|
int hints_left; /*< Number of hints left to add to queries*/
|
||||||
time_t last_modification; /*< Time of the last modifying operation */
|
time_t last_modification; /*< Time of the last modifying operation */
|
||||||
@ -154,8 +163,9 @@ GetModuleObject()
|
|||||||
static FILTER *
|
static FILTER *
|
||||||
createInstance(char **options, FILTER_PARAMETER **params)
|
createInstance(char **options, FILTER_PARAMETER **params)
|
||||||
{
|
{
|
||||||
LAG_INSTANCE *my_instance;
|
LAG_INSTANCE *my_instance;
|
||||||
int i,cflags = 0;
|
int i;
|
||||||
|
int cflags = 0;
|
||||||
|
|
||||||
if ((my_instance = calloc(1, sizeof(LAG_INSTANCE))) != NULL)
|
if ((my_instance = calloc(1, sizeof(LAG_INSTANCE))) != NULL)
|
||||||
{
|
{
|
||||||
@ -170,17 +180,24 @@ int i,cflags = 0;
|
|||||||
for (i = 0; params && params[i]; i++)
|
for (i = 0; params && params[i]; i++)
|
||||||
{
|
{
|
||||||
if (!strcmp(params[i]->name, "count"))
|
if (!strcmp(params[i]->name, "count"))
|
||||||
|
{
|
||||||
my_instance->count = atoi(params[i]->value);
|
my_instance->count = atoi(params[i]->value);
|
||||||
|
}
|
||||||
else if (!strcmp(params[i]->name, "time"))
|
else if (!strcmp(params[i]->name, "time"))
|
||||||
|
{
|
||||||
my_instance->time = atoi(params[i]->value);
|
my_instance->time = atoi(params[i]->value);
|
||||||
|
}
|
||||||
else if (!strcmp(params[i]->name, "match"))
|
else if (!strcmp(params[i]->name, "match"))
|
||||||
|
{
|
||||||
my_instance->match = strdup(params[i]->value);
|
my_instance->match = strdup(params[i]->value);
|
||||||
|
}
|
||||||
else if (!strcmp(params[i]->name, "ignore"))
|
else if (!strcmp(params[i]->name, "ignore"))
|
||||||
|
{
|
||||||
my_instance->nomatch = strdup(params[i]->value);
|
my_instance->nomatch = strdup(params[i]->value);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MXS_ERROR("lagfilter: Unexpected parameter '%s'.\n",
|
MXS_ERROR("lagfilter: Unexpected parameter '%s'.\n", params[i]->name);
|
||||||
params[i]->name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,29 +215,28 @@ int i,cflags = 0;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MXS_ERROR("lagfilter: unsupported option '%s'.",
|
MXS_ERROR("lagfilter: unsupported option '%s'.", options[i]);
|
||||||
options[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(my_instance->match)
|
if (my_instance->match)
|
||||||
{
|
{
|
||||||
if(regcomp(&my_instance->re,my_instance->match,cflags))
|
if (regcomp(&my_instance->re, my_instance->match, cflags))
|
||||||
{
|
{
|
||||||
MXS_ERROR("lagfilter: Failed to compile regex '%s'.",
|
MXS_ERROR("lagfilter: Failed to compile regex '%s'.", my_instance->match);
|
||||||
my_instance->match);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(my_instance->nomatch)
|
|
||||||
|
if (my_instance->nomatch)
|
||||||
{
|
{
|
||||||
if(regcomp(&my_instance->nore,my_instance->nomatch,cflags))
|
if (regcomp(&my_instance->nore,my_instance->nomatch,cflags))
|
||||||
{
|
{
|
||||||
MXS_ERROR("lagfilter: Failed to compile regex '%s'.",
|
MXS_ERROR("lagfilter: Failed to compile regex '%s'.", my_instance->nomatch);
|
||||||
my_instance->nomatch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (FILTER *)my_instance;
|
return (FILTER *)my_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,13 +245,14 @@ int i,cflags = 0;
|
|||||||
*
|
*
|
||||||
* @param instance The filter instance data
|
* @param instance The filter instance data
|
||||||
* @param session The session itself
|
* @param session The session itself
|
||||||
|
*
|
||||||
* @return Session specific data for this session
|
* @return Session specific data for this session
|
||||||
*/
|
*/
|
||||||
static void *
|
static void *
|
||||||
newSession(FILTER *instance, SESSION *session)
|
newSession(FILTER *instance, SESSION *session)
|
||||||
{
|
{
|
||||||
LAG_INSTANCE *my_instance = (LAG_INSTANCE *)instance;
|
LAG_INSTANCE *my_instance = (LAG_INSTANCE *)instance;
|
||||||
LAG_SESSION *my_session;
|
LAG_SESSION *my_session;
|
||||||
|
|
||||||
if ((my_session = malloc(sizeof(LAG_SESSION))) != NULL)
|
if ((my_session = malloc(sizeof(LAG_SESSION))) != NULL)
|
||||||
{
|
{
|
||||||
@ -269,7 +286,6 @@ static void
|
|||||||
freeSession(FILTER *instance, void *session)
|
freeSession(FILTER *instance, void *session)
|
||||||
{
|
{
|
||||||
free(session);
|
free(session);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -282,7 +298,7 @@ freeSession(FILTER *instance, void *session)
|
|||||||
static void
|
static void
|
||||||
setDownstream(FILTER *instance, void *session, DOWNSTREAM *downstream)
|
setDownstream(FILTER *instance, void *session, DOWNSTREAM *downstream)
|
||||||
{
|
{
|
||||||
LAG_SESSION *my_session = (LAG_SESSION *)session;
|
LAG_SESSION *my_session = (LAG_SESSION *)session;
|
||||||
|
|
||||||
my_session->down = *downstream;
|
my_session->down = *downstream;
|
||||||
}
|
}
|
||||||
@ -304,10 +320,10 @@ LAG_SESSION *my_session = (LAG_SESSION *)session;
|
|||||||
static int
|
static int
|
||||||
routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
||||||
{
|
{
|
||||||
LAG_INSTANCE *my_instance = (LAG_INSTANCE *)instance;
|
LAG_INSTANCE *my_instance = (LAG_INSTANCE *)instance;
|
||||||
LAG_SESSION *my_session = (LAG_SESSION *)session;
|
LAG_SESSION *my_session = (LAG_SESSION *)session;
|
||||||
char *sql;
|
char *sql;
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
if (modutil_is_SQL(queue))
|
if (modutil_is_SQL(queue))
|
||||||
{
|
{
|
||||||
@ -316,13 +332,14 @@ time_t now = time(NULL);
|
|||||||
queue = gwbuf_make_contiguous(queue);
|
queue = gwbuf_make_contiguous(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(query_classifier_get_operation(queue) & (QUERY_OP_DELETE|QUERY_OP_INSERT|QUERY_OP_UPDATE))
|
if (query_classifier_get_operation(queue) & (QUERY_OP_DELETE | QUERY_OP_INSERT | QUERY_OP_UPDATE))
|
||||||
{
|
{
|
||||||
if((sql = modutil_get_SQL(queue)) != NULL)
|
if ((sql = modutil_get_SQL(queue)) != NULL)
|
||||||
{
|
{
|
||||||
if(my_instance->nomatch == NULL||(my_instance->nomatch && regexec(&my_instance->nore,sql,0,NULL,0) != 0))
|
if (my_instance->nomatch == NULL ||
|
||||||
|
(my_instance->nomatch && regexec(&my_instance->nore, sql, 0, NULL, 0) != 0))
|
||||||
{
|
{
|
||||||
if(my_instance->match == NULL||
|
if (my_instance->match == NULL||
|
||||||
(my_instance->match && regexec(&my_instance->re,sql,0,NULL,0) == 0))
|
(my_instance->match && regexec(&my_instance->re,sql,0,NULL,0) == 0))
|
||||||
{
|
{
|
||||||
my_session->hints_left = my_instance->count;
|
my_session->hints_left = my_instance->count;
|
||||||
@ -330,27 +347,26 @@ time_t now = time(NULL);
|
|||||||
my_instance->stats.n_modified++;
|
my_instance->stats.n_modified++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(sql);
|
free(sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(my_session->hints_left > 0)
|
else if (my_session->hints_left > 0)
|
||||||
{
|
{
|
||||||
queue->hint = hint_create_route(queue->hint,
|
queue->hint = hint_create_route(queue->hint, HINT_ROUTE_TO_MASTER, NULL);
|
||||||
HINT_ROUTE_TO_MASTER,
|
|
||||||
NULL);
|
|
||||||
my_session->hints_left--;
|
my_session->hints_left--;
|
||||||
my_instance->stats.n_add_count++;
|
my_instance->stats.n_add_count++;
|
||||||
}
|
}
|
||||||
else if(difftime(now,my_session->last_modification) < my_instance->time)
|
else if (difftime(now,my_session->last_modification) < my_instance->time)
|
||||||
{
|
{
|
||||||
queue->hint = hint_create_route(queue->hint,
|
queue->hint = hint_create_route(queue->hint, HINT_ROUTE_TO_MASTER, NULL);
|
||||||
HINT_ROUTE_TO_MASTER,
|
|
||||||
NULL);
|
|
||||||
my_instance->stats.n_add_time++;
|
my_instance->stats.n_add_time++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return my_session->down.routeQuery(my_session->down.instance,
|
return my_session->down.routeQuery(my_session->down.instance,
|
||||||
my_session->down.session, queue);
|
my_session->down.session,
|
||||||
|
queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -367,19 +383,13 @@ time_t now = time(NULL);
|
|||||||
static void
|
static void
|
||||||
diagnostic(FILTER *instance, void *fsession, DCB *dcb)
|
diagnostic(FILTER *instance, void *fsession, DCB *dcb)
|
||||||
{
|
{
|
||||||
LAG_INSTANCE *my_instance = (LAG_INSTANCE *)instance;
|
LAG_INSTANCE *my_instance = (LAG_INSTANCE *)instance;
|
||||||
LAG_SESSION *my_session = (LAG_SESSION *)fsession;
|
LAG_SESSION *my_session = (LAG_SESSION *)fsession;
|
||||||
|
|
||||||
dcb_printf(dcb, "Configuration:\n\tCount: %d\n",
|
dcb_printf(dcb, "Configuration:\n\tCount: %d\n", my_instance->count);
|
||||||
my_instance->count);
|
dcb_printf(dcb, "\tTime: %d seconds\n\n", my_instance->time);
|
||||||
dcb_printf(dcb, "\tTime: %d seconds\n\n",
|
|
||||||
my_instance->time);
|
|
||||||
dcb_printf(dcb, "Statistics:\n");
|
dcb_printf(dcb, "Statistics:\n");
|
||||||
dcb_printf(dcb, "\tNo. of data modifications: %d\n",
|
dcb_printf(dcb, "\tNo. of data modifications: %d\n", my_instance->stats.n_modified);
|
||||||
my_instance->stats.n_modified);
|
dcb_printf(dcb, "\tNo. of hints added based on count: %d\n", my_instance->stats.n_add_count);
|
||||||
dcb_printf(dcb, "\tNo. of hints added based on count: %d\n",
|
dcb_printf(dcb, "\tNo. of hints added based on time: %d\n", my_instance->stats.n_add_time);
|
||||||
my_instance->stats.n_add_count);
|
|
||||||
dcb_printf(dcb, "\tNo. of hints added based on time: %d\n",
|
|
||||||
my_instance->stats.n_add_time);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user