Added example code to router.c ModuleInit and to its Makefile. Put example codes behind SS_DEBUG macros. SS_DEBUG compile flag is defined in Makefile if DEBUG is set in build_makefile.inc, or in command line - 'make DEBUG=Y ', for example.

This commit is contained in:
vraatikka
2013-06-28 15:27:02 +03:00
parent a3edff47b0
commit 3e8b19733e
4 changed files with 124 additions and 20 deletions

View File

@ -18,18 +18,32 @@
# Date Who Description
# 27/06/13 Mark Riddoch Initial framework put in place
include ../../../../build_gateway.inc
LOGPATH := $(ROOT_PATH)/log_manager
UTILSPATH := $(ROOT_PATH)/utils
QCLASSPATH := $(ROOT_PATH)/query_classifier
CC=cc
CFLAGS=-c -fPIC -I/usr/include -I../../include -I../../../include -Wall -g
LDFLAGS=-shared
CFLAGS=-c -fPIC -I/usr/include -I../../include -I../../../include \
-I$(LOGPATH) -I$(UTILSPATH) -I$(QCLASSPATH) \
-I$(MARIADB_SRC_PATH)/include -Wall -g
ifdef DEBUG
CFLAGS := $(CFLAGS) -DSS_DEBUG
endif
LDFLAGS=-shared -L$(LOGPATH) -L$(QCLASSPATH) -L$(MARIADB_SRC_PATH)/libmysqld \
-Wl,-rpath,$(LOGPATH) -Wl,-rpath,$(UTILSPATH) -Wl,-rpath,$(QCLASSPATH) \
-Wl,-rpath,$(MARIADB_SRC_PATH)/libmysqld
SRCS=router.c
OBJ=$(SRCS:.c=.o)
LIBS=-lssl
LIBS=-lssl -pthread -llog_manager -lquery_classifier -lmysqld
MODULES=libreadwritesplit.so
all: $(MODULES)
libreadwritesplit.so: $(OBJ)
$(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o $@
$(CC) $(LDFLAGS) $(OBJ) $(UTILSPATH)/skygw_utils.o $(LIBS) -o $@
.c.o:
$(CC) $(CFLAGS) $< -o $@

View File

@ -17,6 +17,13 @@
*/
#include <stdio.h>
#include <router.h>
#if defined(SS_DEBUG)
# include <stdlib.h>
# include <mysql.h>
# include <skygw_utils.h>
# include <log_manager.h>
# include <query_classifier.h>
#endif /* SS_DEBUG */
/**
* @file router.c The entry points for the read/write query splitting
@ -36,6 +43,72 @@ static void diagnostic(ROUTER *instance, DCB *dcb);
static ROUTER_OBJECT MyObject = { createInstance, newSession, closeSession, routeQuery, diagnostic };
#if defined(SS_DEBUG)
static char* server_options[] = {
"raatikka",
"--datadir=/home/raatikka/data/skygw_parse/",
"--skip-innodb",
"--default-storage-engine=myisam",
NULL
};
const int num_elements = (sizeof(server_options) / sizeof(char *)) - 1;
static char* server_groups[] = {
"embedded",
"server",
"server",
"server",
NULL
};
static void vilhos_test_for_query_classifier(void)
{
bool failp;
MYSQL* mysql = NULL;
/**
* Init libmysqld.
*/
failp = mysql_library_init(num_elements, server_options, server_groups);
if (failp) {
MYSQL* mysql = mysql_init(NULL);
ss_dassert(mysql != NULL);
fprintf(stderr,
"mysql_init failed, %d : %s\n",
mysql_errno(mysql),
mysql_error(mysql));
goto return_without_server;
}
char* str = (char *)calloc(1,
sizeof("Query type is ")+
sizeof("QUERY_TYPE_SESSION_WRITE"));
/**
* Call query classifier.
*/
sprintf(str,
"Query type is %s\n",
STRQTYPE(
skygw_query_classifier_get_type(
"SELECT user from mysql.user", 0)));
/**
* generate some log
*/
skygw_log_write(NULL, LOGFILE_MESSAGE,str);
mysql_close(mysql);
mysql_thread_end();
mysql_library_end();
return_without_server:
ss_dfprintf(stderr, "\n<< testmain\n");
fflush(stderr);
}
#endif /* SS_DEBUG */
/**
* Implementation of the mandatory version entry point
*
@ -54,6 +127,9 @@ version()
void
ModuleInit()
{
#if defined(SS_DEBUG)
vilhos_test_for_query_classifier();
#endif
fprintf(stderr, "Initialse read/writer splitting query router module.\n");
}