diff --git a/server/modules/routing/binlogrouter/blr.cc b/server/modules/routing/binlogrouter/blr.cc index 47f461950..0bff46eba 100644 --- a/server/modules/routing/binlogrouter/blr.cc +++ b/server/modules/routing/binlogrouter/blr.cc @@ -817,6 +817,7 @@ static MXS_ROUTER* createInstance(SERVICE *service, MXS_CONFIG_PARAMETER* params * automatic master replication start phase */ + inst->current_config = 0; rc = blr_file_read_master_config(inst); /* diff --git a/server/modules/routing/binlogrouter/blr.hh b/server/modules/routing/binlogrouter/blr.hh index c31ac5496..81cebb709 100644 --- a/server/modules/routing/binlogrouter/blr.hh +++ b/server/modules/routing/binlogrouter/blr.hh @@ -821,7 +821,8 @@ struct ROUTER_INSTANCE: public MXS_ROUTER enum binlog_storage_type storage_type;/*< Enables hierachical binlog file storage */ char *set_slave_hostname; /*< Send custom Hostname to Master */ ROUTER_INSTANCE *next; - std::vector configs; /*< Current config. */ + std::vector configs;/*< Available configs. */ + int current_config; /*< The config currently being used. */ }; /** Master Semi-Sync capability */ diff --git a/server/modules/routing/binlogrouter/blr_master.cc b/server/modules/routing/binlogrouter/blr_master.cc index f2baef686..d062533cc 100644 --- a/server/modules/routing/binlogrouter/blr_master.cc +++ b/server/modules/routing/binlogrouter/blr_master.cc @@ -377,6 +377,23 @@ blr_restart_master(ROUTER_INSTANCE *router) /* Force unconnected state */ router->master_state = BLRM_UNCONNECTED; router->retry_count++; + + int current_config = (router->current_config + 1) % router->configs.size(); + if (current_config != router->current_config) // Will be different unless there is but one. + { + mxb_assert(current_config < static_cast(router->configs.size())); + + const ChangeMasterConfig& old_config = router->configs[router->current_config]; + router->current_config = current_config; + const ChangeMasterConfig& new_config = router->configs[router->current_config]; + + blr_master_set_config(router, new_config); + + MXS_NOTICE("Connection to %s:%d failed, now trying with %s:%d.", + old_config.host.c_str(), old_config.port, + new_config.host.c_str(), new_config.port); + } + spinlock_release(&router->lock); blr_start_master_in_main(router, connect_retry); @@ -3094,6 +3111,15 @@ static int blr_check_connect_retry(ROUTER_INSTANCE *router) return -1; } + mxb_assert(router->configs.size() > 0); + if (router->current_config < static_cast(router->configs.size() - 1)) + { + // We have unused configs; no need to sleep anything at all. We will + // sleep only when we have unsuccessfully cycled through all available + // servers. + return 0; + } + /* Return the interval for next reconnect */ if (router->retry_count >= router->retry_interval / BLR_MASTER_BACKOFF_TIME) {