Make connections and command queues internal to Backends

The SERVER_REF and DCB members of the Backend class are now
private. Access to the stored SERVER_REF is provided with the backend()
function. No accompanying setter function is provided as the backend
server should not change during the lifetime of the session.

The creation of the internal DCB is hidden behind the connect()
function. It simplifies the process of connecting to a server by removing
the need to manually do the bookkeeping of the server reference connection
counts. Access to the DCB is provided by the dcb() function.

The closing of the backend is done with the close() function which
contains the code that was previously in closeSession. If the backend
isn't closed when the destructor is called, it will be done
automatically. This should prevent connection leakage.

The pending command queues and the methods used to write them are now also
internal to the backends. They are simple wrappers around dcb->func.write
and the interfaces provided by the Buffer class. The mapping command queue
is still public. It needs to be combined with the generic command queue.
This commit is contained in:
Markus Mäkelä
2017-03-28 21:04:29 +03:00
parent 66fa4fbc7d
commit 6e218adc1d
5 changed files with 148 additions and 103 deletions

View File

@ -208,7 +208,7 @@ bool connect_backend_servers(BackendList& backends, MXS_SESSION* session)
for (BackendList::iterator it = backends.begin(); it != backends.end(); it++)
{
SERVER_REF* b = (*it)->m_backend;
SERVER_REF* b = (*it)->backend();
MXS_INFO("MaxScale connections : %d (%d) in \t%s:%d %s",
b->connections,
@ -224,7 +224,7 @@ bool connect_backend_servers(BackendList& backends, MXS_SESSION* session)
*/
for (BackendList::iterator it = backends.begin(); it != backends.end(); it++)
{
SERVER_REF* b = (*it)->m_backend;
SERVER_REF* b = (*it)->backend();
if (SERVER_IS_RUNNING(b->server))
{
@ -238,27 +238,9 @@ bool connect_backend_servers(BackendList& backends, MXS_SESSION* session)
/** New server connection */
else
{
if (((*it)->m_dcb = dcb_connect(b->server, session, b->server->protocol)))
if ((*it)->connect(session))
{
servers_connected += 1;
/**
* When server fails, this callback
* is called.
* !!! Todo, routine which removes
* corresponding entries from the hash
* table.
*/
(*it)->m_state = 0;
(*it)->set_state(BREF_IN_USE);
/**
* Increase backend connection counter.
* Server's stats are _increased_ in
* dcb.c:dcb_alloc !
* But decreased in the calling function
* of dcb_close.
*/
atomic_add(&b->connections, 1);
}
else
{
@ -282,7 +264,7 @@ bool connect_backend_servers(BackendList& backends, MXS_SESSION* session)
{
for (BackendList::iterator it = backends.begin(); it != backends.end(); it++)
{
SERVER_REF* b = (*it)->m_backend;
SERVER_REF* b = (*it)->backend();
if (BREF_IS_IN_USE((*it)))
{