Clean up, added comments, removed some dead code.
This commit is contained in:
@ -651,7 +651,7 @@ int rc;
|
||||
}
|
||||
memcpy(&(dcb->func), funcs, sizeof(GWPROTOCOL));
|
||||
|
||||
/*<
|
||||
/**
|
||||
* Link dcb to session. Unlink is called in dcb_final_free
|
||||
*/
|
||||
if (!session_link_dcb(session, dcb))
|
||||
@ -693,7 +693,7 @@ int rc;
|
||||
session->client->fd)));
|
||||
}
|
||||
ss_dassert(dcb->fd == DCBFD_CLOSED); /*< must be uninitialized at this point */
|
||||
/*<
|
||||
/**
|
||||
* Successfully connected to backend. Assign file descriptor to dcb
|
||||
*/
|
||||
dcb->fd = fd;
|
||||
@ -701,14 +701,14 @@ int rc;
|
||||
dcb->dcb_server_status = server->status;
|
||||
ss_debug(dcb->dcb_port = server->port;)
|
||||
|
||||
/*<
|
||||
/**
|
||||
* backend_dcb is connected to backend server, and once backend_dcb
|
||||
* is added to poll set, authentication takes place as part of
|
||||
* EPOLLOUT event that will be received once the connection
|
||||
* is established.
|
||||
*/
|
||||
|
||||
/*<
|
||||
/**
|
||||
* Add the dcb in the poll set
|
||||
*/
|
||||
rc = poll_add_dcb(dcb);
|
||||
@ -718,7 +718,7 @@ int rc;
|
||||
dcb_final_free(dcb);
|
||||
return NULL;
|
||||
}
|
||||
/*<
|
||||
/**
|
||||
* The dcb will be addded into poll set by dcb->func.connect
|
||||
*/
|
||||
atomic_add(&server->stats.n_connections, 1);
|
||||
@ -1218,7 +1218,7 @@ dcb_close(DCB *dcb)
|
||||
"%lu [dcb_close]",
|
||||
pthread_self())));
|
||||
|
||||
/*<
|
||||
/**
|
||||
* dcb_close may be called for freshly created dcb, in which case
|
||||
* it only needs to be freed.
|
||||
*/
|
||||
|
@ -1620,7 +1620,7 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
||||
goto queryresolved;
|
||||
}
|
||||
|
||||
queryresolved:
|
||||
queryresolved:
|
||||
|
||||
free(ipaddr);
|
||||
free(fullquery);
|
||||
|
@ -344,6 +344,8 @@ static int gw_read_backend_event(DCB *dcb) {
|
||||
if (backend_protocol->protocol_auth_state == MYSQL_AUTH_FAILED ||
|
||||
backend_protocol->protocol_auth_state == MYSQL_HANDSHAKE_FAILED)
|
||||
{
|
||||
GWBUF* errbuf;
|
||||
bool succp;
|
||||
/**
|
||||
* protocol state won't change anymore,
|
||||
* lock can be freed
|
||||
@ -358,12 +360,11 @@ static int gw_read_backend_event(DCB *dcb) {
|
||||
GWBUF_LENGTH(dcb->delayq))) != NULL);
|
||||
}
|
||||
spinlock_release(&dcb->delayqlock);
|
||||
{
|
||||
GWBUF* errbuf;
|
||||
bool succp;
|
||||
|
||||
/* try reload users' table for next connection */
|
||||
if (backend_protocol->protocol_auth_state == MYSQL_AUTH_FAILED) {
|
||||
if (backend_protocol->protocol_auth_state ==
|
||||
MYSQL_AUTH_FAILED)
|
||||
{
|
||||
service_refresh_users(dcb->session->service);
|
||||
}
|
||||
#if defined(SS_DEBUG)
|
||||
@ -404,7 +405,6 @@ static int gw_read_backend_event(DCB *dcb) {
|
||||
spinlock_release(&session->ses_lock);
|
||||
ss_dassert(dcb->dcb_errhandle_called);
|
||||
dcb_close(dcb);
|
||||
}
|
||||
rc = 1;
|
||||
goto return_rc;
|
||||
}
|
||||
|
@ -738,7 +738,7 @@ int gw_read_client_event(
|
||||
ss_dassert(nbytes_read >= 5);
|
||||
|
||||
session = dcb->session;
|
||||
ss_dassert( session!= NULL);
|
||||
ss_dassert(session!= NULL);
|
||||
|
||||
if (session != NULL)
|
||||
{
|
||||
@ -749,54 +749,9 @@ int gw_read_client_event(
|
||||
rsession = session->router_session;
|
||||
ss_dassert(rsession != NULL);
|
||||
}
|
||||
|
||||
/* Now, we are assuming in the first buffer there is
|
||||
* the information form mysql command */
|
||||
payload = GWBUF_DATA(read_buffer);
|
||||
/**
|
||||
* Without rsession there is no access to backend.
|
||||
* COM_QUIT : close client dcb
|
||||
* else : write custom error to client dcb.
|
||||
*/
|
||||
if(rsession == NULL)
|
||||
{
|
||||
/** COM_QUIT */
|
||||
if (MYSQL_IS_COM_QUIT(payload))
|
||||
{
|
||||
LOGIF(LD, (skygw_log_write_flush(
|
||||
LOGFILE_DEBUG,
|
||||
"%lu [gw_read_client_event] Client read "
|
||||
"COM_QUIT and rsession == NULL. Closing "
|
||||
"client dcb %p.",
|
||||
pthread_self(),
|
||||
dcb)));
|
||||
/**
|
||||
* close router session and that closes
|
||||
* backends
|
||||
*/
|
||||
dcb_close(dcb);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(SS_DEBUG)
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Client read error handling.")));
|
||||
#endif
|
||||
|
||||
/* Send a custom error as MySQL command reply */
|
||||
mysql_send_custom_error(
|
||||
dcb,
|
||||
1,
|
||||
0,
|
||||
"Can't route query. Connection to "
|
||||
"backend lost");
|
||||
}
|
||||
rc = 1;
|
||||
/** Free buffer */
|
||||
read_buffer = gwbuf_consume(read_buffer, nbytes_read);
|
||||
goto return_rc;
|
||||
}
|
||||
|
||||
/** Ask what type of input the router expects */
|
||||
cap = router->getCapabilities(router_instance, rsession);
|
||||
@ -811,18 +766,47 @@ int gw_read_client_event(
|
||||
/** Mark buffer to as MySQL type */
|
||||
gwbuf_set_type(read_buffer, GWBUF_TYPE_MYSQL);
|
||||
}
|
||||
/**
|
||||
* If router doesn't implement getCapabilities correctly we end
|
||||
* up here.
|
||||
*/
|
||||
else
|
||||
{
|
||||
GWBUF* errbuf;
|
||||
bool succp;
|
||||
|
||||
LOGIF(LD, (skygw_log_write_flush(
|
||||
LOGFILE_DEBUG,
|
||||
"%lu [gw_read_client_event] Reading router "
|
||||
"capabilities failed.",
|
||||
pthread_self())));
|
||||
mysql_send_custom_error(dcb,
|
||||
|
||||
errbuf = mysql_create_custom_error(
|
||||
1,
|
||||
0,
|
||||
"Operation failed. Router "
|
||||
"session is closed.");
|
||||
"Read invalid router capabilities. Routing failed. "
|
||||
"Session will be closed.");
|
||||
|
||||
router->handleError(
|
||||
router_instance,
|
||||
rsession,
|
||||
errbuf,
|
||||
dcb,
|
||||
ERRACT_REPLY_CLIENT,
|
||||
&succp);
|
||||
gwbuf_free(errbuf);
|
||||
/**
|
||||
* If there are not enough backends close
|
||||
* session
|
||||
*/
|
||||
if (!succp)
|
||||
{
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Routing the query failed. "
|
||||
"Session will be closed.")));
|
||||
dcb_close(dcb);
|
||||
}
|
||||
rc = 1;
|
||||
goto return_rc;
|
||||
}
|
||||
@ -843,6 +827,7 @@ int gw_read_client_event(
|
||||
}
|
||||
else
|
||||
{
|
||||
/** Reset error handler when routing of the new query begins */
|
||||
router->handleError(NULL, NULL, NULL, dcb, ERRACT_RESET, NULL);
|
||||
|
||||
if (stmt_input)
|
||||
@ -1525,12 +1510,17 @@ retblock:
|
||||
* It is assumed readbuf includes at least one complete packet.
|
||||
* Return 1 in success. If the last packet is incomplete return success but
|
||||
* leave incomplete packet to readbuf.
|
||||
*
|
||||
* @param session Session pointer
|
||||
* @param p_readbuf Pointer to the address of GWBUF including the query
|
||||
*
|
||||
* @return 1 if succeed,
|
||||
*/
|
||||
static int route_by_statement(
|
||||
SESSION* session,
|
||||
GWBUF** p_readbuf)
|
||||
{
|
||||
int rc = -1;
|
||||
int rc;
|
||||
GWBUF* packetbuf;
|
||||
#if defined(SS_DEBUG)
|
||||
GWBUF* tmpbuf;
|
||||
|
@ -2199,16 +2199,31 @@ static bool route_single_stmt(
|
||||
|
||||
if (bref != NULL && BREF_IS_IN_USE(bref))
|
||||
{
|
||||
/** Create and add MySQL error to eventqueue */
|
||||
modutil_reply_parse_error(
|
||||
bref->bref_dcb,
|
||||
strdup("Routing query to backend failed. "
|
||||
"See the error log for further "
|
||||
"details."),
|
||||
0);
|
||||
succp = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* If there were no available backend references
|
||||
* available return false - session will be closed
|
||||
*/
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Sending error message to client "
|
||||
"failed. Router doesn't have any "
|
||||
"available backends. Session will be "
|
||||
"closed.")));
|
||||
succp = false;
|
||||
}
|
||||
if (query_str) free (query_str);
|
||||
if (qtype_str) free(qtype_str);
|
||||
succp = true;
|
||||
goto retblock;
|
||||
}
|
||||
/**
|
||||
@ -4413,7 +4428,8 @@ static void rwsplit_process_router_options(
|
||||
* @param errmsgbuf The error message to reply
|
||||
* @param backend_dcb The backend DCB
|
||||
* @param action The action: REPLY, REPLY_AND_CLOSE, NEW_CONNECTION
|
||||
* @param succp Result of action.
|
||||
* @param succp Result of action. True if there is at least master
|
||||
* and enough slaves to continue session. Otherwise false.
|
||||
*
|
||||
* Even if succp == true connecting to new slave may have failed. succp is to
|
||||
* tell whether router has enough master/slave connections to continue work.
|
||||
|
Reference in New Issue
Block a user