Fixed backend selection logic in get_dcb. If slave is not found write a warning to error log and fall through to master selection. If master has changed or previous master's state has changed, routing fails.

This commit is contained in:
VilhoRaatikka
2014-11-15 23:57:09 +02:00
parent 419fda5514
commit 4f136fa4d2
2 changed files with 43 additions and 58 deletions

View File

@ -1790,13 +1790,13 @@ void protocol_archive_srv_command(
} }
s1 = &p->protocol_command; s1 = &p->protocol_command;
#if defined(EXTRA_SS_DEBUG)
LOGIF(LT, (skygw_log_write( LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE, LOGFILE_TRACE,
"Move command %s from fd %d to command history.", "Move command %s from fd %d to command history.",
STRPACKETTYPE(s1->scom_cmd), STRPACKETTYPE(s1->scom_cmd),
p->owner_dcb->fd))); p->owner_dcb->fd)));
#endif
/** Copy to history list */ /** Copy to history list */
if ((h1 = p->protocol_cmd_history) == NULL) if ((h1 = p->protocol_cmd_history) == NULL)
{ {
@ -1874,7 +1874,7 @@ void protocol_add_srv_command(
STRPACKETTYPE(cmd), STRPACKETTYPE(cmd),
p->owner_dcb->fd))); p->owner_dcb->fd)));
#if defined(SS_DEBUG) #if defined(EXTRA_SS_DEBUG)
c = &p->protocol_command; c = &p->protocol_command;
while (c != NULL && c->scom_cmd != MYSQL_COM_UNDEFINED) while (c != NULL && c->scom_cmd != MYSQL_COM_UNDEFINED)

View File

@ -1178,37 +1178,14 @@ static bool get_dcb(
"for the service %s.", "for the service %s.",
rses->router->service->name))); rses->router->service->name)));
} }
btype = BE_MASTER;
if (BREF_IS_IN_USE(master_bref))
{
*p_dcb = master_bref->bref_dcb;
succp = true;
ss_dassert(master_bref->bref_dcb->state != DCB_STATE_ZOMBIE);
ss_dassert(
(master_bref->bref_backend &&
(master_bref->bref_backend->backend_server ==
master_bref->bref_backend->backend_server)) &&
smallest_nconn == -1);
LOGIF(LE, (skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Using master %s:%d instead.", "Warning : Using master %s:%d.",
master_bref->bref_backend->backend_server->name, master_bref->bref_backend->backend_server->name,
master_bref->bref_backend->backend_server->port))); master_bref->bref_backend->backend_server->port)));
btype = BE_MASTER;
} }
else /** Found slave, correct the status flag */
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : No master is availabe either. "
"Unable to find backend server for "
"routing.")));
}
}
else if (rses->router->available_slaves == false) else if (rses->router->available_slaves == false)
{ {
rses->router->available_slaves = true; rses->router->available_slaves = true;
@ -1217,24 +1194,30 @@ static bool get_dcb(
"At least one slave has become available for " "At least one slave has become available for "
"the service %s.", "the service %s.",
rses->router->service->name))); rses->router->service->name)));
goto return_succp;
} }
} }
if (btype == BE_MASTER) if (btype == BE_MASTER)
{ {
for (i=0; i<rses->rses_nbackends; i++) if (BREF_IS_IN_USE(master_bref) &&
SERVER_IS_MASTER(master_bref->bref_backend->backend_server))
{ {
BACKEND* b = backend_ref[i].bref_backend; *p_dcb = master_bref->bref_dcb;
if (BREF_IS_IN_USE((&backend_ref[i])) &&
(master_bref->bref_backend &&
(b->backend_server ==
master_bref->bref_backend->backend_server)))
{
*p_dcb = backend_ref[i].bref_dcb;
succp = true; succp = true;
goto return_succp; /** if bref is in use DCB should not be closed */
ss_dassert(master_bref->bref_dcb->state != DCB_STATE_ZOMBIE);
} }
else
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Server at %s:%d should be master but "
"is %s instead and can't be chosen to master.",
master_bref->bref_backend->backend_server->name,
master_bref->bref_backend->backend_server->port,
STRSRVSTATUS(master_bref->bref_backend->backend_server))));
succp = false;
} }
} }
@ -4138,8 +4121,9 @@ static void handleError (
"Session will be closed."))); "Session will be closed.")));
*succp = false; *succp = false;
rses_end_locked_router_action(rses);
} }
else
{
/** /**
* This is called in hope of getting replacement for * This is called in hope of getting replacement for
* failed slave(s). * failed slave(s).
@ -4148,6 +4132,7 @@ static void handleError (
rses, rses,
backend_dcb, backend_dcb,
errmsgbuf); errmsgbuf);
}
rses_end_locked_router_action(rses); rses_end_locked_router_action(rses);
break; break;
} }
@ -4716,7 +4701,7 @@ static backend_ref_t* get_root_master_bref(
LOGIF(LE, (skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Could not find master among the backend " "Error : Could not find master among the backend "
"servers. Previous master state : %s", "servers. Previous master's state : %s",
STRSRVSTATUS(BREFSRV(rses->rses_master_ref))))); STRSRVSTATUS(BREFSRV(rses->rses_master_ref)))));
} }
return candidate_bref; return candidate_bref;