MXS-2196: Allocate a session before allocating DCBs

Allocating the session before a DCB guarantees that at no point will a DCB
have a null session. This further clarifies the concept of the session and
also allows the listener reference to be moved there.

Ideally, the session itself would allocate and assign the client DCB but
since the Listener is the only one who does it, it's acceptable for now.
This commit is contained in:
Markus Mäkelä
2018-12-03 19:25:26 +02:00
parent 692127a2cb
commit 43c33e9f4a
20 changed files with 106 additions and 115 deletions

View File

@ -204,7 +204,7 @@ static int httpd_read_event(DCB* dcb)
/** If listener->authenticator is the default authenticator, it means that
* we don't need to check the user credentials. All other authenticators
* cause a 401 Unauthorized to be returned on the first try. */
bool auth_ok = httpd_default_auth() == std::string(dcb->listener->authenticator());
bool auth_ok = httpd_default_auth() == std::string(dcb->session->listener->authenticator());
/**
* Get the request headers

View File

@ -673,7 +673,7 @@ static void check_packet(DCB* dcb, GWBUF* buf, int bytes)
if (bytes == MYSQL_AUTH_PACKET_BASE_SIZE)
{
/** This is an SSL request packet */
mxb_assert(dcb->listener->ssl());
mxb_assert(dcb->session->listener->ssl());
mxb_assert(buflen == bytes && pktlen >= buflen);
}
else
@ -1463,10 +1463,8 @@ static int gw_client_close(DCB* dcb)
{
MXS_SESSION* target = dcb->session;
if (target->state != SESSION_STATE_TO_BE_FREED)
if (target->state == SESSION_STATE_ROUTER_READY || target->state == SESSION_STATE_STOPPING)
{
mxb_assert(target->state == SESSION_STATE_ROUTER_READY
|| target->state == SESSION_STATE_STOPPING);
MXB_AT_DEBUG(bool removed = ) mxs_rworker_deregister_session(target->ses_id);
mxb_assert(removed);
session_close(target);
@ -1648,7 +1646,7 @@ static int route_by_statement(MXS_SESSION* session, uint64_t capabilities, GWBUF
if (rcap_type_required(capabilities, RCAP_TYPE_CONTIGUOUS_INPUT))
{
mxb_assert(GWBUF_IS_CONTIGUOUS(packetbuf));
SERVICE* service = session->client_dcb->service;
SERVICE* service = session->service;
if (rcap_type_required(capabilities, RCAP_TYPE_TRANSACTION_TRACKING)
&& !service->session_track_trx_state