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