49 Commits

Author SHA1 Message Date
Markus Mäkelä
44f53663ea Keep server state backup even on controlled shutdown
The server state information should be persisted even if a controlled
shutdown is done. This will allow the monitor to retain the server state
information across a restart.
2017-03-17 11:26:49 +02:00
Markus Mäkelä
08cc7a9515 Make MySQL monitor crash-safe
The MySQL monitor stores the server states in a backup file which can be
used to restore the state of the servers even if MaxScale is stoppen in an
uncontrolled fashion.
2017-03-17 11:12:48 +02:00
Markus Mäkelä
6da8cfe97e Fix assignment of master status on failed servers
When the real root master server went down, it still received the master
status bit due to how the replication tree was built. The bit should only
be set for servers that are running.

Also fixed a false state change event when the master status bit was
manually cleared from the downed root master server.
2017-03-12 09:40:21 +02:00
Markus Mäkelä
916cb4df08 Rename failover and failover_recovery
The names of the parameters were misleading as MaxScale doesn't perform
the actual failover but only detects if one has been done.
2017-03-03 18:45:20 +02:00
Markus Mäkelä
7daafd33fc Restrict master failover to non-slave servers
If all but one server in a cluster fail and `failover` is enabled for
mysqlmon, the last server would be used as if it were a master. With this
change, the restrictions on failover also require that the last server is
not configured as a slave.

This change will prevent unintended failovers from happening when network
connectivity is bad. It also allows external actors to clear the slave
configuration from the last remaining server to signal MaxScale that the
server can be used as a master.
2017-03-02 09:41:38 +02:00
Markus Mäkelä
e7c7caebad Add option for failover recovery in mysqlmon
The `failover_recovery` option allows failed servers to rejoin the
cluster. This should make using MaxScale with two node clusters easier.

One use case for this is when the replication-manager promotes the last
node in the cluster as the master. When this is done, the slave
configuration is cleared and the read-only mode is disabled. Since the
failover requires that the server is not configured as a slave and that it
is not in read-only mode, it is safe to use `failover_recovery` with
replication-manager.
2017-02-20 11:20:53 +02:00
Johan Wikman
5648f708af Update license to BSL 1.1 2017-02-14 21:42:28 +02:00
Esa Korhonen
7d51864402 Clean config.h some more
Moved some typedefs to router.h and server.h, changed a few
constants to these enums. Renamed some types in config.h to
remove "Gateway".

There are still some functions in the public header which are
only used in core, but they seem to fit the theme of public functions
so were not moved.
2017-01-25 16:05:51 +02:00
Esa Korhonen
680401cf8e Rename public types and constants in monitor.h
Preparing to split monitor.h into module and core sections. Also
changed a few comments in monitor.h.
2017-01-17 15:47:13 +02:00
Markus Mäkelä
735674bb1b Format monitor modules
Formatted monitor modules with Astyle.
2017-01-17 14:48:41 +02:00
Markus Mäkelä
5b92a1f467 Remove explicit module name from log messages
The module name doesn't need to be logged as MXS_MODULE_NAME will be
automatically added as a prefix to all messages logged by the module.
2017-01-17 12:51:08 +02:00
Markus Mäkelä
2cabcea211 Add definitions of MXS_MODULE_NAME to all modules
All modules now declare a name for the module. This is name is added as a
prefix to all messages logged by a module. The prefix should help
determine which part of the system logs a message.
2017-01-16 11:28:34 +02:00
Markus Mäkelä
cbdab48237 Remove unused functions from config.h
The header is divided into two parts, an external and an internal one. The
actual splitting is done in a later commit and this commit only prepares
the header for the split.
2017-01-16 10:56:33 +02:00
Markus Mäkelä
a196420c2d Move monitor script processing and launching into the core
This removes parts of the nearly identical code from all monitors.

The removal of monitor type specific event checking is done based on the
assumption that only the monitor that is monitoring the server can be the
cause for a state change. This removes the need to actually check that the
state change is relevant for each monitor and allows the event handling to
be moved into the core.
2017-01-11 14:21:57 +02:00
Johan Wikman
a2a38f952a Add [process|thread] [init|finish] functions to modules
The MXS_MODULDE object now contains optinal pointers for functions
to be called att process and thread startup and shutdown. Since the
functions were added to the end, strictly speaking, all structures
would not have needed to have been modified, but better to be
explicit. In a subsequent change, these will be called.

