Merge branch 'master' into blr

This commit is contained in:
Mark Riddoch
2014-05-19 13:46:47 +01:00
parent 29d247319d
commit 9777e83a5a
50 changed files with 829 additions and 553 deletions

Binary file not shown.

View File

@ -29,6 +29,7 @@
* 06/02/14 Massimiliano Pinto Added support for enable/disable root user in services
* 14/02/14 Massimiliano Pinto Added enable_root_user in the service_params list
* 11/03/14 Massimiliano Pinto Added Unix socket support
* 11/05/14 Massimiliano Pinto Added version_string support to service
*
* @endverbatim
*/
@ -43,6 +44,7 @@
#include <monitor.h>
#include <skygw_utils.h>
#include <log_manager.h>
#include <mysql.h>
extern int lm_enabled_logfiles_bitmask;
@ -56,6 +58,7 @@ static void check_config_objects(CONFIG_CONTEXT *context);
static char *config_file = NULL;
static GATEWAY_CONF gateway;
char *version_string = NULL;
/**
* Config item handler for the ini file reader
@ -116,6 +119,21 @@ config_load(char *file)
CONFIG_CONTEXT config;
int rval;
MYSQL *conn;
conn = mysql_init(NULL);
if (conn) {
if (mysql_real_connect(conn, NULL, NULL, NULL, NULL, 0, NULL, 0)) {
char *ptr;
version_string = (char *)mysql_get_server_info(conn);
ptr = strstr(version_string, "-embedded");
if (ptr) {
*ptr = '\0';
}
}
mysql_close(conn);
}
global_defaults();
config.object = "";
@ -146,6 +164,11 @@ int rval;
if (!config_file)
return 0;
if (gateway.version_string)
free(gateway.version_string);
global_defaults();
config.object = "";
@ -202,7 +225,29 @@ int error_count = 0;
config_get_value(obj->parameters, "passwd");
char *enable_root_user =
config_get_value(obj->parameters, "enable_root_user");
char *version_string = config_get_value(obj->parameters, "version_string");
if (version_string) {
((SERVICE *)(obj->element))->version_string = strdup(version_string);
} else {
if (gateway.version_string)
((SERVICE *)(obj->element))->version_string = strdup(gateway.version_string);
}
if (obj->element == NULL) /*< if module load failed */
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Reading configuration "
"for router service '%s' failed. "
"Router %s is not loaded.",
obj->object,
obj->object)));
obj = obj->next;
continue; /*< process next obj */
}
if (enable_root_user)
serviceEnableRootUser(obj->element, atoi(enable_root_user));
@ -580,6 +625,10 @@ static void
global_defaults()
{
gateway.n_threads = 1;
if (version_string != NULL)
gateway.version_string = strdup(version_string);
else
gateway.version_string = NULL;
}
/**
@ -622,6 +671,7 @@ SERVER *server;
char *user;
char *auth;
char *enable_root_user;
char *version_string;
enable_root_user = config_get_value(obj->parameters, "enable_root_user");
@ -629,6 +679,15 @@ SERVER *server;
"user");
auth = config_get_value(obj->parameters,
"passwd");
version_string = config_get_value(obj->parameters, "version_string");
if (version_string) {
if (service->version_string)
free(service->version_string);
service->version_string = strdup(version_string);
}
if (user && auth) {
service_update(service, router,
user,
@ -861,6 +920,7 @@ static char *service_params[] =
"user",
"passwd",
"enable_root_user",
"version_string",
NULL
};

View File

@ -308,6 +308,13 @@ dcb_final_free(DCB *dcb)
free(dcb->data);
if (dcb->remote)
free(dcb->remote);
/* Consume dcb->delayq buffer */
if (dcb->delayq) {
GWBUF *queue = dcb->delayq;
while ((queue = gwbuf_consume(queue, GWBUF_LENGTH(queue))) != NULL);
}
bitmask_free(&dcb->memdata.bitmask);
simple_mutex_done(&dcb->dcb_read_lock);
simple_mutex_done(&dcb->dcb_write_lock);

View File

