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));
|
memcpy(&(dcb->func), funcs, sizeof(GWPROTOCOL));
|
||||||
|
|
||||||
/*<
|
/**
|
||||||
* Link dcb to session. Unlink is called in dcb_final_free
|
* Link dcb to session. Unlink is called in dcb_final_free
|
||||||
*/
|
*/
|
||||||
if (!session_link_dcb(session, dcb))
|
if (!session_link_dcb(session, dcb))
|
||||||
@ -693,7 +693,7 @@ int rc;
|
|||||||
session->client->fd)));
|
session->client->fd)));
|
||||||
}
|
}
|
||||||
ss_dassert(dcb->fd == DCBFD_CLOSED); /*< must be uninitialized at this point */
|
ss_dassert(dcb->fd == DCBFD_CLOSED); /*< must be uninitialized at this point */
|
||||||
/*<
|
/**
|
||||||
* Successfully connected to backend. Assign file descriptor to dcb
|
* Successfully connected to backend. Assign file descriptor to dcb
|
||||||
*/
|
*/
|
||||||
dcb->fd = fd;
|
dcb->fd = fd;
|
||||||
@ -701,14 +701,14 @@ int rc;
|
|||||||
dcb->dcb_server_status = server->status;
|
dcb->dcb_server_status = server->status;
|
||||||
ss_debug(dcb->dcb_port = server->port;)
|
ss_debug(dcb->dcb_port = server->port;)
|
||||||
|
|
||||||
/*<
|
/**
|
||||||
* backend_dcb is connected to backend server, and once backend_dcb
|
* backend_dcb is connected to backend server, and once backend_dcb
|
||||||
* is added to poll set, authentication takes place as part of
|
* is added to poll set, authentication takes place as part of
|
||||||
* EPOLLOUT event that will be received once the connection
|
* EPOLLOUT event that will be received once the connection
|
||||||
* is established.
|
* is established.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*<
|
/**
|
||||||
* Add the dcb in the poll set
|
* Add the dcb in the poll set
|
||||||
*/
|
*/
|
||||||
rc = poll_add_dcb(dcb);
|
rc = poll_add_dcb(dcb);
|
||||||
@ -718,7 +718,7 @@ int rc;
|
|||||||
dcb_final_free(dcb);
|
dcb_final_free(dcb);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/*<
|
/**
|
||||||
* The dcb will be addded into poll set by dcb->func.connect
|
* The dcb will be addded into poll set by dcb->func.connect
|
||||||
*/
|
*/
|
||||||
atomic_add(&server->stats.n_connections, 1);
|
atomic_add(&server->stats.n_connections, 1);
|
||||||
@ -1218,7 +1218,7 @@ dcb_close(DCB *dcb)
|
|||||||
"%lu [dcb_close]",
|
"%lu [dcb_close]",
|
||||||
pthread_self())));
|
pthread_self())));
|
||||||
|
|
||||||
/*<
|
/**
|
||||||
* dcb_close may be called for freshly created dcb, in which case
|
* dcb_close may be called for freshly created dcb, in which case
|
||||||
* it only needs to be freed.
|
* it only needs to be freed.
|
||||||
*/
|
*/
|
||||||
|
@ -1578,7 +1578,7 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
|||||||
bool accept = my_instance->def_op;
|
bool accept = my_instance->def_op;
|
||||||
char *msg = NULL, *fullquery = NULL,*ipaddr;
|
char *msg = NULL, *fullquery = NULL,*ipaddr;
|
||||||
char uname_addr[128];
|
char uname_addr[128];
|
||||||
DCB* dcb = my_session->session->client;
|
DCB* dcb = my_session->session->client;
|
||||||
USER* user = NULL;
|
USER* user = NULL;
|
||||||
GWBUF* forward;
|
GWBUF* forward;
|
||||||
ipaddr = strdup(dcb->remote);
|
ipaddr = strdup(dcb->remote);
|
||||||
@ -1620,7 +1620,7 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
|||||||
goto queryresolved;
|
goto queryresolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
queryresolved:
|
queryresolved:
|
||||||
|
|
||||||
free(ipaddr);
|
free(ipaddr);
|
||||||
free(fullquery);
|
free(fullquery);
|
||||||
@ -1628,7 +1628,7 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
|||||||
if(accept){
|
if(accept){
|
||||||
|
|
||||||
return my_session->down.routeQuery(my_session->down.instance,
|
return my_session->down.routeQuery(my_session->down.instance,
|
||||||
my_session->down.session, queue);
|
my_session->down.session, queue);
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
gwbuf_free(queue);
|
gwbuf_free(queue);
|
||||||
@ -1636,7 +1636,7 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
|||||||
if(my_session->errmsg){
|
if(my_session->errmsg){
|
||||||
msg = my_session->errmsg;
|
msg = my_session->errmsg;
|
||||||
}
|
}
|
||||||
forward = gen_dummy_error(my_session,msg);
|
forward = gen_dummy_error(my_session,msg);
|
||||||
|
|
||||||
if(my_session->errmsg){
|
if(my_session->errmsg){
|
||||||
free(my_session->errmsg);
|
free(my_session->errmsg);
|
||||||
|
@ -344,7 +344,9 @@ static int gw_read_backend_event(DCB *dcb) {
|
|||||||
if (backend_protocol->protocol_auth_state == MYSQL_AUTH_FAILED ||
|
if (backend_protocol->protocol_auth_state == MYSQL_AUTH_FAILED ||
|
||||||
backend_protocol->protocol_auth_state == MYSQL_HANDSHAKE_FAILED)
|
backend_protocol->protocol_auth_state == MYSQL_HANDSHAKE_FAILED)
|
||||||
{
|
{
|
||||||
/**
|
GWBUF* errbuf;
|
||||||
|
bool succp;
|
||||||
|
/**
|
||||||
* protocol state won't change anymore,
|
* protocol state won't change anymore,
|
||||||
* lock can be freed
|
* lock can be freed
|
||||||
*/
|
*/
|
||||||
@ -357,54 +359,52 @@ static int gw_read_backend_event(DCB *dcb) {
|
|||||||
dcb->delayq,
|
dcb->delayq,
|
||||||
GWBUF_LENGTH(dcb->delayq))) != NULL);
|
GWBUF_LENGTH(dcb->delayq))) != NULL);
|
||||||
}
|
}
|
||||||
spinlock_release(&dcb->delayqlock);
|
spinlock_release(&dcb->delayqlock);
|
||||||
{
|
|
||||||
GWBUF* errbuf;
|
|
||||||
bool succp;
|
|
||||||
|
|
||||||
/* try reload users' table for next connection */
|
/* try reload users' table for next connection */
|
||||||
if (backend_protocol->protocol_auth_state == MYSQL_AUTH_FAILED) {
|
if (backend_protocol->protocol_auth_state ==
|
||||||
service_refresh_users(dcb->session->service);
|
MYSQL_AUTH_FAILED)
|
||||||
}
|
{
|
||||||
#if defined(SS_DEBUG)
|
service_refresh_users(dcb->session->service);
|
||||||
LOGIF(LD, (skygw_log_write(
|
}
|
||||||
LOGFILE_DEBUG,
|
#if defined(SS_DEBUG)
|
||||||
"%lu [gw_read_backend_event] "
|
LOGIF(LD, (skygw_log_write(
|
||||||
"calling handleError. Backend "
|
LOGFILE_DEBUG,
|
||||||
"DCB %p, session %p",
|
"%lu [gw_read_backend_event] "
|
||||||
pthread_self(),
|
"calling handleError. Backend "
|
||||||
dcb,
|
"DCB %p, session %p",
|
||||||
dcb->session)));
|
pthread_self(),
|
||||||
|
dcb,
|
||||||
|
dcb->session)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
errbuf = mysql_create_custom_error(
|
errbuf = mysql_create_custom_error(
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
"Authentication with backend failed. "
|
"Authentication with backend failed. "
|
||||||
"Session will be closed.");
|
"Session will be closed.");
|
||||||
|
|
||||||
router->handleError(router_instance,
|
router->handleError(router_instance,
|
||||||
rsession,
|
rsession,
|
||||||
errbuf,
|
errbuf,
|
||||||
dcb,
|
dcb,
|
||||||
ERRACT_REPLY_CLIENT,
|
ERRACT_REPLY_CLIENT,
|
||||||
&succp);
|
&succp);
|
||||||
gwbuf_free(errbuf);
|
gwbuf_free(errbuf);
|
||||||
LOGIF(LD, (skygw_log_write(
|
LOGIF(LD, (skygw_log_write(
|
||||||
LOGFILE_DEBUG,
|
LOGFILE_DEBUG,
|
||||||
"%lu [gw_read_backend_event] "
|
"%lu [gw_read_backend_event] "
|
||||||
"after calling handleError. Backend "
|
"after calling handleError. Backend "
|
||||||
"DCB %p, session %p",
|
"DCB %p, session %p",
|
||||||
pthread_self(),
|
pthread_self(),
|
||||||
dcb,
|
dcb,
|
||||||
dcb->session)));
|
dcb->session)));
|
||||||
|
|
||||||
spinlock_acquire(&session->ses_lock);
|
spinlock_acquire(&session->ses_lock);
|
||||||
session->state = SESSION_STATE_STOPPING;
|
session->state = SESSION_STATE_STOPPING;
|
||||||
spinlock_release(&session->ses_lock);
|
spinlock_release(&session->ses_lock);
|
||||||
ss_dassert(dcb->dcb_errhandle_called);
|
ss_dassert(dcb->dcb_errhandle_called);
|
||||||
dcb_close(dcb);
|
dcb_close(dcb);
|
||||||
}
|
|
||||||
rc = 1;
|
rc = 1;
|
||||||
goto return_rc;
|
goto return_rc;
|
||||||
}
|
}
|
||||||
|
@ -660,7 +660,7 @@ int gw_read_client_event(
|
|||||||
*/
|
*/
|
||||||
mysql_send_ok(dcb, 2, 0, NULL);
|
mysql_send_ok(dcb, 2, 0, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
protocol->protocol_auth_state = MYSQL_AUTH_FAILED;
|
protocol->protocol_auth_state = MYSQL_AUTH_FAILED;
|
||||||
LOGIF(LD, (skygw_log_write(
|
LOGIF(LD, (skygw_log_write(
|
||||||
@ -738,7 +738,7 @@ int gw_read_client_event(
|
|||||||
ss_dassert(nbytes_read >= 5);
|
ss_dassert(nbytes_read >= 5);
|
||||||
|
|
||||||
session = dcb->session;
|
session = dcb->session;
|
||||||
ss_dassert( session!= NULL);
|
ss_dassert(session!= NULL);
|
||||||
|
|
||||||
if (session != NULL)
|
if (session != NULL)
|
||||||
{
|
{
|
||||||
@ -749,54 +749,9 @@ int gw_read_client_event(
|
|||||||
rsession = session->router_session;
|
rsession = session->router_session;
|
||||||
ss_dassert(rsession != NULL);
|
ss_dassert(rsession != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now, we are assuming in the first buffer there is
|
/* Now, we are assuming in the first buffer there is
|
||||||
* the information form mysql command */
|
* the information form mysql command */
|
||||||
payload = GWBUF_DATA(read_buffer);
|
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 */
|
/** Ask what type of input the router expects */
|
||||||
cap = router->getCapabilities(router_instance, rsession);
|
cap = router->getCapabilities(router_instance, rsession);
|
||||||
@ -811,18 +766,47 @@ int gw_read_client_event(
|
|||||||
/** Mark buffer to as MySQL type */
|
/** Mark buffer to as MySQL type */
|
||||||
gwbuf_set_type(read_buffer, GWBUF_TYPE_MYSQL);
|
gwbuf_set_type(read_buffer, GWBUF_TYPE_MYSQL);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* If router doesn't implement getCapabilities correctly we end
|
||||||
|
* up here.
|
||||||
|
*/
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
GWBUF* errbuf;
|
||||||
|
bool succp;
|
||||||
|
|
||||||
LOGIF(LD, (skygw_log_write_flush(
|
LOGIF(LD, (skygw_log_write_flush(
|
||||||
LOGFILE_DEBUG,
|
LOGFILE_DEBUG,
|
||||||
"%lu [gw_read_client_event] Reading router "
|
"%lu [gw_read_client_event] Reading router "
|
||||||
"capabilities failed.",
|
"capabilities failed.",
|
||||||
pthread_self())));
|
pthread_self())));
|
||||||
mysql_send_custom_error(dcb,
|
|
||||||
1,
|
errbuf = mysql_create_custom_error(
|
||||||
0,
|
1,
|
||||||
"Operation failed. Router "
|
0,
|
||||||
"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;
|
rc = 1;
|
||||||
goto return_rc;
|
goto return_rc;
|
||||||
}
|
}
|
||||||
@ -843,6 +827,7 @@ int gw_read_client_event(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/** Reset error handler when routing of the new query begins */
|
||||||
router->handleError(NULL, NULL, NULL, dcb, ERRACT_RESET, NULL);
|
router->handleError(NULL, NULL, NULL, dcb, ERRACT_RESET, NULL);
|
||||||
|
|
||||||
if (stmt_input)
|
if (stmt_input)
|
||||||
@ -1525,12 +1510,17 @@ retblock:
|
|||||||
* It is assumed readbuf includes at least one complete packet.
|
* It is assumed readbuf includes at least one complete packet.
|
||||||
* Return 1 in success. If the last packet is incomplete return success but
|
* Return 1 in success. If the last packet is incomplete return success but
|
||||||
* leave incomplete packet to readbuf.
|
* 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(
|
static int route_by_statement(
|
||||||
SESSION* session,
|
SESSION* session,
|
||||||
GWBUF** p_readbuf)
|
GWBUF** p_readbuf)
|
||||||
{
|
{
|
||||||
int rc = -1;
|
int rc;
|
||||||
GWBUF* packetbuf;
|
GWBUF* packetbuf;
|
||||||
#if defined(SS_DEBUG)
|
#if defined(SS_DEBUG)
|
||||||
GWBUF* tmpbuf;
|
GWBUF* tmpbuf;
|
||||||
|
@ -2198,17 +2198,32 @@ static bool route_single_stmt(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bref != NULL && BREF_IS_IN_USE(bref))
|
if (bref != NULL && BREF_IS_IN_USE(bref))
|
||||||
{
|
{
|
||||||
|
/** Create and add MySQL error to eventqueue */
|
||||||
modutil_reply_parse_error(
|
modutil_reply_parse_error(
|
||||||
bref->bref_dcb,
|
bref->bref_dcb,
|
||||||
strdup("Routing query to backend failed. "
|
strdup("Routing query to backend failed. "
|
||||||
"See the error log for further "
|
"See the error log for further "
|
||||||
"details."),
|
"details."),
|
||||||
0);
|
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 (query_str) free (query_str);
|
||||||
if (qtype_str) free(qtype_str);
|
if (qtype_str) free(qtype_str);
|
||||||
succp = true;
|
|
||||||
goto retblock;
|
goto retblock;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -4413,7 +4428,8 @@ static void rwsplit_process_router_options(
|
|||||||
* @param errmsgbuf The error message to reply
|
* @param errmsgbuf The error message to reply
|
||||||
* @param backend_dcb The backend DCB
|
* @param backend_dcb The backend DCB
|
||||||
* @param action The action: REPLY, REPLY_AND_CLOSE, NEW_CONNECTION
|
* @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
|
* 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.
|
* tell whether router has enough master/slave connections to continue work.
|
||||||
|
Reference in New Issue
Block a user