Removed references to libmysqlclient, and replaced them with those of libmysqld since, in addition to query parsing feature, libmysqld provides external connectivity.

This commit is contained in:
vraatikka
2013-07-09 09:40:25 +03:00
parent 5a731ee2eb
commit 02ad5fad57
4 changed files with 76 additions and 105 deletions

View File

@ -51,7 +51,7 @@ include ../../makefile.inc
LDFLAGS=-rdynamic -L$(LOGPATH) \ LDFLAGS=-rdynamic -L$(LOGPATH) \
-Wl,-rpath,$(LOGPATH) -Wl,-rpath,$(UTILSPATH) \ -Wl,-rpath,$(LOGPATH) -Wl,-rpath,$(UTILSPATH) \
-Wl,-rpath,$(MARIADB_SRC_PATH)/libmysql -Wl,-rpath,$(MARIADB_SRC_PATH)/libmysqld
SRCS= atomic.c buffer.c spinlock.c gateway.c gateway_mysql_protocol.c \ 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 \ gw_utils.c utils.c dcb.c load_utils.c session.c service.c server.c \
@ -65,9 +65,9 @@ HDRS= ../include/atomic.h ../include/buffer.h ../include/dcb.h \
OBJ=$(SRCS:.c=.o) OBJ=$(SRCS:.c=.o)
LIBS=-L../inih/extra -linih -lssl -lstdc++ \ LIBS=-L../inih/extra -linih -lssl -lstdc++ \
-L$(MARIADB_SRC_PATH)/libmysql \ -L$(MARIADB_SRC_PATH)/libmysqld \
-lmysqlclient \ -lz -lm -lcrypto -ldl -pthread -llog_manager \
-lz -lm -lcrypto -ldl -pthread -llog_manager -lmysqld
gateway: $(OBJ) gateway: $(OBJ)
$(CC) $(LDFLAGS) $(OBJ) $(UTILSPATH)/skygw_utils.o $(LIBS) -o $@ $(CC) $(LDFLAGS) $(OBJ) $(UTILSPATH)/skygw_utils.o $(LIBS) -o $@

View File

@ -45,24 +45,37 @@
int int
load_mysql_users(SERVICE *service) load_mysql_users(SERVICE *service)
{ {
MYSQL *con = NULL; MYSQL* con = NULL;
MYSQL_ROW row; MYSQL_ROW row;
MYSQL_RES *result = NULL; MYSQL_RES* result = NULL;
int num_fields = 0; int num_fields = 0;
char *service_user = NULL; char* service_user = NULL;
char *service_passwd = NULL; char* service_passwd = NULL;
int total_users = 0; int total_users = 0;
serviceGetUser(service, &service_user, &service_passwd); serviceGetUser(service, &service_user, &service_passwd);
/** multi-thread environment requires that thread init succeeds. */
if (mysql_thread_init()) {
skygw_log_write_flush(NULL, "ERROR : mysql_thread_init failed.\n");
return -1;
}
con = mysql_init(NULL); con = mysql_init(NULL);
if (con == NULL) { if (con == NULL) {
fprintf(stderr, "%s\n", mysql_error(con)); fprintf(stderr, "%s\n", mysql_error(con));
return -1; return -1;
} }
if (mysql_real_connect(con, service->databases->name, service_user, service_passwd, NULL, service->databases->port, NULL, 0) == NULL) { if (mysql_real_connect(
con,
service->databases->name,
service_user,
service_passwd,
NULL,
service->databases->port,
NULL, 0) == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con)); fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con); mysql_close(con);
return -1; return -1;
@ -94,9 +107,8 @@ load_mysql_users(SERVICE *service)
} }
mysql_free_result(result); mysql_free_result(result);
mysql_close(con); mysql_close(con);
mysql_thread_end();
return total_users; return total_users;
} }

View File

@ -49,11 +49,30 @@
#include <poll.h> #include <poll.h>
#include <stdlib.h> #include <stdlib.h>
#include <mysql.h>
#if defined(SS_DEBUG)
# include <skygw_utils.h> # include <skygw_utils.h>
# include <log_manager.h> # include <log_manager.h>
#endif /* SS_DEBUG */
static char* server_options[] = {
"SkySQL Gateway",
"--datadir=/tmp/",
"--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
};
/* basic signal handling */ /* basic signal handling */
static void sighup_handler (int i) { static void sighup_handler (int i) {
@ -179,11 +198,13 @@ sigset_t sigset;
int n, n_threads; int n, n_threads;
void **threads; void **threads;
char buf[1024], *home, *cnf_file = NULL; char buf[1024], *home, *cnf_file = NULL;
bool failp;
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
int i; int i;
i = atexit(skygw_logmanager_exit); i = atexit(skygw_logmanager_exit);
i = atexit(mysql_library_end);
if (i != 0) { if (i != 0) {
fprintf(stderr, "Couldn't register exit function.\n"); fprintf(stderr, "Couldn't register exit function.\n");
@ -214,30 +235,32 @@ char buf[1024], *home, *cnf_file = NULL;
} }
} }
if (cnf_file == NULL) if (cnf_file == NULL) {
{ skygw_log_write(
#if defined(SS_DEBUG)
skygw_log_write(
NULL, NULL,
LOGFILE_ERROR, LOGFILE_ERROR,
("Unable to find a gateway configuration file, either " "Fatal : Unable to find a gateway configuration file, either "
"install one in /etc/gateway.cnf, " "install one in /etc/gateway.cnf, $GATEWAY_HOME/etc/gateway.cnf "
"$GATEWAY_HOME/etc/gateway.cnf or use the -c " "or use the -c option. Exiting.\n");
"option.\n")); exit(1);
#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);
} }
failp = mysql_server_init(num_elements, server_options, server_groups);
if (failp) {
skygw_log_write_flush(
NULL,
LOGFILE_ERROR,
"Fatal : mysql_server_init failed. It is mandatory component needed "
"by router service and gateway can't continue without it. Exiting.\n");
exit(1);
}
if (!config_load(cnf_file)) if (!config_load(cnf_file))
{ {
#if defined(SS_DEBUG)
skygw_log_write(NULL, skygw_log_write(NULL,
LOGFILE_ERROR, LOGFILE_ERROR,
"Failed to load gateway configuration file %s\n"); "Failed to load gateway configuration file %s\n");
#endif
fprintf(stderr, "Failed to load gateway configuration file %s\n", cnf_file);
exit(1); exit(1);
} }