@ -53,6 +53,17 @@ static void register_module(const char *module,
void *modobj);
static void unregister_module(const char *module);
char* get_maxscale_home(void)
{
char* home = getenv("MAXSCALE_HOME");
if (home == NULL)
{
home = "/usr/local/skysql/MaxScale";
}
return home;
}
/**
* Load the dynamic library related to a gateway module. The routine
* will look for library files in the current directory,
@ -82,10 +93,10 @@ MODULES *mod;
sprintf(fname, "./lib%s.so", module);
if (access(fname, F_OK) == -1)
{
if ((home = getenv("MAXSCALE_HOME")) == NULL)
home = "/usr/local/skysql/MaxScale";
home = get_maxscale_home ();
sprintf(fname, "%s/modules/lib%s.so", home, module);
if (access(fname, F_OK) == -1)
if (access(fname, F_OK) == -1)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
@ -100,7 +111,7 @@ MODULES *mod;
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Unable to load library for module: "
"%s, %s.",
"%s\n\t\t\t %s.",
module,
dlerror())));
return NULL;
@ -111,7 +122,7 @@ MODULES *mod;
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Version interface not supported by "
"module: %s, %s.",
"module: %s\n\t\t\t %s.",
module,
dlerror())));
dlclose(dlhandle);
@ -134,7 +145,7 @@ MODULES *mod;
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Expected entry point interface missing "
"from module: %s, %s.",
"from module: %s\n\t\t\t %s.",
module,
dlerror())));
dlclose(dlhandle);

View File

@ -28,12 +28,15 @@
* 06/02/14 Massimiliano Pinto Added: serviceEnableRootUser routine
* 25/02/14 Massimiliano Pinto Added: service refresh limit feature
* 28/02/14 Massimiliano Pinto users_alloc moved from service_alloc to serviceStartPort (generic hashable for services)
* 07/05/14 Massimiliano Pinto Added: version_string initialized to NULL
*
* @endverbatim
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <session.h>
#include <service.h>
#include <server.h>
@ -70,11 +73,26 @@ SERVICE *service;
return NULL;
if ((service->router = load_module(router, MODULE_ROUTER)) == NULL)
{
char* home = get_maxscale_home();
char* ldpath = getenv("LD_LIBRARY_PATH");
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Unable to load %s module \"%s\".\n\t\t\t"
" Ensure that lib%s.so exists in one of the "
"following directories :\n\t\t\t "
"- %s/modules\n\t\t\t - %s",
MODULE_ROUTER,
router,
router,
home,
ldpath)));
free(service);
return NULL;
}
service->name = strdup(servname);
service->routerModule = strdup(router);
service->version_string = NULL;
memset(&service->stats, 0, sizeof(SERVICE_STATS));
service->ports = NULL;
service->stats.started = time(0);
@ -159,7 +177,7 @@ GWPROTOCOL *funcs;
if (port->listener->func.listen(port->listener, config_bind)) {
port->listener->session = session_alloc(service, port->listener);
if (port->listener->session != NULL) {
port->listener->session->state = SESSION_STATE_LISTENER;
listeners += 1;
@ -625,7 +643,7 @@ SERVICE *ptr;
/**
* Print all services to a DCB
*
* Designed to be called within a debugger session in order
* Designed to be called within a CLI command in order
* to display all active services within the gateway
*/
void
@ -637,30 +655,42 @@ SERVICE *ptr;
ptr = allServices;
while (ptr)
{
SERVER *server = ptr->databases;
dcb_printf(dcb, "Service %p\n", ptr);
dcb_printf(dcb, "\tService: %s\n", ptr->name);
dcb_printf(dcb, "\tRouter: %s (%p)\n", ptr->routerModule,
ptr->router);
if (ptr->router)
ptr->router->diagnostics(ptr->router_instance, dcb);
dcb_printf(dcb, "\tStarted: %s",
asctime(localtime(&ptr->stats.started)));
dcb_printf(dcb, "\tBackend databases\n");
while (server)
{
dcb_printf(dcb, "\t\t%s:%d Protocol: %s\n", server->name, server->port,
server->protocol);
server = server->nextdb;
}
dcb_printf(dcb, "\tUsers data: %p\n", ptr->users);
dcb_printf(dcb, "\tTotal connections: %d\n", ptr->stats.n_sessions);
dcb_printf(dcb, "\tCurrently connected: %d\n", ptr->stats.n_current);
dprintService(dcb, ptr);
ptr = ptr->next;
}
spinlock_release(&service_spin);
}
/**
* Print details of a single service.
*
* @param dcb DCB to print data to
* @param service The service to print
*/
dprintService(DCB *dcb, SERVICE *service)
{
SERVER *server = service->databases;
dcb_printf(dcb, "Service %p\n", service);
dcb_printf(dcb, "\tService: %s\n", service->name);
dcb_printf(dcb, "\tRouter: %s (%p)\n", service->routerModule,
service->router);
if (service->router)
service->router->diagnostics(service->router_instance, dcb);
dcb_printf(dcb, "\tStarted: %s",
asctime(localtime(&service->stats.started)));
dcb_printf(dcb, "\tBackend databases\n");
while (server)
{
dcb_printf(dcb, "\t\t%s:%d Protocol: %s\n", server->name, server->port,
server->protocol);
server = server->nextdb;
}
dcb_printf(dcb, "\tUsers data: %p\n", service->users);
dcb_printf(dcb, "\tTotal connections: %d\n", service->stats.n_sessions);
dcb_printf(dcb, "\tCurrently connected: %d\n", service->stats.n_current);
}
/**
* Update the definition of a service
*

View File

@ -5,6 +5,7 @@
include ../../../build_gateway.inc
include ../../../makefile.inc
include ../../../test.inc
CC=cc
TESTLOG := $(shell pwd)/testhash.log
@ -26,7 +27,7 @@ buildtests :
testhash.c ../hashtable.o ../atomic.o ../spinlock.o -o testhash
runtests:
@echo "" >> $(TESTLOG)
@echo "" > $(TESTLOG)
@echo "-------------------------------" >> $(TESTLOG)
@echo $(shell date) >> $(TESTLOG)
@echo "Test MaxScale core" >> $(TESTLOG)
@ -38,3 +39,4 @@ else
@echo "MaxScale core FAILED" >> $(TESTLOG)
endif
@echo "" >> $(TESTLOG)
@cat $(TESTLOG) >> $(TEST_MAXSCALE_LOG)