In gw_create_backend_connection, replaced inlined protocol init with call to mysql_protocol_init (mysql_common.c). Replaced fprintfs with logging commands.
This commit is contained in:
@ -395,64 +395,99 @@ static int gw_error_backend_event(DCB *dcb) {
|
|||||||
/*
|
/*
|
||||||
* Create a new backend connection.
|
* Create a new backend connection.
|
||||||
*
|
*
|
||||||
* This routine will connect to a backend server and it is called by dbc_connect in router->newSession
|
* This routine will connect to a backend server and it is called by dbc_connect
|
||||||
|
* in router->newSession
|
||||||
*
|
*
|
||||||
* @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
|
||||||
* @param session The current session from Client DCB
|
* @param session The current session from Client DCB
|
||||||
* @return 0 on Success or 1 on Failure.
|
* @return 0 on Success or 1 on Failure.
|
||||||
*/
|
*/
|
||||||
|
static int gw_create_backend_connection(
|
||||||
static int gw_create_backend_connection(DCB *backend, SERVER *server, SESSION *session) {
|
DCB *backend_dcb,
|
||||||
MySQLProtocol *protocol = NULL;
|
SERVER *server,
|
||||||
|
SESSION *session)
|
||||||
|
{
|
||||||
MYSQL_session *s_data = NULL;
|
MYSQL_session *s_data = NULL;
|
||||||
|
MySQLProtocol *protocol = NULL;
|
||||||
int rv = -1;
|
int rv = -1;
|
||||||
|
int fd = -1;
|
||||||
|
bool succp;
|
||||||
|
|
||||||
protocol = (MySQLProtocol *) calloc(1, sizeof(MySQLProtocol));
|
succp = mysql_protocol_init(backend_dcb);
|
||||||
protocol->state = MYSQL_ALLOC;
|
|
||||||
protocol->protocol_chk_top = CHK_NUM_PROTOCOL;
|
|
||||||
protocol->protocol_chk_tail = CHK_NUM_PROTOCOL;
|
|
||||||
/* put the backend dcb in the protocol struct */
|
|
||||||
protocol->descriptor = backend;
|
|
||||||
backend->protocol = protocol;
|
|
||||||
|
|
||||||
|
if (!succp) {
|
||||||
|
skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"%lu [gw_create_backend_connection] Failed to establish "
|
||||||
|
"connection to back-end server.",
|
||||||
|
pthread_self());
|
||||||
|
goto return_fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
protocol = (MySQLProtocol *)backend_dcb->protocol;
|
||||||
s_data = (MYSQL_session *)session->client->data;
|
s_data = (MYSQL_session *)session->client->data;
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
||||||
memcpy(&backend->fd, &protocol->fd, sizeof(backend->fd));
|
* NOTE that protocol->fd can be -1 too. Not sure if it is necessary.
|
||||||
|
*/
|
||||||
|
backend_dcb->fd = protocol->fd;
|
||||||
|
fd = backend_dcb->fd;
|
||||||
|
|
||||||
switch (rv) {
|
switch (rv) {
|
||||||
case 0:
|
case 0:
|
||||||
//fprintf(stderr, "Connected to backend mysql server: fd is %i\n", backend->fd);
|
ss_dassert(backend_dcb->fd > 0);
|
||||||
protocol->state = MYSQL_CONNECTED;
|
protocol->state = MYSQL_CONNECTED;
|
||||||
|
skygw_log_write(
|
||||||
|
LOGFILE_TRACE,
|
||||||
|
"%lu [gw_create_backend_connection] Established "
|
||||||
|
"connection to %s:%i, backend fd %d client fd %d.",
|
||||||
|
pthread_self(),
|
||||||
|
server->name,
|
||||||
|
server->port,
|
||||||
|
backend_dcb->fd,
|
||||||
|
session->client->fd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
//fprintf(stderr, ">>> Connection is PENDING to backend mysql server: fd is %i\n", backend->fd);
|
ss_dassert(backend_dcb->fd > 0);
|
||||||
protocol->state = MYSQL_PENDING_CONNECT;
|
protocol->state = MYSQL_PENDING_CONNECT;
|
||||||
|
skygw_log_write(
|
||||||
|
LOGFILE_TRACE,
|
||||||
|
"%lu [gw_create_backend_connection] Connection "
|
||||||
|
"pending to %s:%i, backend fd %d client fd %d.",
|
||||||
|
pthread_self(),
|
||||||
|
server->name,
|
||||||
|
server->port,
|
||||||
|
backend_dcb->fd,
|
||||||
|
session->client->fd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, ">>> ERROR: NOT Connected to the backend mysql server!!!\n");
|
ss_dassert(backend_dcb->fd == -1);
|
||||||
backend->fd = -1;
|
ss_dassert(protocol->state == MYSQL_ALLOC);
|
||||||
|
skygw_log_write(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"%lu [gw_create_backend_connection] Connection "
|
||||||
|
"failed to %s:%i, backend fd %d client fd %d.",
|
||||||
|
pthread_self(),
|
||||||
|
server->name,
|
||||||
|
server->port,
|
||||||
|
backend_dcb->fd,
|
||||||
|
session->client->fd);
|
||||||
break;
|
break;
|
||||||
}
|
} /**< switch */
|
||||||
|
|
||||||
if (backend->fd > 0) {
|
backend_dcb->state = DCB_STATE_POLLING;
|
||||||
fprintf(stderr, ">>> Backend [%s:%i] added [%i], in the client session [%i]\n", server->name, server->port, backend->fd, session->client->fd);
|
return_fd:
|
||||||
}
|
ss_dassert(backend_dcb->fd == fd);
|
||||||
|
ss_dassert(backend_dcb->fd == protocol->fd);
|
||||||
backend->state = DCB_STATE_POLLING;
|
return fd;
|
||||||
return backend->fd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hangup routine the backend dcb: it does nothing right now
|
* Hangup routine the backend dcb: it does nothing right now
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user