diff --git a/core/Makefile b/core/Makefile index d08da82d9..cfd40d162 100644 --- a/core/Makefile +++ b/core/Makefile @@ -28,7 +28,9 @@ # 28/06/13 Vilho Raatikka Added query classifier-related libs and # commented out mysql client headers and # lib to avoid conflicts. MARIADB_SRC_PATH -# is set in build_gateway.inc +# is set in build_gateway.inc. Examples +# are behind SS_DEBUG macros. + include ../../build_gateway.inc LOGPATH := $(ROOT_PATH)/log_manager @@ -44,6 +46,10 @@ CFLAGS=-c -I/usr/include -I../include -I../inih \ -I$(MARIADB_SRC_PATH)/include \ -Wall -g +ifdef DEBUG + CFLAGS := $(CFLAGS) -DSS_DEBUG +endif + LDFLAGS=-rdynamic -L$(LOGPATH) -L$(QCLASSPATH) -L$(MARIADB_SRC_PATH)/libmysqld \ -Wl,-rpath,$(LOGPATH) -Wl,-rpath,$(UTILSPATH) -Wl,-rpath,$(QCLASSPATH) \ -Wl,-rpath,$(MARIADB_SRC_PATH)/libmysqld diff --git a/core/gateway.c b/core/gateway.c index 8d27c5b74..d3de29a7b 100644 --- a/core/gateway.c +++ b/core/gateway.c @@ -30,9 +30,10 @@ * and bind addr is 0.0.0.0 * 19/06/13 Mark Riddoch Extract the epoll functionality * 21/06/13 Mark Riddoch Added initial config support - * 26/06/13 - * 27/06/13 Vilho Raatikka Added necessary headers, example functions and + * 27/06/13 + * 28/06/13 Vilho Raatikka Added necessary headers, example functions and * calls to log manager and to query classifier. + * Put example code behind SS_DEBUG macros. * * @endverbatim */ @@ -49,9 +50,12 @@ #include #include -#include -#include -#include + +#if defined(SS_DEBUG) +# include +# include +# include +#endif /* SS_DEBUG */ /* basic signal handling */ static void sighup_handler (int i) { @@ -173,7 +177,7 @@ int handle_event_errors_backend(DCB *dcb) { return 0; } - +#if defined(SS_DEBUG) static char* server_options[] = { "raatikka", "--datadir=/home/raatikka/data/skygw_parse/", @@ -238,26 +242,27 @@ return_without_server: ss_dfprintf(stderr, "\n<< testmain\n"); fflush(stderr); } +#endif /* SS_DEBUG */ // main function int main(int argc, char **argv) { - int daemon_mode = 1; - sigset_t sigset; -int n, n_threads; -void **threads; -char buf[1024], *home, *cnf_file = NULL; -int i; + int daemon_mode = 1; + sigset_t sigset; + int n, n_threads; + void **threads; + char buf[1024], *home, *cnf_file = NULL; + int i; +#if defined(SS_DEBUG) i = atexit(skygw_logmanager_exit); if (i != 0) { fprintf(stderr, "Couldn't register exit function.\n"); } - vilhos_test_for_query_classifier(); - +#endif if ((home = getenv("GATEWAY_HOME")) != NULL) { sprintf(buf, "%s/etc/gateway.cnf", home); @@ -284,6 +289,7 @@ int i; if (cnf_file == NULL) { +#if defined(SS_DEBUG) skygw_log_write( NULL, LOGFILE_ERROR, @@ -291,7 +297,7 @@ int i; "install one in /etc/gateway.cnf, " "$GATEWAY_HOME/etc/gateway.cnf or use the -c " "option.\n")); - +#endif fprintf(stderr, "Unable to find a gateway configuration file, either install one in\n"); fprintf(stderr, "/etc/gateway.cnf, $GATEWAY_HOME/etc/gateway.cnf or use the -c option.\n"); exit(1); @@ -299,9 +305,11 @@ int i; if (!config_load(cnf_file)) { +#if defined(SS_DEBUG) skygw_log_write(NULL, LOGFILE_ERROR, "Failed to load gateway configuration file %s\n"); +#endif fprintf(stderr, "Failed to load gateway configuration file %s\n", cnf_file); exit(1); } diff --git a/modules/routing/readwritesplit/Makefile b/modules/routing/readwritesplit/Makefile index a5d6601d7..8152eb5e7 100644 --- a/modules/routing/readwritesplit/Makefile +++ b/modules/routing/readwritesplit/Makefile @@ -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 $@ diff --git a/modules/routing/readwritesplit/router.c b/modules/routing/readwritesplit/router.c index 0ab2c79b0..75a0dc4b0 100644 --- a/modules/routing/readwritesplit/router.c +++ b/modules/routing/readwritesplit/router.c @@ -17,6 +17,13 @@ */ #include #include +#if defined(SS_DEBUG) +# include +# include +# include +# include +# include +#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"); }