Send KILL commands to backends

KILL commands are now sent to the backends in an asynchronous manner. As
the LocalClient class is used to connect to the servers, this will cause
an extra connection to be created on top of the original connections
created by the session.

If the user does not have the permissions to execute the KILL, the error
message is currently lost. This could be solved by adding a "result
handler" into the LocalClient class which is called with the result.
This commit is contained in:
Markus Mäkelä
2017-09-27 16:18:36 +03:00
parent a7e610a70a
commit 4dd6842447
11 changed files with 144 additions and 154 deletions

View File

@ -0,0 +1,86 @@
#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(MXS_SESSION* session, SERVICE* service);
static LocalClient* create(MXS_SESSION* session, 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(MXS_SESSION* session, const char* ip, uint64_t port);
LocalClient(MXS_SESSION* session, 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;
};

View File

@ -624,4 +624,13 @@ uint32_t mxs_mysql_extract_ps_id(GWBUF* buffer);
*/
bool mxs_mysql_command_will_respond(uint8_t cmd);
/* Type of the kill-command sent by client. */
typedef enum kill_type
{
KT_CONNECTION,
KT_QUERY
} kill_type_t;
void mxs_mysql_execute_kill(MXS_SESSION* issuer, uint64_t target_id, kill_type_t type);
MXS_END_DECLS

View File

@ -414,15 +414,6 @@ bool session_take_stmt(MXS_SESSION *session, GWBUF **buffer, const struct server
*/
void session_clear_stmt(MXS_SESSION *session);
/**
* Try to kill a specific session. This function only sends messages to
* worker threads without waiting for the result.
*
* @param issuer The session where the command originates.
* @param target_id Target session id.
*/
void session_broadcast_kill_command(MXS_SESSION* issuer, uint64_t target_id);
/**
* @brief Convert a session to JSON
*