From fa14dceb4b53f6967925cb54973780dddcad45d7 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Thu, 20 Feb 2014 13:26:16 +0100 Subject: [PATCH 1/2] Traffic is routed to the master if no slaves available Traffic is routed to the master if no slaves available, this applies for router_options=slave in config file --- server/modules/routing/readconnroute.c | 34 ++++++++++++++++++++------ 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/server/modules/routing/readconnroute.c b/server/modules/routing/readconnroute.c index c4f982b41..a467ea2e6 100644 --- a/server/modules/routing/readconnroute.c +++ b/server/modules/routing/readconnroute.c @@ -283,6 +283,7 @@ ROUTER_INSTANCE *inst = (ROUTER_INSTANCE *)instance; ROUTER_CLIENT_SES *client_rses; BACKEND *candidate = NULL; int i; +int master_host = -1; LOGIF(LD, (skygw_log_write_flush( LOGFILE_DEBUG, @@ -336,6 +337,16 @@ int i; inst->bitmask))); } + /* + * If router_options=slave, get the running master + * It will be used if there arw no running slaves at all + */ + if (inst->bitvalue == SERVER_SLAVE) { + if (master_host < 0 && (SERVER_IS_MASTER(inst->servers[i]->server))) { + master_host = i; + } + } + if (inst->servers[i] && SERVER_IS_RUNNING(inst->servers[i]->server) && (inst->servers[i]->server->status & inst->bitmask) == @@ -368,15 +379,22 @@ int i; } } - /* no candidate server here, clean and return NULL */ + /* The are no candidate server here! + * With router_option=slave a master_host could be set, so route traffic there. + * Otherwise, just clean up and return NULL + */ if (!candidate) { - LOGIF(LE, (skygw_log_write_flush( - LOGFILE_ERROR, - "Error : Failed to create new routing session. " - "Couldn't find eligible candidate server. Freeing " - "allocated resources."))); - free(client_rses); - return NULL; + if (master_host >= 0) { + candidate = inst->servers[master_host]; + } else { + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Error : Failed to create new routing session. " + "Couldn't find eligible candidate server. Freeing " + "allocated resources."))); + free(client_rses); + return NULL; + } } /* From ec7d748275b581546306b916911d768ed5b530bc Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Thu, 20 Feb 2014 16:28:54 +0100 Subject: [PATCH 2/2] Code clean up and removed text typos in comments Code clean up and removed text typos in comments --- server/modules/routing/readconnroute.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/modules/routing/readconnroute.c b/server/modules/routing/readconnroute.c index a467ea2e6..6121a0502 100644 --- a/server/modules/routing/readconnroute.c +++ b/server/modules/routing/readconnroute.c @@ -61,8 +61,9 @@ * 31/07/2013 Massimiliano Pinto Added a check for candidate server, if NULL return * 12/08/2013 Mark Riddoch Log unsupported router options * 04/09/2013 Massimiliano Pinto Added client NULL check in clientReply - * 22/10/2013 Massimiliano Pinto errorReply called from backend, for client error replyi + * 22/10/2013 Massimiliano Pinto errorReply called from backend, for client error reply * or take different actions such as open a new backend connection + * 20/02/2014 Massimiliano Pinto If router_options=slave, route traffic to master if no slaves available * * @endverbatim */ @@ -339,7 +340,7 @@ int master_host = -1; /* * If router_options=slave, get the running master - * It will be used if there arw no running slaves at all + * It will be used if there are no running slaves at all */ if (inst->bitvalue == SERVER_SLAVE) { if (master_host < 0 && (SERVER_IS_MASTER(inst->servers[i]->server))) { @@ -379,7 +380,7 @@ int master_host = -1; } } - /* The are no candidate server here! + /* There is no candidate server here! * With router_option=slave a master_host could be set, so route traffic there. * Otherwise, just clean up and return NULL */ @@ -691,9 +692,8 @@ errorReply( int action) { DCB *client = NULL; - ROUTER_OBJECT *router = NULL; SESSION *session = backend_dcb->session; - client = backend_dcb->session->client; + client = session->client; ss_dassert(client != NULL); }