Added error_msg to blr_slave_send_slave_status()
Added error_msg to blr_slave_send_slave_status()
This commit is contained in:
@ -28,6 +28,7 @@
|
|||||||
* 02/04/14 Mark Riddoch Initial implementation
|
* 02/04/14 Mark Riddoch Initial implementation
|
||||||
* 25/05/15 Massimiliano Pinto Added BLRM_SLAVE_STOPPED state
|
* 25/05/15 Massimiliano Pinto Added BLRM_SLAVE_STOPPED state
|
||||||
* 05/06/15 Massimiliano Pinto Addition of m_errno, m_errmsg fields
|
* 05/06/15 Massimiliano Pinto Addition of m_errno, m_errmsg fields
|
||||||
|
* 08/06/15 Massimiliano Pinto Modification of MYSQL_ERROR_CODE and MYSQL_ERROR_MSG
|
||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
@ -77,8 +78,8 @@
|
|||||||
#define MYSQL_RESPONSE_OK(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0x00)
|
#define MYSQL_RESPONSE_OK(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0x00)
|
||||||
#define MYSQL_RESPONSE_EOF(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0xfe)
|
#define MYSQL_RESPONSE_EOF(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0xfe)
|
||||||
#define MYSQL_RESPONSE_ERR(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0xff)
|
#define MYSQL_RESPONSE_ERR(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0xff)
|
||||||
#define MYSQL_ERROR_CODE(buf) (*((uint8_t *)GWBUF_DATA(buf) + 5))
|
#define MYSQL_ERROR_CODE(buf) ((uint8_t *)GWBUF_DATA(buf) + 5)
|
||||||
#define MYSQL_ERROR_MSG(buf) ((uint8_t *)GWBUF_DATA(buf) + 6)
|
#define MYSQL_ERROR_MSG(buf) ((uint8_t *)GWBUF_DATA(buf) + 7)
|
||||||
#define MYSQL_COMMAND(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4))
|
#define MYSQL_COMMAND(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,8 @@
|
|||||||
*
|
*
|
||||||
* Date Who Description
|
* Date Who Description
|
||||||
* 02/04/2014 Mark Riddoch Initial implementation
|
* 02/04/2014 Mark Riddoch Initial implementation
|
||||||
* 25/05/2015 Massimiliano Pinto Addev BLRM_SLAVE_STOPPED state
|
* 25/05/2015 Massimiliano Pinto Added BLRM_SLAVE_STOPPED state
|
||||||
|
* 08/06/2015 Massimiliano Pinto Addev m_errno and m_errmsg
|
||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
@ -365,16 +366,34 @@ char query[128];
|
|||||||
}
|
}
|
||||||
else if (router->master_state != BLRM_BINLOGDUMP && MYSQL_RESPONSE_ERR(buf))
|
else if (router->master_state != BLRM_BINLOGDUMP && MYSQL_RESPONSE_ERR(buf))
|
||||||
{
|
{
|
||||||
|
char *msg_err = NULL;
|
||||||
|
int msg_len=0;
|
||||||
|
int len = gwbuf_length(buf);
|
||||||
|
unsigned long mysql_errno = extract_field(MYSQL_ERROR_CODE(buf), 16);
|
||||||
|
|
||||||
|
msg_len = len-7-6; // +7 is where msg starts, 6 is skipped the status message (#42000)
|
||||||
|
msg_err = (char *)malloc(msg_len + 1);
|
||||||
|
|
||||||
LOGIF(LE, (skygw_log_write(
|
LOGIF(LE, (skygw_log_write(
|
||||||
LOGFILE_ERROR,
|
LOGFILE_ERROR,
|
||||||
"%s: Received error: %d, %s from master during %s phase "
|
"%s: Received error: %u, '%s' from master during '%s' phase "
|
||||||
"of the master state machine.",
|
"of the master state machine.",
|
||||||
router->service->name,
|
router->service->name,
|
||||||
MYSQL_ERROR_CODE(buf), MYSQL_ERROR_MSG(buf),
|
mysql_errno, msg_err,
|
||||||
blrm_states[router->master_state]
|
blrm_states[router->master_state]
|
||||||
)));
|
)));
|
||||||
gwbuf_consume(buf, gwbuf_length(buf));
|
gwbuf_consume(buf, gwbuf_length(buf));
|
||||||
|
|
||||||
spinlock_acquire(&router->lock);
|
spinlock_acquire(&router->lock);
|
||||||
|
|
||||||
|
/* set mysql errno */
|
||||||
|
router->m_errno = mysql_errno;
|
||||||
|
|
||||||
|
/* set mysql error message */
|
||||||
|
if (router->m_errmsg)
|
||||||
|
free(router->m_errmsg);
|
||||||
|
router->m_errmsg = msg_err;
|
||||||
|
|
||||||
router->active_logs = 0;
|
router->active_logs = 0;
|
||||||
if (router->reconnect_pending)
|
if (router->reconnect_pending)
|
||||||
{
|
{
|
||||||
@ -923,6 +942,11 @@ static REP_HEADER phdr;
|
|||||||
/* set mysql errno to 0 */
|
/* set mysql errno to 0 */
|
||||||
router->m_errno = 0;
|
router->m_errno = 0;
|
||||||
|
|
||||||
|
/* Remove error message */
|
||||||
|
if (router->m_errmsg)
|
||||||
|
free(router->m_errmsg);
|
||||||
|
router->m_errmsg = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First check that the checksum we calculate matches the
|
* First check that the checksum we calculate matches the
|
||||||
* checksum in the packet we received.
|
* checksum in the packet we received.
|
||||||
@ -1097,10 +1121,27 @@ static REP_HEADER phdr;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned long mysql_errno = extract_field(ptr+5, 16);
|
unsigned long mysql_errno = extract_field(ptr+5, 16);
|
||||||
|
char *msg_err = NULL;
|
||||||
|
int msg_len=0;
|
||||||
|
msg_err = (char *)ptr+7+6; // err msg starts after 7 bytes + 6 of status message
|
||||||
|
msg_len = len-7-6; // msg len is decreased by 7 and 6
|
||||||
|
msg_err = (uint8_t *)malloc(msg_len + 1);
|
||||||
|
strncpy(msg_err, (char *)ptr+7+6, msg_len);
|
||||||
|
/* NULL terminate error string */
|
||||||
|
*(msg_err+msg_len)='\0';
|
||||||
|
|
||||||
|
spinlock_acquire(&router->lock);
|
||||||
|
|
||||||
/* set mysql_errno */
|
/* set mysql_errno */
|
||||||
router->m_errno = mysql_errno;
|
router->m_errno = mysql_errno;
|
||||||
|
|
||||||
|
/* set io error message */
|
||||||
|
if (router->m_errmsg)
|
||||||
|
free(router->m_errmsg);
|
||||||
|
router->m_errmsg = msg_err;
|
||||||
|
|
||||||
|
spinlock_release(&router->lock);
|
||||||
|
|
||||||
LOGIF(LE,(skygw_log_write(LOGFILE_ERROR,
|
LOGIF(LE,(skygw_log_write(LOGFILE_ERROR,
|
||||||
"Error packet in binlog stream.%s @ %d.",
|
"Error packet in binlog stream.%s @ %d.",
|
||||||
router->binlog_name,
|
router->binlog_name,
|
||||||
|
|||||||
@ -41,6 +41,7 @@
|
|||||||
* 29/05/2015 Massimiliano Pinto Addition of CHANGE MASTER TO ...
|
* 29/05/2015 Massimiliano Pinto Addition of CHANGE MASTER TO ...
|
||||||
* 05/06/2015 Massimiliano Pinto router->service->dbref->sever->name instead of master->remote
|
* 05/06/2015 Massimiliano Pinto router->service->dbref->sever->name instead of master->remote
|
||||||
* in blr_slave_send_slave_status()
|
* in blr_slave_send_slave_status()
|
||||||
|
* 08/06/2015 Massimiliano Pinto blr_slave_send_slave_status() shows mysql_errno and error_msg
|
||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
@ -826,6 +827,7 @@ GWBUF *pkt;
|
|||||||
char column[42];
|
char column[42];
|
||||||
uint8_t *ptr;
|
uint8_t *ptr;
|
||||||
int len, actual_len, col_len, seqno, ncols, i;
|
int len, actual_len, col_len, seqno, ncols, i;
|
||||||
|
char *dyn_column=NULL;
|
||||||
|
|
||||||
/* Count the columns */
|
/* Count the columns */
|
||||||
for (ncols = 0; slave_status_columns[ncols]; ncols++);
|
for (ncols = 0; slave_status_columns[ncols]; ncols++);
|
||||||
@ -836,7 +838,8 @@ int len, actual_len, col_len, seqno, ncols, i;
|
|||||||
blr_slave_send_columndef(router, slave, slave_status_columns[i], 0xf, 40, seqno++);
|
blr_slave_send_columndef(router, slave, slave_status_columns[i], 0xf, 40, seqno++);
|
||||||
blr_slave_send_eof(router, slave, seqno++);
|
blr_slave_send_eof(router, slave, seqno++);
|
||||||
|
|
||||||
len = 5 + (ncols * 41); // Max length
|
len = 5 + (ncols * 41) + 250; // Max length + 250 bytes error message
|
||||||
|
|
||||||
if ((pkt = gwbuf_alloc(len)) == NULL)
|
if ((pkt = gwbuf_alloc(len)) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
ptr = GWBUF_DATA(pkt);
|
ptr = GWBUF_DATA(pkt);
|
||||||
@ -932,7 +935,18 @@ int len, actual_len, col_len, seqno, ncols, i;
|
|||||||
strncpy((char *)ptr, column, col_len); // Result string
|
strncpy((char *)ptr, column, col_len); // Result string
|
||||||
ptr += col_len;
|
ptr += col_len;
|
||||||
|
|
||||||
|
/* Last error message */
|
||||||
|
if (router->m_errmsg == NULL) {
|
||||||
*ptr++ = 0;
|
*ptr++ = 0;
|
||||||
|
} else {
|
||||||
|
dyn_column = (char*)router->m_errmsg;
|
||||||
|
col_len = strlen(dyn_column);
|
||||||
|
if (col_len > 250)
|
||||||
|
col_len = 250;
|
||||||
|
*ptr++ = col_len; // Length of result string
|
||||||
|
strncpy((char *)ptr, dyn_column, col_len); // Result string
|
||||||
|
ptr += col_len;
|
||||||
|
}
|
||||||
|
|
||||||
/* Skip_Counter */
|
/* Skip_Counter */
|
||||||
sprintf(column, "%d", 0);
|
sprintf(column, "%d", 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user