C++ does not support flexible arrays, so for the time being C++
modules are restricted to 10 parameters. Better approach is to
factor out the parameters to a separate array and then just store
a pointer to that array in MXS_MODULE.
2017-01-05 14:44:02 +02:00
Markus Mäkelä
5a290cb0b8 Use module parameters in monitors
All monitors now declare the parameters that they use. This allows the
core to check the validity of the parameters before they are passed to the
monitor. It also simplifies the processing of the parameters as they are
guaranteed to be valid.
2017-01-05 09:58:11 +02:00
Markus Mäkelä
c96bd64aa8 Rename MODULE_INFO to MXS_MODULE
The MODULE_INFO is now the main object which is used by modules to convey
information to the MaxScale core. The MXS_MODULE name is more apt as it
now contains the actual module definition.

The old MODULES structure was moved into load_utils.c as an internal
implementation and was renamed so that it is not confused with the new
MODULE structure.
2017-01-03 18:01:14 +02:00
Markus Mäkelä
b00e0328d5 Create a macro for module declarations
The modules are now declared with a common macro. This allows future
additions to the module loading process while also making the loaded
symbol name a constant.
2017-01-03 18:01:13 +02:00
Markus Mäkelä
ae0577c695 Move module object inside MODULE_INFO
This allows modules to only expose one entry point with a consistent
signature. In the future, this could be used to implement declarations of
module parameters.
2017-01-03 18:01:13 +02:00
Markus Mäkelä
6c53999c97 Combine ModuleInit and GetModuleObject
The two functions can be combined into one as both are called only
once. This removes the need for the explicit ModuleInit function.
2017-01-03 18:01:13 +02:00
Markus Mäkelä
7df29aa1ec Move version entry point into MODULE_INFO
The MODULE_INFO can easily hold the version information of the
module. This removes the need for a explicit version entry point.
2017-01-03 18:01:13 +02:00
Esa Korhonen
7e9db7ed0c Have server status updates applied during monitor loop
Previously, server status changes from MaxAdmin would be set immediately
as long as the server lock could be acquired. This meant that it might take
several seconds until the next monitor pass is executed. Usually, this was
fine but in some situations we would want the monitor to run immediately
after the change (MXS-740 and Galera). This patch changes the logic of
setting and clearing status bits to a delayed mode: changes are first applied
to a "status_pending"-variable, and only once the monitor runs will the
setting be applied. To reduce the delay, the monitor now has a flag
which is checked during sleep (between short 0.1s naps). If set, the
sleep is cut short.

If a server is not monitored, the status bits are set directly.

There is a small possibility of a race condition: If a monitor is stopped or
destroyed before the pending change is applied, the change is forgotten.
2016-12-19 10:19:23 +02:00
ekorh475
259e944b3d Server status changes now happen under a lock
MXS-873 To prevent monitors and MaxAdmin from interfering with each other,
changes to the server status flags now happen under a lock. To avoid
interfering with monitor logic, the monitors now acquire locks to all
of their servers at the start of the monitor loop and release them
before sleeping.
2016-12-12 15:04:05 +02:00
Markus Makela
72622bc92f MXS-977: Move common diagnostic code to the core
Almost all monitors printed the same diagnostic output inside the
modules. This should be a part of the core, not the modules themselves.
2016-11-17 12:36:44 +02:00
Markus Makela
3c15b58891 Merge branch '2.0' into develop-2.0-merge 2016-11-15 00:09:24 +02:00
Markus Makela
16e8aa7178 Fix server usage bugs in monitors and servers
The MySQL Monitor did not reset the pointer to the root master reference
which would lead to a crash if the master was removed.

When service details were shown, it listed all servers that existed. Only
servers that haven't been removed or destroyed should be shown.
2016-11-11 10:54:34 +02:00
Markus Makela
bbd3e13a54 Only use valid server credentials
The server credentials are only used if both the monuser and monpw
parameters are defined. This is a sort of a bugfix as a monitor connection
could use a username from server but a password from the monitor.
2016-11-10 15:15:10 +02:00
Markus Makela
35d2959395 Enable online modification of servers
The address, port, monuser and monpw parameters of an existing server can
be changed at runtime. The support for enabling SSL will come in a later
commit.

Allowing servers to be modified could also be done by destroying and
recreating them. Since the servers are never actually destroyed, it is
better to allow the alteration of the existing ones.
2016-11-10 15:15:10 +02:00
Markus Makela
b51af51365 Allow monitors and services to start without servers
MaxScale can now start without any defined monitors. This allows the core
services to be configured beforehand. With the changes to dynamic
modifications to servers, automatic scaling of slaves is possible.
2016-11-10 15:15:10 +02:00
Markus Makela
4cb6d9227e MXS-778: Set read-only masters into Slave status
When a master server is set into read-only mode, it can be treated as an
always up-to-date slave. This gives us a somewhat graceful way to prevent
writes to a master.

