Merge branch 'SESvars' of https://github.com/skysql/MaxScale into SESvars
Conflicts: server/core/dcb.c server/core/poll.c server/modules/include/mysql_client_server_protocol.h server/modules/routing/readwritesplit/readwritesplit.c
This commit is contained in:
@ -297,6 +297,7 @@ void gw_str_xor(
|
||||
const uint8_t *input1,
|
||||
const uint8_t *input2,
|
||||
unsigned int len);
|
||||
<<<<<<< HEAD
|
||||
char *gw_bin2hex(char *out, const uint8_t *in, unsigned int len);
|
||||
int gw_hex2bin(uint8_t *out, const char *in, unsigned int len);
|
||||
int gw_generate_random_str(char *output, int len);
|
||||
@ -304,3 +305,13 @@ char *gw_strend(register const char *s);
|
||||
int setnonblocking(int fd);
|
||||
int setipaddress(struct in_addr *a, char *p);
|
||||
int gw_read_gwbuff(DCB *dcb, GWBUF **head, int b);
|
||||
=======
|
||||
char *gw_bin2hex(char *out, const uint8_t *in, unsigned int len);
|
||||
int gw_hex2bin(uint8_t *out, const char *in, unsigned int len);
|
||||
int gw_generate_random_str(char *output, int len);
|
||||
char *gw_strend(register const char *s);
|
||||
int setnonblocking(int fd);
|
||||
void setipaddress(struct in_addr *a, char *p);
|
||||
int gw_read_gwbuff(DCB *dcb, GWBUF **head, int b);
|
||||
GWBUF* gw_MySQL_get_next_stmt(GWBUF** p_readbuf);
|
||||
>>>>>>> 67d9b3afb94559f13b44780c9c54760b667a068a
|
||||
|
||||
@ -53,8 +53,8 @@ typedef struct router_client_session {
|
||||
bool rses_closed; /*< true when closeSession is called */
|
||||
BACKEND *backend; /*< Backend used by the client session */
|
||||
DCB *backend_dcb; /*< DCB Connection to the backend */
|
||||
struct router_client_session
|
||||
*next;
|
||||
struct router_client_session *next;
|
||||
int rses_capabilities; /*< input type, for example */
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_chk_t rses_chk_tail;
|
||||
#endif
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* bazaar..
|
||||
* See GitHub https://github.com/skysql/MaxScale
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -41,25 +41,91 @@ typedef struct backend {
|
||||
int backend_conn_count; /*< Number of connections to the server */
|
||||
} BACKEND;
|
||||
|
||||
typedef struct rses_property_st rses_property_t;
|
||||
typedef struct router_client_session ROUTER_CLIENT_SES;
|
||||
|
||||
typedef enum rses_property_type_t {
|
||||
RSES_PROP_TYPE_UNDEFINED=0,
|
||||
RSES_PROP_TYPE_SESCMD,
|
||||
RSES_PROP_TYPE_FIRST = RSES_PROP_TYPE_SESCMD,
|
||||
RSES_PROP_TYPE_LAST=RSES_PROP_TYPE_SESCMD,
|
||||
RSES_PROP_TYPE_COUNT=RSES_PROP_TYPE_LAST+1
|
||||
} rses_property_type_t;
|
||||
|
||||
typedef enum backend_type_t {
|
||||
BE_UNDEFINED=-1,
|
||||
BE_MASTER,
|
||||
BE_SLAVE,
|
||||
BE_COUNT
|
||||
} backend_type_t;
|
||||
|
||||
/**
|
||||
* Session variable command
|
||||
*/
|
||||
typedef struct mysql_sescmd_st {
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_chk_t my_sescmd_chk_top;
|
||||
#endif
|
||||
rses_property_t* my_sescmd_prop; /*< parent property */
|
||||
GWBUF* my_sescmd_buf; /*< query buffer */
|
||||
unsigned char my_sescmd_packet_type;/*< packet type */
|
||||
bool my_sescmd_is_replied; /*< is cmd replied to client */
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_chk_t my_sescmd_chk_tail;
|
||||
#endif
|
||||
} mysql_sescmd_t;
|
||||
|
||||
|
||||
/**
|
||||
* Property structure
|
||||
*/
|
||||
struct rses_property_st {
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_chk_t rses_prop_chk_top;
|
||||
#endif
|
||||
ROUTER_CLIENT_SES* rses_prop_rsession; /*< parent router session */
|
||||
int rses_prop_refcount;
|
||||
rses_property_type_t rses_prop_type;
|
||||
union rses_prop_data {
|
||||
mysql_sescmd_t sescmd;
|
||||
void* placeholder; /*< to be removed due new type */
|
||||
} rses_prop_data;
|
||||
rses_property_t* rses_prop_next; /*< next property of same type */
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_chk_t rses_prop_chk_tail;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct sescmd_cursor_st {
|
||||
ROUTER_CLIENT_SES* scmd_cur_rses; /*< pointer to owning router session */
|
||||
rses_property_t** scmd_cur_ptr_property; /*< address of pointer to owner property */
|
||||
mysql_sescmd_t* scmd_cur_cmd; /*< pointer to current session command */
|
||||
bool scmd_cur_active; /*< true if command is being executed */
|
||||
backend_type_t scmd_cur_be_type; /*< BE_MASTER or BE_SLAVE */
|
||||
} sescmd_cursor_t;
|
||||
|
||||
/**
|
||||
* The client session structure used within this router.
|
||||
*/
|
||||
typedef struct router_client_session {
|
||||
struct router_client_session {
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_chk_t rses_chk_top;
|
||||
skygw_chk_t rses_chk_top;
|
||||
#endif
|
||||
SPINLOCK rses_lock; /*< protects rses_deleted */
|
||||
int rses_versno; /*< even = no active update, else odd */
|
||||
bool rses_closed; /*< true when closeSession is called */
|
||||
BACKEND* be_slave; /*< Slave backend used by client session */
|
||||
BACKEND* be_master; /*< Master backend used by client session */
|
||||
DCB* slave_dcb; /*< Slave connection */
|
||||
DCB* master_dcb; /*< Master connection */
|
||||
SPINLOCK rses_lock; /*< protects rses_deleted */
|
||||
int rses_versno; /*< even = no active update, else odd */
|
||||
bool rses_closed; /*< true when closeSession is called */
|
||||
/** Properties listed by their type */
|
||||
rses_property_t* rses_properties[RSES_PROP_TYPE_COUNT];
|
||||
BACKEND* rses_backend[BE_COUNT];/*< Backends used by client session */
|
||||
DCB* rses_dcb[BE_COUNT];
|
||||
/*< cursor is pointer and status variable to current session command */
|
||||
sescmd_cursor_t rses_cursor[BE_COUNT];
|
||||
int rses_capabilities; /*< input type, for example */
|
||||
struct router_client_session* next;
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_chk_t rses_chk_tail;
|
||||
skygw_chk_t rses_chk_tail;
|
||||
#endif
|
||||
} ROUTER_CLIENT_SES;
|
||||
};
|
||||
|
||||
/**
|
||||
* The statistics for this router instance
|
||||
@ -88,5 +154,4 @@ typedef struct router_instance {
|
||||
struct router_instance* next; /*< Next router on the list */
|
||||
} ROUTER_INSTANCE;
|
||||
|
||||
|
||||
#endif
|
||||
#endif /*< _RWSPLITROUTER_H */
|
||||
|
||||
@ -283,6 +283,8 @@ static int gw_read_backend_event(DCB *dcb) {
|
||||
}
|
||||
|
||||
if (backend_protocol->state == MYSQL_AUTH_FAILED) {
|
||||
|
||||
spinlock_acquire(&dcb->delayqlock);
|
||||
/*<
|
||||
* vraa : errorHandle
|
||||
* check the delayq before the reply
|
||||
@ -295,10 +297,12 @@ static int gw_read_backend_event(DCB *dcb) {
|
||||
0,
|
||||
"Connection to backend lost.");
|
||||
// consume all the delay queue
|
||||
dcb->delayq = gwbuf_consume(
|
||||
while ((dcb->delayq = gwbuf_consume(
|
||||
dcb->delayq,
|
||||
gwbuf_length(dcb->delayq));
|
||||
GWBUF_LENGTH(dcb->delayq))) != NULL);
|
||||
}
|
||||
spinlock_release(&dcb->delayqlock);
|
||||
|
||||
|
||||
/* try reload users' table for next connection */
|
||||
service_refresh_users(dcb->session->client->service);
|
||||
@ -350,7 +354,7 @@ static int gw_read_backend_event(DCB *dcb) {
|
||||
pthread_self(),
|
||||
dcb->fd,
|
||||
current_session->user)));
|
||||
|
||||
|
||||
/* check the delay queue and flush the data */
|
||||
if (dcb->delayq)
|
||||
{
|
||||
@ -524,7 +528,7 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
|
||||
/*<
|
||||
* Don't write to backend if backend_dcb is not in poll set anymore.
|
||||
*/
|
||||
spinlock_acquire(&dcb->authlock);
|
||||
spinlock_acquire(&dcb->dcb_initlock);
|
||||
if (dcb->state != DCB_STATE_POLLING) {
|
||||
/*< vraa : errorHandle */
|
||||
/*< Free buffer memory */
|
||||
@ -539,10 +543,12 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
|
||||
dcb->fd,
|
||||
STRDCBSTATE(dcb->state))));
|
||||
|
||||
spinlock_release(&dcb->authlock);
|
||||
spinlock_release(&dcb->dcb_initlock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
spinlock_release(&dcb->dcb_initlock);
|
||||
|
||||
spinlock_acquire(&dcb->authlock);
|
||||
/*<
|
||||
* Now put the incoming data to the delay queue unless backend is
|
||||
* connected with auth ok
|
||||
@ -556,7 +562,6 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
|
||||
dcb,
|
||||
dcb->fd,
|
||||
STRPROTOCOLSTATE(backend_protocol->state))));
|
||||
|
||||
backend_set_delayqueue(dcb, queue);
|
||||
spinlock_release(&dcb->authlock);
|
||||
return 1;
|
||||
@ -565,8 +570,6 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
|
||||
/*<
|
||||
* Now we set the last command received, from the current queue
|
||||
*/
|
||||
memcpy(&dcb->command, &queue->command, sizeof(dcb->command));
|
||||
|
||||
spinlock_release(&dcb->authlock);
|
||||
rc = dcb_write(dcb, queue);
|
||||
return rc;
|
||||
@ -804,12 +807,6 @@ static int backend_write_delayqueue(DCB *dcb)
|
||||
localq = dcb->delayq;
|
||||
dcb->delayq = NULL;
|
||||
|
||||
/*<
|
||||
* Now we set the last command received, from the delayed queue
|
||||
*/
|
||||
|
||||
memcpy(&dcb->command, &localq->command, sizeof(dcb->command));
|
||||
|
||||
spinlock_release(&dcb->delayqlock);
|
||||
rc = dcb_write(dcb, localq);
|
||||
|
||||
@ -851,15 +848,12 @@ static int gw_change_user(DCB *backend, SERVER *server, SESSION *in_session, GWB
|
||||
unsigned int auth_token_len = 0;
|
||||
uint8_t *auth_token = NULL;
|
||||
int rv = -1;
|
||||
int len = 0;
|
||||
int auth_ret = 1;
|
||||
|
||||
current_session = (MYSQL_session *)in_session->client->data;
|
||||
backend_protocol = backend->protocol;
|
||||
client_protocol = in_session->client->protocol;
|
||||
|
||||
queue->command = ROUTER_CHANGE_SESSION;
|
||||
|
||||
// now get the user, after 4 bytes header and 1 byte command
|
||||
client_auth_packet += 5;
|
||||
strcpy(username, (char *)client_auth_packet);
|
||||
@ -910,31 +904,14 @@ static int gw_change_user(DCB *backend, SERVER *server, SESSION *in_session, GWB
|
||||
|
||||
rv = gw_send_change_user_to_backend(database, username, client_sha1, backend_protocol);
|
||||
|
||||
/*<
|
||||
* The current queue was not handled by func.write() in gw_send_change_user_to_backend()
|
||||
* We wrote a new gwbuf
|
||||
* Set backend command here!
|
||||
*/
|
||||
memcpy(&backend->command, &queue->command, sizeof(backend->command));
|
||||
|
||||
/*<
|
||||
* Now copy new data into user session
|
||||
*/
|
||||
strcpy(current_session->user, username);
|
||||
strcpy(current_session->db, database);
|
||||
memcpy(current_session->client_sha1, client_sha1, sizeof(current_session->client_sha1));
|
||||
|
||||
}
|
||||
|
||||
// consume all the data received from client
|
||||
|
||||
spinlock_acquire(&backend->writeqlock);
|
||||
|
||||
len = gwbuf_length(queue);
|
||||
queue = gwbuf_consume(queue, len);
|
||||
|
||||
spinlock_release(&backend->writeqlock);
|
||||
|
||||
}
|
||||
gwbuf_free(queue);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -951,7 +928,6 @@ static int gw_session(DCB *backend_dcb, void *data) {
|
||||
GWBUF *queue = NULL;
|
||||
|
||||
queue = (GWBUF *) data;
|
||||
queue->command = ROUTER_CHANGE_SESSION;
|
||||
backend_dcb->func.write(backend_dcb, queue);
|
||||
|
||||
return 1;
|
||||
|
||||
@ -57,6 +57,11 @@ static int gw_client_hangup_event(DCB *dcb);
|
||||
int mysql_send_ok(DCB *dcb, int packet_number, int in_affected_rows, const char* mysql_message);
|
||||
int MySQLSendHandshake(DCB* dcb);
|
||||
static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue);
|
||||
static int route_by_statement(
|
||||
ROUTER* router_instance,
|
||||
ROUTER_OBJECT* router,
|
||||
void* rsession,
|
||||
GWBUF* read_buf);
|
||||
|
||||
/*
|
||||
* The "module object" for the mysqld client protocol module.
|
||||
@ -73,7 +78,7 @@ static GWPROTOCOL MyObject = {
|
||||
gw_MySQLListener, /* Listen */
|
||||
NULL, /* Authentication */
|
||||
NULL /* Session */
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of the mandatory version entry point
|
||||
@ -621,10 +626,11 @@ int gw_read_client_event(DCB* dcb) {
|
||||
*/
|
||||
{
|
||||
int len = -1;
|
||||
GWBUF *queue = NULL;
|
||||
GWBUF *gw_buffer = NULL;
|
||||
uint8_t cap = 0;
|
||||
GWBUF *read_buffer = NULL;
|
||||
uint8_t *ptr_buff = NULL;
|
||||
int mysql_command = -1;
|
||||
bool stmt_input; /*< router input type */
|
||||
|
||||
session = dcb->session;
|
||||
|
||||
@ -640,21 +646,20 @@ int gw_read_client_event(DCB* dcb) {
|
||||
//////////////////////////////////////////////////////
|
||||
// read and handle errors & close, or return if busy
|
||||
//////////////////////////////////////////////////////
|
||||
rc = gw_read_gwbuff(dcb, &gw_buffer, b);
|
||||
rc = gw_read_gwbuff(dcb, &read_buffer, b);
|
||||
|
||||
if (rc != 0) {
|
||||
goto return_rc;
|
||||
}
|
||||
/* Now, we are assuming in the first buffer there is
|
||||
* the information form mysql command */
|
||||
queue = gw_buffer;
|
||||
len = GWBUF_LENGTH(queue);
|
||||
ptr_buff = GWBUF_DATA(queue);
|
||||
len = GWBUF_LENGTH(read_buffer);
|
||||
ptr_buff = GWBUF_DATA(read_buffer);
|
||||
|
||||
/* get mysql commang at fifth byte */
|
||||
if (ptr_buff) {
|
||||
mysql_command = ptr_buff[4];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Without rsession there is no access to backend.
|
||||
* COM_QUIT : close client dcb
|
||||
@ -683,12 +688,38 @@ int gw_read_client_event(DCB* dcb) {
|
||||
}
|
||||
rc = 1;
|
||||
/** Free buffer */
|
||||
queue = gwbuf_consume(queue, len);
|
||||
read_buffer = gwbuf_consume(read_buffer, len);
|
||||
goto return_rc;
|
||||
}
|
||||
/** Ask what type of input the router expects */
|
||||
cap = router->getCapabilities(router_instance, rsession);
|
||||
|
||||
if (cap == 0 || (cap == RCAP_TYPE_PACKET_INPUT))
|
||||
{
|
||||
stmt_input = false;
|
||||
}
|
||||
else if (cap == RCAP_TYPE_STMT_INPUT)
|
||||
{
|
||||
stmt_input = true;
|
||||
/** Mark buffer to as MySQL type */
|
||||
gwbuf_set_type(read_buffer, GWBUF_TYPE_MYSQL);
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_send_custom_error(dcb,
|
||||
1,
|
||||
0,
|
||||
"Reading router capabilities "
|
||||
"failed. Router session is "
|
||||
"closed.");
|
||||
rc = 1;
|
||||
goto return_rc;
|
||||
}
|
||||
|
||||
|
||||
/** Route COM_QUIT to backend */
|
||||
if (mysql_command == '\x01') {
|
||||
router->routeQuery(router_instance, rsession, queue);
|
||||
router->routeQuery(router_instance, rsession, read_buffer);
|
||||
LOGIF(LD, (skygw_log_write_flush(
|
||||
LOGFILE_DEBUG,
|
||||
"%lu [gw_read_client_event] Routed COM_QUIT to "
|
||||
@ -704,10 +735,25 @@ int gw_read_client_event(DCB* dcb) {
|
||||
}
|
||||
else
|
||||
{
|
||||
/** Route other commands to backend */
|
||||
rc = router->routeQuery(router_instance,
|
||||
if (stmt_input)
|
||||
{
|
||||
/**
|
||||
* Feed each statement completely and separately
|
||||
* to router.
|
||||
*/
|
||||
rc = route_by_statement(router_instance,
|
||||
router,
|
||||
rsession,
|
||||
read_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
/** Feed whole packet to router */
|
||||
rc = router->routeQuery(router_instance,
|
||||
rsession,
|
||||
queue);
|
||||
read_buffer);
|
||||
}
|
||||
|
||||
/** succeed */
|
||||
if (rc == 1) {
|
||||
rc = 0; /**< here '0' means success */
|
||||
@ -1193,7 +1239,6 @@ static int gw_error_client_event(DCB *dcb) {
|
||||
router = session->service->router;
|
||||
router_instance = session->service->router_instance;
|
||||
rsession = session->router_session;
|
||||
|
||||
router->closeSession(router_instance, rsession);
|
||||
}
|
||||
dcb_close(dcb);
|
||||
@ -1251,7 +1296,8 @@ gw_client_hangup_event(DCB *dcb)
|
||||
void* router_instance;
|
||||
void* rsession;
|
||||
int rc = 1;
|
||||
#if defined(SS_DEBUG)
|
||||
|
||||
#if defined(SS_DEBUG)
|
||||
MySQLProtocol* protocol = (MySQLProtocol *)dcb->protocol;
|
||||
if (dcb->state == DCB_STATE_POLLING ||
|
||||
dcb->state == DCB_STATE_NOPOLLING ||
|
||||
@ -1260,8 +1306,6 @@ gw_client_hangup_event(DCB *dcb)
|
||||
CHK_PROTOCOL(protocol);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
CHK_DCB(dcb);
|
||||
|
||||
if (dcb->state != DCB_STATE_POLLING) {
|
||||
@ -1278,7 +1322,6 @@ gw_client_hangup_event(DCB *dcb)
|
||||
router = session->service->router;
|
||||
router_instance = session->service->router_instance;
|
||||
rsession = session->router_session;
|
||||
|
||||
router->closeSession(router_instance, rsession);
|
||||
}
|
||||
|
||||
@ -1286,3 +1329,99 @@ gw_client_hangup_event(DCB *dcb)
|
||||
return_rc:
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detect if buffer includes partial mysql packet or multiple packets.
|
||||
* Store partial packet to pendingqueue. Send complete packets one by one
|
||||
* to router.
|
||||
*/
|
||||
static int route_by_statement(
|
||||
ROUTER* router_instance,
|
||||
ROUTER_OBJECT* router,
|
||||
void* rsession,
|
||||
GWBUF* readbuf)
|
||||
{
|
||||
int rc = -1;
|
||||
DCB* master_dcb;
|
||||
GWBUF* stmtbuf;
|
||||
uint8_t* payload;
|
||||
static size_t len;
|
||||
|
||||
do
|
||||
{
|
||||
stmtbuf = gw_MySQL_get_next_stmt(&readbuf);
|
||||
ss_dassert(stmtbuf != NULL);
|
||||
CHK_GWBUF(stmtbuf);
|
||||
|
||||
payload = (uint8_t *)GWBUF_DATA(stmtbuf);
|
||||
/**
|
||||
* If message is longer than read data, suspend routing and
|
||||
* add statement buffer to wait queue.
|
||||
*/
|
||||
rc = router->routeQuery(router_instance, rsession, stmtbuf);
|
||||
}
|
||||
while (readbuf != NULL);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a character array including the query string.
|
||||
* GWBUF given as input includes either one complete or partial query.
|
||||
* Length of buffer is at most the query length+4 (length of packet header).
|
||||
*/
|
||||
#if defined(NOT_USED)
|
||||
static char* gw_get_or_create_querystr (
|
||||
void* data,
|
||||
bool* new_allocation)
|
||||
{
|
||||
GWBUF* buf = (GWBUF *)data;
|
||||
size_t buflen; /*< first gw buffer data length */
|
||||
size_t packetlen; /*< length of mysql packet */
|
||||
size_t querylen; /*< total buffer length-<length of type indicator> */
|
||||
size_t nbytes_copied;
|
||||
char* startpos; /*< first byte of query in gw buffer */
|
||||
char* str; /*< resulting query string */
|
||||
|
||||
CHK_GWBUF(buf);
|
||||
packetlen = MYSQL_GET_PACKET_LEN((uint8_t *)GWBUF_DATA(buf));
|
||||
str = (char *)malloc(packetlen); /*< leave space for terminating null */
|
||||
|
||||
if (str == NULL)
|
||||
{
|
||||
goto return_str;
|
||||
}
|
||||
*new_allocation = true;
|
||||
/**
|
||||
* First buffer includes 4 bytes header and a type indicator byte.
|
||||
*/
|
||||
buflen = GWBUF_LENGTH(buf);
|
||||
querylen = packetlen-1;
|
||||
ss_dassert(buflen<=querylen+5); /*< 5 == header+type indicator */
|
||||
startpos = (char *)GWBUF_DATA(buf)+5;
|
||||
nbytes_copied = MIN(querylen, buflen-5);
|
||||
memcpy(str, startpos, nbytes_copied);
|
||||
memset(&str[querylen-1], 0, 1);
|
||||
buf = gwbuf_consume(buf, querylen-1);
|
||||
|
||||
/**
|
||||
* In case of multi-packet statement whole buffer consists of query
|
||||
* string.
|
||||
*/
|
||||
while (buf != NULL)
|
||||
{
|
||||
buflen = GWBUF_LENGTH(buf);
|
||||
memcpy(str+nbytes_copied, GWBUF_DATA(buf), buflen);
|
||||
nbytes_copied += buflen;
|
||||
buf = gwbuf_consume(buf, buflen);
|
||||
}
|
||||
ss_dassert(str[querylen-1] == 0);
|
||||
|
||||
return_str:
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@ -182,7 +182,7 @@ int gw_read_backend_handshake(MySQLProtocol *conn) {
|
||||
conn->state = MYSQL_AUTH_SENT;
|
||||
|
||||
// consume all the data here
|
||||
head = gwbuf_consume(head, gwbuf_length(head));
|
||||
head = gwbuf_consume(head, GWBUF_LENGTH(head));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -342,7 +342,7 @@ int gw_receive_backend_auth(
|
||||
/*<
|
||||
* Remove data from buffer.
|
||||
*/
|
||||
head = gwbuf_consume(head, gwbuf_length(head));
|
||||
head = gwbuf_consume(head, GWBUF_LENGTH(head));
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
@ -1280,3 +1280,57 @@ mysql_send_auth_error (DCB *dcb, int packet_number, int in_affected_rows, const
|
||||
|
||||
return sizeof(mysql_packet_header) + mysql_payload_size;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the first mysql statement from buffer. Return pointer to the removed
|
||||
* statement or NULL if buffer is empty.
|
||||
*
|
||||
* Clone buf, calculate the length of included mysql stmt, and point the
|
||||
* statement with cloned buffer. Move the start pointer of buf accordingly
|
||||
* so that it only cover the remaining buffer.
|
||||
*
|
||||
*/
|
||||
GWBUF* gw_MySQL_get_next_stmt(
|
||||
GWBUF** p_readbuf)
|
||||
{
|
||||
GWBUF* stmtbuf;
|
||||
size_t buflen;
|
||||
size_t strlen;
|
||||
uint8_t* packet;
|
||||
|
||||
if (*p_readbuf == NULL)
|
||||
{
|
||||
stmtbuf = NULL;
|
||||
goto return_stmtbuf;
|
||||
}
|
||||
CHK_GWBUF(*p_readbuf);
|
||||
|
||||
if (GWBUF_EMPTY(*p_readbuf))
|
||||
{
|
||||
stmtbuf = NULL;
|
||||
goto return_stmtbuf;
|
||||
}
|
||||
buflen = GWBUF_LENGTH((*p_readbuf));
|
||||
packet = GWBUF_DATA((*p_readbuf));
|
||||
strlen = MYSQL_GET_PACKET_LEN(packet);
|
||||
|
||||
if (strlen+4 == buflen)
|
||||
{
|
||||
stmtbuf = *p_readbuf;
|
||||
*p_readbuf = NULL;
|
||||
goto return_stmtbuf;
|
||||
}
|
||||
/** vraa :Multi-packet stmt is not supported as of 7.3.14 */
|
||||
if (strlen-1 > buflen-5)
|
||||
{
|
||||
stmtbuf = NULL;
|
||||
goto return_stmtbuf;
|
||||
}
|
||||
stmtbuf = gwbuf_clone_portion(*p_readbuf, 0, strlen+4);
|
||||
*p_readbuf = gwbuf_consume(*p_readbuf, strlen+4);
|
||||
|
||||
return_stmtbuf:
|
||||
return stmtbuf;
|
||||
}
|
||||
|
||||
|
||||
@ -54,6 +54,7 @@ static void closeSession(ROUTER *instance, void *router_session);
|
||||
static void freeSession(ROUTER *instance, void *router_session);
|
||||
static int execute(ROUTER *instance, void *router_session, GWBUF *queue);
|
||||
static void diagnostics(ROUTER *instance, DCB *dcb);
|
||||
static uint8_t getCapabilities (ROUTER* inst, void* router_session);
|
||||
|
||||
/** The module object definition */
|
||||
static ROUTER_OBJECT MyObject = {
|
||||
@ -64,7 +65,8 @@ static ROUTER_OBJECT MyObject = {
|
||||
execute,
|
||||
diagnostics,
|
||||
NULL,
|
||||
NULL
|
||||
NULL,
|
||||
getCapabilities
|
||||
};
|
||||
|
||||
extern int execute_cmd(CLI_SESSION *cli);
|
||||
@ -273,3 +275,10 @@ diagnostics(ROUTER *instance, DCB *dcb)
|
||||
{
|
||||
return; /* Nothing to do currently */
|
||||
}
|
||||
|
||||
static uint8_t getCapabilities(
|
||||
ROUTER* inst,
|
||||
void* router_session)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -108,6 +108,8 @@ static void errorReply(
|
||||
char *message,
|
||||
DCB *backend_dcb,
|
||||
int action);
|
||||
static uint8_t getCapabilities (ROUTER* inst, void* router_session);
|
||||
|
||||
|
||||
/** The module object definition */
|
||||
static ROUTER_OBJECT MyObject = {
|
||||
@ -118,13 +120,14 @@ static ROUTER_OBJECT MyObject = {
|
||||
routeQuery,
|
||||
diagnostics,
|
||||
clientReply,
|
||||
errorReply
|
||||
errorReply,
|
||||
getCapabilities
|
||||
};
|
||||
|
||||
static bool rses_begin_router_action(
|
||||
static bool rses_begin_locked_router_action(
|
||||
ROUTER_CLIENT_SES* rses);
|
||||
|
||||
static void rses_exit_router_action(
|
||||
static void rses_end_locked_router_action(
|
||||
ROUTER_CLIENT_SES* rses);
|
||||
|
||||
static SPINLOCK instlock;
|
||||
@ -399,6 +402,8 @@ int master_host = -1;
|
||||
}
|
||||
}
|
||||
|
||||
client_rses->rses_capabilities = RCAP_TYPE_PACKET_INPUT;
|
||||
|
||||
/*
|
||||
* We now have the server with the least connections.
|
||||
* Bump the connection count for this server
|
||||
@ -517,7 +522,7 @@ DCB* backend_dcb;
|
||||
/**
|
||||
* Lock router client session for secure read and update.
|
||||
*/
|
||||
if (rses_begin_router_action(router_cli_ses))
|
||||
if (rses_begin_locked_router_action(router_cli_ses))
|
||||
{
|
||||
/* decrease server current connection counter */
|
||||
atomic_add(&router_cli_ses->backend->server->stats.n_current, -1);
|
||||
@ -526,7 +531,7 @@ DCB* backend_dcb;
|
||||
router_cli_ses->backend_dcb = NULL;
|
||||
router_cli_ses->rses_closed = true;
|
||||
/** Unlock */
|
||||
rses_exit_router_action(router_cli_ses);
|
||||
rses_end_locked_router_action(router_cli_ses);
|
||||
|
||||
/**
|
||||
* Close the backend server connection
|
||||
@ -572,14 +577,14 @@ routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
|
||||
/**
|
||||
* Lock router client session for secure read of DCBs
|
||||
*/
|
||||
rses_is_closed = !(rses_begin_router_action(router_cli_ses));
|
||||
rses_is_closed = !(rses_begin_locked_router_action(router_cli_ses));
|
||||
}
|
||||
|
||||
if (!rses_is_closed)
|
||||
{
|
||||
backend_dcb = router_cli_ses->backend_dcb;
|
||||
/** unlock */
|
||||
rses_exit_router_action(router_cli_ses);
|
||||
rses_end_locked_router_action(router_cli_ses);
|
||||
}
|
||||
|
||||
if (rses_is_closed || backend_dcb == NULL)
|
||||
@ -690,7 +695,7 @@ static void
|
||||
errorReply(
|
||||
ROUTER *instance,
|
||||
void *router_session,
|
||||
char *message,
|
||||
char *message,
|
||||
DCB *backend_dcb,
|
||||
int action)
|
||||
{
|
||||
@ -717,7 +722,7 @@ errorReply(
|
||||
* @details (write detailed description here)
|
||||
*
|
||||
*/
|
||||
static bool rses_begin_router_action(
|
||||
static bool rses_begin_locked_router_action(
|
||||
ROUTER_CLIENT_SES* rses)
|
||||
{
|
||||
bool succp = false;
|
||||
@ -752,9 +757,17 @@ return_succp:
|
||||
* @details (write detailed description here)
|
||||
*
|
||||
*/
|
||||
static void rses_exit_router_action(
|
||||
static void rses_end_locked_router_action(
|
||||
ROUTER_CLIENT_SES* rses)
|
||||
{
|
||||
CHK_CLIENT_RSES(rses);
|
||||
spinlock_release(&rses->rses_lock);
|
||||
}
|
||||
|
||||
|
||||
static uint8_t getCapabilities(
|
||||
ROUTER* inst,
|
||||
void* router_session)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -26,6 +26,7 @@ static void closeSession(ROUTER *instance, void *session);
|
||||
static void freeSession(ROUTER *instance, void *session);
|
||||
static int routeQuery(ROUTER *instance, void *session, GWBUF *queue);
|
||||
static void diagnostic(ROUTER *instance, DCB *dcb);
|
||||
static uint8_t getCapabilities (ROUTER* inst, void* router_session);
|
||||
|
||||
|
||||
static ROUTER_OBJECT MyObject = {
|
||||
@ -36,7 +37,8 @@ static ROUTER_OBJECT MyObject = {
|
||||
routeQuery,
|
||||
diagnostic,
|
||||
NULL,
|
||||
NULL
|
||||
NULL,
|
||||
getCapabilities
|
||||
};
|
||||
|
||||
/**
|
||||
@ -137,3 +139,10 @@ static void
|
||||
diagnostic(ROUTER *instance, DCB *dcb)
|
||||
{
|
||||
}
|
||||
|
||||
static uint8_t getCapabilities(
|
||||
ROUTER* inst,
|
||||
void* router_session)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user