From 75e7de182fc7507ed4731b6701385f2972091812 Mon Sep 17 00:00:00 2001 From: Massimiliano Pinto Date: Wed, 7 Aug 2013 09:39:29 +0200 Subject: [PATCH 1/6] fprintf debug for added backend connection is protected by if (backend->fd > 0) --- server/modules/protocol/mysql_backend.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/modules/protocol/mysql_backend.c b/server/modules/protocol/mysql_backend.c index e84b9c304..3b0d79def 100644 --- a/server/modules/protocol/mysql_backend.c +++ b/server/modules/protocol/mysql_backend.c @@ -368,7 +368,9 @@ static int gw_create_backend_connection(DCB *backend, SERVER *server, SESSION *s break; } - fprintf(stderr, ">>> Backend [%s:%i] added [%i], in the client session [%i]\n", server->name, server->port, backend->fd, session->client->fd); + if (backend->fd > 0) { + fprintf(stderr, ">>> Backend [%s:%i] added [%i], in the client session [%i]\n", server->name, server->port, backend->fd, session->client->fd); + } backend->state = DCB_STATE_POLLING; From 719c8168e81bab28a1d8b7f85d8dce5253bfa5c2 Mon Sep 17 00:00:00 2001 From: ec2-user Date: Wed, 7 Aug 2013 16:50:08 +0200 Subject: [PATCH 2/6] fix .spec to work with Jenkins --- maxscale.spec | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/maxscale.spec b/maxscale.spec index b5000ea7b..675b865e6 100644 --- a/maxscale.spec +++ b/maxscale.spec @@ -1,7 +1,7 @@ %define _topdir %(echo $PWD)/ %define name maxscale -%define release ##RELEASE_TAG## -%define version ##VERSION_TAG## +%define release 1 +%define version . %define buildroot %{_topdir}/%{name}-%{version}-%{release}root %define install_path /usr/local/sbin/ @@ -18,16 +18,17 @@ Group: Development/Tools BuildRequires: gcc gcc-c++ ncurses-devel bison glibc-devel cmake libgcc perl make libtool openssl-devel %description -galera-remote-exec +MaxScale %prep %setup -q %build -make ROOT_PATH=`pwd` MARIADB_SRC_PATH=/home/skysql/mariadb-5.5.32 depend -make ROOT_PATH=`pwd` MARIADB_SRC_PATH=/home/skysql/mariadb-5.5.32 -make DEST=`pwd`/binaries ROOT_PATH=`pwd` MARIADB_SRC_PATH=/home/skysql/mariadb-5.5.32 install +MARIADB_SRC_PATH=/home/ec2-user/.jenkins/jobs/MariaDB_for_MaxScale/workspace +make ROOT_PATH=`pwd` MARIADB_SRC_PATH=$MARIADB_SRC_PATH depend +make ROOT_PATH=`pwd` MARIADB_SRC_PATH=$MARIADB_SRC_PATH +make DEST=`pwd`/binaries ROOT_PATH=`pwd` MARIADB_SRC_PATH=$MARIADB_SRC_PATH install %post From dcc72f017e26752ed0c1f69beedfc982574dd901 Mon Sep 17 00:00:00 2001 From: ec2-user Date: Wed, 7 Aug 2013 16:51:09 +0200 Subject: [PATCH 3/6] use ##VERSION_TAG## in .spec --- maxscale.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maxscale.spec b/maxscale.spec index 675b865e6..b1a42d1ff 100644 --- a/maxscale.spec +++ b/maxscale.spec @@ -1,7 +1,7 @@ %define _topdir %(echo $PWD)/ %define name maxscale -%define release 1 -%define version . +%define release ##RELEASE_TAG## +%define version ##VERSION_TAG## %define buildroot %{_topdir}/%{name}-%{version}-%{release}root %define install_path /usr/local/sbin/ From a4475832145be7623ce78a41c11aa120c99e64ce Mon Sep 17 00:00:00 2001 From: vraatikka Date: Thu, 8 Aug 2013 00:06:38 +0300 Subject: [PATCH 4/6] If MaxScale.cnf exists, install takes a backup of it before overwriting it with version from maxscale/server. --- server/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Makefile b/server/Makefile index 4bb91be7b..8a483162a 100644 --- a/server/Makefile +++ b/server/Makefile @@ -58,7 +58,7 @@ install: @mkdir -p $(DEST)/MaxScale/etc @mkdir -p $(DEST)/lib @mkdir -p $(DEST)/Documentation - install MaxScale.cnf $(DEST)/MaxScale/etc + install -b MaxScale.cnf $(DEST)/MaxScale/etc install ../Documentation/*.pdf $(DEST)/Documentation (cd core; make DEST=$(DEST) install) (cd modules/routing; make DEST=$(DEST) install) From f1498e44031609c4ec2be6bb27a7c4ac37d2c2ac Mon Sep 17 00:00:00 2001 From: vraatikka Date: Thu, 8 Aug 2013 00:08:45 +0300 Subject: [PATCH 5/6] Added log flusher thread, which flushes once per second. --- server/core/gateway.c | 45 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/server/core/gateway.c b/server/core/gateway.c index 08ebd32cd..c81aa63b0 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -84,6 +84,15 @@ static char* server_groups[] = { /* The data directory we created for this gateway instance */ static char datadir[1024] = ""; +/** + * exit flag for log flusher. + */ +static bool do_exit = FALSE; + +static void log_flush_shutdown(void); +static void log_flush_cb(void* arg); + + /** * Handler for SIGHUP signal. Reload the configuration for the * gateway. @@ -234,6 +243,8 @@ int i, n, n_threads, n_services; void **threads; char mysql_home[1024], buf[1024], *home, *cnf_file = NULL; char ddopt[1024]; +void* log_flush_thr = NULL; +ssize_t log_flush_timeout_ms = 0; int l; @@ -424,9 +435,13 @@ char ddopt[1024]; * Start the services that were created above */ n_services = serviceStartAll(); - skygw_log_write_flush(LOGFILE_MESSAGE, - "Start modules completed"); + skygw_log_write(LOGFILE_MESSAGE, "Started modules succesfully."); + /** + * Start periodic log flusher thread. + */ + log_flush_timeout_ms = 1000; + log_flush_thr = thread_start(log_flush_cb, (void *)&log_flush_timeout_ms); /* * Start the polling threads, note this is one less than is * configured as the main thread will also poll. @@ -439,6 +454,11 @@ char ddopt[1024]; for (n = 0; n < n_threads - 1; n++) thread_wait(threads[n]); + /** + * Wait the timer thread. + */ + thread_wait(log_flush_thr); + /* Stop all the monitors */ monitorStopAll(); @@ -457,4 +477,25 @@ void shutdown_gateway() { poll_shutdown(); + log_flush_shutdown(); +} + +static void log_flush_shutdown(void) +{ + do_exit = TRUE; +} + +static void log_flush_cb( + void* arg) +{ + ssize_t timeout_ms = *(ssize_t *)arg; + + skygw_log_write(LOGFILE_MESSAGE, "Started MaxScale log flusher."); + while (!do_exit) { + skygw_log_flush(LOGFILE_ERROR); + skygw_log_flush(LOGFILE_MESSAGE); + skygw_log_flush(LOGFILE_TRACE); + usleep(timeout_ms*1000); + } + skygw_log_write(LOGFILE_MESSAGE, "Finished MaxScale log flusher."); } From d94153c29f1ad6bd2c40e85db91f3fe6cdbffe16 Mon Sep 17 00:00:00 2001 From: vraatikka Date: Thu, 8 Aug 2013 00:10:33 +0300 Subject: [PATCH 6/6] If maxscale is compiled with DEBUG=Y readconnrouter module writes slave selection info to trace log. Example: SkySQL MaxScale Thu Aug 8 00:01:08 2013 ------------------------------------------ 2013 08/08 00:01:17 Selected server in port 3003 to as candidate. Connections : 0 2013 08/08 00:01:17 Examine server in port 3002 with 0 connections. Status is 5, inst->bitvalue is 6 2013 08/08 00:01:17 Examine server in port 3001 with 0 connections. Status is 5, inst->bitvalue is 6 2013 08/08 00:01:17 Examine server in port 3000 with 0 connections. Status is 3, inst->bitvalue is 6 2013 08/08 00:01:17 Final selection is server in port 3003. Connections : 1 2013 08/08 00:01:22 Selected server in port 3003 to as candidate. Connections : 1 2013 08/08 00:01:22 Examine server in port 3002 with 0 connections. Status is 5, inst->bitvalue is 6 2013 08/08 00:01:22 Examine server in port 3001 with 0 connections. Status is 5, inst->bitvalue is 6 2013 08/08 00:01:22 Examine server in port 3000 with 0 connections. Status is 3, inst->bitvalue is 6 2013 08/08 00:01:22 Final selection is server in port 3002. Connections : 1 --- server/modules/routing/readconnroute.c | 39 +++++++++++++++++++++----- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/server/modules/routing/readconnroute.c b/server/modules/routing/readconnroute.c index 155ec7504..1b6e0f6bb 100644 --- a/server/modules/routing/readconnroute.c +++ b/server/modules/routing/readconnroute.c @@ -263,6 +263,14 @@ int i; && (inst->servers[i]->server->status & inst->bitmask) == inst->bitvalue) { candidate = inst->servers[i]; +#if defined(SS_DEBUG) + skygw_log_write( + LOGFILE_TRACE, + "Selected server in port %d to as candidate. " + "Connections : %d\n", + candidate->server->port, + candidate->count); +#endif /* SS_DEBUG */ break; } } @@ -281,22 +289,32 @@ int i; */ for (i = 1; inst->servers[i]; i++) { +#if defined(SS_DEBUG) + skygw_log_write( + LOGFILE_TRACE, + "Examine server in port %d with %d connections. Status is %d, " + "inst->bitvalue is %d", + inst->servers[i]->server->port, + inst->servers[i]->count, + inst->servers[i]->server->status, + inst->bitmask); +#endif /* SS_DEBUG */ if (inst->servers[i] && SERVER_IS_RUNNING(inst->servers[i]->server) && (inst->servers[i]->server->status & inst->bitmask) == inst->bitvalue) - { + { if (inst->servers[i]->count < candidate->count) { - candidate = inst->servers[i]; + candidate = inst->servers[i]; } else if (inst->servers[i]->count == candidate->count && inst->servers[i]->server->stats.n_connections < candidate->server->stats.n_connections) { - candidate = inst->servers[i]; - } + candidate = inst->servers[i]; + } } } - + /* no candidate server here, clean and return NULL */ if (!candidate) { free(client); @@ -310,8 +328,15 @@ int i; atomic_add(&candidate->count, 1); client->backend = candidate; - - /* +#if defined(SS_DEBUG) + skygw_log_write( + LOGFILE_TRACE, + "Final selection is server in port %d. " + "Connections : %d\n", + candidate->server->port, + candidate->count); +#endif /* SS_DEBUG */ + /* * Open a backend connection, putting the DCB for this * connection in the client->dcb */