Added blr_abort_change_master() routine

Added blr_abort_change_master() routine
This commit is contained in:
MassimilianoPinto
2017-09-08 11:52:25 +02:00
parent ac0de09c7c
commit 9617119aa9

View File

@ -356,9 +356,13 @@ static void blr_log_config_changes(ROUTER_INSTANCE *router,
CHANGE_MASTER_OPTIONS *change_master); CHANGE_MASTER_OPTIONS *change_master);
extern void blr_log_disabled_heartbeat(const ROUTER_INSTANCE *inst); extern void blr_log_disabled_heartbeat(const ROUTER_INSTANCE *inst);
extern void blr_close_master_in_main(void* data); extern void blr_close_master_in_main(void* data);
static bool blr_check_connecting_slave(ROUTER_INSTANCE *router, static bool blr_check_connecting_slave(const ROUTER_INSTANCE *router,
ROUTER_SLAVE *slave, ROUTER_SLAVE *slave,
enum blr_slave_check check); enum blr_slave_check check);
static void blr_abort_change_master(ROUTER_INSTANCE *router,
MASTER_SERVER_CFG *current_master,
CHANGE_MASTER_OPTIONS *change_master,
const char *error);
/** /**
* Process a request packet from the slave server. * Process a request packet from the slave server.
* *
@ -3892,10 +3896,26 @@ int blr_handle_change_master(ROUTER_INSTANCE* router,
/* save current config option data */ /* save current config option data */
blr_master_get_config(router, current_master); blr_master_get_config(router, current_master);
/* /* Abort if MASTER_USE_GTID is in use and
* Change values in the router->service->dbref->server structure * router->mariadb10_master_gtid is not set
* Change filename and position in the router structure
*/ */
if (!router->mariadb10_master_gtid &&
change_master.use_mariadb10_gtid)
{
snprintf(error,
BINLOG_ERROR_MSG_LEN,
"Cannot use MASTER_USE_GTID. "
"Enable 'mariadb10_master_gtid' option first.");
blr_abort_change_master(router,
current_master,
&change_master,
error);
spinlock_release(&router->lock);
return -1;
}
/** /**
* Handle connection options * Handle connection options
@ -3916,12 +3936,10 @@ int blr_handle_change_master(ROUTER_INSTANCE* router,
"(%d seconds).", "(%d seconds).",
BLR_HEARTBEAT_MAX_INTERVAL); BLR_HEARTBEAT_MAX_INTERVAL);
MXS_ERROR("%s: %s", router->service->name, error); blr_abort_change_master(router,
current_master,
/* restore previous master_host and master_port */ &change_master,
blr_master_restore_config(router, current_master); error);
blr_master_free_parsed_options(&change_master);
spinlock_release(&router->lock); spinlock_release(&router->lock);
@ -3950,12 +3968,10 @@ int blr_handle_change_master(ROUTER_INSTANCE* router,
"interval is not valid: %s.", "interval is not valid: %s.",
master_connect_retry); master_connect_retry);
MXS_ERROR("%s: %s", router->service->name, error); blr_abort_change_master(router,
current_master,
/* restore previous master_host and master_port */ &change_master,
blr_master_restore_config(router, current_master); error);
blr_master_free_parsed_options(&change_master);
spinlock_release(&router->lock); spinlock_release(&router->lock);
@ -4012,12 +4028,10 @@ int blr_handle_change_master(ROUTER_INSTANCE* router,
if (ssl_error == -1) if (ssl_error == -1)
{ {
MXS_ERROR("%s: %s", router->service->name, error); blr_abort_change_master(router,
current_master,
/* restore previous master_host and master_port */ &change_master,
blr_master_restore_config(router, current_master); error);
blr_master_free_parsed_options(&change_master);
spinlock_release(&router->lock); spinlock_release(&router->lock);
@ -4096,12 +4110,10 @@ int blr_handle_change_master(ROUTER_INSTANCE* router,
if (change_binlog_error) if (change_binlog_error)
{ {
MXS_ERROR("%s: %s", router->service->name, error); blr_abort_change_master(router,
current_master,
/* restore previous master_host and master_port */ &change_master,
blr_master_restore_config(router, current_master); error);
blr_master_free_parsed_options(&change_master);
spinlock_release(&router->lock); spinlock_release(&router->lock);
@ -4121,12 +4133,11 @@ int blr_handle_change_master(ROUTER_INSTANCE* router,
BINLOG_ERROR_MSG_LEN, BINLOG_ERROR_MSG_LEN,
"%s MASTER_USE_GTID=Slave_pos is required", "%s MASTER_USE_GTID=Slave_pos is required",
err_prefix); err_prefix);
MXS_ERROR("%s: %s", router->service->name, error);
/* restore previous master_host and master_port */ blr_abort_change_master(router,
blr_master_restore_config(router, current_master); current_master,
&change_master,
blr_master_free_parsed_options(&change_master); error);
spinlock_release(&router->lock); spinlock_release(&router->lock);
@ -4187,13 +4198,10 @@ int blr_handle_change_master(ROUTER_INSTANCE* router,
/* Return an error or set new binlog name at pos 4 */ /* Return an error or set new binlog name at pos 4 */
if (return_error) if (return_error)
{ {
blr_abort_change_master(router,
MXS_ERROR("%s: %s", router->service->name, error); current_master,
&change_master,
/* Restore previous master_host and master_port */ error);
blr_master_restore_config(router, current_master);
blr_master_free_parsed_options(&change_master);
MXS_FREE(master_logfile); MXS_FREE(master_logfile);
@ -4283,12 +4291,10 @@ int blr_handle_change_master(ROUTER_INSTANCE* router,
/* log error and return */ /* log error and return */
if (return_error) if (return_error)
{ {
MXS_ERROR("%s: %s", router->service->name, error); blr_abort_change_master(router,
current_master,
/* restore previous master_host and master_port */ &change_master,
blr_master_restore_config(router, current_master); error);
blr_master_free_parsed_options(&change_master);
MXS_FREE(master_logfile); MXS_FREE(master_logfile);
@ -9023,12 +9029,12 @@ static void blr_log_config_changes(ROUTER_INSTANCE *router,
* *
* @param router The router instance * @param router The router instance
* @param slave The registering slave * @param slave The registering slave
* * @param check The check requested by the caller
* @return true on succes, false otherwise * @return true on succes, false otherwise
*/ */
static bool blr_check_connecting_slave(ROUTER_INSTANCE *router, static bool blr_check_connecting_slave(const ROUTER_INSTANCE *router,
ROUTER_SLAVE *slave, ROUTER_SLAVE *slave,
enum blr_slave_check check) enum blr_slave_check check)
{ {
int rv = true; int rv = true;
char *err_msg = NULL; char *err_msg = NULL;
@ -9105,3 +9111,23 @@ static bool blr_check_connecting_slave(ROUTER_INSTANCE *router,
return rv; return rv;
} }
/**
* Abort the change master process
*
* @param router The router instance
* @param current_master Current master configuration
* @param change_master The CHANGE MASTER TO options
* @param error Error message to log
*/
static void blr_abort_change_master(ROUTER_INSTANCE *router,
MASTER_SERVER_CFG *current_master,
CHANGE_MASTER_OPTIONS *change_master,
const char *error)
{
MXS_ERROR("%s: %s", router->service->name, error);
/* restore previous master_host and master_port */
blr_master_restore_config(router, current_master);
/* Free parsed options */
blr_master_free_parsed_options(change_master);
}