View File

@ -15,16 +15,14 @@
* *
* Copyright SkySQL Ab 2013 * Copyright SkySQL Ab 2013
*/ */
#include <dlfcn.h>
#include <stdio.h> #include <stdio.h>
#include <router.h> #include <router.h>
#if defined(SS_DEBUG)
# include <stdlib.h> # include <stdlib.h>
# include <mysql.h> # include <mysql.h>
# include <skygw_utils.h> # include <skygw_utils.h>
# include <log_manager.h> # include <log_manager.h>
# include <query_classifier.h> # include <query_classifier.h>
#endif /* SS_DEBUG */
/** /**
* @file router.c The entry points for the read/write query splitting * @file router.c The entry points for the read/write query splitting
@ -39,47 +37,13 @@ static char *version_str = "V1.0.0";
static ROUTER *createInstance(SERVICE *service, char **options); static ROUTER *createInstance(SERVICE *service, char **options);
static void *newSession(ROUTER *instance, SESSION *session); static void *newSession(ROUTER *instance, SESSION *session);
static void closeSession(ROUTER *instance, void *session); static void closeSession(ROUTER *instance, void *session);
static int routeQuery(ROUTER *instance, void *session, GWBUF *queue); static int routeQuery(ROUTER *instance, void *session, GWBUF *queue);
static void diagnostic(ROUTER *instance, DCB *dcb); static void diagnostic(ROUTER *instance, DCB *dcb);
static ROUTER_OBJECT MyObject = { createInstance, newSession, closeSession, routeQuery, diagnostic }; static ROUTER_OBJECT MyObject = { createInstance, newSession, closeSession, routeQuery, diagnostic };
/**
* mysql_library_* functions are redefined to refer to correct renamed versions
* of initialization functions. Renamed instances are loaded explicitly from
* libmysqld to avoid conflicts with those from libmysqlclient.
*/
#define mysql_library_init _mysql_server_init
#define mysql_library_end _mysql_server_end
/**
* smysql_server_init points to mysql_library_init alias mysql_server_init in
* libmysqld, and especially not to that included in libmysqlclient.
*/
int (*_mysql_server_init)(int, char **, char **);
void (*_mysql_server_end) (void);
void (*_mysql_close) (MYSQL*);
#if defined(SS_DEBUG) #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) static void vilhos_test_for_query_classifier(void)
{ {
bool failp; bool failp;
@ -88,17 +52,8 @@ static void vilhos_test_for_query_classifier(void)
/** /**
* Init libmysqld. * Init libmysqld.
*/ */
failp = mysql_library_init(num_elements, server_options, server_groups); ss_dassert(mysql_thread_safe());
mysql_thread_init();
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, char* str = (char *)calloc(1,
sizeof("Query type is ")+ sizeof("Query type is ")+
@ -116,9 +71,8 @@ static void vilhos_test_for_query_classifier(void)
*/ */
skygw_log_write(NULL, LOGFILE_MESSAGE,str); skygw_log_write(NULL, LOGFILE_MESSAGE,str);
_mysql_close(mysql); mysql_close(mysql);
_mysql_thread_end(); mysql_thread_end();
mysql_library_end();
return_without_server: return_without_server:
ss_dfprintf(stderr, "\n<< testmain\n"); ss_dfprintf(stderr, "\n<< testmain\n");
@ -126,24 +80,6 @@ return_without_server:
} }
#endif /* SS_DEBUG */ #endif /* SS_DEBUG */
static void rename_libfuncs(void)
{
void* dlhandle;
void* sym;
dlhandle = dlopen(
"/home/raatikka/src/bazaar/shared/maria/5.5/libmysqld/libmysqld.so.18",
RTLD_NOW|RTLD_LOCAL);
sym = dlsym(dlhandle, "mysql_server_init");
_mysql_server_init = (int (*)(int, char**, char**))sym;
sym = dlsym(dlhandle, "mysql_server_end");
_mysql_server_end = (void (*)(void))sym;
sym = dlsym(dlhandle, "mysql_close");
_mysql_close = (void (*)(MYSQL*))sym;
sym = dlsym(dlhandle, "mysql_thread_end");
_mysql_thread_end = (void (*)(MYSQL*))sym;
}
/** /**
* Implementation of the mandatory version entry point * Implementation of the mandatory version entry point
* *
@ -162,7 +98,7 @@ version()
void void
ModuleInit() ModuleInit()
{ {
rename_libfuncs(); // rename_libfuncs();
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
vilhos_test_for_query_classifier(); vilhos_test_for_query_classifier();
#endif #endif