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