
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.
87 lines
2.5 KiB
C++
87 lines
2.5 KiB
C++
#pragma once
|
|
/*
|
|
* Copyright (c) 2016 MariaDB Corporation Ab
|
|
*
|
|
* Use of this software is governed by the Business Source License included
|
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
|
*
|
|
* Change Date: 2020-01-01
|
|
*
|
|
* On the date above, in accordance with the Business Source License, use
|
|
* of this software will be governed by version 2 or later of the General
|
|
* Public License.
|
|
*/
|
|
|
|
#include <maxscale/cppdefs.hh>
|
|
|
|
#include <deque>
|
|
|
|
#include <maxscale/buffer.hh>
|
|
#include <maxscale/service.h>
|
|
#include <maxscale/protocol/mysql.h>
|
|
|
|
/** A DCB-like client abstraction which ignores responses */
|
|
class LocalClient: public MXS_POLL_DATA
|
|
{
|
|
LocalClient(const LocalClient&);
|
|
LocalClient& operator=(const LocalClient&);
|
|
|
|
public:
|
|
~LocalClient();
|
|
|
|
/**
|
|
* Create a local client for a service
|
|
*
|
|
* @param session Client session
|
|
* @param service Service to connect to
|
|
*
|
|
* @return New virtual client or NULL on error
|
|
*/
|
|
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
|
|
*
|
|
* @param buffer Buffer containing the query
|
|
*
|
|
* @return True if query was successfully queued
|
|
*/
|
|
bool queue_query(GWBUF* buffer);
|
|
|
|
/**
|
|
* Destroy the client by sending a COM_QUIT to the backend
|
|
*
|
|
* @note After calling this function, object must be treated as a deleted object
|
|
*/
|
|
void self_destruct();
|
|
|
|
private:
|
|
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();
|
|
void drain_queue();
|
|
void error();
|
|
void close();
|
|
|
|
/** Client states */
|
|
enum vc_state
|
|
{
|
|
VC_WAITING_HANDSHAKE, // Initial state
|
|
VC_RESPONSE_SENT, // Handshake received and response sent
|
|
VC_OK, // Authentication is complete, ready for queries
|
|
VC_ERROR // Something went wrong
|
|
};
|
|
|
|
vc_state m_state;
|
|
int m_sock;
|
|
mxs::Buffer m_partial;
|
|
size_t m_expected_bytes;
|
|
std::deque<mxs::Buffer> m_queue;
|
|
MYSQL_session m_client;
|
|
MySQLProtocol m_protocol;
|
|
bool m_self_destruct;
|
|
};
|