Check if master reference is disabled

If a Backend is closed, the associated DCB is no longer valid. This needs
to be taken into account when the stored master reference is used.
This commit is contained in:
Markus Mäkelä
2018-01-08 10:55:32 +02:00
parent 336a508cda
commit e5d9ca4af8
3 changed files with 7 additions and 6 deletions

View File

@ -1294,7 +1294,8 @@ static void handleError(MXS_ROUTER *instance,
{ {
case ERRACT_NEW_CONNECTION: case ERRACT_NEW_CONNECTION:
{ {
if (rses->current_master && rses->current_master->dcb() == problem_dcb) if (rses->current_master && rses->current_master->in_use() &&
rses->current_master->dcb() == problem_dcb)
{ {
/** The connection to the master has failed */ /** The connection to the master has failed */
SERVER *srv = rses->current_master->server(); SERVER *srv = rses->current_master->server();

View File

@ -778,7 +778,7 @@ handle_multi_temp_and_load(RWSplitSession *rses, GWBUF *querybuf,
(check_for_multi_stmt(querybuf, rses->client_dcb->protocol, packet_type) || (check_for_multi_stmt(querybuf, rses->client_dcb->protocol, packet_type) ||
check_for_sp_call(querybuf, packet_type))) check_for_sp_call(querybuf, packet_type)))
{ {
if (rses->current_master) if (rses->current_master && rses->current_master->in_use())
{ {
rses->target_node = rses->current_master; rses->target_node = rses->current_master;
MXS_INFO("Multi-statement query or stored procedure call, routing " MXS_INFO("Multi-statement query or stored procedure call, routing "
@ -989,7 +989,7 @@ SRWBackend handle_slave_is_target(RWSplit *inst, RWSplitSession *rses,
static void log_master_routing_failure(RWSplitSession *rses, bool found, static void log_master_routing_failure(RWSplitSession *rses, bool found,
SRWBackend& old_master, SRWBackend& curr_master) SRWBackend& old_master, SRWBackend& curr_master)
{ {
ss_dassert(!old_master || old_master->dcb()->dcb_role == DCB_ROLE_BACKEND_HANDLER); ss_dassert(!old_master || !old_master->in_use() || old_master->dcb()->dcb_role == DCB_ROLE_BACKEND_HANDLER);
ss_dassert(!curr_master || curr_master->dcb()->dcb_role == DCB_ROLE_BACKEND_HANDLER); ss_dassert(!curr_master || curr_master->dcb()->dcb_role == DCB_ROLE_BACKEND_HANDLER);
char errmsg[MAX_SERVER_ADDRESS_LEN * 2 + 100]; // Extra space for error message char errmsg[MAX_SERVER_ADDRESS_LEN * 2 + 100]; // Extra space for error message
@ -997,7 +997,7 @@ static void log_master_routing_failure(RWSplitSession *rses, bool found,
{ {
sprintf(errmsg, "Could not find a valid master connection"); sprintf(errmsg, "Could not find a valid master connection");
} }
else if (old_master && curr_master) else if (old_master && curr_master && old_master->in_use())
{ {
/** We found a master but it's not the same connection */ /** We found a master but it's not the same connection */
ss_dassert(old_master != curr_master); ss_dassert(old_master != curr_master);
@ -1016,7 +1016,7 @@ static void log_master_routing_failure(RWSplitSession *rses, bool found,
curr_master->name()); curr_master->name());
} }
} }
else if (old_master) else if (old_master && old_master->in_use())
{ {
/** We have an original master connection but we couldn't find it */ /** We have an original master connection but we couldn't find it */
sprintf(errmsg, "The connection to master server '%s' is not available", sprintf(errmsg, "The connection to master server '%s' is not available",

View File

@ -50,7 +50,7 @@ void process_sescmd_response(RWSplitSession* rses, SRWBackend& backend,
if (rses->recv_sescmd < rses->sent_sescmd && if (rses->recv_sescmd < rses->sent_sescmd &&
id == rses->recv_sescmd + 1 && id == rses->recv_sescmd + 1 &&
(!rses->current_master || // Session doesn't have a master (!rses->current_master || !rses->current_master->in_use() || // Session doesn't have a master
rses->current_master == backend)) // This is the master's response rses->current_master == backend)) // This is the master's response
{ {
/** First reply to this session command, route it to the client */ /** First reply to this session command, route it to the client */