MXS-1267: Remove DCB cloning
The DCB cloning is no longer needed as the tee filter now does the session branching by simulating a local client connection.
This commit is contained in:
@ -274,7 +274,6 @@ DCB *dcb_alloc(dcb_role_t, struct servlistener *);
|
||||
void dcb_free(DCB *);
|
||||
void dcb_free_all_memory(DCB *dcb);
|
||||
DCB *dcb_connect(struct server *, struct session *, const char *);
|
||||
DCB *dcb_clone(DCB *);
|
||||
int dcb_read(DCB *, GWBUF **, int);
|
||||
int dcb_drain_writeq(DCB *);
|
||||
void dcb_close(DCB *);
|
||||
@ -363,11 +362,9 @@ int dcb_get_port(const DCB *dcb);
|
||||
/**
|
||||
* DCB flags values
|
||||
*/
|
||||
#define DCBF_CLONE 0x0001 /*< DCB is a clone */
|
||||
#define DCBF_HUNG 0x0002 /*< Hangup has been dispatched */
|
||||
#define DCBF_REPLIED 0x0004 /*< DCB was written to */
|
||||
|
||||
#define DCB_IS_CLONE(d) ((d)->flags & DCBF_CLONE)
|
||||
#define DCB_REPLIED(d) ((d)->flags & DCBF_REPLIED)
|
||||
|
||||
MXS_END_DECLS
|
||||
|
@ -144,7 +144,6 @@ typedef struct session
|
||||
MXS_DOWNSTREAM head; /*< Head of the filter chain */
|
||||
MXS_UPSTREAM tail; /*< The tail of the filter chain */
|
||||
int refcount; /*< Reference count on the session */
|
||||
bool ses_is_child; /*< this is a child session */
|
||||
mxs_session_trx_state_t trx_state; /*< The current transaction state. */
|
||||
bool autocommit; /*< Whether autocommit is on. */
|
||||
struct
|
||||
|
@ -232,68 +232,6 @@ dcb_free(DCB *dcb)
|
||||
dcb_close(dcb);
|
||||
}
|
||||
|
||||
/*
|
||||
* Clone a DCB for internal use, mostly used for specialist filters
|
||||
* to create dummy clients based on real clients.
|
||||
*
|
||||
* @param orig The DCB to clone
|
||||
* @return A DCB that can be used as a client
|
||||
*/
|
||||
DCB *
|
||||
dcb_clone(DCB *orig)
|
||||
{
|
||||
char *remote = orig->remote;
|
||||
|
||||
if (remote)
|
||||
{
|
||||
remote = MXS_STRDUP(remote);
|
||||
if (!remote)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char *user = orig->user;
|
||||
if (user)
|
||||
{
|
||||
user = MXS_STRDUP(user);
|
||||
if (!user)
|
||||
{
|
||||
MXS_FREE(remote);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DCB *clonedcb = dcb_alloc(orig->dcb_role, orig->listener);
|
||||
|
||||
if (clonedcb)
|
||||
{
|
||||
clonedcb->fd = DCBFD_CLOSED;
|
||||
clonedcb->flags |= DCBF_CLONE;
|
||||
clonedcb->state = orig->state;
|
||||
clonedcb->data = orig->data;
|
||||
clonedcb->ssl_state = orig->ssl_state;
|
||||
clonedcb->remote = remote;
|
||||
clonedcb->user = user;
|
||||
clonedcb->poll.thread.id = orig->poll.thread.id;
|
||||
clonedcb->protocol = orig->protocol;
|
||||
|
||||
clonedcb->func.write = dcb_null_write;
|
||||
/**
|
||||
* Close triggers closing of router session as well which is needed.
|
||||
*/
|
||||
clonedcb->func.close = orig->func.close;
|
||||
clonedcb->func.auth = dcb_null_auth;
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_FREE(remote);
|
||||
MXS_FREE(user);
|
||||
}
|
||||
|
||||
return clonedcb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free a DCB and remove it from the chain of all DCBs
|
||||
*
|
||||
@ -357,11 +295,11 @@ dcb_free_all_memory(DCB *dcb)
|
||||
{
|
||||
DCB_CALLBACK *cb_dcb;
|
||||
|
||||
if (dcb->protocol && (!DCB_IS_CLONE(dcb)))
|
||||
if (dcb->protocol)
|
||||
{
|
||||
MXS_FREE(dcb->protocol);
|
||||
}
|
||||
if (dcb->data && dcb->authfunc.free && !DCB_IS_CLONE(dcb))
|
||||
if (dcb->data && dcb->authfunc.free)
|
||||
{
|
||||
dcb->authfunc.free(dcb);
|
||||
dcb->data = NULL;
|
||||
@ -771,8 +709,7 @@ int dcb_read(DCB *dcb,
|
||||
|
||||
if (dcb->fd <= 0)
|
||||
{
|
||||
MXS_ERROR("Read failed, dcb is %s.", dcb->fd == DCBFD_CLOSED ?
|
||||
"closed" : "cloned, not readable");
|
||||
MXS_ERROR("Read failed, dcb is closed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -935,8 +872,7 @@ dcb_read_SSL(DCB *dcb, GWBUF **head)
|
||||
|
||||
if (dcb->fd <= 0)
|
||||
{
|
||||
MXS_ERROR("Read failed, dcb is %s.", dcb->fd == DCBFD_CLOSED ?
|
||||
"closed" : "cloned, not readable");
|
||||
MXS_ERROR("Read failed, dcb is closed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1123,8 +1059,7 @@ dcb_write_parameter_check(DCB *dcb, GWBUF *queue)
|
||||
|
||||
if (dcb->fd <= 0)
|
||||
{
|
||||
MXS_ERROR("Write failed, dcb is %s.",
|
||||
dcb->fd == DCBFD_CLOSED ? "closed" : "cloned, not writable");
|
||||
MXS_ERROR("Write failed, dcb is closed.");
|
||||
gwbuf_free(queue);
|
||||
return false;
|
||||
}
|
||||
@ -1552,10 +1487,7 @@ dprintOneDCB(DCB *pdcb, DCB *dcb)
|
||||
dcb_printf(pdcb, "\t\tNo. of Accepts: %d\n", dcb->stats.n_accepts);
|
||||
dcb_printf(pdcb, "\t\tNo. of High Water Events: %d\n", dcb->stats.n_high_water);
|
||||
dcb_printf(pdcb, "\t\tNo. of Low Water Events: %d\n", dcb->stats.n_low_water);
|
||||
if (dcb->flags & DCBF_CLONE)
|
||||
{
|
||||
dcb_printf(pdcb, "\t\tDCB is a clone.\n");
|
||||
}
|
||||
|
||||
if (dcb->persistentstart)
|
||||
{
|
||||
char buff[20];
|
||||
@ -1717,10 +1649,6 @@ dprintDCB(DCB *pdcb, DCB *dcb)
|
||||
dcb_printf(pdcb, "\t\tPending events in the queue: %x %s\n",
|
||||
dcb->evq.pending_events, dcb->evq.processing ? "(processing)" : "");
|
||||
}
|
||||
if (dcb->flags & DCBF_CLONE)
|
||||
{
|
||||
dcb_printf(pdcb, "\t\tDCB is a clone.\n");
|
||||
}
|
||||
|
||||
if (dcb->persistentstart)
|
||||
{
|
||||
@ -2122,41 +2050,6 @@ dcb_hangup_foreach(struct server* server)
|
||||
Worker::broadcast_message(MXS_WORKER_MSG_CALL, arg1, arg2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Null protocol write routine used for cloned dcb's. It merely consumes
|
||||
* buffers written on the cloned DCB and sets the DCB_REPLIED flag.
|
||||
*
|
||||
* @param dcb The descriptor control block
|
||||
* @param buf The buffer being written
|
||||
* @return Always returns a good write operation result
|
||||
*/
|
||||
static int
|
||||
dcb_null_write(DCB *dcb, GWBUF *buf)
|
||||
{
|
||||
while (buf)
|
||||
{
|
||||
buf = gwbuf_consume(buf, GWBUF_LENGTH(buf));
|
||||
}
|
||||
|
||||
dcb->flags |= DCBF_REPLIED;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Null protocol auth operation for use by cloned DCB's.
|
||||
*
|
||||
* @param dcb The DCB being closed.
|
||||
* @param server The server to auth against
|
||||
* @param session The user session
|
||||
* @param buf The buffer with the new auth request
|
||||
*/
|
||||
static int
|
||||
dcb_null_auth(DCB *dcb, SERVER *server, MXS_SESSION *session, GWBUF *buf)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check persistent pool for expiry or excess size and count
|
||||
*
|
||||
@ -3565,12 +3458,9 @@ int poll_remove_dcb(DCB *dcb)
|
||||
|
||||
/**
|
||||
* Only positive fds can be removed from epoll set.
|
||||
* Cloned DCBs can have a state of DCB_STATE_POLLING but are not in
|
||||
* the epoll set and do not have a valid file descriptor. Hence the
|
||||
* only action for them is already done - the change of state to
|
||||
* DCB_STATE_NOPOLLING.
|
||||
*/
|
||||
dcbfd = dcb->fd;
|
||||
ss_dassert(dcbfd > 0);
|
||||
|
||||
if (dcbfd > 0)
|
||||
{
|
||||
|
@ -178,7 +178,6 @@ MXS_SESSION* session_alloc_with_id(SERVICE *service, DCB *client_dcb, uint64_t i
|
||||
static MXS_SESSION* session_alloc_body(SERVICE* service, DCB* client_dcb,
|
||||
MXS_SESSION* session)
|
||||
{
|
||||
session->ses_is_child = (bool) DCB_IS_CLONE(client_dcb);
|
||||
session->service = service;
|
||||
session->client_dcb = client_dcb;
|
||||
session->stats.connect = time(0);
|
||||
@ -309,7 +308,6 @@ session_set_dummy(DCB *client_dcb)
|
||||
session = &session_dummy_struct;
|
||||
session->ses_chk_top = CHK_NUM_SESSION;
|
||||
session->ses_chk_tail = CHK_NUM_SESSION;
|
||||
session->ses_is_child = false;
|
||||
session->service = NULL;
|
||||
session->client_dcb = NULL;
|
||||
session->n_filters = 0;
|
||||
@ -359,7 +357,7 @@ static void
|
||||
session_simple_free(MXS_SESSION *session, DCB *dcb)
|
||||
{
|
||||
/* Does this possibly need a lock? */
|
||||
if (dcb->data && !DCB_IS_CLONE(dcb))
|
||||
if (dcb->data)
|
||||
{
|
||||
void * clientdata = dcb->data;
|
||||
dcb->data = NULL;
|
||||
@ -385,7 +383,7 @@ session_simple_free(MXS_SESSION *session, DCB *dcb)
|
||||
|
||||
void session_close(MXS_SESSION *session)
|
||||
{
|
||||
if (!session->ses_is_child && session->router_session)
|
||||
if (session->router_session)
|
||||
{
|
||||
if (session->state != SESSION_STATE_STOPPING)
|
||||
{
|
||||
@ -421,7 +419,7 @@ static void session_free(MXS_SESSION *session)
|
||||
* If session is not child of some other session, free router_session.
|
||||
* Otherwise let the parent free it.
|
||||
*/
|
||||
if (!session->ses_is_child && session->router_session)
|
||||
if (session->router_session)
|
||||
{
|
||||
session->service->router->freeSession(session->service->router_instance,
|
||||
session->router_session);
|
||||
@ -450,13 +448,9 @@ static void session_free(MXS_SESSION *session)
|
||||
|
||||
MXS_INFO("Stopped %s client session [%" PRIu64 "]", session->service->name, session->ses_id);
|
||||
|
||||
/** If session doesn't have parent referencing to it, it can be freed */
|
||||
if (!session->ses_is_child)
|
||||
{
|
||||
session->state = SESSION_STATE_FREE;
|
||||
session_final_free(session);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
session_final_free(MXS_SESSION *session)
|
||||
|
@ -1451,10 +1451,7 @@ static GWBUF* process_response_data(DCB* dcb,
|
||||
|
||||
/** Get command which was stored in gw_MySQLWrite_backend */
|
||||
p = DCB_PROTOCOL(dcb, MySQLProtocol);
|
||||
if (!DCB_IS_CLONE(dcb))
|
||||
{
|
||||
CHK_PROTOCOL(p);
|
||||
}
|
||||
|
||||
/** All buffers processed here are sescmd responses */
|
||||
gwbuf_set_type(*readbuf, GWBUF_TYPE_SESCMD_RESPONSE);
|
||||
@ -1600,10 +1597,7 @@ static bool sescmd_response_complete(DCB* dcb)
|
||||
bool succp;
|
||||
|
||||
p = DCB_PROTOCOL(dcb, MySQLProtocol);
|
||||
if (!DCB_IS_CLONE(dcb))
|
||||
{
|
||||
CHK_PROTOCOL(p);
|
||||
}
|
||||
|
||||
protocol_get_response_status(p, &npackets_left, &nbytes_left);
|
||||
|
||||
|
@ -728,13 +728,6 @@ route_target_t get_route_target(ROUTER_CLIENT_SES *rses,
|
||||
{
|
||||
target = TARGET_MASTER;
|
||||
}
|
||||
/**
|
||||
* A cloned session, route everything to the master
|
||||
*/
|
||||
else if (DCB_IS_CLONE(rses->client_dcb))
|
||||
{
|
||||
target = TARGET_MASTER;
|
||||
}
|
||||
/**
|
||||
* These queries are not affected by hints
|
||||
*/
|
||||
|
Reference in New Issue
Block a user