MXS-2011 Use alternative servers

If the replication fails using the current config, we retry
immediately using another config, without waiting anything at
all.

Only when we have unsuccessfully tried with all servers, will
we wait a while before starting again.
This commit is contained in:
Johan Wikman
2018-09-03 11:03:48 +03:00
parent ae28f8189b
commit 812d80e403
3 changed files with 29 additions and 1 deletions

View File

@ -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);
/*

View File

@ -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<ChangeMasterConfig> configs; /*< Current config. */
std::vector<ChangeMasterConfig> configs;/*< Available configs. */
int current_config; /*< The config currently being used. */
};
/** Master Semi-Sync capability */

View File

@ -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<int>(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<int>(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)
{