Clean up route target resolution function
Cleaned up the function that resolves to which type of a server the query should go.
This commit is contained in:
@ -545,7 +545,7 @@ SRWBackend get_target_backend(RWSplitSession *rses, backend_type_t btype,
|
|||||||
* if the query would otherwise be routed to slave.
|
* if the query would otherwise be routed to slave.
|
||||||
*/
|
*/
|
||||||
route_target_t get_route_target(RWSplitSession *rses, uint8_t command,
|
route_target_t get_route_target(RWSplitSession *rses, uint8_t command,
|
||||||
uint32_t qtype, HINT *hint)
|
uint32_t qtype, HINT *query_hints)
|
||||||
{
|
{
|
||||||
bool trx_active = session_trx_is_active(rses->client_dcb->session);
|
bool trx_active = session_trx_is_active(rses->client_dcb->session);
|
||||||
bool load_active = rses->load_data_state != LOAD_DATA_INACTIVE;
|
bool load_active = rses->load_data_state != LOAD_DATA_INACTIVE;
|
||||||
@ -556,6 +556,9 @@ route_target_t get_route_target(RWSplitSession *rses, uint8_t command,
|
|||||||
{
|
{
|
||||||
target = TARGET_MASTER;
|
target = TARGET_MASTER;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Prepared statements preparations should go to all servers
|
||||||
|
*/
|
||||||
else if (qc_query_is_type(qtype, QUERY_TYPE_PREPARE_STMT) ||
|
else if (qc_query_is_type(qtype, QUERY_TYPE_PREPARE_STMT) ||
|
||||||
qc_query_is_type(qtype, QUERY_TYPE_PREPARE_NAMED_STMT) ||
|
qc_query_is_type(qtype, QUERY_TYPE_PREPARE_NAMED_STMT) ||
|
||||||
command == MYSQL_COM_STMT_CLOSE ||
|
command == MYSQL_COM_STMT_CLOSE ||
|
||||||
@ -564,7 +567,7 @@ route_target_t get_route_target(RWSplitSession *rses, uint8_t command,
|
|||||||
target = TARGET_ALL;
|
target = TARGET_ALL;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* These queries are not affected by hints
|
* These queries should be routed to all servers
|
||||||
*/
|
*/
|
||||||
else if (!load_active &&
|
else if (!load_active &&
|
||||||
(qc_query_is_type(qtype, QUERY_TYPE_SESSION_WRITE) ||
|
(qc_query_is_type(qtype, QUERY_TYPE_SESSION_WRITE) ||
|
||||||
@ -640,7 +643,7 @@ route_target_t get_route_target(RWSplitSession *rses, uint8_t command,
|
|||||||
}
|
}
|
||||||
else if (session_trx_is_read_only(rses->client_dcb->session))
|
else if (session_trx_is_read_only(rses->client_dcb->session))
|
||||||
{
|
{
|
||||||
/* Force TARGET_SLAVE for READ ONLY tranaction (active or ending) */
|
/* Force TARGET_SLAVE for READ ONLY transaction (active or ending) */
|
||||||
target = TARGET_SLAVE;
|
target = TARGET_SLAVE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -673,14 +676,13 @@ route_target_t get_route_target(RWSplitSession *rses, uint8_t command,
|
|||||||
target = TARGET_MASTER;
|
target = TARGET_MASTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** process routing hints */
|
/** Process routing hints */
|
||||||
while (hint != NULL)
|
for (HINT* hint = query_hints; hint; hint = hint->next)
|
||||||
{
|
{
|
||||||
if (hint->type == HINT_ROUTE_TO_MASTER)
|
if (hint->type == HINT_ROUTE_TO_MASTER)
|
||||||
{
|
{
|
||||||
target = TARGET_MASTER; /*< override */
|
target = TARGET_MASTER; /*< override */
|
||||||
MXS_DEBUG("%lu [get_route_target] Hint: route to master.",
|
MXS_DEBUG("Hint: route to master");
|
||||||
pthread_self());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (hint->type == HINT_ROUTE_TO_NAMED_SERVER)
|
else if (hint->type == HINT_ROUTE_TO_NAMED_SERVER)
|
||||||
@ -690,42 +692,38 @@ route_target_t get_route_target(RWSplitSession *rses, uint8_t command,
|
|||||||
* found, the oroginal target is chosen.
|
* found, the oroginal target is chosen.
|
||||||
*/
|
*/
|
||||||
target |= TARGET_NAMED_SERVER;
|
target |= TARGET_NAMED_SERVER;
|
||||||
MXS_DEBUG("%lu [get_route_target] Hint: route to "
|
MXS_DEBUG("Hint: route to named server: %s", (char*)hint->data);
|
||||||
"named server : ",
|
|
||||||
pthread_self());
|
|
||||||
}
|
}
|
||||||
else if (hint->type == HINT_ROUTE_TO_UPTODATE_SERVER)
|
else if (hint->type == HINT_ROUTE_TO_UPTODATE_SERVER)
|
||||||
{
|
{
|
||||||
/** not implemented */
|
/** not implemented */
|
||||||
|
ss_dassert(false);
|
||||||
}
|
}
|
||||||
else if (hint->type == HINT_ROUTE_TO_ALL)
|
else if (hint->type == HINT_ROUTE_TO_ALL)
|
||||||
{
|
{
|
||||||
/** not implemented */
|
/** not implemented */
|
||||||
|
ss_dassert(false);
|
||||||
}
|
}
|
||||||
else if (hint->type == HINT_PARAMETER)
|
else if (hint->type == HINT_PARAMETER)
|
||||||
{
|
{
|
||||||
if (strncasecmp((char *)hint->data, "max_slave_replication_lag",
|
if (strncasecmp((char*)hint->data, "max_slave_replication_lag",
|
||||||
strlen("max_slave_replication_lag")) == 0)
|
strlen("max_slave_replication_lag")) == 0)
|
||||||
{
|
{
|
||||||
target |= TARGET_RLAG_MAX;
|
target |= TARGET_RLAG_MAX;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MXS_ERROR("Unknown hint parameter "
|
MXS_ERROR("Unknown hint parameter '%s' when "
|
||||||
"'%s' when 'max_slave_replication_lag' "
|
"'max_slave_replication_lag' was expected.",
|
||||||
"was expected.",
|
(char*)hint->data);
|
||||||
(char *)hint->data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (hint->type == HINT_ROUTE_TO_SLAVE)
|
else if (hint->type == HINT_ROUTE_TO_SLAVE)
|
||||||
{
|
{
|
||||||
target = TARGET_SLAVE;
|
target = TARGET_SLAVE;
|
||||||
MXS_DEBUG("%lu [get_route_target] Hint: route to "
|
MXS_DEBUG("Hint: route to slave.");
|
||||||
"slave.",
|
|
||||||
pthread_self());
|
|
||||||
}
|
}
|
||||||
hint = hint->next;
|
}
|
||||||
} /*< while (hint != NULL) */
|
|
||||||
|
|
||||||
return (route_target_t)target;
|
return (route_target_t)target;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user