dcb.c, gateway.c little tuning.

poll.c
	Removed mutex from epoll_wait.
	Removed read and write mutexes from poll_waitevents.

session.c
	If session_alloc fails, instead of calling directly free(session), call session_free, which decreases refcounter and only frees session when there are no references left. 
	Added session_unlink_dcb function which removes link from session and optionally sets the dcb->session pointer to NULL.

readconnection.h, readwritesplit.h
	Added check fields to ROUTER_CLIENT_SES strct as well as lock, version number (not used yet) and closed flag.

mysql_backend.c
	gw_read_backend_event: if backend_protocol->state was set to MYSQL_AUTH_RECV, function returned, which was unnecessary. If mysql state became MYSQL_AUTH_FAILED, router client session was closed. Removed unnecessary NULL checks because rsession is not allowed to be NULL. Similarly, removed other NULL checks and replaced them with asserts checking that router client session is not NULL at any phase.

mysql_client.c
	Removed unused code blocks. Polished log commands. Replaced router client sessions NULL checks with asserts.

mysql_common.c
	mysql_send_custom_error: if called with dcb == NULL, return.

readconnroute.c
	Replaced malloc with calloc. Added functions rses_begin_router_action and rses_exit_router_action. If router client session is not closed, they take a lock and release it, respectively. Those functions are used for protecting all operations which modify the contents of router client session struct.

readwritesplit.c
	Identical changes than in readconnroute.c

skygw_debug.h
	Added check number and - macro for ROUTER_CLIENT_SES, and added COM_QUIT to STRPACKETTYPE.
This commit is contained in:
vraatikka
2013-10-30 22:07:51 +02:00
parent 5e6b0a3b1a
commit e803acb036
12 changed files with 623 additions and 359 deletions

View File

@ -226,11 +226,11 @@ dcb_final_free(DCB *dcb)
ss_info_dassert(dcb->state == DCB_STATE_DISCONNECTED,
"dcb not in DCB_STATE_DISCONNECTED state.");
/* First remove this DCB from the chain */
/** First remove this DCB from the chain */
spinlock_acquire(&dcbspin);
if (allDCBs == dcb)
{
/*
/**
* Deal with the special case of removing the DCB at the head of
* the chain.
*/
@ -238,7 +238,7 @@ dcb_final_free(DCB *dcb)
}
else
{
/*
/**
* We find the DCB that point to the one we are removing and then
* set the next pointer of that DCB to the next pointer of the
* DCB we are removing.
@ -255,15 +255,16 @@ dcb_final_free(DCB *dcb)
/**
* Terminate client session.
*/
{
SESSION *local_session = dcb->session;
{
SESSION *local_session = dcb->session;
CHK_SESSION(local_session);
/**
* Remove reference from session if dcb is client.
*/
if (local_session->client == dcb) {
local_session->client = NULL;
}
dcb->session = NULL;
dcb->session = NULL;
session_free(local_session);
}
}
@ -431,6 +432,7 @@ int rc;
{
return NULL;
}
if ((funcs = (GWPROTOCOL *)load_module(protocol,
MODULE_PROTOCOL)) == NULL)
{
@ -446,6 +448,9 @@ 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))
{
skygw_log_write(
@ -459,10 +464,11 @@ int rc;
fd = dcb->func.connect(dcb, server, session);
if (fd == -1) {
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Failed to connect to server %s:%d, "
skygw_log_write(
LOGFILE_TRACE,
"%lu [dcb_connect] Failed to connect to server %s:%d, "
"from backend dcb %p, client dcp %p fd %d.",
pthread_self(),
server->name,
server->port,
dcb,
@ -489,12 +495,6 @@ int rc;
*/
dcb->fd = fd;
/*
* The dcb will be addded into poll set by dcb->func.connect
*/
atomic_add(&server->stats.n_connections, 1);
atomic_add(&server->stats.n_current, 1);
/**
* backend_dcb is connected to backend server, and once backend_dcb
* is added to poll set, authentication takes place as part of
@ -512,6 +512,11 @@ 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);
atomic_add(&server->stats.n_current, 1);
return dcb;
}