MXS-2720: Fix service session count
The number of sessions wasn't always incremented but it was always decremented. This happened primarily when authentication failed. By making the management of the counters a part of the object lifecycle, this problem goes away.
This commit is contained in:
		@ -244,7 +244,6 @@ static MXS_SESSION* session_alloc_body(SERVICE* service,
 | 
				
			|||||||
                 session->client_dcb->remote);
 | 
					                 session->client_dcb->remote);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    mxb::atomic::add(&service->stats.n_sessions, 1, mxb::atomic::RELAXED);
 | 
					    mxb::atomic::add(&service->stats.n_sessions, 1, mxb::atomic::RELAXED);
 | 
				
			||||||
    mxb::atomic::add(&service->stats.n_current, 1, mxb::atomic::RELAXED);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Store the session in the client DCB even if the session creation fails.
 | 
					    // Store the session in the client DCB even if the session creation fails.
 | 
				
			||||||
    // It will be freed later on when the DCB is closed.
 | 
					    // It will be freed later on when the DCB is closed.
 | 
				
			||||||
@ -383,9 +382,6 @@ static void session_final_free(MXS_SESSION* ses)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    session->state = SESSION_STATE_TO_BE_FREED;
 | 
					    session->state = SESSION_STATE_TO_BE_FREED;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mxb::atomic::add(&session->service->stats.n_current, -1, mxb::atomic::RELAXED);
 | 
					 | 
				
			||||||
    mxb_assert(session->service->stats.n_current >= 0);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (session->client_dcb)
 | 
					    if (session->client_dcb)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        dcb_free_all_memory(session->client_dcb);
 | 
					        dcb_free_all_memory(session->client_dcb);
 | 
				
			||||||
@ -1265,6 +1261,9 @@ Session::Session(SERVICE* service)
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        m_retain_last_statements = this_unit.retain_last_statements;
 | 
					        m_retain_last_statements = this_unit.retain_last_statements;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    mxb::atomic::add(&service->stats.n_current, 1, mxb::atomic::RELAXED);
 | 
				
			||||||
 | 
					    mxb_assert(service->stats.n_current >= 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Session::~Session()
 | 
					Session::~Session()
 | 
				
			||||||
@ -1279,6 +1278,9 @@ Session::~Session()
 | 
				
			|||||||
        f.filter->obj->closeSession(f.instance, f.session);
 | 
					        f.filter->obj->closeSession(f.instance, f.session);
 | 
				
			||||||
        f.filter->obj->freeSession(f.instance, f.session);
 | 
					        f.filter->obj->freeSession(f.instance, f.session);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    mxb::atomic::add(&service->stats.n_current, -1, mxb::atomic::RELAXED);
 | 
				
			||||||
 | 
					    mxb_assert(service->stats.n_current >= 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace
 | 
					namespace
 | 
				
			||||||
 | 
				
			|||||||
@ -17,7 +17,6 @@ namespace
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SERVICE dummy_service;
 | 
					SERVICE dummy_service;
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace maxscale
 | 
					namespace maxscale
 | 
				
			||||||
@ -44,6 +43,7 @@ Session::Session(Client* pClient)
 | 
				
			|||||||
    strcpy(m_mysql_session.db, "dummy");
 | 
					    strcpy(m_mysql_session.db, "dummy");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_client_dcb.data = &m_mysql_session;
 | 
					    m_client_dcb.data = &m_mysql_session;
 | 
				
			||||||
 | 
					    service = &dummy_service;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Session::~Session()
 | 
					Session::~Session()
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user