Added session refcount in session.h
The refcount is incremented in dcb_connect and in mysql_client.c after session_alloc
This commit is contained in:
@ -39,7 +39,8 @@
|
|||||||
* for handling backend asynchronous protocol connection
|
* for handling backend asynchronous protocol connection
|
||||||
* and a generic lock for backend authentication
|
* and a generic lock for backend authentication
|
||||||
* 16/07/2013 Massimiliano Pinto Added command type for dcb
|
* 16/07/2013 Massimiliano Pinto Added command type for dcb
|
||||||
* 23/07/13 Mark Riddoch Tidy up logging
|
* 23/07/2013 Mark Riddoch Tidy up logging
|
||||||
|
* 02/09/2013 Massimiliano Pinto Added session refcount
|
||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
@ -314,6 +315,8 @@ GWPROTOCOL *funcs;
|
|||||||
memcpy(&(dcb->func), funcs, sizeof(GWPROTOCOL));
|
memcpy(&(dcb->func), funcs, sizeof(GWPROTOCOL));
|
||||||
dcb->session = session;
|
dcb->session = session;
|
||||||
|
|
||||||
|
atomic_add(&dcb->session->refcount, 1);
|
||||||
|
|
||||||
if ((dcb->fd = dcb->func.connect(dcb, server, session)) == -1)
|
if ((dcb->fd = dcb->func.connect(dcb, server, session)) == -1)
|
||||||
{
|
{
|
||||||
dcb_final_free(dcb);
|
dcb_final_free(dcb);
|
||||||
@ -646,6 +649,8 @@ dcb_close(DCB *dcb)
|
|||||||
pthread_self());
|
pthread_self());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (dcb->session) {
|
||||||
session_free(dcb->session);
|
session_free(dcb->session);
|
||||||
skygw_log_write_flush(
|
skygw_log_write_flush(
|
||||||
LOGFILE_TRACE,
|
LOGFILE_TRACE,
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
*
|
*
|
||||||
* Date Who Description
|
* Date Who Description
|
||||||
* 17/06/13 Mark Riddoch Initial implementation
|
* 17/06/13 Mark Riddoch Initial implementation
|
||||||
|
* 02/09/13 Massimiliano Pinto Added session refcounter
|
||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
@ -75,6 +76,9 @@ session_alloc(SERVICE *service, DCB *client)
|
|||||||
strerror(eno));
|
strerror(eno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session->refcount = 0;
|
||||||
|
|
||||||
session->ses_chk_top = CHK_NUM_SESSION;
|
session->ses_chk_top = CHK_NUM_SESSION;
|
||||||
session->ses_chk_tail = CHK_NUM_SESSION;
|
session->ses_chk_tail = CHK_NUM_SESSION;
|
||||||
spinlock_init(&session->ses_lock);
|
spinlock_init(&session->ses_lock);
|
||||||
@ -149,8 +153,12 @@ SESSION *ptr;
|
|||||||
}
|
}
|
||||||
spinlock_release(&session_spin);
|
spinlock_release(&session_spin);
|
||||||
atomic_add(&session->service->stats.n_current, -1);
|
atomic_add(&session->service->stats.n_current, -1);
|
||||||
|
|
||||||
/* Clean up session and free the memory */
|
/* Clean up session and free the memory */
|
||||||
|
if (atomic_add(&session->refcount, -1) == 1)
|
||||||
|
{
|
||||||
free(session);
|
free(session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -29,7 +29,9 @@
|
|||||||
* 14-06-2013 Massimiliano Pinto Added void *data to session
|
* 14-06-2013 Massimiliano Pinto Added void *data to session
|
||||||
* for session specific data
|
* for session specific data
|
||||||
* 01-07-2013 Massimiliano Pinto Removed backends pointer
|
* 01-07-2013 Massimiliano Pinto Removed backends pointer
|
||||||
from struct session
|
* from struct session
|
||||||
|
* 02-09-2013 Massimiliano Pinto Added session ref counter
|
||||||
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -81,6 +83,7 @@ typedef struct session {
|
|||||||
struct service *service; /**< The service this session is using */
|
struct service *service; /**< The service this session is using */
|
||||||
struct session *next; /**< Linked list of all sessions */
|
struct session *next; /**< Linked list of all sessions */
|
||||||
skygw_chk_t ses_chk_tail;
|
skygw_chk_t ses_chk_tail;
|
||||||
|
int refcount; /**< Reference count on the session */
|
||||||
} SESSION;
|
} SESSION;
|
||||||
|
|
||||||
#define SESSION_PROTOCOL(x, type) DCB_PROTOCOL((x)->client, type)
|
#define SESSION_PROTOCOL(x, type) DCB_PROTOCOL((x)->client, type)
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
* 14/06/2013 Mark Riddoch Initial version
|
* 14/06/2013 Mark Riddoch Initial version
|
||||||
* 17/06/2013 Massimiliano Pinto Added Client To Gateway routines
|
* 17/06/2013 Massimiliano Pinto Added Client To Gateway routines
|
||||||
* 24/06/2013 Massimiliano Pinto Added: fetch passwords from service users' hashtable
|
* 24/06/2013 Massimiliano Pinto Added: fetch passwords from service users' hashtable
|
||||||
|
* 02/09/2013 Massimiliano Pinto Added: session refcount
|
||||||
*/
|
*/
|
||||||
#include <skygw_utils.h>
|
#include <skygw_utils.h>
|
||||||
#include <log_manager.h>
|
#include <log_manager.h>
|
||||||
@ -587,6 +588,7 @@ int gw_read_client_event(DCB* dcb) {
|
|||||||
//write to client mysql AUTH_OK packet, packet n. is 2
|
//write to client mysql AUTH_OK packet, packet n. is 2
|
||||||
// start a new session, and connect to backends
|
// start a new session, and connect to backends
|
||||||
session = session_alloc(dcb->service, dcb);
|
session = session_alloc(dcb->service, dcb);
|
||||||
|
atomic_add(&dcb->session->refcount, 1);
|
||||||
CHK_SESSION(session);
|
CHK_SESSION(session);
|
||||||
ss_dassert(session->state != SESSION_STATE_ALLOC);
|
ss_dassert(session->state != SESSION_STATE_ALLOC);
|
||||||
protocol->state = MYSQL_IDLE;
|
protocol->state = MYSQL_IDLE;
|
||||||
|
|||||||
Reference in New Issue
Block a user