MXS-1985: Kill connections inside workers

The LocalClient micro-client required a reference to the session that was
valid at construction time. This is the reason why the previous
implementation used dcb_foreach to first gather the targets and then
execute queries on them. By replacing this reference with pointers to the
raw data it requires, we lift the requirement of the orignating session
being alive at construction time.

Now that the LocalClient no longer holds a reference to the session, the
killing of the connection does not have to be done on the same thread that
started the process. This prevents the deadlock that occurred when
concurrect dcb_foreach calls were made.

Replaced the unused dcb_foreach_parallel with a version of dcb_foreach
that allows iteration of DCBs local to this worker. The dcb_foreach_local
is the basis upon which all DCB access outside of administrative tasks
should be built on.

This change will introduce a regression in functionality: The client will
no longer receive an error if no connections match the KILL query
criteria. This is done to avoid having to synchronize the workers after
they have performed the killing of their own connections.
This commit is contained in:
Markus Mäkelä
2018-07-20 04:30:54 +03:00
parent 101dad74a7
commit 21eef8a670
6 changed files with 126 additions and 126 deletions

View File

@ -367,21 +367,15 @@ static inline void dcb_readq_set(DCB *dcb, GWBUF *buffer)
bool dcb_foreach(bool (*func)(DCB *dcb, void *data), void *data);
/**
* @brief Call a function for each connected DCB
* @brief Call a function for each connected DCB on the current worker
*
* @note This function can call @c func from multiple thread at one time.
* @param func Function to call. The function should return @c true to continue
* iteration and @c false to stop iteration earlier. The first parameter
* is the current DCB.
*
* @param func Function to call. The function should return @c true to continue iteration
* and @c false to stop iteration earlier. The first is a DCB and
* the second is this thread's value in the @c data array that
* the user provided.
*
* @param data Array of user provided data passed as the second parameter to @c func.
* The array must have more space for pointers thann the return
* value of `config_threadcount()`. The value passed to @c func will
* be the value of the array at the index of the current thread's ID.
* @param data User provided data passed as the second parameter to @c func
*/
void dcb_foreach_parallel(bool (*func)(DCB *dcb, void *data), void **data);
void dcb_foreach_local(bool (*func)(DCB *dcb, void *data), void *data);
/**
* @brief Return the port number this DCB is connected to

View File

@ -37,8 +37,8 @@ public:
*
* @return New virtual client or NULL on error
*/
static LocalClient* create(MXS_SESSION* session, SERVICE* service);
static LocalClient* create(MXS_SESSION* session, SERVER* server);
static LocalClient* create(MYSQL_session* session, MySQLProtocol* proto, SERVICE* service);
static LocalClient* create(MYSQL_session* session, MySQLProtocol* proto, SERVER* server);
/**
* Queue a new query for execution
@ -57,8 +57,8 @@ public:
void self_destruct();
private:
static LocalClient* create(MXS_SESSION* session, const char* ip, uint64_t port);
LocalClient(MXS_SESSION* session, int fd);
static LocalClient* create(MYSQL_session* session, MySQLProtocol* proto, const char* ip, uint64_t port);
LocalClient(MYSQL_session* session, MySQLProtocol* proto, int fd);
static uint32_t poll_handler(struct mxs_poll_data* data, int wid, uint32_t events);
void process(uint32_t events);
GWBUF* read_complete_packet();