Usually setting the master into read-only mode is done before a change in
the replication topology to prevent stray writes arriving on the
master. MaxScale should respect the read-only mode and not send any writes
to a server that's in read-only mode.
2016-10-17 10:03:25 +03:00
Johan Wikman
e41589be10 Move headers from server/include to include/maxscale
- Headers now to be included as <maxscale/xyz.h>
- First step, no cleanup of headers has been made. Only moving
  from one place to another + necessary modifications.
2016-10-13 16:19:20 +03:00
Markus Makela
9b2209a8d1 Log only one warning when failover is initiated
Mysqlmon would log a warning at every monitoring interval when failover
was initiated.
2016-10-06 16:53:37 +03:00
Markus Makela
81fa8c6c0c Assign master status immediately to the replacement master
As the failover status check is done after the pending status has been
moved to the current status, the do_failover should set the current status
of the server as Master.
2016-10-06 14:30:02 +03:00
Markus Makela
c919511ba7 Implement simple failover mode into mysqlmon
The mysqlmon simple failover mode allows it to direct write traffic to a
secondary node. This enables a very simple failover mode with MaxScale
when it is used in a two node master-slave setup.
2016-09-26 11:00:16 +03:00
Markus Makela
ca9021b835 Merge branch '2.0' into develop 2016-09-21 02:51:27 +03:00
Markus Makela
60955ba70d Clean up mysqlmon after pull request merge
The pull request introduced some minor whitespace errors.
2016-09-20 09:23:58 +03:00
TheTuxKeeper
e849297fc8 line length now less than 110 characters 2016-09-20 09:23:58 +03:00
Daniel
48456833da fixed memleak and potential call of mysql_num_rows with NULL 2016-09-20 09:23:58 +03:00
counterpoint
73c974c286 Remove automatic create database - requires too powerful database user. 2016-09-20 09:23:58 +03:00
counterpoint
ec42413db8 Initial changes to implement test before creating maxscale_schema. 2016-09-20 09:23:57 +03:00
Markus Makela
ff7634113b Assign Relay Master only to running servers
The Relay Master status was set for servers that were down. The check for
valid master and node IDs was missing which caused a false positive.
2016-09-15 07:13:10 +03:00
Markus Makela
36e243e07d Refactor monitor_mysql_db functions
The different server monitoring functions all did similar work and
combining them into one function makes the whole process of monitoring a
server simpler.
2016-09-12 15:57:27 +03:00
Markus Makela
4cd36161ee Fix stale master detection in multimaster mode
The MySQL monitor now correctly assigns stale status to master servers.
2016-09-12 15:57:27 +03:00
Markus Makela
506ef1b9f6 Assign master status only to root level masters
If a relay master server is found in the replication tree, it should not
get the master status. Previously all master servers were assigned the
master status regardless of their depth in the replication tree.

By comparing the depth value of each potential master, the monitor can
find the right master at the root of the replication tree.
2016-09-12 15:57:27 +03:00
Markus Makela
46c8a6f66b MXS-839: Detect multi-master topologies with mysqlmon
The mysqlmon now supports proper detection of multi-master topologies by
building a directed graph out of the monitored server. If cycles are found from
this graph, they are assigned a master group ID. All servers with a positive
master group ID will receive the Master status unless they have `@@read_only`
enabled.

This new functionality can be enabled with the 'multimaster' boolean
parameter.
2016-09-12 15:57:27 +03:00
Markus Makela
d745781bd0 MXS-839: Store additional server information in mysqlmon
Mysqlmon now stores the values of read_only, slave_sql_running,
slave_io_running, the name and position of the masters binlog and the
replication configuration status of the slave.

This allows more detailed server information to be displayed with the
`show monitor <name>` diagnostic interface. In addition to this, the new
structure used to store them provides an easy way to store information
that is specific to a monitor and the servers it monitors.

These new status variables can be used to implement better multi-master
detection in mysqlmon by using the value of read_only to resolve
situations where multiple master candidates are available.
2016-09-12 15:57:27 +03:00
Johan Wikman
d7f79942be Merge branch '2.0' into develop 2016-09-09 15:12:58 +03:00
Johan Wikman
3eb25df676 Update monitor APIs
No need to use void* as the types of the arguments in the monitor
functions as the types are known and will always be the same.
2016-08-19 11:21:01 +03:00
Johan Wikman
cf7988c8e3 Move all monitors into subdirs of their own
Each monitor module now resides in a subdirectory of its own.
The name of the subdirectory is the same as the name of the
library in the module's CMakeLists.txt file.
2016-08-18 13:35:28 +03:00