In this post, we’ll address how MaxScale monitors servers. We saw in the
We saw in the previous post how we could deal with high availability (HA) and read-write split using MaxScale.
If you remember from the previous post, we used this section to monitor replication:
|
1 |
[Replication Monitor]<br>type=monitor<br>module=mysqlmon<br>servers=percona1, percona2, percona3<br>user=maxscale<br>passwd=264D375EC77998F13F4D0EC739AABAD4<br>monitor_interval=1000<br>script=/usr/local/bin/failover.sh<br>events=master_down<br> |
But what are we monitoring? We are monitoring the assignment of master and slave roles inside MaxScale according to the actual replication tree in the cluster using the default check from the mysqlmon monitoring modules.
There are other monitoring modules available with MaxScale:
So back to our setup. MaxScale monitors the roles of our servers involved in replication. We can see the status of every server like this:
|
1 |
# maxadmin -pmariadb show server percona2<br>Server 0x1cace90 (percona2)<br> Server: 192.168.90.3<br> Status: Slave, Running<br> Protocol: MySQLBackend<br> Port: 3306<br> Server Version: 5.6.28-76.1-log<br> Node Id: 2<br> Master Id: 1<br> Slave Ids: <br> Repl Depth: 1<br> Number of connections: 0<br> Current no. of conns: 0<br> Current no. of operations: 0<br> |
Now if we stop the slave, we can see:
|
1 |
# maxadmin -pmariadb show server percona2<br>Server 0x1cace90 (percona2)<br> Server: 192.168.90.3<br> Status: Running<br> Protocol: MySQLBackend<br> Port: 3306<br> Server Version: 5.6.28-76.1-log<br> Node Id: 2<br> Master Id: -1<br> Slave Ids: <br> Repl Depth: -1<br> Number of connections: 40<br> Current no. of conns: 0<br> Current no. of operations: 0<br><br># maxadmin -pmariadb list servers<br>Servers.<br>-------------------+-----------------+-------+-------------+--------------------<br>Server | Address | Port | Connections | Status <br>-------------------+-----------------+-------+-------------+--------------------<br>percona1 | 192.168.90.2 | 3306 | 0 | Master, Running<br>percona2 | 192.168.90.3 | 3306 | 0 | Running<br>percona3 | 192.168.90.4 | 3306 | 0 | Slave, Running<br>-------------------+-----------------+-------+-------------+--------------------<br> |
and in the MaxScale logs:
|
1 |
2016-02-23 14:29:09 notice : Server changed state: percona2[192.168.90.3:3306]: lost_slave<br> |
Now if the slave is lagging, nothing happens, and we will then keep sending reads to a slave that is not up to date 🙁
To avoid that situation, we can add to the “[Replication Monitor]” section the following parameter:
|
1 |
detect_replication_lag=true |
If we do so, MaxScale (if it has enough privileges) will create a schema maxscale_schema with a table replication_heartbeat . This table will be used to verify the replication lag like pt-heartbeat does.
When enabled, after we restart MaxScale, we can see the slave lag:
|
1 |
# maxadmin -pmariadb show server percona2<br>Server 0x2784f00 (percona2)<br> Server: 192.168.90.3<br> Status: Slave, Running<br> Protocol: MySQLBackend<br> Port: 3306<br> Server Version: 5.6.28-76.1-log<br> Node Id: 2<br> Master Id: 1<br> Slave Ids: <br> Repl Depth: 1<br> Slave delay: 670<br> Last Repl Heartbeat: Tue Feb 23 14:25:24 2016<br> Number of connections: 0<br> Current no. of conns: 0<br> Current no. of operations: 0<br> |
Does this mean that now the node won’t be reached (no queries will be routed to it)?
Let’s check:
|
1 |
percona3 mysql> select @@hostname;<br>+------------+<br>| @@hostname |<br>+------------+<br>| percona2 |<br>+------------+<br> |
That doesn’t sound good…
|
1 |
# maxadmin -pmariadb show server percona2<br>Server 0x2784f00 (percona2)<br> Server: 192.168.90.3<br> Status: Slave, Running<br> Protocol: MySQLBackend<br> Port: 3306<br> Server Version: 5.6.28-76.1-log<br> Node Id: 2<br> Master Id: 1<br> Slave Ids: <br> Repl Depth: 1<br> Slave delay: 1099<br> Last Repl Heartbeat: Tue Feb 23 14:25:24 2016<br> Number of connections: 1<br> Current no. of conns: 1<br> Current no. of operations: 0<br> |
We can see that there is 1 current connection .
How come? The monitoring actually works as expected, but we didn’t configure our Splitter Service to not use that lagging slave.
We need to configure it like this:
|
1 |
[Splitter Service]<br>type=service<br>router=readwritesplit<br>servers=percona1, percona2<br>max_slave_replication_lag=30<br>...<br> |
And now, if the slave lags for 30 seconds or more, it won’t be used.
But what happen if for any reason we need to stop all the slaves (or if replication breaks)?
To find out, I performed a STOP SLAVE; on percona2 and percona3. This what we see in the logs:
|
1 |
2016-02-23 22:55:16 notice : Server changed state: percona2[192.168.90.3:3306]: lost_slave<br>2016-02-23 22:55:34 notice : Server changed state: percona1[192.168.90.2:3306]: lost_master<br>2016-02-23 22:55:34 notice : Server changed state: percona3[192.168.90.4:3306]: lost_slave<br>2016-02-23 22:55:34 error : No Master can be determined. Last known was 192.168.90.2:3306<br>2016-02-23 22:55:45 error : Couldn't find suitable Master from 2 candidates.<br>2016-02-23 22:55:45 error : 140003532506880 [session_alloc] Error : Failed to create Splitter Service session because routercould not establish a new router session, see earlier error.<br>2016-02-23 22:55:46 error : Couldn't find suitable Master from 2 candidates.<br>2016-02-23 22:55:46 error : 140003542996736 [session_alloc] Error : Failed to create Splitter Service session because routercould not establish a new router session, see earlier error.<br> |
If there are no more slaves, the master is not a master anymore, and the routing doesn’t work. The service is unavailable!
As soon as we start a slave, the service is back:
|
1 |
2016-02-23 22:59:17 notice : Server changed state: percona3[192.168.90.4:3306]: new_slave<br>2016-02-23 22:59:17 notice : A Master Server is now available: 192.168.90.2:3306<br> |
Can we avoid this situation when all slaves are stopped?
Yes we can, but we need to add into the monitoring section the following line:
|
1 |
detect_stale_master=true<br> |
If we stop the two slaves again, in MaxScale’s log we can now read:
|
1 |
2016-02-23 23:02:19 notice : Server changed state: percona2[192.168.90.3:3306]: lost_slave<br>2016-02-23 23:02:46 warning: [mysql_mon]: root server [192.168.90.2:3306] is no longer Master, let's use it again even if it could be a stale master, you have been warned!<br>2016-02-23 23:02:46 notice : Server changed state: percona3[192.168.90.4:3306]: lost_slave<br> |
And we can still connect to our service and use the single master.
Next time we will see how the read-write split works.
Resources
RELATED POSTS