From fd9a08b9f452aa752756cc5eaaf4ff3d06fdcbe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 29 Jun 2017 10:56:15 +0300 Subject: [PATCH] Make Slave of External Server status configurable The assignment of the Slave status with Slave of External Server can now be controlled with the allow_external_slaves parameter. --- Documentation/Monitors/MySQL-Monitor.md | 13 ++++++++++++ server/modules/monitor/mysqlmon.h | 1 + server/modules/monitor/mysqlmon/mysql_mon.c | 23 ++++++++++++++++----- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Documentation/Monitors/MySQL-Monitor.md b/Documentation/Monitors/MySQL-Monitor.md index 95747c76a..35500446e 100644 --- a/Documentation/Monitors/MySQL-Monitor.md +++ b/Documentation/Monitors/MySQL-Monitor.md @@ -201,6 +201,19 @@ external agent that automatically reintegrates failed servers into the cluster. One of these agents is the _replication-manager_ which automatically configures the failed servers as new slaves of the current master. +### `allow_external_slaves` + +Allow the use of external slaves. This option is enabled by default. + +If a slave server is replicating from a master that is not being monitored by +the MySQL monitor, the slaves will be assigned the _Slave of External Server_ +status (a status mainly for informational purposes). + +When the `allow_external_slaves` option is enabled, the server will also be +assigned the _Slave_ status which allows them to be used like normal slave +servers. When the option is disabled, the servers will only receive the _Slave +of External Server_ status and they will not be used. + ### `journal_max_age` The maximum journal file age in seconds. The default value is 28800 seconds. diff --git a/server/modules/monitor/mysqlmon.h b/server/modules/monitor/mysqlmon.h index 46d43cdba..b9324a581 100644 --- a/server/modules/monitor/mysqlmon.h +++ b/server/modules/monitor/mysqlmon.h @@ -80,6 +80,7 @@ typedef struct bool warn_failover; /**< Log a warning when failover happens */ bool load_journal; /**< Whether journal file should be loaded */ time_t journal_max_age; /**< Maximum age of journal file */ + bool allow_external_slaves; /**< Whether to allow usage of external slave servers */ MXS_MONITOR* monitor; } MYSQL_MONITOR; diff --git a/server/modules/monitor/mysqlmon/mysql_mon.c b/server/modules/monitor/mysqlmon/mysql_mon.c index 4f1a8baaf..c2ce96f33 100644 --- a/server/modules/monitor/mysqlmon/mysql_mon.c +++ b/server/modules/monitor/mysqlmon/mysql_mon.c @@ -104,6 +104,7 @@ MXS_MODULE* MXS_CREATE_MODULE() {"detect_standalone_master", MXS_MODULE_PARAM_BOOL, "false"}, {"failcount", MXS_MODULE_PARAM_COUNT, "5"}, {"allow_cluster_recovery", MXS_MODULE_PARAM_BOOL, "true"}, + {"allow_external_slaves", MXS_MODULE_PARAM_BOOL, "true"}, {"journal_max_age", MXS_MODULE_PARAM_COUNT, DEFAULT_JOURNAL_MAX_AGE}, { "script", @@ -264,6 +265,7 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params) handle->script = config_copy_string(params, "script"); handle->events = config_get_enum(params, "events", mxs_monitor_event_enum_values); handle->journal_max_age = config_get_integer(params, "journal_max_age"); + handle->allow_external_slaves = config_get_bool(params, "allow_external_slaves"); if (journal_is_stale(monitor, handle->journal_max_age)) { @@ -641,7 +643,14 @@ static MXS_MONITOR_SERVERS *build_mysql51_replication_tree(MXS_MONITOR *mon) (database->server->master_id <= 0 || database->server->master_id != handle->master->server->node_id)) { - monitor_set_pending_status(database, SERVER_SLAVE); + if (handle->allow_external_slaves) + { + monitor_set_pending_status(database, SERVER_SLAVE); + } + else + { + monitor_clear_pending_status(database, SERVER_SLAVE); + } monitor_set_pending_status(database, SERVER_SLAVE_OF_EXTERNAL_MASTER); } database = database->next; @@ -1848,10 +1857,14 @@ static MXS_MONITOR_SERVERS *get_replication_tree(MXS_MONITOR *mon, int num_serve { if (current->master_id > 0) { - /* this server is slave of another server not in MaxScale configuration - * we cannot use it as a real slave. - */ - monitor_set_pending_status(ptr, SERVER_SLAVE); + if (handle->allow_external_slaves) + { + monitor_set_pending_status(ptr, SERVER_SLAVE); + } + else + { + monitor_clear_pending_status(ptr, SERVER_SLAVE); + } monitor_set_pending_status(ptr, SERVER_SLAVE_OF_EXTERNAL_MASTER); } }