Merge branch '2.2' into develop
This commit is contained in:
		@ -8,6 +8,11 @@ The C++ connector for the [MariaDB MaxScale](https://mariadb.com/products/techno
 | 
			
		||||
The CDC connector is a single-file connector which allows it to be relatively
 | 
			
		||||
easily embedded into existing applications.
 | 
			
		||||
 | 
			
		||||
To start using the connector, either download it from the
 | 
			
		||||
[MariaDB website](https://mariadb.com/downloads/mariadb-tx/connector) or
 | 
			
		||||
[configure the MaxScale repository](https://mariadb.com/kb/en/library/mariadb-package-repository-setup-and-usage/)
 | 
			
		||||
and install the `maxscale-cdc-connector` package.
 | 
			
		||||
 | 
			
		||||
## API Overview
 | 
			
		||||
 | 
			
		||||
A CDC connection object is prepared by instantiating the `CDC::Connection`
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										46
									
								
								Documentation/Release-Notes/MaxScale-2.2.3-Release-Notes.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								Documentation/Release-Notes/MaxScale-2.2.3-Release-Notes.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
			
		||||
# MariaDB MaxScale 2.2.3 Release Notes
 | 
			
		||||
 | 
			
		||||
Release 2.2.3 is a GA release.
 | 
			
		||||
 | 
			
		||||
This document describes the changes in release 2.2.3, when compared to
 | 
			
		||||
release 2.2.2.
 | 
			
		||||
 | 
			
		||||
For any problems you encounter, please consider submitting a bug
 | 
			
		||||
report at [Jira](https://jira.mariadb.org).
 | 
			
		||||
 | 
			
		||||
## Changed Features
 | 
			
		||||
 | 
			
		||||
### GTID output in MaxCtrl `list servers`
 | 
			
		||||
 | 
			
		||||
The output of the `list servers` command now has a GTID column. If a server is
 | 
			
		||||
being monitored by the mariadbmon monitor, the current GTID position will be
 | 
			
		||||
displayed in the newly added column. If no GTID is available, an empty value is
 | 
			
		||||
returned.
 | 
			
		||||
 | 
			
		||||
## Dropped Features
 | 
			
		||||
 | 
			
		||||
## New Features
 | 
			
		||||
 | 
			
		||||
## Bug fixes
 | 
			
		||||
 | 
			
		||||
[Here is a list of bugs fixed in MaxScale 2.2.3.](https://jira.mariadb.org/issues/?jql=project%20%3D%20MXS%20AND%20issuetype%20%3D%20Bug%20AND%20status%20%3D%20Closed%20AND%20fixVersion%20%3D%202.2.3)
 | 
			
		||||
 | 
			
		||||
## Known Issues and Limitations
 | 
			
		||||
 | 
			
		||||
There are some limitations and known issues within this version of MaxScale.
 | 
			
		||||
For more information, please refer to the [Limitations](../About/Limitations.md) document.
 | 
			
		||||
 | 
			
		||||
## Packaging
 | 
			
		||||
 | 
			
		||||
RPM and Debian packages are provided for the Linux distributions supported
 | 
			
		||||
by MariaDB Enterprise.
 | 
			
		||||
 | 
			
		||||
Packages can be downloaded [here](https://mariadb.com/resources/downloads).
 | 
			
		||||
 | 
			
		||||
## Source Code
 | 
			
		||||
 | 
			
		||||
The source code of MaxScale is tagged at GitHub with a tag, which is identical
 | 
			
		||||
with the version of MaxScale. For instance, the tag of version X.Y.Z of MaxScale
 | 
			
		||||
is X.Y.Z. Further, *master* always refers to the latest released non-beta version.
 | 
			
		||||
 | 
			
		||||
The source code is available [here](https://github.com/mariadb-corporation/MaxScale).
 | 
			
		||||
@ -70,35 +70,62 @@ module.exports = function() {
 | 
			
		||||
            })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.filterResource = function (res, fields) {
 | 
			
		||||
        table = []
 | 
			
		||||
 | 
			
		||||
        res.data.forEach(function(i) {
 | 
			
		||||
            row = []
 | 
			
		||||
 | 
			
		||||
            fields.forEach(function(p) {
 | 
			
		||||
                var v = _.getPath(i, p[Object.keys(p)[0]], '')
 | 
			
		||||
 | 
			
		||||
                if (Array.isArray(v)) {
 | 
			
		||||
                    v = v.join(', ')
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                row.push(v)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            table.push(row)
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        return table
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.tableToString = function(table) {
 | 
			
		||||
        str = table.toString()
 | 
			
		||||
        if (this.argv.tsv) {
 | 
			
		||||
            // Based on the regex found in: https://github.com/jonschlinkert/strip-color
 | 
			
		||||
            str = str.replace( /\x1B\[[(?);]{0,2}(;?\d)*./g, '')
 | 
			
		||||
        }
 | 
			
		||||
        return str
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Get a resource as raw collection; a matrix of strings
 | 
			
		||||
    this.getRawCollection = function (host, resource, fields) {
 | 
			
		||||
        return getJson(host, resource)
 | 
			
		||||
            .then((res) => filterResource(res, fields))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.rawCollectionAsTable = function (arr, fields) {
 | 
			
		||||
        var header = []
 | 
			
		||||
 | 
			
		||||
        fields.forEach(function(i) {
 | 
			
		||||
            header.push(Object.keys(i))
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        var table = getTable(header)
 | 
			
		||||
 | 
			
		||||
        arr.forEach((row) => {
 | 
			
		||||
            table.push(row)
 | 
			
		||||
        })
 | 
			
		||||
        return tableToString(table)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Request a resource collection and format it as a table
 | 
			
		||||
    this.getCollection = function (host, resource, fields) {
 | 
			
		||||
        return doRequest(host, resource, function(res) {
 | 
			
		||||
 | 
			
		||||
            var header = []
 | 
			
		||||
 | 
			
		||||
            fields.forEach(function(i) {
 | 
			
		||||
                header.push(Object.keys(i))
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            var table = getTable(header)
 | 
			
		||||
 | 
			
		||||
            res.data.forEach(function(i) {
 | 
			
		||||
                row = []
 | 
			
		||||
 | 
			
		||||
                fields.forEach(function(p) {
 | 
			
		||||
                    var v = _.getPath(i, p[Object.keys(p)[0]], '')
 | 
			
		||||
 | 
			
		||||
                    if (Array.isArray(v)) {
 | 
			
		||||
                        v = v.join(', ')
 | 
			
		||||
                    }
 | 
			
		||||
                    row.push(v)
 | 
			
		||||
                })
 | 
			
		||||
 | 
			
		||||
                table.push(row)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            return table.toString()
 | 
			
		||||
        })
 | 
			
		||||
        return getRawCollection(host, resource, fields)
 | 
			
		||||
            .then((res) => rawCollectionAsTable(res, fields))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Request a part of a resource as a collection
 | 
			
		||||
@ -130,7 +157,7 @@ module.exports = function() {
 | 
			
		||||
                table.push(row)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            return table.toString()
 | 
			
		||||
            return tableToString(table)
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -156,7 +183,7 @@ module.exports = function() {
 | 
			
		||||
                table.push(o)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            return table.toString()
 | 
			
		||||
            return tableToString(table)
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -250,6 +277,12 @@ module.exports = function() {
 | 
			
		||||
        return doAsyncRequest(host, resource, cb, obj)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.getJson = function(host, resource) {
 | 
			
		||||
        return doAsyncRequest(host, resource, (res) => {
 | 
			
		||||
            return res
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.error = function(err) {
 | 
			
		||||
        return Promise.reject(colors.red('Error: ') +  err)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -23,13 +23,63 @@ exports.builder = function(yargs) {
 | 
			
		||||
                .usage('Usage: list servers')
 | 
			
		||||
        }, function(argv) {
 | 
			
		||||
            maxctrl(argv, function(host) {
 | 
			
		||||
                return getCollection(host, 'servers', [
 | 
			
		||||
                fields = [
 | 
			
		||||
                    {'Server': 'id'},
 | 
			
		||||
                    {'Address': 'attributes.parameters.address'},
 | 
			
		||||
                    {'Port': 'attributes.parameters.port'},
 | 
			
		||||
                    {'Connections': 'attributes.statistics.connections'},
 | 
			
		||||
                    {'State': 'attributes.state'}
 | 
			
		||||
                ])
 | 
			
		||||
                    {'State': 'attributes.state'},
 | 
			
		||||
                    {'GTID': 'attributes.gtid_current_pos'}
 | 
			
		||||
                ]
 | 
			
		||||
 | 
			
		||||
                // First, get the list of all servers
 | 
			
		||||
                return getJson(host, 'servers')
 | 
			
		||||
                    .then((res) => {
 | 
			
		||||
 | 
			
		||||
                        // Build a set of unique monitors, flatten it into an array of strings and
 | 
			
		||||
                        // filter out any duplicate or undefined values (from servers that aren't
 | 
			
		||||
                        // monitored).
 | 
			
		||||
                        var v = _.uniq(_.flatten(_.getPath(res, 'data[].relationships.monitors.data[].id'))).filter(i => i)
 | 
			
		||||
 | 
			
		||||
                        // Get the server_info object for each monitor (if it defines one)
 | 
			
		||||
                        var infos = []
 | 
			
		||||
                        var promises = v.map((i) => getJson(host, 'monitors/' + i)
 | 
			
		||||
                                             .then((j) => {
 | 
			
		||||
                                                 info = _.get(j, 'data.attributes.monitor_diagnostics.server_info')
 | 
			
		||||
                                                 if (info) {
 | 
			
		||||
                                                     info.forEach((k) => infos.push(k))
 | 
			
		||||
                                                 }
 | 
			
		||||
                                             }))
 | 
			
		||||
 | 
			
		||||
                        // Wait for promises to resolve
 | 
			
		||||
                        return Promise.all(promises)
 | 
			
		||||
                            .then(() => {
 | 
			
		||||
                                res.data.forEach((i) => {
 | 
			
		||||
 | 
			
		||||
                                    // Get the gtid_current_pos value for each server from the server_info list
 | 
			
		||||
                                    var idx = infos.findIndex((info) => info.name == i.id)
 | 
			
		||||
 | 
			
		||||
                                    if (idx != -1 && infos[idx].gtid_current_pos) {
 | 
			
		||||
                                        // Found the GTID position of this server
 | 
			
		||||
                                        i.attributes.gtid_current_pos = infos[idx].gtid_current_pos
 | 
			
		||||
                                    } else {
 | 
			
		||||
                                        // Assign an empty value so we always have something to print
 | 
			
		||||
                                        i.attributes.gtid_current_pos = ''
 | 
			
		||||
                                    }
 | 
			
		||||
                                })
 | 
			
		||||
                            })
 | 
			
		||||
                            .then(() => filterResource(res, fields))
 | 
			
		||||
                            .then((res) => rawCollectionAsTable(res, fields))
 | 
			
		||||
                    })
 | 
			
		||||
 | 
			
		||||
                return getRawCollection(host, 'servers', fields)
 | 
			
		||||
                    .then((res) => {
 | 
			
		||||
                        res.forEach((i) => {
 | 
			
		||||
                            // The server name will be first
 | 
			
		||||
                            //console.log(i[0])
 | 
			
		||||
                        })
 | 
			
		||||
                        return rawCollectionAsTable(res, fields);
 | 
			
		||||
                    })
 | 
			
		||||
            })
 | 
			
		||||
        })
 | 
			
		||||
        .command('services', 'List services', function(yargs) {
 | 
			
		||||
 | 
			
		||||
@ -33,3 +33,34 @@ describe("Diagnostic Commands", function() {
 | 
			
		||||
 | 
			
		||||
    after(stopMaxScale)
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe("MXS-1656: `list servers` with GTIDs", function() {
 | 
			
		||||
    before(startMaxScale)
 | 
			
		||||
 | 
			
		||||
    doCheck = function() {
 | 
			
		||||
        return doCommand('list servers --tsv')
 | 
			
		||||
            .then((res) => {
 | 
			
		||||
                // Check that at least 5 columns are returned with the last column consisting of
 | 
			
		||||
                // empty strings. This is because the test setup uses file and position based
 | 
			
		||||
                // replication.
 | 
			
		||||
                res = res.split('\n').map(i => i.split('\t')).map(i => i[5])
 | 
			
		||||
                _.uniq(res).should.deep.equal([''])
 | 
			
		||||
            })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    it('Lists monitored servers', function() {
 | 
			
		||||
        return doCheck()
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('Lists unmonitored servers', function() {
 | 
			
		||||
        return doCommand('unlink monitor MariaDB-Monitor server1 server2 server3 server4')
 | 
			
		||||
            .then(() => doCheck())
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('Lists partially monitored servers', function() {
 | 
			
		||||
        return doCommand('link monitor MariaDB-Monitor server1 server3')
 | 
			
		||||
            .then(() => doCheck())
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    after(stopMaxScale)
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -491,6 +491,7 @@ void check_server_statuses(TestConnections& test)
 | 
			
		||||
 | 
			
		||||
    if (masters == 0)
 | 
			
		||||
    {
 | 
			
		||||
        test.global_result = 0;
 | 
			
		||||
        test.tprintf("No master, checking that autofail has been turned off.");
 | 
			
		||||
        test.log_includes(0, "disabling automatic failover");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -1773,7 +1773,7 @@ void mon_process_state_changes(MXS_MONITOR *monitor, const char *script, uint64_
 | 
			
		||||
                master_up = true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (script && (events & event))
 | 
			
		||||
            if (script && *script && (events & event))
 | 
			
		||||
            {
 | 
			
		||||
                monitor_launch_script(monitor, ptr, script, monitor->script_timeout);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@
 | 
			
		||||
 | 
			
		||||
#define MXS_MODULE_NAME "mariadbmon"
 | 
			
		||||
 | 
			
		||||
#include "../mysqlmon.h"
 | 
			
		||||
#include "mariadbmon.hh"
 | 
			
		||||
#include <inttypes.h>
 | 
			
		||||
#include <limits>
 | 
			
		||||
#include <string>
 | 
			
		||||
@ -31,6 +31,7 @@
 | 
			
		||||
#include <maxscale/modulecmd.h>
 | 
			
		||||
#include <maxscale/modutil.h>
 | 
			
		||||
#include <maxscale/mysql_utils.h>
 | 
			
		||||
#include <maxscale/secrets.h>
 | 
			
		||||
#include <maxscale/utils.h>
 | 
			
		||||
// TODO: For monitorAddParameters
 | 
			
		||||
#include "../../../core/internal/monitor.h"
 | 
			
		||||
@ -989,8 +990,10 @@ static bool set_replication_credentials(MYSQL_MONITOR *handle, const MXS_CONFIG_
 | 
			
		||||
 | 
			
		||||
    if (*repl_user && *repl_pw)
 | 
			
		||||
    {
 | 
			
		||||
        handle->replication_user = MXS_STRDUP_A(repl_user);
 | 
			
		||||
        handle->replication_password = decrypt_password(repl_pw);
 | 
			
		||||
        handle->replication_user = repl_user;
 | 
			
		||||
        char* decrypted = decrypt_password(repl_pw);
 | 
			
		||||
        handle->replication_password = decrypted;
 | 
			
		||||
        MXS_FREE(decrypted);
 | 
			
		||||
        rval = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -1033,22 +1036,22 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
 | 
			
		||||
    if (handle)
 | 
			
		||||
    {
 | 
			
		||||
        handle->shutdown = 0;
 | 
			
		||||
        MXS_FREE(handle->script);
 | 
			
		||||
        MXS_FREE(handle->replication_user);
 | 
			
		||||
        MXS_FREE(handle->replication_password);
 | 
			
		||||
        handle->script.clear();
 | 
			
		||||
        handle->replication_user.clear();
 | 
			
		||||
        handle->replication_password.clear();
 | 
			
		||||
        MXS_FREE(handle->excluded_servers);
 | 
			
		||||
        handle->excluded_servers = NULL;
 | 
			
		||||
        handle->n_excluded = 0;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        handle = (MYSQL_MONITOR *) MXS_MALLOC(sizeof(MYSQL_MONITOR));
 | 
			
		||||
        handle = new MYSQL_MONITOR;
 | 
			
		||||
        HASHTABLE *server_info = hashtable_alloc(MAX_NUM_SLAVES,
 | 
			
		||||
                                                 hashtable_item_strhash, hashtable_item_strcmp);
 | 
			
		||||
 | 
			
		||||
        if (handle == NULL || server_info == NULL)
 | 
			
		||||
        if (server_info == NULL)
 | 
			
		||||
        {
 | 
			
		||||
            MXS_FREE(handle);
 | 
			
		||||
            delete handle;
 | 
			
		||||
            hashtable_free(server_info);
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
@ -1060,7 +1063,6 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
 | 
			
		||||
        handle->id = config_get_global_options()->id;
 | 
			
		||||
        handle->warn_set_standalone_master = true;
 | 
			
		||||
        handle->master_gtid_domain = -1;
 | 
			
		||||
        handle->external_master_host[0] = '\0';
 | 
			
		||||
        handle->external_master_port = PORT_UNKNOWN;
 | 
			
		||||
        handle->monitor = monitor;
 | 
			
		||||
    }
 | 
			
		||||
@ -1077,15 +1079,14 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
 | 
			
		||||
    handle->failcount = config_get_integer(params, CN_FAILCOUNT);
 | 
			
		||||
    handle->allow_cluster_recovery = config_get_bool(params, "allow_cluster_recovery");
 | 
			
		||||
    handle->mysql51_replication = config_get_bool(params, "mysql51_replication");
 | 
			
		||||
    handle->script = config_copy_string(params, "script");
 | 
			
		||||
    handle->script = config_get_string(params, "script");
 | 
			
		||||
    handle->events = config_get_enum(params, "events", mxs_monitor_event_enum_values);
 | 
			
		||||
    handle->auto_failover = config_get_bool(params, CN_AUTO_FAILOVER);
 | 
			
		||||
    handle->failover_timeout = config_get_integer(params, CN_FAILOVER_TIMEOUT);
 | 
			
		||||
    handle->switchover_timeout = config_get_integer(params, CN_SWITCHOVER_TIMEOUT);
 | 
			
		||||
    handle->auto_failover = config_get_bool(params, CN_AUTO_FAILOVER);
 | 
			
		||||
    handle->auto_rejoin = config_get_bool(params, CN_AUTO_REJOIN);
 | 
			
		||||
    handle->verify_master_failure = config_get_bool(params, CN_VERIFY_MASTER_FAILURE);
 | 
			
		||||
    handle->master_failure_timeout = config_get_integer(params, CN_MASTER_FAILURE_TIMEOUT);
 | 
			
		||||
    handle->auto_rejoin = config_get_bool(params, CN_AUTO_REJOIN);
 | 
			
		||||
 | 
			
		||||
    handle->excluded_servers = NULL;
 | 
			
		||||
    handle->n_excluded = mon_config_get_servers(params, CN_NO_PROMOTE_SERVERS, monitor,
 | 
			
		||||
                                                &handle->excluded_servers);
 | 
			
		||||
@ -1114,9 +1115,8 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
 | 
			
		||||
    if (error)
 | 
			
		||||
    {
 | 
			
		||||
        hashtable_free(handle->server_info);
 | 
			
		||||
        MXS_FREE(handle->script);
 | 
			
		||||
        MXS_FREE(handle->excluded_servers);
 | 
			
		||||
        MXS_FREE(handle);
 | 
			
		||||
        delete handle;
 | 
			
		||||
        handle = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
@ -1127,8 +1127,7 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
 | 
			
		||||
        {
 | 
			
		||||
            MXS_ERROR("Failed to start monitor thread for monitor '%s'.", monitor->name);
 | 
			
		||||
            hashtable_free(handle->server_info);
 | 
			
		||||
            MXS_FREE(handle->script);
 | 
			
		||||
            MXS_FREE(handle);
 | 
			
		||||
            delete handle;
 | 
			
		||||
            handle = NULL;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@ -1207,8 +1206,7 @@ static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
 | 
			
		||||
    dcb_printf(dcb, "Switchover timeout:     %u\n", handle->switchover_timeout);
 | 
			
		||||
    dcb_printf(dcb, "Automatic rejoin:       %s\n", handle->auto_rejoin ? "Enabled" : "Disabled");
 | 
			
		||||
    dcb_printf(dcb, "MaxScale monitor ID:    %lu\n", handle->id);
 | 
			
		||||
    dcb_printf(dcb, "Detect replication lag: %s\n", (handle->replicationHeartbeat == 1) ?
 | 
			
		||||
               "Enabled" : "Disabled");
 | 
			
		||||
    dcb_printf(dcb, "Detect replication lag: %s\n", (handle->replicationHeartbeat) ? "Enabled" : "Disabled");
 | 
			
		||||
    dcb_printf(dcb, "Detect stale master:    %s\n", (handle->detectStaleMaster == 1) ?
 | 
			
		||||
               "Enabled" : "Disabled");
 | 
			
		||||
    if (handle->n_excluded > 0)
 | 
			
		||||
@ -1282,9 +1280,9 @@ static json_t* diagnostics_json(const MXS_MONITOR *mon)
 | 
			
		||||
    json_object_set_new(rval, CN_SWITCHOVER_TIMEOUT, json_integer(handle->switchover_timeout));
 | 
			
		||||
    json_object_set_new(rval, CN_AUTO_REJOIN, json_boolean(handle->auto_rejoin));
 | 
			
		||||
 | 
			
		||||
    if (handle->script)
 | 
			
		||||
    if (!handle->script.empty())
 | 
			
		||||
    {
 | 
			
		||||
        json_object_set_new(rval, "script", json_string(handle->script));
 | 
			
		||||
        json_object_set_new(rval, "script", json_string(handle->script.c_str()));
 | 
			
		||||
    }
 | 
			
		||||
    if (handle->n_excluded > 0)
 | 
			
		||||
    {
 | 
			
		||||
@ -2112,7 +2110,7 @@ monitorMain(void *arg)
 | 
			
		||||
    MYSQL_MONITOR *handle  = (MYSQL_MONITOR *) arg;
 | 
			
		||||
    MXS_MONITOR* mon = handle->monitor;
 | 
			
		||||
    MXS_MONITORED_SERVER *ptr;
 | 
			
		||||
    int replication_heartbeat;
 | 
			
		||||
    bool replication_heartbeat;
 | 
			
		||||
    bool detect_stale_master;
 | 
			
		||||
    int num_servers = 0;
 | 
			
		||||
    MXS_MONITORED_SERVER *root_master = NULL;
 | 
			
		||||
@ -2285,21 +2283,20 @@ monitorMain(void *arg)
 | 
			
		||||
                if (master_info->slave_status.master_host != handle->external_master_host ||
 | 
			
		||||
                    master_info->slave_status.master_port != handle->external_master_port)
 | 
			
		||||
                {
 | 
			
		||||
                    const char* new_ext_host =  master_info->slave_status.master_host.c_str();
 | 
			
		||||
                    const string new_ext_host =  master_info->slave_status.master_host;
 | 
			
		||||
                    const int new_ext_port = master_info->slave_status.master_port;
 | 
			
		||||
                    if (handle->external_master_port == PORT_UNKNOWN)
 | 
			
		||||
                    {
 | 
			
		||||
                        MXS_NOTICE("Cluster master server is replicating from an external master: %s:%d",
 | 
			
		||||
                                   new_ext_host, new_ext_port);
 | 
			
		||||
                                   new_ext_host.c_str(), new_ext_port);
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        MXS_NOTICE("The external master of the cluster has changed: %s:%d -> %s:%d.",
 | 
			
		||||
                                   handle->external_master_host, handle->external_master_port,
 | 
			
		||||
                                   new_ext_host, new_ext_port);
 | 
			
		||||
                                   handle->external_master_host.c_str(), handle->external_master_port,
 | 
			
		||||
                                   new_ext_host.c_str(), new_ext_port);
 | 
			
		||||
                    }
 | 
			
		||||
                    snprintf(handle->external_master_host, sizeof(handle->external_master_host),
 | 
			
		||||
                             "%s", new_ext_host);
 | 
			
		||||
                    handle->external_master_host = new_ext_host;
 | 
			
		||||
                    handle->external_master_port = new_ext_port;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@ -2309,7 +2306,7 @@ monitorMain(void *arg)
 | 
			
		||||
                {
 | 
			
		||||
                    MXS_NOTICE("Cluster lost the external master.");
 | 
			
		||||
                }
 | 
			
		||||
                handle->external_master_host[0] = '\0';
 | 
			
		||||
                handle->external_master_host.clear();
 | 
			
		||||
                handle->external_master_port = PORT_UNKNOWN;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@ -2470,7 +2467,7 @@ monitorMain(void *arg)
 | 
			
		||||
         * After updating the status of all servers, check if monitor events
 | 
			
		||||
         * need to be launched.
 | 
			
		||||
         */
 | 
			
		||||
        mon_process_state_changes(mon, handle->script, handle->events);
 | 
			
		||||
        mon_process_state_changes(mon, handle->script.c_str(), handle->events);
 | 
			
		||||
        bool failover_performed = false; // Has an automatic failover been performed this loop?
 | 
			
		||||
 | 
			
		||||
        if (handle->auto_failover)
 | 
			
		||||
@ -3669,7 +3666,7 @@ bool start_external_replication(MYSQL_MONITOR* mon, MXS_MONITORED_SERVER* new_ma
 | 
			
		||||
        mxs_mysql_query(new_master->con, "START SLAVE;") == 0)
 | 
			
		||||
    {
 | 
			
		||||
        MXS_NOTICE("New master starting replication from external master %s:%d.",
 | 
			
		||||
                   mon->external_master_host, mon->external_master_port);
 | 
			
		||||
                   mon->external_master_host.c_str(), mon->external_master_port);
 | 
			
		||||
        rval = true;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#ifndef _MYSQLMON_H
 | 
			
		||||
#define _MYSQLMON_H
 | 
			
		||||
#ifndef _MARIADBMON_H
 | 
			
		||||
#define _MARIADBMON_H
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2016 MariaDB Corporation Ab
 | 
			
		||||
 *
 | 
			
		||||
@ -15,72 +15,65 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file mysqlmon.h - The MySQL monitor
 | 
			
		||||
 * @file mysqlmon.hh - The MySQL monitor
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <maxscale/cdefs.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <maxscale/monitor.h>
 | 
			
		||||
#include <maxscale/spinlock.h>
 | 
			
		||||
#include <maxscale/thread.h>
 | 
			
		||||
#include <mysql.h>
 | 
			
		||||
#include <mysqld_error.h>
 | 
			
		||||
#include <maxscale/log_manager.h>
 | 
			
		||||
#include <maxscale/secrets.h>
 | 
			
		||||
#include <maxscale/dcb.h>
 | 
			
		||||
#include <maxscale/modinfo.h>
 | 
			
		||||
#include <maxscale/cppdefs.hh>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
#include <maxscale/config.h>
 | 
			
		||||
#include <maxscale/dcb.h>
 | 
			
		||||
#include <maxscale/hashtable.h>
 | 
			
		||||
#include <maxscale/monitor.h>
 | 
			
		||||
#include <maxscale/thread.h>
 | 
			
		||||
 | 
			
		||||
MXS_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The handle for an instance of a MySQL Monitor module
 | 
			
		||||
 */
 | 
			
		||||
typedef struct
 | 
			
		||||
using std::string;
 | 
			
		||||
// MySQL Monitor module instance
 | 
			
		||||
class MYSQL_MONITOR
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    MXS_MONITOR* monitor;          /**< Generic monitor object */
 | 
			
		||||
    THREAD thread;                 /**< Monitor thread */
 | 
			
		||||
    int shutdown;                  /**< Flag to shutdown the monitor thread */
 | 
			
		||||
    int status;                    /**< Monitor status */
 | 
			
		||||
    MXS_MONITORED_SERVER *master;  /**< Master server for MySQL Master/Slave replication */
 | 
			
		||||
    HASHTABLE *server_info;        /**< Contains server specific information */
 | 
			
		||||
    bool warn_set_standalone_master; /**< Log a warning when setting standalone master */
 | 
			
		||||
    unsigned long id;              /**< Monitor ID */
 | 
			
		||||
    int replicationHeartbeat;      /**< Monitor flag for MySQL replication heartbeat */
 | 
			
		||||
 | 
			
		||||
    // Values updated by monitor
 | 
			
		||||
    int64_t master_gtid_domain;    /**< Gtid domain currently used by the master */
 | 
			
		||||
    string external_master_host;   /**< External master host, for fail/switchover */
 | 
			
		||||
    int external_master_port;      /**< External master port */
 | 
			
		||||
 | 
			
		||||
    // Replication topology detection settings
 | 
			
		||||
    bool mysql51_replication;      /**< Use MySQL 5.1 replication */
 | 
			
		||||
    bool detectStaleMaster;        /**< Monitor flag for MySQL replication Stale Master detection */
 | 
			
		||||
    bool detectStaleSlave;         /**< Monitor flag for MySQL replication Stale Master detection */
 | 
			
		||||
    bool multimaster;              /**< Detect and handle multi-master topologies */
 | 
			
		||||
    bool ignore_external_masters;  /**< Ignore masters outside of the monitor configuration */
 | 
			
		||||
    int disableMasterFailback;     /**< Monitor flag for Galera Cluster Master failback */
 | 
			
		||||
    int availableWhenDonor;        /**< Monitor flag for Galera Cluster Donor availability */
 | 
			
		||||
    int disableMasterRoleSetting;  /**< Monitor flag to disable setting master role */
 | 
			
		||||
    bool mysql51_replication;      /**< Use MySQL 5.1 replication */
 | 
			
		||||
    MXS_MONITORED_SERVER *master;  /**< Master server for MySQL Master/Slave replication */
 | 
			
		||||
    char* script;                  /**< Script to call when state changes occur on servers */
 | 
			
		||||
    uint64_t events;               /**< enabled events */
 | 
			
		||||
    HASHTABLE *server_info;        /**< Contains server specific information */
 | 
			
		||||
    bool detect_standalone_master; /**< If standalone master are detected */
 | 
			
		||||
    int failcount;                 /**< How many monitoring cycles servers must be
 | 
			
		||||
                                      down before failover is initiated */
 | 
			
		||||
    bool allow_cluster_recovery;   /**< Allow failed servers to rejoin the cluster */
 | 
			
		||||
    bool warn_set_standalone_master; /**< Log a warning when setting standalone master */
 | 
			
		||||
    bool auto_failover;            /**< If automatic master failover is enabled */
 | 
			
		||||
    bool replicationHeartbeat;     /**< Monitor flag for MySQL replication heartbeat */
 | 
			
		||||
 | 
			
		||||
    // Failover, switchover and rejoin settings
 | 
			
		||||
    string replication_user;       /**< Replication user for CHANGE MASTER TO-commands */
 | 
			
		||||
    string replication_password;   /**< Replication password for CHANGE MASTER TO-commands */
 | 
			
		||||
    int failcount;                 /**< How many monitoring cycles master must be down before auto-failover
 | 
			
		||||
                                    *   begins */
 | 
			
		||||
    uint32_t failover_timeout;     /**< Timeout in seconds for the master failover */
 | 
			
		||||
    uint32_t switchover_timeout;   /**< Timeout in seconds for the master switchover */
 | 
			
		||||
    char* replication_user;        /**< Replication user for failover */
 | 
			
		||||
    char* replication_password;    /**< Replication password for failover*/
 | 
			
		||||
    bool verify_master_failure;    /**< Whether master failure is verified via slaves */
 | 
			
		||||
    int master_failure_timeout;    /**< Time in seconds to wait before doing failover */
 | 
			
		||||
    int64_t master_gtid_domain;    /**< Gtid domain currently used by the master */
 | 
			
		||||
    char external_master_host[MAX_SERVER_ADDRESS_LEN]; /**< External master host, for fail/switchover */
 | 
			
		||||
    int external_master_port;      /**< External master port */
 | 
			
		||||
    int master_failure_timeout;    /**< Master failure verification (via slaves) time in seconds */
 | 
			
		||||
    bool auto_failover;            /**< If automatic master failover is enabled */
 | 
			
		||||
    bool auto_rejoin;              /**< Attempt to start slave replication on standalone servers or servers
 | 
			
		||||
                                        replicating from the wrong master. */
 | 
			
		||||
    int n_excluded;                /**< Number of excluded servers */
 | 
			
		||||
                                    *   replicating from the wrong master automatically. */
 | 
			
		||||
    MXS_MONITORED_SERVER** excluded_servers; /**< Servers banned for master promotion during auto-failover. */
 | 
			
		||||
    int n_excluded;                /**< Number of excluded servers */
 | 
			
		||||
 | 
			
		||||
    MXS_MONITOR* monitor;
 | 
			
		||||
} MYSQL_MONITOR;
 | 
			
		||||
 | 
			
		||||
MXS_END_DECLS
 | 
			
		||||
    // Other settings
 | 
			
		||||
    string script;                 /**< Script to call when state changes occur on servers */
 | 
			
		||||
    uint64_t events;               /**< enabled events */
 | 
			
		||||
    bool allow_cluster_recovery;   /**< Allow failed servers to rejoin the cluster */
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -17,7 +17,7 @@
 | 
			
		||||
 | 
			
		||||
#define MXS_MODULE_NAME "ndbclustermon"
 | 
			
		||||
 | 
			
		||||
#include "../mysqlmon.h"
 | 
			
		||||
#include "ndbclustermon.h"
 | 
			
		||||
#include <maxscale/alloc.h>
 | 
			
		||||
#include <maxscale/mysql_utils.h>
 | 
			
		||||
 | 
			
		||||
@ -103,7 +103,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
 | 
			
		||||
static void *
 | 
			
		||||
startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
 | 
			
		||||
{
 | 
			
		||||
    MYSQL_MONITOR *handle = mon->handle;
 | 
			
		||||
    NDBC_MONITOR *handle = mon->handle;
 | 
			
		||||
    bool have_events = false, script_error = false;
 | 
			
		||||
 | 
			
		||||
    if (handle != NULL)
 | 
			
		||||
@ -113,7 +113,7 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        if ((handle = (MYSQL_MONITOR *) MXS_MALLOC(sizeof(MYSQL_MONITOR))) == NULL)
 | 
			
		||||
        if ((handle = (NDBC_MONITOR *) MXS_MALLOC(sizeof(NDBC_MONITOR))) == NULL)
 | 
			
		||||
        {
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
@ -154,7 +154,7 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
 | 
			
		||||
static void
 | 
			
		||||
stopMonitor(MXS_MONITOR *mon)
 | 
			
		||||
{
 | 
			
		||||
    MYSQL_MONITOR *handle = (MYSQL_MONITOR *) mon->handle;
 | 
			
		||||
    NDBC_MONITOR *handle = (NDBC_MONITOR *) mon->handle;
 | 
			
		||||
 | 
			
		||||
    handle->shutdown = 1;
 | 
			
		||||
    thread_wait(handle->thread);
 | 
			
		||||
@ -306,7 +306,7 @@ monitorDatabase(MXS_MONITORED_SERVER *database, char *defaultUser, char *default
 | 
			
		||||
static void
 | 
			
		||||
monitorMain(void *arg)
 | 
			
		||||
{
 | 
			
		||||
    MYSQL_MONITOR *handle = (MYSQL_MONITOR*)arg;
 | 
			
		||||
    NDBC_MONITOR *handle = (NDBC_MONITOR*)arg;
 | 
			
		||||
    MXS_MONITOR* mon = handle->monitor;
 | 
			
		||||
    MXS_MONITORED_SERVER *ptr;
 | 
			
		||||
    size_t nrounds = 0;
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,6 @@
 | 
			
		||||
#ifndef _MYSQLMON_H
 | 
			
		||||
#define _MYSQLMON_H
 | 
			
		||||
#pragma once
 | 
			
		||||
#ifndef _NDBCMON_H
 | 
			
		||||
#define _NDBCMON_H
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2016 MariaDB Corporation Ab
 | 
			
		||||
 *
 | 
			
		||||
@ -13,39 +14,27 @@
 | 
			
		||||
 * Public License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <monitor.h>
 | 
			
		||||
#include <spinlock.h>
 | 
			
		||||
#include <thread.h>
 | 
			
		||||
#include <mysql.h>
 | 
			
		||||
#include <mysqld_error.h>
 | 
			
		||||
#include <log_manager.h>
 | 
			
		||||
#include <secrets.h>
 | 
			
		||||
#include <dcb.h>
 | 
			
		||||
#include <modinfo.h>
 | 
			
		||||
#include <config.h>
 | 
			
		||||
#include <externcmd.h>
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file ndbclustermon.h - The NDB Cluster monitor
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The handle for an instance of a NDB Cluster Monitor module
 | 
			
		||||
 */
 | 
			
		||||
#include <maxscale/monitor.h>
 | 
			
		||||
#include <maxscale/spinlock.h>
 | 
			
		||||
#include <maxscale/thread.h>
 | 
			
		||||
 | 
			
		||||
// The handle for an instance of a NDB Cluster Monitor module
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    THREAD thread; /**< Monitor thread */
 | 
			
		||||
    SPINLOCK lock; /**< The monitor spinlock */
 | 
			
		||||
    pthread_t tid; /**< id of monitor thread */
 | 
			
		||||
    unsigned long id; /**< Monitor ID */
 | 
			
		||||
    uint64_t events; /*< enabled events */
 | 
			
		||||
    int shutdown; /**< Flag to shutdown the monitor thread */
 | 
			
		||||
    int status; /**< Monitor status */
 | 
			
		||||
    unsigned long id; /**< Monitor ID */
 | 
			
		||||
    MONITOR_SERVERS *master; /**< Master server for MySQL Master/Slave replication */
 | 
			
		||||
    MXS_MONITORED_SERVER *master; /**< Master server for MySQL Master/Slave replication */
 | 
			
		||||
    char* script; /*< Script to call when state changes occur on servers */
 | 
			
		||||
    bool events[MAX_MONITOR_EVENT]; /*< enabled events */
 | 
			
		||||
} MYSQL_MONITOR;
 | 
			
		||||
    MXS_MONITOR* monitor;
 | 
			
		||||
} NDBC_MONITOR;
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user