Move decrement of server connections into zombie processing; introduce dcb_close_finish to be called either in dcb_close or when persistent dcb is discarded.

This commit is contained in:
counterpoint
2015-06-09 11:41:43 +01:00
parent 99e9987f9b
commit d0e92a15f8
4 changed files with 46 additions and 65 deletions

View File

@ -94,6 +94,7 @@ static int dcb_null_write(DCB *dcb, GWBUF *buf);
static int dcb_null_close(DCB *dcb); static int dcb_null_close(DCB *dcb);
static int dcb_null_auth(DCB *dcb, SERVER *server, SESSION *session, GWBUF *buf); static int dcb_null_auth(DCB *dcb, SERVER *server, SESSION *session, GWBUF *buf);
static int dcb_isvalid_nolock(DCB *dcb); static int dcb_isvalid_nolock(DCB *dcb);
static void dcb_close_finish(DCB *);
size_t dcb_get_session_id( size_t dcb_get_session_id(
DCB* dcb) DCB* dcb)
@ -570,6 +571,7 @@ bool succp = false;
* Close file descriptor and move to clean-up phase. * Close file descriptor and move to clean-up phase.
*/ */
rc = close(dcb->fd); rc = close(dcb->fd);
if (dcb->server) atomic_add(&dcb->server->stats.n_persistent, -1);
if (rc < 0) if (rc < 0)
{ {
@ -1268,8 +1270,6 @@ int above_water;
void void
dcb_close(DCB *dcb) dcb_close(DCB *dcb)
{ {
int rc = 0;
CHK_DCB(dcb); CHK_DCB(dcb);
LOGIF(LD, (skygw_log_write(LOGFILE_DEBUG, LOGIF(LD, (skygw_log_write(LOGFILE_DEBUG,
@ -1296,8 +1296,7 @@ dcb_close(DCB *dcb)
*/ */
if (dcb->state == DCB_STATE_POLLING) if (dcb->state == DCB_STATE_POLLING)
{ {
rc = poll_remove_dcb(dcb); if (poll_remove_dcb(dcb))
if (rc)
{ {
LOGIF(LE, (skygw_log_write( LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR, LOGFILE_ERROR,
@ -1315,12 +1314,10 @@ dcb_close(DCB *dcb)
pthread_self(), pthread_self(),
dcb, dcb,
STRDCBSTATE(dcb->state)))); STRDCBSTATE(dcb->state))));
}
char *user; char *user;
user = session_getUser(dcb->session); user = session_getUser(dcb->session);
if (0 == rc if (user
&& user
&& strlen(user) && strlen(user)
&& dcb->server && dcb->server
&& dcb->server->persistpoolmax && dcb->server->persistpoolmax
@ -1334,44 +1331,10 @@ dcb_close(DCB *dcb)
dcb->session = NULL; dcb->session = NULL;
spinlock_release(&dcb->server->persistlock); spinlock_release(&dcb->server->persistlock);
atomic_add(&dcb->server->stats.n_persistent, 1); atomic_add(&dcb->server->stats.n_persistent, 1);
/* Because we're not going to close the connection, need to do */
/* the session closedown processing here */
if (dcb->session)
{
spinlock_acquire(&dcb->session->ses_lock);
/**
* If session->state is STOPPING, start closing client session.
* Otherwise only this backend connection is closed.
*/
if (dcb->session->state == SESSION_STATE_STOPPING &&
dcb->session->client != NULL &&
dcb->session->client->state == DCB_STATE_POLLING)
{
spinlock_release(&dcb->session->ses_lock);
/** Close client DCB */
dcb_close(dcb->session->client);
} }
else else
{ {
spinlock_release(&dcb->session->ses_lock); dcb_close_finish(dcb);
}
}
}
else if (!rc)
{
/**
* close protocol and router session
*/
if (dcb->func.close != NULL)
{
dcb->func.close(dcb);
}
/** Call possible callback for this DCB in case of close */
dcb_call_callback(dcb, DCB_REASON_CLOSE);
if (dcb->state == DCB_STATE_NOPOLLING)
{
dcb_add_to_zombieslist(dcb);
} }
} }
ss_dassert(dcb->state == DCB_STATE_NOPOLLING || ss_dassert(dcb->state == DCB_STATE_NOPOLLING ||
@ -1379,6 +1342,29 @@ dcb_close(DCB *dcb)
} }
} }
/**
* Final calls for DCB close
*
* @param dcb The DCB to print
*
*/
static void
dcb_close_finish(DCB *dcb)
{
/**
* check persistent list, close protocol and router session
*/
if (dcb->server && dcb->server->persistent) CHK_DCB(dcb->server->persistent);
if (dcb->func.close)
{
dcb->func.close(dcb);
}
/** Call possible callback for this DCB in case of close */
dcb_call_callback(dcb, DCB_REASON_CLOSE);
/** Must be DCB_STATE_NOPOLLING when this function is called */
dcb_add_to_zombieslist(dcb);
}
/** /**
* Diagnostic to print a DCB * Diagnostic to print a DCB
* *
@ -2330,9 +2316,7 @@ dcb_persistent_clean_count(DCB *dcb, bool cleanall)
server->persistent = persistentdcb->nextpersistent; server->persistent = persistentdcb->nextpersistent;
} }
/** Call possible callback for this DCB in case of close */ /** Call possible callback for this DCB in case of close */
dcb_call_callback(persistentdcb, DCB_REASON_CLOSE); dcb_close_finish(persistentdcb);
dcb_add_to_zombieslist(persistentdcb);
atomic_add(&server->stats.n_persistent, -1);
} }
else else
{ {

View File

@ -657,7 +657,6 @@ DCB* backend_dcb;
if (rses_begin_locked_router_action(router_cli_ses)) if (rses_begin_locked_router_action(router_cli_ses))
{ {
/* decrease server current connection counter */ /* decrease server current connection counter */
atomic_add(&router_cli_ses->backend->server->stats.n_current, -1);
backend_dcb = router_cli_ses->backend_dcb; backend_dcb = router_cli_ses->backend_dcb;
router_cli_ses->backend_dcb = NULL; router_cli_ses->backend_dcb = NULL;

View File

@ -1022,7 +1022,6 @@ static void closeSession(
*/ */
dcb_close(dcb); dcb_close(dcb);
/** decrease server current connection counters */ /** decrease server current connection counters */
atomic_add(&bref->bref_backend->backend_server->stats.n_current, -1);
atomic_add(&bref->bref_backend->backend_conn_count, -1); atomic_add(&bref->bref_backend->backend_conn_count, -1);
} }
} }

View File

@ -1153,7 +1153,6 @@ static void closeSession(
*/ */
dcb_close(dcb); dcb_close(dcb);
/** decrease server current connection counters */ /** decrease server current connection counters */
atomic_add(&bref->bref_backend->backend_server->stats.n_current, -1);
atomic_add(&bref->bref_backend->backend_conn_count, -1); atomic_add(&bref->bref_backend->backend_conn_count, -1);
} }
} }