From 7a144079b9a38e016bc7ca1fd6bc6ddfec935b52 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 8 Sep 2016 15:56:48 +0300 Subject: [PATCH] MXS-812: Fix active operation counters When a client executes commands which do not return results (for example inserting BLOB data via the C API), readwritesplit expects a result for each sent packet. This is a somewhat of a false assumption but it clears itself out when the session is closed normally. If the session is closed due to an error, the counter is not decremented. Each sesssion should only increase the number of active operation on a server by one operation. By checking that the session is not already executing an operation before incrementing the active operation count the runtime operation count will be correct. --- .../routing/readwritesplit/readwritesplit.c | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 0c980a631..f6a60f788 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -942,7 +942,7 @@ static void closeSession(ROUTER *instance, void *router_session) } #endif /** Clean operation counter in bref and in SERVER */ - while (BREF_IS_WAITING_RESULT(bref)) + if (BREF_IS_WAITING_RESULT(bref)) { bref_clear_state(bref, BREF_WAITING_RESULT); } @@ -955,6 +955,10 @@ static void closeSession(ROUTER *instance, void *router_session) /** decrease server current connection counters */ atomic_add(&bref->bref_backend->backend_conn_count, -1); } + else + { + ss_dassert(!BREF_IS_WAITING_RESULT(bref)); + } } /** Unlock */ rses_end_locked_router_action(router_cli_ses); @@ -2796,11 +2800,8 @@ static void bref_clear_state(backend_ref_t *bref, bref_state_t state) MXS_ERROR("[%s] Error: NULL parameter.", __FUNCTION__); return; } - if (state != BREF_WAITING_RESULT) - { - bref->bref_state &= ~state; - } - else + + if ((state & BREF_WAITING_RESULT) && (bref->bref_state & BREF_WAITING_RESULT)) { int prev1; int prev2; @@ -2825,6 +2826,8 @@ static void bref_clear_state(backend_ref_t *bref, bref_state_t state) } } } + + bref->bref_state &= ~state; } static void bref_set_state(backend_ref_t *bref, bref_state_t state) @@ -2834,11 +2837,8 @@ static void bref_set_state(backend_ref_t *bref, bref_state_t state) MXS_ERROR("[%s] Error: NULL parameter.", __FUNCTION__); return; } - if (state != BREF_WAITING_RESULT) - { - bref->bref_state |= state; - } - else + + if ((state & BREF_WAITING_RESULT) && (bref->bref_state & BREF_WAITING_RESULT) == 0) { int prev1; int prev2; @@ -2864,6 +2864,8 @@ static void bref_set_state(backend_ref_t *bref, bref_state_t state) bref->bref_backend->backend_server->port); } } + + bref->bref_state |= state; } /**