Replaced write system function with wrapper gw_write. It allows for generating failures by using telnet commands, fail backendfd, fail clientfd, which are available in debug build only.

This commit is contained in:
vraatikka
2013-09-17 00:07:56 +03:00
parent db7004e6ae
commit 8bf73ea154
11 changed files with 197 additions and 42 deletions

View File

@ -267,7 +267,9 @@ httpd_write_event(DCB *dcb)
static int
httpd_write(DCB *dcb, GWBUF *queue)
{
return dcb_write(dcb, queue);
int rc;
rc = dcb_write(dcb, queue);
return rc;
}
/**

View File

@ -149,11 +149,10 @@ static int gw_read_backend_event(DCB *dcb) {
CHK_DCB(dcb);
CHK_SESSION(dcb->session);
ss_info_dassert(dcb->session != NULL,
"Backend dcb doesn't have session");
backend_protocol = (MySQLProtocol *) dcb->protocol;
CHK_PROTOCOL(backend_protocol);
/** return only with complete session */
current_session = gw_get_shared_session_auth_info(dcb);
ss_dassert(current_session != NULL);
@ -180,7 +179,8 @@ static int gw_read_backend_event(DCB *dcb) {
current_session->db,
current_session->user,
current_session->client_sha1,
backend_protocol) != 0) {
backend_protocol) != 0)
{
backend_protocol->state = MYSQL_AUTH_FAILED;
rc = 1;
} else {
@ -411,6 +411,7 @@ static int
gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
{
MySQLProtocol *backend_protocol = dcb->protocol;
int rc;
/**
* Don't write to backend if backend_dcb is not in poll set anymore.
@ -444,8 +445,8 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
memcpy(&dcb->command, &queue->command, sizeof(dcb->command));
spinlock_release(&dcb->authlock);
return dcb_write(dcb, queue);
rc = dcb_write(dcb, queue);
return rc;
}
/**
@ -631,6 +632,7 @@ static void backend_set_delayqueue(DCB *dcb, GWBUF *queue) {
static int backend_write_delayqueue(DCB *dcb)
{
GWBUF *localq = NULL;
int rc;
spinlock_acquire(&dcb->delayqlock);
@ -644,8 +646,8 @@ static int backend_write_delayqueue(DCB *dcb)
memcpy(&dcb->command, &localq->command, sizeof(dcb->command));
spinlock_release(&dcb->delayqlock);
return dcb_write(dcb, localq);
rc = dcb_write(dcb, localq);
return rc;
}

View File

@ -461,7 +461,7 @@ int w, saved_errno = 0;
{
len = GWBUF_LENGTH(queue);
GW_NOINTR_CALL(
w = write(dcb->fd,GWBUF_DATA(queue), len);
w = gw_write(dcb->fd,GWBUF_DATA(queue), len);
dcb->stats.n_writes++);
saved_errno = errno;
if (w < 0)
@ -642,12 +642,17 @@ int gw_read_client_event(DCB* dcb) {
/* len = GWBUF_LENGTH(queue); */
ptr_buff = GWBUF_DATA(queue);
/* get mysql commang at fourth byte */
/* get mysql commang at fifth byte */
if (ptr_buff) {
mysql_command = ptr_buff[4];
}
if (mysql_command == '\x03') {
/**
* SQL Trace here.
* Length can be calculated and it must be passed as
* argument.
*/
/* this is a standard MySQL query !!!! */
}
/**
@ -716,27 +721,43 @@ return_rc:
///////////////////////////////////////////////
// client write event to Client triggered by EPOLLOUT
//////////////////////////////////////////////
/**
* @node Client's fd became writable, and EPOLLOUT event
* arrived. As a consequence, client input buffer (writeq) is flushed.
*
* Parameters:
* @param dcb - in, use
* client dcb
*
* @return constantly 1
*
*
* @details (write detailed description here)
*
*/
int gw_write_client_event(DCB *dcb)
{
MySQLProtocol *protocol = NULL;
CHK_DCB(dcb);
ss_dassert(dcb->state != DCB_STATE_DISCONNECTED);
if (dcb == NULL) {
fprintf(stderr, "DCB is NULL, return\n");
return 1;
goto return_1;
}
ss_dassert(dcb->state != DCB_STATE_DISCONNECTED);
if (dcb->state == DCB_STATE_DISCONNECTED) {
return 1;
goto return_1;
}
if (dcb->protocol) {
protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
} else {
goto return_1;
if (dcb->protocol == NULL) {
goto return_1;
}
protocol = (MySQLProtocol *)dcb->protocol;
CHK_PROTOCOL(protocol);
if (protocol->state == MYSQL_IDLE ||
protocol->state == MYSQL_WAITING_RESULT)
{

View File

@ -504,7 +504,7 @@ int gw_send_authentication_to_backend(char *dbname, char *user, uint8_t *passwd,
// write to backend dcb
// ToDO: handle the EAGAIN | EWOULDBLOCK
rv = write(dcb->fd, GWBUF_DATA(buffer), bytes);
rv = gw_write(dcb->fd, GWBUF_DATA(buffer), bytes);
gwbuf_consume(buffer, bytes);

View File

@ -224,7 +224,9 @@ telnetd_write_event(DCB *dcb)
static int
telnetd_write(DCB *dcb, GWBUF *queue)
{
return dcb_write(dcb, queue);
int rc;
rc = dcb_write(dcb, queue);
return rc;
}
/**