readwritesplit.c:routeQuery if target is master but it is found out when get_dcb returns that master DCB has changed, routeQuery fails and logs to trace that master changed.

This commit is contained in:
VilhoRaatikka 2014-10-20 10:40:32 +03:00
parent 319dd4b3e6
commit ebd92c8741

View File

@ -849,7 +849,7 @@ static void* newSession(
free(client_rses);
client_rses = NULL;
goto return_rses;
}
}
/** Copy backend pointers to router session. */
client_rses->rses_master_ref = master_ref;
/* assert with master_host */
@ -1065,9 +1065,12 @@ static bool get_dcb(
/** get root master from available servers */
master_bref = get_root_master_bref(rses);
#if defined(SS_DEBUG)
master_host = get_root_master(backend_ref, rses->rses_nbackends);
ss_dassert(master_bref->bref_backend == master_host);
if (master_bref->bref_backend != master_host)
{
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE,
"Master has changed.")));
}
#endif
if (name != NULL) /*< Choose backend by name from a hint */
{
@ -1714,6 +1717,7 @@ static int routeQuery(
querybuf = gwbuf_make_contiguous(querybuf);
}
/** Read stored master DCB pointer */
master_dcb = router_cli_ses->rses_master_ref->bref_dcb;
CHK_DCB(master_dcb);
@ -2000,30 +2004,43 @@ static int routeQuery(
if (!succp && TARGET_IS_MASTER(route_target))
{
if (master_dcb == NULL)
DCB* curr_master_dcb;
succp = get_dcb(&curr_master_dcb,
router_cli_ses,
BE_MASTER,
NULL,
MAX_RLAG_UNDEFINED);
if (succp && (master_dcb == NULL || master_dcb == curr_master_dcb))
{
succp = get_dcb(&master_dcb,
router_cli_ses,
BE_MASTER,
NULL,
MAX_RLAG_UNDEFINED);
if (!succp)
atomic_add(&inst->stats.n_master, 1);
target_dcb = master_dcb;
}
else
{
if (succp && master_dcb != curr_master_dcb)
{
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE,
"Was supposed to "
"route to master "
"but couldn't find "
"master in a "
"suitable state "
"failed.")));
"but master has "
"changed.")));
}
else
{
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE,
"Was supposed to "
"route to master "
"but couldn't find "
"master in a "
"suitable state "
"failed.")));
}
succp = false;
ret = 0;
}
else
{
succp = true;
}
atomic_add(&inst->stats.n_master, 1);
target_dcb = master_dcb;
}
if (succp) /*< Have DCB of the target backend */
@ -2595,7 +2612,7 @@ static bool select_connect_backend_servers(
}
/* get the root Master */
master_host = get_root_master(backend_ref, router_nservers);
master_host = get_root_master(backend_ref, router_nservers);
/** Master is already chosen and connected. This is slave failure case */
if (*p_master_ref != NULL &&
@ -2610,11 +2627,16 @@ static bool select_connect_backend_servers(
master_found = true;
master_connected = true;
/* assert with master_host */
/**
* Ensure that *p_master_ref and master_host point to same backend
* and it has a master role.
*/
ss_dassert(master_host &&
((*p_master_ref)->bref_backend->backend_server ==
master_host->backend_server) &&
SERVER_MASTER);
(master_host->backend_server->status &
(SERVER_MASTER|SERVER_MAINT)) == SERVER_MASTER);
}
/** New session or master failure case */
else