diff --git a/server/modules/include/blr.h b/server/modules/include/blr.h index 08f0acbea..51e967650 100644 --- a/server/modules/include/blr.h +++ b/server/modules/include/blr.h @@ -552,7 +552,7 @@ extern void blr_close_binlog(ROUTER_INSTANCE *, BLFILE *); extern unsigned long blr_file_size(BLFILE *); extern int blr_statistics(ROUTER_INSTANCE *, ROUTER_SLAVE *, GWBUF *); extern int blr_ping(ROUTER_INSTANCE *, ROUTER_SLAVE *, GWBUF *); -extern int blr_send_custom_error(DCB *, int, int, char *); +extern int blr_send_custom_error(DCB *, int, int, char *, char *, unsigned int); extern int blr_file_next_exists(ROUTER_INSTANCE *, ROUTER_SLAVE *); uint32_t extract_field(uint8_t *src, int bits); #endif diff --git a/server/modules/routing/binlog/blr.c b/server/modules/routing/binlog/blr.c index 1e9c636d7..ecaad0175 100644 --- a/server/modules/routing/binlog/blr.c +++ b/server/modules/routing/binlog/blr.c @@ -1604,17 +1604,18 @@ GWBUF *ret; * mysql_send_custom_error * * Send a MySQL protocol Generic ERR message, to the dcb - * Note the errno and state are still fixed now * - * @param dcb Owner_Dcb Control Block for the connection to which the OK is sent + * @param dcb Owner_Dcb Control Block for the connection to which the error message is sent * @param packet_number * @param in_affected_rows - * @param msg + * @param msg Message to send + * @param statemsg MySQL State message + * @param errcode MySQL Error code * @return 1 Non-zero if data was sent * */ int -blr_send_custom_error(DCB *dcb, int packet_number, int affected_rows, char *msg) +blr_send_custom_error(DCB *dcb, int packet_number, int affected_rows, char *msg, char *statemsg, unsigned int errcode) { uint8_t *outbuf = NULL; uint32_t mysql_payload_size = 0; @@ -1627,10 +1628,17 @@ unsigned int mysql_errno = 0; const char *mysql_error_msg = NULL; const char *mysql_state = NULL; GWBUF *errbuf = NULL; - - mysql_errno = 1064; - mysql_error_msg = "An errorr occurred ..."; - mysql_state = "42000"; + + if (errcode == 0) + mysql_errno = 1064; + else + mysql_errno = errcode; + + mysql_error_msg = "An errorr occurred ..."; + if (statemsg == NULL) + mysql_state = "42000"; + else + mysql_state = statemsg; field_count = 0xff; gw_mysql_set_byte2(mysql_err, mysql_errno); diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index a6a90d813..e27d150ab 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -215,7 +215,7 @@ blr_slave_request(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) if (router->mariadb10_compat && !slave->mariadb10_compat) { slave->state = BLRS_ERRORED; blr_send_custom_error(slave->dcb, 1, 0, - "MariaDB 10 Slave is required for Slave registration"); + "MariaDB 10 Slave is required for Slave registration", "42000", 1064); LOGIF(LE, (skygw_log_write( LOGFILE_ERROR, @@ -260,7 +260,8 @@ blr_slave_request(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) break; default: blr_send_custom_error(slave->dcb, 1, 0, - "You have an error in your SQL syntax; Check the syntax the MaxScale binlog router accepts."); + "You have an error in your SQL syntax; Check the syntax the MaxScale binlog router accepts.", + "42000", 1064); LOGIF(LE, (skygw_log_write( LOGFILE_ERROR, "Unexpected MySQL Command (%d) received from slave",