MXS-1460 Add failover_script parameter
The failover script can now be specified in the configuration file.
This commit is contained in:
parent
613994ca8a
commit
df816ea2a9
@ -230,6 +230,14 @@ error is logged and the failover functionality is disabled. If this happens, the
|
||||
cluster must be fixed manually and the failover needs to be re-enabled via the
|
||||
REST API or MaxAdmin.
|
||||
|
||||
### `failover_script`
|
||||
|
||||
*NOTE* By default, MariaDB MaxScale uses the MariaDB provided failover
|
||||
script, so `failover_script` need not be specified.
|
||||
|
||||
This command will be executed in order to perform a failover. `failover_script`
|
||||
should be specified the same way as [script](./Monitor-Common.md#script) is.
|
||||
|
||||
### `failover_timeout`
|
||||
|
||||
The timeout for the cluster failover in seconds. The default value is 90
|
||||
|
@ -310,6 +310,7 @@ void mon_process_state_changes(MXS_MONITOR *monitor, const char *script, uint64_
|
||||
* This function should be called immediately after @c mon_process_state_changes.
|
||||
*
|
||||
* @param monitor Monitor whose cluster is processed
|
||||
* @param failover_script The script to be used for performing the failover.
|
||||
* @param failover_timeout Timeout in seconds for the failover
|
||||
*
|
||||
* @return True on success, false on error
|
||||
@ -317,7 +318,9 @@ void mon_process_state_changes(MXS_MONITOR *monitor, const char *script, uint64_
|
||||
* @todo Currently this only works with flat replication topologies and
|
||||
* needs to be moved inside mysqlmon as it is MariaDB specific code.
|
||||
*/
|
||||
bool mon_process_failover(MXS_MONITOR *monitor, uint32_t failover_timeout);
|
||||
bool mon_process_failover(MXS_MONITOR *monitor,
|
||||
const char* failover_script,
|
||||
uint32_t failover_timeout);
|
||||
|
||||
/**
|
||||
* @brief Hangup connections to failed servers
|
||||
|
@ -1775,7 +1775,7 @@ void mon_process_state_changes(MXS_MONITOR *monitor, const char *script, uint64_
|
||||
}
|
||||
}
|
||||
|
||||
bool mon_process_failover(MXS_MONITOR *monitor, uint32_t failover_timeout)
|
||||
bool mon_process_failover(MXS_MONITOR *monitor, const char* failover_script, uint32_t failover_timeout)
|
||||
{
|
||||
bool rval = true;
|
||||
MXS_CONFIG* cnf = config_get_global_options();
|
||||
@ -1839,15 +1839,7 @@ bool mon_process_failover(MXS_MONITOR *monitor, uint32_t failover_timeout)
|
||||
{
|
||||
MXS_NOTICE("Performing failover of server '%s'", failed_master->server->unique_name);
|
||||
|
||||
// TODO: Use the actual failover command
|
||||
const char* failover_cmd = "/usr/bin/echo INITIATOR=$INITIATOR "
|
||||
"PARENT=$PARENT CHILDREN=$CHILDREN EVENT=$EVENT "
|
||||
"CREDENTIALS=$CREDENTIALS NODELIST=$NODELIST "
|
||||
"LIST=$LIST MASTERLIST=$MASTERLIST "
|
||||
"SLAVELIST=$SLAVELIST SYNCEDLIST=$SYNCEDLIST";
|
||||
|
||||
if (monitor_launch_script(monitor, failed_master, failover_cmd,
|
||||
failover_timeout))
|
||||
if (monitor_launch_script(monitor, failed_master, failover_script, failover_timeout))
|
||||
{
|
||||
rval = false;
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ typedef struct
|
||||
bool warn_failover; /**< Log a warning when failover happens */
|
||||
bool allow_external_slaves; /**< Whether to allow usage of external slave servers */
|
||||
bool failover; /**< If master failover is enabled */
|
||||
char* failover_script; /**< Script to call for performing master failover */
|
||||
uint32_t failover_timeout; /**< Timeout in seconds for the master failover */
|
||||
bool switchover; /**< If master switchover is enabled */
|
||||
char* switchover_script; /**< Script to call for performing master switchover */
|
||||
|
@ -68,6 +68,7 @@ static bool report_version_err = true;
|
||||
static const char* hb_table_name = "maxscale_schema.replication_heartbeat";
|
||||
|
||||
static const char CN_FAILOVER[] = "failover";
|
||||
static const char CN_FAILOVER_SCRIPT[] = "failover_script";
|
||||
static const char CN_FAILOVER_TIMEOUT[] = "failover_timeout";
|
||||
static const char CN_SWITCHOVER[] = "switchover";
|
||||
static const char CN_SWITCHOVER_SCRIPT[] = "switchover_script";
|
||||
@ -78,7 +79,15 @@ static const char CN_SWITCHOVER_TIMEOUT[] = "switchover_timeout";
|
||||
/** Default switchover timeout */
|
||||
#define DEFAULT_SWITCHOVER_TIMEOUT "90"
|
||||
|
||||
// TODO: Specify the default switchover script.
|
||||
// TODO: Specify the real default failover script.
|
||||
static const char DEFAULT_FAILOVER_SCRIPT[] =
|
||||
"/usr/bin/echo INITIATOR=$INITIATOR "
|
||||
"PARENT=$PARENT CHILDREN=$CHILDREN EVENT=$EVENT "
|
||||
"CREDENTIALS=$CREDENTIALS NODELIST=$NODELIST "
|
||||
"LIST=$LIST MASTERLIST=$MASTERLIST "
|
||||
"SLAVELIST=$SLAVELIST SYNCEDLIST=$SYNCEDLIST";
|
||||
|
||||
// TODO: Specify the real default switchover script.
|
||||
static const char DEFAULT_SWITCHOVER_SCRIPT[] =
|
||||
"/usr/bin/echo CURRENT_MASTER=$CURRENT_MASTER NEW_MASTER=$NEW_MASTER "
|
||||
"INITIATOR=$INITIATOR "
|
||||
@ -511,6 +520,12 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
mxs_monitor_event_enum_values
|
||||
},
|
||||
{CN_FAILOVER, MXS_MODULE_PARAM_BOOL, "false"},
|
||||
{
|
||||
CN_FAILOVER_SCRIPT,
|
||||
MXS_MODULE_PARAM_PATH,
|
||||
NULL,
|
||||
MXS_MODULE_OPT_PATH_X_OK
|
||||
},
|
||||
{CN_FAILOVER_TIMEOUT, MXS_MODULE_PARAM_COUNT, DEFAULT_FAILOVER_TIMEOUT},
|
||||
{CN_SWITCHOVER, MXS_MODULE_PARAM_BOOL, "false"},
|
||||
{
|
||||
@ -669,6 +684,7 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
|
||||
handle->events = config_get_enum(params, "events", mxs_monitor_event_enum_values);
|
||||
handle->allow_external_slaves = config_get_bool(params, "allow_external_slaves");
|
||||
handle->failover = config_get_bool(params, CN_FAILOVER);
|
||||
handle->failover_script = config_copy_string(params, CN_FAILOVER_SCRIPT);
|
||||
handle->failover_timeout = config_get_integer(params, CN_FAILOVER_TIMEOUT);
|
||||
handle->switchover = config_get_bool(params, CN_SWITCHOVER);
|
||||
handle->switchover_script = config_copy_string(params, CN_SWITCHOVER_SCRIPT);
|
||||
@ -1873,7 +1889,14 @@ monitorMain(void *arg)
|
||||
|
||||
if (handle->failover)
|
||||
{
|
||||
if (!mon_process_failover(mon, handle->failover_timeout))
|
||||
const char* failover_script = handle->failover_script;
|
||||
|
||||
if (!failover_script)
|
||||
{
|
||||
failover_script = DEFAULT_FAILOVER_SCRIPT;
|
||||
}
|
||||
|
||||
if (!mon_process_failover(mon, failover_script, handle->failover_timeout))
|
||||
{
|
||||
MXS_ALERT("Failed to perform failover, disabling failover functionality. "
|
||||
"To enable failover functionality, manually set 'failover' to "
|
||||
|
Loading…
x
Reference in New Issue
Block a user