Removed fprintf in backend operations.

Some fprinf still available for gateway incoming connection and backend selection
This commit is contained in:
Massimiliano Pinto
2013-07-05 10:36:59 +02:00
parent 5e06ba76dd
commit 29d260e6bf
4 changed files with 41 additions and 44 deletions

View File

@ -87,7 +87,7 @@ int gw_read_gwbuff(DCB *dcb, GWBUF **head, int b) {
int n = -1; int n = -1;
if (b <= 0) { if (b <= 0) {
fprintf(stderr, "||| read_gwbuff called with 0 bytes for %i, closing\n", dcb->fd); //fprintf(stderr, "||| read_gwbuff called with 0 bytes for %i, closing\n", dcb->fd);
dcb->func.close(dcb); dcb->func.close(dcb);
return 1; return 1;
} }

View File

@ -35,9 +35,10 @@
* 01/07/2013 Massimiliano Pinto Put Log Manager example code behind SS_DEBUG macros. * 01/07/2013 Massimiliano Pinto Put Log Manager example code behind SS_DEBUG macros.
* 03/07/2013 Massimiliano Pinto Added delayq for incoming data before mysql connection * 03/07/2013 Massimiliano Pinto Added delayq for incoming data before mysql connection
* 04/07/2013 Massimiliano Pinto Added asyncrhronous MySQL protocol connection to backend * 04/07/2013 Massimiliano Pinto Added asyncrhronous MySQL protocol connection to backend
* 05/07/2013 Massimiliano Pinto Added closeSession if backend auth fails
*/ */
static char *version_str = "V1.0.0"; static char *version_str = "V2.0.0";
int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *passwd, MySQLProtocol *conn); int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *passwd, MySQLProtocol *conn);
static int gw_create_backend_connection(DCB *client_dcb, SERVER *server, SESSION *in_session); static int gw_create_backend_connection(DCB *client_dcb, SERVER *server, SESSION *in_session);
static int gw_read_backend_event(DCB* dcb); static int gw_read_backend_event(DCB* dcb);
@ -109,7 +110,6 @@ GetModuleObject()
* @param dcb The backend Descriptor Control Block * @param dcb The backend Descriptor Control Block
* @return 1 on operation, 0 for no action * @return 1 on operation, 0 for no action
*/ */
static int gw_read_backend_event(DCB *dcb) { static int gw_read_backend_event(DCB *dcb) {
MySQLProtocol *client_protocol = NULL; MySQLProtocol *client_protocol = NULL;
MySQLProtocol *backend_protocol = NULL; MySQLProtocol *backend_protocol = NULL;
@ -122,9 +122,14 @@ static int gw_read_backend_event(DCB *dcb) {
backend_protocol = (MySQLProtocol *) dcb->protocol; backend_protocol = (MySQLProtocol *) dcb->protocol;
current_session = (MYSQL_session *)dcb->session->data; current_session = (MYSQL_session *)dcb->session->data;
fprintf(stderr, ">>> backend EPOLLIN from %i, protocol state [%s]\n", dcb->fd, gw_mysql_protocol_state2string(backend_protocol->state)); //fprintf(stderr, ">>> backend EPOLLIN from %i, protocol state [%s]\n", dcb->fd, gw_mysql_protocol_state2string(backend_protocol->state));
// backend is connected: read server handshake and write auth request and return /* backend is connected:
*
* 1. read server handshake
* 2. and write auth request
* 3. and return
*/
if (backend_protocol->state == MYSQL_CONNECTED) { if (backend_protocol->state == MYSQL_CONNECTED) {
gw_read_backend_handshake(backend_protocol); gw_read_backend_handshake(backend_protocol);
@ -133,7 +138,8 @@ static int gw_read_backend_event(DCB *dcb) {
return 1; return 1;
} }
// ready to check the authentication reply /* ready to check the authentication reply from backend */
if (backend_protocol->state == MYSQL_AUTH_RECV) { if (backend_protocol->state == MYSQL_AUTH_RECV) {
ROUTER_OBJECT *router = NULL; ROUTER_OBJECT *router = NULL;
ROUTER *router_instance = NULL; ROUTER *router_instance = NULL;
@ -147,11 +153,12 @@ static int gw_read_backend_event(DCB *dcb) {
rsession = session->router_session; rsession = session->router_session;
} }
/* read backed auth reply */
rv = gw_receive_backend_auth(backend_protocol); rv = gw_receive_backend_auth(backend_protocol);
switch (rv) { switch (rv) {
case MYSQL_FAILED_AUTHENTICATION: case MYSQL_FAILED_AUTHENTICATION:
fprintf(stderr, ">>>> Backend Auth failed for %i\n", dcb->fd); fprintf(stderr, ">>>> Backend Auth failed for user [%s], fd %i\n", current_session->user, dcb->fd);
backend_protocol->state = MYSQL_AUTH_FAILED; backend_protocol->state = MYSQL_AUTH_FAILED;
@ -215,17 +222,11 @@ static int gw_read_backend_event(DCB *dcb) {
static int gw_write_backend_event(DCB *dcb) { static int gw_write_backend_event(DCB *dcb) {
MySQLProtocol *backend_protocol = dcb->protocol; MySQLProtocol *backend_protocol = dcb->protocol;
fprintf(stderr, ">>> backend EPOLLOUT %i, protocol state [%s]\n", backend_protocol->fd, gw_mysql_protocol_state2string(backend_protocol->state)); //fprintf(stderr, ">>> backend EPOLLOUT %i, protocol state [%s]\n", backend_protocol->fd, gw_mysql_protocol_state2string(backend_protocol->state));
if (backend_protocol->state == MYSQL_AUTH_FAILED) {
fprintf(stderr, ">>> Backend epollout auth failed, EXIT\n");
return 0;
}
// spinlock_acquire(&dcb->connectlock); // spinlock_acquire(&dcb->connectlock);
if (backend_protocol->state == MYSQL_PENDING_CONNECT) { if (backend_protocol->state == MYSQL_PENDING_CONNECT) {
//fprintf(stderr, ">>>> Now the backend %i is CONNECTED\n", backend_protocol->fd);
backend_protocol->state = MYSQL_CONNECTED; backend_protocol->state = MYSQL_CONNECTED;
// spinlock_release(&dcb->connectlock); // spinlock_release(&dcb->connectlock);
@ -250,15 +251,11 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
{ {
MySQLProtocol *backend_protocol = dcb->protocol; MySQLProtocol *backend_protocol = dcb->protocol;
if (backend_protocol->state == MYSQL_AUTH_FAILED) {
fprintf(stderr, ">>> backend %i auth failed, EXIT\n", dcb->fd);
dcb_close(dcb);
return 0;
}
spinlock_acquire(&dcb->authlock); spinlock_acquire(&dcb->authlock);
// put incoming data to the delay queue unless backend is connected with auth ok /**
* Now put the incoming data to the delay queue unless backend is connected with auth ok
*/
if (backend_protocol->state != MYSQL_IDLE) { if (backend_protocol->state != MYSQL_IDLE) {
//fprintf(stderr, ">>> Writing in the backend %i delay queue\n", dcb->fd); //fprintf(stderr, ">>> Writing in the backend %i delay queue\n", dcb->fd);
@ -269,7 +266,6 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
spinlock_release(&dcb->authlock); spinlock_release(&dcb->authlock);
// Normal flow of backend write;
return dcb_write(dcb, queue); return dcb_write(dcb, queue);
} }
@ -279,7 +275,7 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
*/ */
static int gw_error_backend_event(DCB *dcb) { static int gw_error_backend_event(DCB *dcb) {
fprintf(stderr, "#### Handle Backend error function for %i\n", dcb->fd); fprintf(stderr, ">>> Handle Backend error function for %i\n", dcb->fd);
dcb_close(dcb); dcb_close(dcb);
@ -287,13 +283,9 @@ static int gw_error_backend_event(DCB *dcb) {
} }
/* /*
* Create a new ackend connection. * Create a new backend connection.
* *
* This routine will connect to a backend server * This routine will connect to a backend server and it is called by dbc_connect in router->newSession
*
* - backend dcb allocation
* - MySQL session data fetch
* - backend connection using data in MySQL session
* *
* @param backend The Backend DCB allocated from dcb_connect * @param backend The Backend DCB allocated from dcb_connect
* @param server The selected server to connect to * @param server The selected server to connect to
@ -313,13 +305,15 @@ static int gw_create_backend_connection(DCB *backend, SERVER *server, SESSION *s
backend->protocol = protocol; backend->protocol = protocol;
// put the backend dcb in the protocol struct /* put the backend dcb in the protocol struct */
protocol->descriptor = backend; protocol->descriptor = backend;
s_data = (MYSQL_session *)session->client->data; s_data = (MYSQL_session *)session->client->data;
// let's try to connecte to a backend server, only connect sys call /**
// The socket descriptor is in Non Blocking status, this is set in the function * let's try to connect to a backend server, only connect sys call
* The socket descriptor is in Non Blocking status, this is set in the function
*/
rv = gw_do_connect_to_backend(server->name, server->port, protocol); rv = gw_do_connect_to_backend(server->name, server->port, protocol);
// we could also move later, this in to the gw_do_connect_to_backend using protocol->descriptor // we could also move later, this in to the gw_do_connect_to_backend using protocol->descriptor
@ -329,13 +323,13 @@ static int gw_create_backend_connection(DCB *backend, SERVER *server, SESSION *s
switch (rv) { switch (rv) {
case 0: case 0:
fprintf(stderr, "Connected to backend mysql server: fd is %i\n", backend->fd); //fprintf(stderr, "Connected to backend mysql server: fd is %i\n", backend->fd);
protocol->state = MYSQL_CONNECTED; protocol->state = MYSQL_CONNECTED;
break; break;
case 1: case 1:
fprintf(stderr, ">>> Connection is PENDING to backend mysql server: fd is %i\n", backend->fd); //fprintf(stderr, ">>> Connection is PENDING to backend mysql server: fd is %i\n", backend->fd);
protocol->state = MYSQL_PENDING_CONNECT; protocol->state = MYSQL_PENDING_CONNECT;
break; break;

View File

@ -812,7 +812,7 @@ int gw_read_client_event(DCB* dcb) {
if(!rsession) { if(!rsession) {
if (mysql_command == '\x01') { if (mysql_command == '\x01') {
/* COM_QUIT handling */ /* COM_QUIT handling */
fprintf(stderr, "COM_QUIT received with no connected backends from %i\n", dcb->fd); //fprintf(stderr, "COM_QUIT received with no connected backends from %i\n", dcb->fd);
(dcb->func).close(dcb); (dcb->func).close(dcb);
return 1; return 1;
@ -830,10 +830,10 @@ int gw_read_client_event(DCB* dcb) {
/* COM_QUIT handling */ /* COM_QUIT handling */
if (mysql_command == '\x01') { if (mysql_command == '\x01') {
fprintf(stderr, "COM_QUIT received for %i\n", dcb->fd); //fprintf(stderr, "COM_QUIT received from %i and passed to backed\n", dcb->fd);
/* this will propagate COM_QUIT to backend(s) */ /* this will propagate COM_QUIT to backend(s) */
fprintf(stderr, "<<< Routing the COM_QUIT ...\n"); //fprintf(stderr, "<<< Routing the COM_QUIT ...\n");
router->routeQuery(router_instance, rsession, queue); router->routeQuery(router_instance, rsession, queue);
/* close client connection */ /* close client connection */
@ -848,7 +848,7 @@ int gw_read_client_event(DCB* dcb) {
/* writing in the backend buffer queue, via routeQuery */ /* writing in the backend buffer queue, via routeQuery */
fprintf(stderr, "<<< Routing the Query ...\n"); //fprintf(stderr, "<<< Routing the Query ...\n");
router->routeQuery(router_instance, rsession, queue); router->routeQuery(router_instance, rsession, queue);
protocol->state = MYSQL_WAITING_RESULT; protocol->state = MYSQL_WAITING_RESULT;
@ -1057,7 +1057,8 @@ int gw_MySQLAccept(DCB *listener) {
/* /*
*/ */
static int gw_error_client_event(DCB *dcb) { static int gw_error_client_event(DCB *dcb) {
fprintf(stderr, "#### Handle error function gw_error_client_event, for [%i] is [%s]\n", dcb->fd, gw_dcb_state2string(dcb->state)); //fprintf(stderr, "#### Handle error function gw_error_client_event, for [%i] is [%s]\n", dcb->fd, gw_dcb_state2string(dcb->state));
//dcb_close(dcb);
return 1; return 1;
} }

View File

@ -450,28 +450,30 @@ int gw_do_connect_to_backend(char *host, int port, MySQLProtocol *conn) {
if (so < 0) { if (so < 0) {
fprintf(stderr, "Error creating backend socket: [%s] %i\n", strerror(errno), errno); fprintf(stderr, "Error creating backend socket: [%s] %i\n", strerror(errno), errno);
// this is an error /* this is an error */
return -1; return -1;
} }
setipaddress(&serv_addr.sin_addr, host); setipaddress(&serv_addr.sin_addr, host);
serv_addr.sin_port = htons(port); serv_addr.sin_port = htons(port);
/* set NON BLOCKING here */
setnonblocking(so); setnonblocking(so);
if ((rv = connect(so, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0) { if ((rv = connect(so, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0) {
// If connection is not yet completed just return 1 /* If connection is not yet completed just return 1 */
if (errno == EINPROGRESS) { if (errno == EINPROGRESS) {
fprintf(stderr, ">>> Connection is not yet completed for backend server [%s:%i]: errno %i, %s: RV = [%i]\n", host, port, errno, strerror(errno), rv); //fprintf(stderr, ">>> Connection is not yet completed for backend server [%s:%i]: errno %i, %s: RV = [%i]\n", host, port, errno, strerror(errno), rv);
return 1; return 1;
} else { } else {
// this is a real error /* this is a real error */
fprintf(stderr, ">>> ERROR connecting to backend server [%s:%i]: errno %i, %s: RV = [%i]\n", host, port, errno, strerror(errno), rv); fprintf(stderr, ">>> ERROR connecting to backend server [%s:%i]: errno %i, %s: RV = [%i]\n", host, port, errno, strerror(errno), rv);
return -1; return -1;
} }
} }
// connection succesfully completed /* The connection succesfully completed now */
return 0; return 0;
} }