Merge branch '2.2' into 2.2-mrm
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
#include <limits.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <maxscale/modinfo.h>
|
||||
#include <maxscale/jansson.h>
|
||||
@ -133,6 +134,8 @@ extern const char CN_PORT[];
|
||||
extern const char CN_PROTOCOL[];
|
||||
extern const char CN_QUERY_CLASSIFIER[];
|
||||
extern const char CN_QUERY_CLASSIFIER_ARGS[];
|
||||
extern const char CN_QUERY_RETRIES[];
|
||||
extern const char CN_QUERY_RETRY_TIMEOUT[];
|
||||
extern const char CN_RELATIONSHIPS[];
|
||||
extern const char CN_LINKS[];
|
||||
extern const char CN_REQUIRED[];
|
||||
@ -223,6 +226,8 @@ typedef struct
|
||||
char admin_ssl_key[PATH_MAX]; /**< Admin SSL key */
|
||||
char admin_ssl_cert[PATH_MAX]; /**< Admin SSL cert */
|
||||
char admin_ssl_ca_cert[PATH_MAX]; /**< Admin SSL CA cert */
|
||||
int query_retries; /**< Number of times a interrupted query is retried */
|
||||
time_t query_retry_timeout; /**< Timeout for query retries */
|
||||
} MXS_CONFIG;
|
||||
|
||||
/**
|
||||
|
@ -113,7 +113,7 @@ json_t* mxs_logs_to_json(const char* host);
|
||||
static inline bool mxs_log_priority_is_enabled(int priority)
|
||||
{
|
||||
assert((priority & ~LOG_PRIMASK) == 0);
|
||||
return MXS_LOG_PRIORITY_IS_ENABLED(priority);
|
||||
return MXS_LOG_PRIORITY_IS_ENABLED(priority) || priority == LOG_ALERT;
|
||||
}
|
||||
|
||||
int mxs_log_message(int priority,
|
||||
|
@ -29,7 +29,29 @@ uint64_t mxs_leint_consume(uint8_t ** c);
|
||||
char* mxs_lestr_consume_dup(uint8_t** c);
|
||||
char* mxs_lestr_consume(uint8_t** c, size_t *size);
|
||||
|
||||
MYSQL *mxs_mysql_real_connect(MYSQL *mysql, SERVER *server, const char *user, const char *passwd);
|
||||
/**
|
||||
* Creates a connection to a MySQL database engine. If necessary, initializes SSL.
|
||||
*
|
||||
* @param con A valid MYSQL structure.
|
||||
* @param server The server on which the MySQL engine is running.
|
||||
* @param user The MySQL login ID.
|
||||
* @param passwd The password for the user.
|
||||
*
|
||||
* @return New connection or NULL on error
|
||||
*/
|
||||
MYSQL* mxs_mysql_real_connect(MYSQL *mysql, SERVER *server, const char *user, const char *passwd);
|
||||
|
||||
/**
|
||||
* Execute a query
|
||||
*
|
||||
* This function wraps mysql_query in a way that automatic query retry is possible.
|
||||
*
|
||||
* @param conn MySQL connection
|
||||
* @param query Query to execute
|
||||
*
|
||||
* @return return value of mysql_query
|
||||
*/
|
||||
int mxs_mysql_query(MYSQL* conn, const char* query);
|
||||
|
||||
/**
|
||||
* Trim MySQL quote characters surrounding a string.
|
||||
|
86
include/maxscale/protocol/mariadb_client.hh
Normal file
86
include/maxscale/protocol/mariadb_client.hh
Normal 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;
|
||||
};
|
@ -487,14 +487,14 @@ int gw_decode_mysql_server_handshake(MySQLProtocol *conn, uint8_t *payload);
|
||||
/**
|
||||
* Create a response to the server handshake
|
||||
*
|
||||
* @param session Session object
|
||||
* @param client Shared session data
|
||||
* @param conn MySQL Protocol object for this connection
|
||||
* @param with_ssl Whether to create an SSL response or a normal response packet
|
||||
* @param ssl_established Set to true if the SSL response has been sent
|
||||
*
|
||||
* @return Generated response packet
|
||||
*/
|
||||
GWBUF* gw_generate_auth_response(MXS_SESSION* session, MySQLProtocol *conn,
|
||||
GWBUF* gw_generate_auth_response(MYSQL_session* client, MySQLProtocol *conn,
|
||||
bool with_ssl, bool ssl_established);
|
||||
|
||||
/** Read the backend server's handshake */
|
||||
@ -624,4 +624,16 @@ 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 = (1 << 0),
|
||||
KT_QUERY = (1 << 1),
|
||||
KT_SOFT = (1 << 2),
|
||||
KT_HARD = (1 << 3)
|
||||
} kill_type_t;
|
||||
|
||||
void mxs_mysql_execute_kill(MXS_SESSION* issuer, uint64_t target_id, kill_type_t type);
|
||||
void mxs_mysql_execute_kill_user(MXS_SESSION* issuer, const char* user, kill_type_t type);
|
||||
|
||||
MXS_END_DECLS
|
||||
|
@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user