Added necessary headers and example functions and calls to gateway.c. Added necessary libs, and path definitions to Makefile so that query classifier-related headers and libs can be founded. Commented out mysql client -related stuff from Makefile to avoid conflicts.

This commit is contained in:
vraatikka 2013-06-28 12:24:53 +03:00
parent c0261fd627
commit a3edff47b0
2 changed files with 95 additions and 16 deletions

View File

@ -25,16 +25,28 @@
# 27/06/13 Vilho Raatikka Added logmanager-related libs and
# headers so that liblog_manager.so can
# be linked in.
# 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
include ../../build_gateway.inc
LOGPATH := $(ROOT_PATH)/log_manager
UTILSPATH := $(ROOT_PATH)/utils
QCLASSPATH := $(ROOT_PATH)/query_classifier
CC=cc
CFLAGS=-c -I/usr/include -I../include -I../inih -I/usr/include/mysql \
-I$(LOGPATH) -I$(UTILSPATH) -Wall -g
#CFLAGS=-c -I/usr/include -I../include -I../inih \
#-I/usr/include/mysql \
LDFLAGS=-rdynamic -L$(LOGPATH) -Wl,-rpath,$(LOGPATH) -Wl,-rpath,$(UTILSPATH)
CFLAGS=-c -I/usr/include -I../include -I../inih \
-I$(LOGPATH) -I$(UTILSPATH) -I$(QCLASSPATH) \
-I$(MARIADB_SRC_PATH)/include \
-Wall -g
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
SRCS= atomic.c buffer.c spinlock.c gateway.c gateway_mysql_protocol.c \
gw_utils.c utils.c dcb.c load_utils.c session.c service.c server.c \
@ -47,9 +59,11 @@ HDRS= ../include/atomic.h ../include/buffer.h ../include/dcb.h \
../include/users.h ../include/hashtable.h
OBJ=$(SRCS:.c=.o)
#LIBS=-L../inih/extra -linih -lssl -lstdc++ \
# -L/packages/mariadb-5.5.25/libmysql -lmysqlclient \
LIBS=-L../inih/extra -linih -lssl -lstdc++ \
-L/packages/mariadb-5.5.25/libmysql -lmysqlclient \
-lz -lm -lcrypto -ldl -pthread -llog_manager
-lz -lm -lcrypto -ldl -pthread -llog_manager -lquery_classifier -lmysqld
gateway: $(OBJ)
$(CC) $(LDFLAGS) $(OBJ) $(UTILSPATH)/skygw_utils.o $(LIBS) -o $@

View File

@ -30,6 +30,9 @@
* 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
* calls to log manager and to query classifier.
*
* @endverbatim
*/
@ -45,8 +48,10 @@
#include <poll.h>
#include <stdlib.h>
#include <mysql.h>
#include <skygw_utils.h>
#include <log_manager.h>
#include <query_classifier.h>
/* basic signal handling */
static void sighup_handler (int i) {
@ -169,21 +174,90 @@ int handle_event_errors_backend(DCB *dcb) {
return 0;
}
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;
/**
* 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);
return_with_handle:
mysql_close(mysql);
mysql_thread_end();
mysql_library_end();
return_without_server:
ss_dfprintf(stderr, "\n<< testmain\n");
fflush(stderr);
}
// main function
int
main(int argc, char **argv)
{
int daemon_mode = 1;
sigset_t sigset;
int daemon_mode = 1;
sigset_t sigset;
int n, n_threads;
void **threads;
char buf[1024], *home, *cnf_file = NULL;
int i;
i = atexit(skygw_logmanager_exit);
if (i != 0) {
fprintf(stderr, "Couldn't register exit function.\n");
}
vilhos_test_for_query_classifier();
if ((home = getenv("GATEWAY_HOME")) != NULL)
{
sprintf(buf, "%s/etc/gateway.cnf", home);
@ -210,15 +284,6 @@ int i;
if (cnf_file == NULL)
{
char* str = (char *)calloc(1,
sizeof("Query type is ")+
sizeof("QUERY_TYPE_SESSION_WRITE"));
sprintf(str,
"Query type is %s\n",
STRQTYPE(
skygw_query_classifier_get_type(
"SELECT user from mysql.user", 0)));
skygw_log_write(NULL, LOGFILE_MESSAGE,str);
skygw_log_write(
NULL,
LOGFILE_ERROR,