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:
@ -219,7 +219,7 @@ static int cdc_auth_check(DCB* dcb,
|
||||
{
|
||||
int rval = CDC_STATE_AUTH_FAILED;
|
||||
|
||||
if (dcb->listener->users())
|
||||
if (dcb->session->listener->users())
|
||||
{
|
||||
/* compute SHA1 of auth_data */
|
||||
uint8_t sha1_step1[SHA_DIGEST_LENGTH] = "";
|
||||
@ -228,7 +228,7 @@ static int cdc_auth_check(DCB* dcb,
|
||||
gw_sha1_str(auth_data, SHA_DIGEST_LENGTH, sha1_step1);
|
||||
gw_bin2hex(hex_step1, sha1_step1, SHA_DIGEST_LENGTH);
|
||||
|
||||
if (users_auth(dcb->listener->users(), username, hex_step1))
|
||||
if (users_auth(dcb->session->listener->users(), username, hex_step1))
|
||||
{
|
||||
rval = CDC_STATE_AUTH_OK;
|
||||
}
|
||||
@ -263,7 +263,8 @@ static int cdc_auth_authenticate(DCB* dcb)
|
||||
cdc_auth_check(dcb, protocol, client_data->user, client_data->auth_data, client_data->flags);
|
||||
|
||||
/* On failed authentication try to reload users and authenticate again */
|
||||
if (CDC_STATE_AUTH_OK != auth_ret && cdc_replace_users(dcb->listener.get()) == MXS_AUTH_LOADUSERS_OK)
|
||||
if (CDC_STATE_AUTH_OK != auth_ret
|
||||
&& cdc_replace_users(dcb->session->listener.get()) == MXS_AUTH_LOADUSERS_OK)
|
||||
{
|
||||
auth_ret = cdc_auth_check(dcb,
|
||||
protocol,
|
||||
|
@ -491,7 +491,7 @@ int gssapi_auth_authenticate(DCB* dcb)
|
||||
{
|
||||
int rval = MXS_AUTH_FAILED;
|
||||
gssapi_auth_t* auth = (gssapi_auth_t*)dcb->authenticator_data;
|
||||
GSSAPI_INSTANCE* instance = (GSSAPI_INSTANCE*)dcb->listener->auth_instance();
|
||||
GSSAPI_INSTANCE* instance = (GSSAPI_INSTANCE*)dcb->session->listener->auth_instance();
|
||||
|
||||
if (auth->state == GSSAPI_AUTH_INIT)
|
||||
{
|
||||
|
@ -293,7 +293,7 @@ static int mysql_auth_authenticate(DCB* dcb)
|
||||
client_data->user,
|
||||
client_data->db);
|
||||
|
||||
MYSQL_AUTH* instance = (MYSQL_AUTH*)dcb->listener->auth_instance();
|
||||
MYSQL_AUTH* instance = (MYSQL_AUTH*)dcb->session->listener->auth_instance();
|
||||
MySQLProtocol* protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
|
||||
auth_ret = validate_mysql_user(instance,
|
||||
dcb,
|
||||
@ -684,7 +684,7 @@ int mysql_auth_reauthenticate(DCB* dcb,
|
||||
temp.auth_token = token;
|
||||
temp.auth_token_len = token_len;
|
||||
|
||||
MYSQL_AUTH* instance = (MYSQL_AUTH*)dcb->listener->auth_instance();
|
||||
MYSQL_AUTH* instance = (MYSQL_AUTH*)dcb->session->listener->auth_instance();
|
||||
int rc = validate_mysql_user(instance, dcb, &temp, scramble, scramble_len);
|
||||
|
||||
if (rc != MXS_AUTH_SUCCEEDED && service_refresh_users(dcb->service) == 0)
|
||||
|
@ -174,7 +174,7 @@ class ResultSetDCB : public DCB
|
||||
{
|
||||
public:
|
||||
ResultSetDCB()
|
||||
: DCB(DCB_ROLE_CLIENT_HANDLER, nullptr, nullptr)
|
||||
: DCB(DCB_ROLE_CLIENT_HANDLER, nullptr)
|
||||
{
|
||||
DCB* pDcb = this;
|
||||
|
||||
|
@ -34,7 +34,7 @@ Dcb::Dcb(MXS_SESSION* pSession,
|
||||
const char* zUser,
|
||||
const char* zHost,
|
||||
Handler* pHandler)
|
||||
: DCB(DCB_ROLE_CLIENT_HANDLER, nullptr, nullptr)
|
||||
: DCB(DCB_ROLE_CLIENT_HANDLER, nullptr)
|
||||
, m_user(zUser)
|
||||
, m_host(zHost)
|
||||
, m_pHandler(pHandler)
|
||||
|
@ -17,7 +17,6 @@ namespace
|
||||
{
|
||||
|
||||
SERVICE dummy_service;
|
||||
|
||||
}
|
||||
|
||||
namespace maxscale
|
||||
@ -27,7 +26,7 @@ namespace mock
|
||||
{
|
||||
|
||||
Session::Session(Client* pClient)
|
||||
: mxs::Session(&dummy_service, &m_client_dcb)
|
||||
: mxs::Session(nullptr)
|
||||
, m_client(*pClient)
|
||||
, m_client_dcb(this, pClient->user(), pClient->host(), pClient)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -55,6 +55,8 @@
|
||||
#include <maxscale/session.hh>
|
||||
#include <maxscale/utils.h>
|
||||
|
||||
#include "../../../core/internal/session.hh"
|
||||
|
||||
static GWBUF* blr_make_query(DCB* dcb, char* query);
|
||||
static GWBUF* blr_make_registration(ROUTER_INSTANCE* router);
|
||||
static GWBUF* blr_make_binlog_dump(ROUTER_INSTANCE* router);
|
||||
@ -186,7 +188,8 @@ static void blr_start_master(void* data)
|
||||
|
||||
pthread_mutex_unlock(&router->lock);
|
||||
|
||||
DCB* client = dcb_alloc(DCB_ROLE_INTERNAL, NULL, NULL);
|
||||
// TODO: Fix this
|
||||
DCB* client = dcb_alloc(DCB_ROLE_INTERNAL, NULL);
|
||||
|
||||
/* Create fake 'client' DCB */
|
||||
if (client == NULL)
|
||||
@ -201,7 +204,8 @@ static void blr_start_master(void* data)
|
||||
|
||||
/* Create MySQL Athentication from configured user/passwd */
|
||||
client->data = CreateMySQLAuthData(router->user, router->password, "");
|
||||
client->session = session_alloc(router->service, client);
|
||||
// TODO: Fix this
|
||||
client->session = new mxs::Session(nullptr);
|
||||
router->session = client->session;
|
||||
|
||||
/* Create a session for dummy client DCB */
|
||||
@ -210,7 +214,6 @@ static void blr_start_master(void* data)
|
||||
MXS_ERROR("failed to create session for connection to master");
|
||||
return;
|
||||
}
|
||||
client->service = router->service;
|
||||
|
||||
/**
|
||||
* 'client' is the fake DCB that emulates a client session:
|
||||
@ -237,7 +240,6 @@ static void blr_start_master(void* data)
|
||||
return;
|
||||
}
|
||||
router->master->remote = MXS_STRDUP_A(router->service->dbref->server->address);
|
||||
router->master->service = router->service;
|
||||
|
||||
MXS_NOTICE("%s: attempting to connect to master"
|
||||
" server [%s]:%d, binlog='%s', pos=%lu%s%s",
|
||||
|
@ -205,7 +205,6 @@ Dcb HintRouter::connect_to_backend(MXS_SESSION* session,
|
||||
{
|
||||
HR_DEBUG("Connected.");
|
||||
mxb::atomic::add(&sref->connections, 1, mxb::atomic::RELAXED);
|
||||
new_connection->service = session->service;
|
||||
|
||||
result = Dcb(new_connection);
|
||||
string name(new_connection->server->name);
|
||||
|
Reference in New Issue
Block a user