added checks in blr_stop_slave()

errorReply sets mysql_errno into router struct
blr_slave_send_slave_status displays mysql errno
added checks in blr_stop_slave()
This commit is contained in:
MassimilianoPinto
2015-06-05 17:37:05 +02:00
parent 2a15e6e774
commit 945e2f8132
4 changed files with 46 additions and 5 deletions

View File

@ -27,6 +27,7 @@
* Date Who Description * Date Who Description
* 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
* *
* @endverbatim * @endverbatim
*/ */
@ -288,6 +289,8 @@ typedef struct router_instance {
int retry_backoff; int retry_backoff;
time_t connect_time; time_t connect_time;
int handling_threads; int handling_threads;
unsigned long m_errno; /*< master response mysql errno */
char *m_errmsg; /*< master response mysql error message */
struct router_instance struct router_instance
*next; *next;
} ROUTER_INSTANCE; } ROUTER_INSTANCE;

View File

@ -199,6 +199,9 @@ unsigned char *defuuid;
inst->user = strdup(service->credentials.name); inst->user = strdup(service->credentials.name);
inst->password = strdup(service->credentials.authdata); inst->password = strdup(service->credentials.authdata);
inst->m_errno = 0;
inst->m_errmsg = NULL
my_uuid_init((ulong)rand()*12345,12345); my_uuid_init((ulong)rand()*12345,12345);
if ((defuuid = (char *)malloc(20)) != NULL) if ((defuuid = (char *)malloc(20)) != NULL)
{ {
@ -1018,6 +1021,7 @@ errorReply(ROUTER *instance, void *router_session, GWBUF *message, DCB *backend_
ROUTER_INSTANCE *router = (ROUTER_INSTANCE *)instance; ROUTER_INSTANCE *router = (ROUTER_INSTANCE *)instance;
int error, len; int error, len;
char msg[85], *errmsg; char msg[85], *errmsg;
unsigned long mysql_errno;
if (action == ERRACT_RESET) if (action == ERRACT_RESET)
{ {
@ -1046,12 +1050,25 @@ char msg[85], *errmsg;
else else
strcpy(msg, ""); strcpy(msg, "");
mysql_errno = (unsigned long) extract_field((uint8_t *)(GWBUF_DATA(message) + 5), 16);
errmsg = extract_message(message); errmsg = extract_message(message);
LOGIF(LE, (skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, "%s: Master connection error '%s' in state '%s', " LOGFILE_ERROR, "%s: Master connection error '%s' in state '%s', "
"%sattempting reconnect to master", "%sattempting reconnect to master",
router->service->name, errmsg, router->service->name, errmsg,
blrm_states[router->master_state], msg))); blrm_states[router->master_state], msg)));
if (router->master_state < BLRM_BINLOGDUMP || router->master_state != BLRM_SLAVE_STOPPED) {
/* set mysql_errno */
router->m_errno = mysql_errno;
/* set io error message */
if (router->m_errmsg)
free(router->m_errmsg);
router->m_errmsg = strdup(errmsg);
}
if (errmsg) if (errmsg)
free(errmsg); free(errmsg);
*succp = true; *succp = true;

View File

@ -472,7 +472,17 @@ char query[128];
break; break;
case BLRM_MUUID: case BLRM_MUUID:
{ {
char *val = blr_extract_column(buf, 2); char *key;
char *val = NULL;
key = blr_extract_column(buf, 1);
if (key && strlen(key))
val = blr_extract_column(buf, 2);
if (key)
free(key);
if (router->master_uuid)
free(router->master_uuid);
router->master_uuid = val; router->master_uuid = val;
// Response to the SERVER_UUID, should be stored // Response to the SERVER_UUID, should be stored
@ -907,6 +917,9 @@ static REP_HEADER phdr;
phdr = hdr; phdr = hdr;
if (hdr.ok == 0) if (hdr.ok == 0)
{ {
/* set mysql errno to 0 */
router->m_errno = 0;
/* /*
* 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.
@ -1080,6 +1093,11 @@ static REP_HEADER phdr;
} }
else else
{ {
unsigned long mysql_errno = extract_field(ptr+5, 16);
/* set mysql_errno */
router->m_errno = mysql_errno;
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,

View File

@ -39,6 +39,8 @@
* 25/05/2015 Massimiliano Pinto Addition of BLRM_SLAVE_STOPPED state and blr_start/stop_slave. * 25/05/2015 Massimiliano Pinto Addition of BLRM_SLAVE_STOPPED state and blr_start/stop_slave.
* New commands STOP SLAVE, START SLAVE added. * New commands STOP SLAVE, START SLAVE added.
* 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
* in blr_slave_send_slave_status()
* *
* @endverbatim * @endverbatim
*/ */
@ -848,7 +850,7 @@ 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;
sprintf(column, "%s", router->master->remote ? router->master->remote : ""); sprintf(column, "%s", router->service->dbref->server->name ? router->service->dbref->server->name : "");
col_len = strlen(column); col_len = strlen(column);
*ptr++ = col_len; // Length of result string *ptr++ = col_len; // Length of result string
strncpy((char *)ptr, column, col_len); // Result string strncpy((char *)ptr, column, col_len); // Result string
@ -924,7 +926,7 @@ int len, actual_len, col_len, seqno, ncols, i;
*ptr++ = 0; *ptr++ = 0;
/* Last error information */ /* Last error information */
sprintf(column, "%d", 0); sprintf(column, "%lu", router->m_errno);
col_len = strlen(column); col_len = strlen(column);
*ptr++ = col_len; // Length of result string *ptr++ = col_len; // Length of result string
strncpy((char *)ptr, column, col_len); // Result string strncpy((char *)ptr, column, col_len); // Result string
@ -2209,7 +2211,7 @@ blr_stop_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave)
if (router->master_state != BLRM_SLAVE_STOPPED) { if (router->master_state != BLRM_SLAVE_STOPPED) {
if (router->master->fd != -1) if (router->master->fd != -1 && router->master->state == DCB_STATE_POLLING)
blr_master_close(router); blr_master_close(router);
spinlock_acquire(&router->lock); spinlock_acquire(&router->lock);
@ -2218,6 +2220,7 @@ blr_stop_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave)
spinlock_release(&router->lock); spinlock_release(&router->lock);
if (router->client->fd != -1 && router->client->state == DCB_STATE_POLLING)
dcb_close(router->client); dcb_close(router->client);
/* Discard the queued residual data */ /* Discard the queued residual data */