MXS-2710: Move client_count handling inside Session
By incrementing the counters when the session is created, we know that the counter will always be decremented correctly. This does cause the listener session to be counted as an actual session but this is already present in the statistics calculations and is something we have to live with in 2.3 This change also makes it possible to overshoot the connection count limitation as the session creation is delayed until authentication fails. Both of these problems are fixed in 2.4.
This commit is contained in:
@ -361,18 +361,7 @@ private:
|
||||
static void session_free(MXS_SESSION* session)
|
||||
{
|
||||
MXS_INFO("Stopped %s client session [%" PRIu64 "]", session->service->name, session->ses_id);
|
||||
Service* service = static_cast<Service*>(session->service);
|
||||
|
||||
session_final_free(session);
|
||||
bool should_destroy = !mxb::atomic::load(&service->active);
|
||||
|
||||
if (mxb::atomic::add(&service->client_count, -1) == 1 && should_destroy)
|
||||
{
|
||||
// Destroy the service in the main routing worker thread
|
||||
mxs::RoutingWorker* main_worker = mxs::RoutingWorker::get(mxs::RoutingWorker::MAIN);
|
||||
main_worker->execute(std::unique_ptr<ServiceDestroyTask>(new ServiceDestroyTask(service)),
|
||||
Worker::EXECUTE_AUTO);
|
||||
}
|
||||
}
|
||||
|
||||
static void session_final_free(MXS_SESSION* ses)
|
||||
@ -1264,6 +1253,7 @@ Session::Session(SERVICE* service)
|
||||
|
||||
mxb::atomic::add(&service->stats.n_current, 1, mxb::atomic::RELAXED);
|
||||
mxb_assert(service->stats.n_current >= 0);
|
||||
mxb::atomic::add(&service->client_count, 1, mxb::atomic::RELAXED);
|
||||
}
|
||||
|
||||
Session::~Session()
|
||||
@ -1281,6 +1271,17 @@ Session::~Session()
|
||||
|
||||
mxb::atomic::add(&service->stats.n_current, -1, mxb::atomic::RELAXED);
|
||||
mxb_assert(service->stats.n_current >= 0);
|
||||
|
||||
bool should_destroy = !mxb::atomic::load(&service->active);
|
||||
|
||||
if (mxb::atomic::add(&service->client_count, -1) == 1 && should_destroy)
|
||||
{
|
||||
// Destroy the service in the main routing worker thread
|
||||
mxs::RoutingWorker* main_worker = mxs::RoutingWorker::get(mxs::RoutingWorker::MAIN);
|
||||
main_worker->execute(
|
||||
std::unique_ptr<ServiceDestroyTask>(new ServiceDestroyTask(static_cast<Service*>(service))),
|
||||
Worker::EXECUTE_AUTO);
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
|
||||
Reference in New Issue
Block a user