Close sessions in MaxScale core

The core now provides a simple function to close a session. This removes
the need for the modules to directly call the API entry points when the
session should be closed. It is also in line with the style that other
objects, namely the DCBs, use. This makes the new session_close very
similar to dcb_close.
This commit is contained in:
Markus Mäkelä
2017-03-13 22:56:18 +02:00
parent 29be8436e5
commit 7b3c287ac3
5 changed files with 50 additions and 90 deletions

View File

@ -1112,46 +1112,31 @@ static int gw_backend_hangup(DCB *dcb)
*/
static int gw_backend_close(DCB *dcb)
{
MXS_SESSION* session;
GWBUF* quitbuf;
CHK_DCB(dcb);
session = dcb->session;
MXS_DEBUG("%lu [gw_backend_close]", pthread_self());
quitbuf = mysql_create_com_quit(NULL, 0);
gwbuf_set_type(quitbuf, GWBUF_TYPE_MYSQL);
ss_dassert(dcb->session);
/** Send COM_QUIT to the backend being closed */
GWBUF* quitbuf = mysql_create_com_quit(NULL, 0);
gwbuf_set_type(quitbuf, GWBUF_TYPE_MYSQL);
mysql_send_com_quit(dcb, 0, quitbuf);
/** Free protocol data */
mysql_protocol_done(dcb);
if (session)
{
CHK_SESSION(session);
/**
* The lock is needed only to protect the read of session->state and
* session->client_dcb values. Client's state may change by other thread
* but client's close and adding client's DCB to zombies list is executed
* only if client's DCB's state does _not_ change in parallel.
*/
MXS_SESSION* session = dcb->session;
CHK_SESSION(session);
/**
* If session->state is STOPPING, start closing client session.
* Otherwise only this backend connection is closed.
*/
if (session->state == SESSION_STATE_STOPPING &&
session->client_dcb != NULL)
{
if (session->client_dcb->state == DCB_STATE_POLLING)
{
/** Close client DCB */
dcb_close(session->client_dcb);
}
}
/**
* If session state is SESSION_STATE_STOPPING, start closing client session.
* Otherwise only this backend connection is closed.
*/
if (session->client_dcb &&
session->state == SESSION_STATE_STOPPING &&
session->client_dcb->state == DCB_STATE_POLLING)
{
dcb_close(session->client_dcb);
}
return 1;
}

View File

@ -1347,52 +1347,12 @@ retblock:
return 1;
}
static int
gw_client_close(DCB *dcb)
static int gw_client_close(DCB *dcb)
{
MXS_SESSION* session;
MXS_ROUTER_OBJECT* router;
void* router_instance;
#if defined(SS_DEBUG)
MySQLProtocol* protocol = (MySQLProtocol *)dcb->protocol;
if (dcb->state == DCB_STATE_POLLING ||
dcb->state == DCB_STATE_NOPOLLING ||
dcb->state == DCB_STATE_ZOMBIE)
{
if (!DCB_IS_CLONE(dcb))
{
CHK_PROTOCOL(protocol);
}
}
#endif
MXS_DEBUG("%lu [gw_client_close]", pthread_self());
CHK_DCB(dcb);
ss_dassert(dcb->protocol);
mysql_protocol_done(dcb);
session = dcb->session;
/**
* session may be NULL if session_alloc failed.
* In that case, router session wasn't created.
*/
if (session != NULL && SESSION_STATE_DUMMY != session->state)
{
CHK_SESSION(session);
if (session->state != SESSION_STATE_STOPPING)
{
session->state = SESSION_STATE_STOPPING;
}
router_instance = session->service->router_instance;
router = session->service->router;
/**
* If router session is being created concurrently router
* session might be NULL and it shouldn't be closed.
*/
if (session->router_session != NULL)
{
/** Close router session and all its connections */
router->closeSession(router_instance, session->router_session);
}
}
session_close(dcb->session);
return 1;
}