MySQL Statsdb Switch¶
Archived (pre-2022)
Preserved for reference only -- likely outdated. View original | Last updated: January 2017
Statsdb switch is done by running the statsb_switch script. See below for a functionality overview.
Note:* The procedure for performing a statsdb2* switch is basically the same. Simply use --newstatsdb2 parameter.
Performing a statsdb switch¶
Simply run this command to eg switch the current statsdb to dbs004:
Attention:* Contrary to the MySQL Master Switch script, a switch will be performed immediately, without waiting for confirmation!***
Note: Always use the fqdn for the new host!
Note2: Always run the script as a regular user, never as root! The user must have full sudo rights on all servers, however.
Tip:* Run mytop in a separate screen on the new statsdb to see if clients connect properly (see Troubleshooting*).
The script will run a sanity check, then perform the necessary steps to make dbs004 statsdb (see below).
It doesn't actually matter on which host the script is run. I () have made it a habit to always run the script on the soon-to-become-statsdb.
Troubleshooting¶
If no client connections start appearing immediately after the switch, it might be necessary to clear neighboring arp caches again.
For statsdb¶
For statsdb2¶
Finalizing the switch in chef¶
After the switch both servers (old and new statsdb) have to be cheffed to update their local configuration:
- Edit
roles/dbs00X.jsonfor the new statsb, replacerole[db_slave]withrole[db_statsdb] - Edit
roles/dbs00X.jsonfor the old statsb, replacerole[db_statsdb]withrole[db_slave] Chef the old statsdbChef the new statsdbChef mon003 (to make monitoring aware of the change).
Overview¶
Running the script without parameters simply displays the current configuration:
rwunderer@dbs004:~$ statsdb_switch
Checking configuration...
dbs003.prd.fyber.com dbs002.prd.fyber.com dbs004.prd.fyber.com dbs005.prd.fyber.com
WARN: No mha_manager host found!
#######################
Current configuration:
MASTER is dbs002.prd.fyber.com
STATSDB is dbs004.prd.fyber.com
STATSDB2 is dbs003.prd.fyber.com
MHA_MANAGER is
Current layout as reported by mha_manager:
+--dbs003.prd.fyber.com(10.99.36.33:3306)
+--dbs004.prd.fyber.com(10.99.36.34:3306)
+--dbs005.prd.fyber.com(10.99.36.35:3306)
(ignore the warning about the missing mha_manager, it would only be needed for automated failover)
Using --help gives an overview of the possible parameters:
rwunderer@dbs004:~$ statsdb_switch --help
Usage:
/usr/local/bin/statsdb_switch [OPTIONS] [--oldstatsdb=name] [--newstatsdb=name] [--oldstatsdb2=name] [--newstatsdb2=name]
-h, --help Display this help and exit
-q, --quiet Do not display information about actions performed
-f, --force Continue even though sanity check of environment fails
--oldstatsdb Name of old statsdb host
--newstatsdb Name of new statsdb host
--oldstatsdb2 Name of old statsdb2 host
--newstatsdb2 Name of new statsdb2 host
Steps performed¶
- Sanity check. If any of the following preconditions are not met, the script will abort.
--forcewill override this and continue in any case - master, statsdb and statsdb2 can be identified correctly
- statsdb and statsdb2 are not the same as master
- the new master is actually different from current master
- the master will not be moved to current statsdb or statsdb2
- Take down the VIP on the old statsdb (
ip addr del) - Take up the VIP on the new master (
ip addr add) and usearping -Uto clear arp caches on neighboring nodes/switches.