Merge "Traffic is routed to the master if no slaves available". Fix bug-129
This commit is contained in:
@ -61,8 +61,9 @@
|
|||||||
* 31/07/2013 Massimiliano Pinto Added a check for candidate server, if NULL return
|
* 31/07/2013 Massimiliano Pinto Added a check for candidate server, if NULL return
|
||||||
* 12/08/2013 Mark Riddoch Log unsupported router options
|
* 12/08/2013 Mark Riddoch Log unsupported router options
|
||||||
* 04/09/2013 Massimiliano Pinto Added client NULL check in clientReply
|
* 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
|
* 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
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
@ -283,6 +284,7 @@ ROUTER_INSTANCE *inst = (ROUTER_INSTANCE *)instance;
|
|||||||
ROUTER_CLIENT_SES *client_rses;
|
ROUTER_CLIENT_SES *client_rses;
|
||||||
BACKEND *candidate = NULL;
|
BACKEND *candidate = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
int master_host = -1;
|
||||||
|
|
||||||
LOGIF(LD, (skygw_log_write_flush(
|
LOGIF(LD, (skygw_log_write_flush(
|
||||||
LOGFILE_DEBUG,
|
LOGFILE_DEBUG,
|
||||||
@ -336,6 +338,16 @@ int i;
|
|||||||
inst->bitmask)));
|
inst->bitmask)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If router_options=slave, get the running master
|
||||||
|
* 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))) {
|
||||||
|
master_host = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (inst->servers[i] &&
|
if (inst->servers[i] &&
|
||||||
SERVER_IS_RUNNING(inst->servers[i]->server) &&
|
SERVER_IS_RUNNING(inst->servers[i]->server) &&
|
||||||
(inst->servers[i]->server->status & inst->bitmask) ==
|
(inst->servers[i]->server->status & inst->bitmask) ==
|
||||||
@ -368,8 +380,14 @@ int i;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no candidate server here, clean and return NULL */
|
/* 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
|
||||||
|
*/
|
||||||
if (!candidate) {
|
if (!candidate) {
|
||||||
|
if (master_host >= 0) {
|
||||||
|
candidate = inst->servers[master_host];
|
||||||
|
} else {
|
||||||
LOGIF(LE, (skygw_log_write_flush(
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
LOGFILE_ERROR,
|
LOGFILE_ERROR,
|
||||||
"Error : Failed to create new routing session. "
|
"Error : Failed to create new routing session. "
|
||||||
@ -378,6 +396,7 @@ int i;
|
|||||||
free(client_rses);
|
free(client_rses);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We now have the server with the least connections.
|
* We now have the server with the least connections.
|
||||||
@ -673,9 +692,8 @@ errorReply(
|
|||||||
int action)
|
int action)
|
||||||
{
|
{
|
||||||
DCB *client = NULL;
|
DCB *client = NULL;
|
||||||
ROUTER_OBJECT *router = NULL;
|
|
||||||
SESSION *session = backend_dcb->session;
|
SESSION *session = backend_dcb->session;
|
||||||
client = backend_dcb->session->client;
|
client = session->client;
|
||||||
|
|
||||||
ss_dassert(client != NULL);
|
ss_dassert(client != NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user