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

@ -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

View File

@ -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 <stdlib.h>
#include <mysql.h>
#include <skygw_utils.h>
#include <log_manager.h>
#include <query_classifier.h>
#if defined(SS_DEBUG)
# include <skygw_utils.h>
# include <log_manager.h>
# include <query_classifier.h>
#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);
}

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");
}