From c33f1199d9ab71b025db63a1ca3a317b78c910c3 Mon Sep 17 00:00:00 2001 From: counterpoint Date: Tue, 21 Jul 2015 09:53:52 +0100 Subject: [PATCH] Fix lack of declaration for session_unlink_dcb; restructure dcb closedown logic to fix counting problem and reduce code. --- server/core/dcb.c | 52 +++++++++++++++++----------------------- server/include/session.h | 1 + 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/server/core/dcb.c b/server/core/dcb.c index 375293988..d49b68657 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -1836,27 +1836,7 @@ dcb_close(DCB *dcb) if ((dcb->state == DCB_STATE_POLLING && !dcb_maybe_add_persistent(dcb)) || (dcb->state == DCB_STATE_LISTENING)) { - poll_remove_dcb(dcb); - /* - * Return will always be 0 or function will have crashed, so we - * threw away return value. - */ - LOGIF(LD, (skygw_log_write( - LOGFILE_DEBUG, - "%lu [dcb_close] Removed dcb %p in state %s from " - "poll set.", - pthread_self(), - dcb, - STRDCBSTATE(dcb->state)))); - /** - * 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); + dcb_close_finish(dcb); } } @@ -1940,22 +1920,34 @@ dcb_maybe_add_persistent(DCB *dcb) static void dcb_close_finish(DCB *dcb) { - /** - * check persistent list, close protocol and router session + poll_remove_dcb(dcb); + /* + * Return will always be 0 or function will have crashed, so we + * threw away return value. + */ + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG," + "%lu [dcb_close] Removed dcb %p in state %s from poll set.", + pthread_self(), + dcb, + STRDCBSTATE(dcb->state)))); + /** + * Do a consistency check, then adjust counter if not from persistent pool */ - if (dcb->func.close) - { - dcb->func.close(dcb); - } if (dcb->server) { if (dcb->server->persistent) CHK_DCB(dcb->server->persistent); if (0 == dcb->persistentstart) atomic_add(&dcb->server->stats.n_current, -1); } + /** + * 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); - /** Must be DCB_STATE_NOPOLLING when this function is called */ - dcb_close(dcb); } /** @@ -2847,8 +2839,8 @@ dcb_persistent_clean_count(DCB *dcb, bool cleanall) while (disposals) { nextdcb = disposals->nextpersistent; - poll_remove_dcb(disposals); dcb_close_finish(disposals); + dcb_close(disposals); disposals = nextdcb; } } diff --git a/server/include/session.h b/server/include/session.h index 908277e41..7a9381507 100644 --- a/server/include/session.h +++ b/server/include/session.h @@ -174,6 +174,7 @@ void dprintSession(struct dcb *, SESSION *); void dListSessions(struct dcb *); char *session_state(int); bool session_link_dcb(SESSION *, struct dcb *); +int session_unlink_dcb(SESSION*, DCB*); SESSION* get_session_by_router_ses(void* rses); void session_enable_log(SESSION* ses, logfile_id_t id); void session_disable_log(SESSION* ses, logfile_id_t id);