Merge remote-tracking branch 'origin/develop' into header_rename
This commit is contained in:
@ -1282,9 +1282,10 @@ static route_target_t get_route_target (
|
||||
if (hint->type == HINT_ROUTE_TO_MASTER)
|
||||
{
|
||||
target = TARGET_MASTER; /*< override */
|
||||
LOGIF(LT, (skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Hint: route to master.")));
|
||||
LOGIF(LD, (skygw_log_write(
|
||||
LOGFILE_DEBUG,
|
||||
"%lu [get_route_target] Hint: route to master.",
|
||||
pthread_self())));
|
||||
break;
|
||||
}
|
||||
else if (hint->type == HINT_ROUTE_TO_NAMED_SERVER)
|
||||
@ -1294,9 +1295,11 @@ static route_target_t get_route_target (
|
||||
* found, the oroginal target is chosen.
|
||||
*/
|
||||
target |= TARGET_NAMED_SERVER;
|
||||
LOGIF(LT, (skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Hint: route to named server : ")));
|
||||
LOGIF(LD, (skygw_log_write(
|
||||
LOGFILE_DEBUG,
|
||||
"%lu [get_route_target] Hint: route to "
|
||||
"named server : ",
|
||||
pthread_self())));
|
||||
}
|
||||
else if (hint->type == HINT_ROUTE_TO_UPTODATE_SERVER)
|
||||
{
|
||||
@ -1334,9 +1337,11 @@ static route_target_t get_route_target (
|
||||
else if (hint->type == HINT_ROUTE_TO_SLAVE)
|
||||
{
|
||||
target = TARGET_SLAVE;
|
||||
LOGIF(LT, (skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Hint: route to slave.")));
|
||||
LOGIF(LD, (skygw_log_write(
|
||||
LOGFILE_DEBUG,
|
||||
"%lu [get_route_target] Hint: route to "
|
||||
"slave.",
|
||||
pthread_self())));
|
||||
}
|
||||
hint = hint->next;
|
||||
} /*< while (hint != NULL) */
|
||||
@ -1653,7 +1658,6 @@ static int routeQuery(
|
||||
GWBUF* querybuf)
|
||||
{
|
||||
skygw_query_type_t qtype = QUERY_TYPE_UNKNOWN;
|
||||
char* querystr = NULL;
|
||||
mysql_server_cmd_t packet_type;
|
||||
uint8_t* packet;
|
||||
int ret = 0;
|
||||
@ -1793,8 +1797,33 @@ static int routeQuery(
|
||||
{
|
||||
router_cli_ses->rses_autocommit_enabled = true;
|
||||
router_cli_ses->rses_transaction_active = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (LOG_IS_ENABLED(LOGFILE_TRACE))
|
||||
{
|
||||
uint8_t* packet = GWBUF_DATA(querybuf);
|
||||
unsigned char ptype = packet[4];
|
||||
size_t len = MIN(GWBUF_LENGTH(querybuf),
|
||||
MYSQL_GET_PACKET_LEN((unsigned char *)querybuf->start)-1);
|
||||
char* data = (char*)&packet[5];
|
||||
char* contentstr = strndup(data, len);
|
||||
char* qtypestr = skygw_get_qtype_str(qtype);
|
||||
|
||||
LOGIF(LT, (skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"> Autocommit: %s, trx is %s, cmd: %s, type: %s, "
|
||||
"stmt: %s%s %s",
|
||||
(router_cli_ses->rses_autocommit_enabled ? "[enabled]" : "[disabled]"),
|
||||
(router_cli_ses->rses_transaction_active ? "[open]" : "[not open]"),
|
||||
STRPACKETTYPE(ptype),
|
||||
(qtypestr==NULL ? "N/A" : qtypestr),
|
||||
contentstr,
|
||||
(querybuf->hint == NULL ? "" : ", Hint:"),
|
||||
(querybuf->hint == NULL ? "" : STRHINTTYPE(querybuf->hint->type)))));
|
||||
|
||||
free(contentstr);
|
||||
free(qtypestr);
|
||||
}
|
||||
/**
|
||||
* Find out where to route the query. Result may not be clear; it is
|
||||
* possible to have a hint for routing to a named server which can
|
||||
@ -1911,6 +1940,27 @@ static int routeQuery(
|
||||
btype,
|
||||
named_server,
|
||||
rlag_max);
|
||||
if (!succp)
|
||||
{
|
||||
if (TARGET_IS_NAMED_SERVER(route_target))
|
||||
{
|
||||
LOGIF(LT, (skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Was supposed to route to named server "
|
||||
"%s but couldn't find the server in a "
|
||||
"suitable state.",
|
||||
named_server)));
|
||||
}
|
||||
else if (TARGET_IS_RLAG_MAX(route_target))
|
||||
{
|
||||
LOGIF(LT, (skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Was supposed to route to server with "
|
||||
"replication lag at most %d but couldn't "
|
||||
"find such a slave.",
|
||||
rlag_max)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!succp && TARGET_IS_SLAVE(route_target))
|
||||
@ -1930,9 +1980,16 @@ static int routeQuery(
|
||||
NULL,
|
||||
rlag_max);
|
||||
if (succp)
|
||||
{
|
||||
{
|
||||
atomic_add(&inst->stats.n_slave, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE,
|
||||
"Was supposed to route to slave"
|
||||
"but finding suitable one "
|
||||
"failed.")));
|
||||
}
|
||||
}
|
||||
|
||||
if (!succp && TARGET_IS_MASTER(route_target))
|
||||
@ -1944,6 +2001,16 @@ static int routeQuery(
|
||||
BE_MASTER,
|
||||
NULL,
|
||||
MAX_RLAG_UNDEFINED);
|
||||
if (!succp)
|
||||
{
|
||||
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE,
|
||||
"Was supposed to "
|
||||
"route to master "
|
||||
"but couldn't find "
|
||||
"master in a "
|
||||
"suitable state "
|
||||
"failed.")));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1951,9 +2018,7 @@ static int routeQuery(
|
||||
}
|
||||
atomic_add(&inst->stats.n_master, 1);
|
||||
target_dcb = master_dcb;
|
||||
}
|
||||
ss_dassert(succp);
|
||||
|
||||
}
|
||||
|
||||
if (succp) /*< Have DCB of the target backend */
|
||||
{
|
||||
@ -1962,6 +2027,14 @@ static int routeQuery(
|
||||
|
||||
bref = get_bref_from_dcb(router_cli_ses, target_dcb);
|
||||
scur = &bref->bref_sescmd_cur;
|
||||
|
||||
LOGIF(LT, (skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Route query to %s\t%s:%d <",
|
||||
(SERVER_IS_MASTER(bref->bref_backend->backend_server) ?
|
||||
"master" : "slave"),
|
||||
bref->bref_backend->backend_server->name,
|
||||
bref->bref_backend->backend_server->port)));
|
||||
/**
|
||||
* Store current stmt if execution of previous session command
|
||||
* haven't completed yet. Note that according to MySQL protocol
|
||||
@ -1993,8 +2066,7 @@ static int routeQuery(
|
||||
{
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Routing query \"%s\" failed.",
|
||||
querystr)));
|
||||
"Error : Routing query failed.")));
|
||||
}
|
||||
}
|
||||
rses_end_locked_router_action(router_cli_ses);
|
||||
@ -3441,12 +3513,6 @@ static bool execute_sescmd_in_backend(
|
||||
sescmd_cursor_clone_querybuf(scur));
|
||||
break;
|
||||
}
|
||||
LOGIF(LT, (skygw_log_write_flush(
|
||||
LOGFILE_TRACE,
|
||||
"%lu [execute_sescmd_in_backend] Routed %s cmd %p.",
|
||||
pthread_self(),
|
||||
STRPACKETTYPE(scur->scmd_cur_cmd->my_sescmd_packet_type),
|
||||
scur->scmd_cur_cmd)));
|
||||
|
||||
if (rc == 1)
|
||||
{
|
||||
@ -3573,8 +3639,8 @@ static void tracelog_routed_query(
|
||||
querystr = (char *)malloc(len);
|
||||
memcpy(querystr, startpos, len-1);
|
||||
querystr[len-1] = '\0';
|
||||
LOGIF(LT, (skygw_log_write_flush(
|
||||
LOGFILE_TRACE,
|
||||
LOGIF(LD, (skygw_log_write_flush(
|
||||
LOGFILE_DEBUG,
|
||||
"%lu [%s] %d bytes long buf, \"%s\" -> %s:%d %s dcb %p",
|
||||
pthread_self(),
|
||||
funcname,
|
||||
@ -3595,8 +3661,8 @@ static void tracelog_routed_query(
|
||||
querystr = (char *)malloc(len);
|
||||
memcpy(querystr, startpos, len-1);
|
||||
querystr[len-1] = '\0';
|
||||
LOGIF(LT, (skygw_log_write_flush(
|
||||
LOGFILE_TRACE,
|
||||
LOGIF(LD, (skygw_log_write_flush(
|
||||
LOGFILE_DEBUG,
|
||||
"%lu [%s] %d bytes long buf, \"%s\" -> %s:%d %s dcb %p",
|
||||
pthread_self(),
|
||||
funcname,
|
||||
@ -3663,10 +3729,7 @@ static bool route_session_write(
|
||||
|
||||
LOGIF(LT, (skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Session write, query type\t%s, packet type %s, "
|
||||
"routing to all servers.",
|
||||
STRQTYPE(qtype),
|
||||
STRPACKETTYPE(packet_type))));
|
||||
"Session write, routing to all servers.")));
|
||||
|
||||
backend_ref = router_cli_ses->rses_backend_ref;
|
||||
|
||||
@ -3693,7 +3756,19 @@ static bool route_session_write(
|
||||
|
||||
for (i=0; i<router_cli_ses->rses_nbackends; i++)
|
||||
{
|
||||
DCB* dcb = backend_ref[i].bref_dcb;
|
||||
DCB* dcb = backend_ref[i].bref_dcb;
|
||||
|
||||
if (LOG_IS_ENABLED(LOGFILE_TRACE))
|
||||
{
|
||||
LOGIF(LT, (skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Route query to %s\t%s:%d%s",
|
||||
(SERVER_IS_MASTER(backend_ref[i].bref_backend->backend_server) ?
|
||||
"master" : "slave"),
|
||||
backend_ref[i].bref_backend->backend_server->name,
|
||||
backend_ref[i].bref_backend->backend_server->port,
|
||||
(i+1==router_cli_ses->rses_nbackends ? " <" : ""))));
|
||||
}
|
||||
|
||||
if (BREF_IS_IN_USE((&backend_ref[i])))
|
||||
{
|
||||
@ -3703,14 +3778,7 @@ static bool route_session_write(
|
||||
{
|
||||
succp = false;
|
||||
}
|
||||
else if (LOG_IS_ENABLED(LOGFILE_TRACE))
|
||||
{
|
||||
LOGIF(LT, (skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Wrote to %s:%d",
|
||||
backend_ref[i].bref_backend->backend_server->name,
|
||||
backend_ref[i].bref_backend->backend_server->port)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
rses_end_locked_router_action(router_cli_ses);
|
||||
@ -3740,6 +3808,18 @@ static bool route_session_write(
|
||||
{
|
||||
sescmd_cursor_t* scur;
|
||||
|
||||
if (LOG_IS_ENABLED(LOGFILE_TRACE))
|
||||
{
|
||||
LOGIF(LT, (skygw_log_write(
|
||||
LOGFILE_TRACE,
|
||||
"Route query to %s\t%s:%d%s",
|
||||
(SERVER_IS_MASTER(backend_ref[i].bref_backend->backend_server) ?
|
||||
"master" : "slave"),
|
||||
backend_ref[i].bref_backend->backend_server->name,
|
||||
backend_ref[i].bref_backend->backend_server->port,
|
||||
(i+1==router_cli_ses->rses_nbackends ? " <" : ""))));
|
||||
}
|
||||
|
||||
scur = backend_ref_get_sescmd_cursor(&backend_ref[i]);
|
||||
|
||||
/**
|
||||
@ -3747,7 +3827,7 @@ static bool route_session_write(
|
||||
*/
|
||||
bref_set_state(get_bref_from_dcb(router_cli_ses,
|
||||
backend_ref[i].bref_dcb),
|
||||
BREF_WAITING_RESULT);
|
||||
BREF_WAITING_RESULT);
|
||||
/**
|
||||
* Start execution if cursor is not already executing.
|
||||
* Otherwise, cursor will execute pending commands
|
||||
|
Reference in New Issue
Block a user