This section discusses steps and some of the best practices recommendations for migrating an application or set of applications that are currently deployed on MySQL database(s) to Xpand. 

Migration Overview

There are essentially three basic steps to achieve successful migration from MySQL environment:

There are several additional steps which may be taken to minimize risk:

Migration Prerequisites

In order to migrate your application from MySQL to Xpand, the following must be true:

Migration Steps

Take a consistent dump of the database

mysql> mysqldump -u user -h mysql_host --single-transaction --master-data=2 --all-databases > mydumpfile.dump

Please note that --single-transaction argument is important in order to get a consistent snapshot from where to start the replication slave. Additionally, --master-data argument stores the binlog position corresponding to the snapshot in the dump file.

It is recommended to use the linux screen window manager to insure that the session is not killed before the backup finishes (better than the & and nohup alternative). For monitoring the dump and ensure successful completion, the tail command may be used. Using tail on the dump file should show something like:

-- Dump completed on 2016-08-02 19:50:56 

If the dump is incomplete or incorrect due to wrong usage of mysqldump arguments, lots of time may be wasted before finding out that replication won’t work. Correctness of mysqldump command is critical.

Import the database dump using clustrix_import utility

shell> clustrix_import -i dumpfile.sql -H clustrix_ip  

- Use screen

tee the output

- Pay close attention to the final output indicating success or failure

clustrix_import has many advantages over mysql client in loading data as it imports data in parallel, taking full advantage of cluster resources. This tool is also designed to optimally distribute the data across all Xpand nodes and automatically retries transient errors.

Migrate Permissions with clustrix_clone_users

clustrix_clone_users utility will query a MySQL (or Xpand) database to dump the users and permissions, generating SQL which can then be imported, per this example. 

shell> ./clustrix_clone_users -H localhost > /tmp/grants.sql  
shell> head /tmp/grants.sql
-- Clustrix Users dumpfile ver: 113:82f8694c98db
-- Host: localhost
GRANT ALL PRIVILEGES ON `statd`.* TO 'statd'@'%' IDENTIFIED BY PASSWORD '*58D9255AEB513581F38430D559A1455461E6B74E';
shell>  mysql -h mogwai -u root < /tmp/grants.sql     

Start Replication Slave on Xpand

Once the import is complete, the slave can be created on Xpand using the following command:

sql> CREATE SLAVE 'slave1' MASTER_LOG_FILE = 'foo.000001'
, MASTER_HOST = 'host_name'
, MASTER_USER = 'user_name'
, MASTER_PASSWORD = 'password';

sql> START SLAVE 'slave1';

The proper log file and position are obtained from the beginning of the mysqldump (as generated by --master-data=2 argument).

Please refer to Configuring Replication module for obtaining information on monitoring slave status. 

Application Server Cutover

Methods to cut over application servers

There are two common methods for switching app servers from MySQL to Xpand:

  1. Reconfiguring application servers to point to Xpand instead of MySQL
  2. Using an external load balancer e.g. HAProxy to direct traffic to Xpand instead of MySQL. Please refer Load Balancing Xpand with HAProxy.

Risk Mitigation

Validating Xpand Compatibility

To reduce cutover surprises, ensure that Xpand properly handles all queries generated by the application

Enable failing back to MySQL

The ability to switch back to MySQL greatly minimizes the risk of impact to production. Configuring MySQL to slave from Xpand beforehand ensures a smooth transition should the need arise.

Steps to fail over are discussed under Configuring Replication Failover section and also outlined below:

  1. Retain privileges for all application logins on the MySQL slave instance, but keep the instance read only, by setting read_only global:

    slave> SET GLOBAL read_only = true;
  2. Enable binlogging on Xpand, ensuring format is same as MySQL master.  To enable failing back to MySQL, the binlog must be created on Xpand before application writes are allowed.

    CREATE BINLOG binlog_name [format='row']
  3. Once application servers have been cut over to Xpand, the slave on Xpand (from MySQL master) can be stopped.  Alternatively, bi-directional, or master-master replication can be configured, where Xpand continues to replicate from MySQL, while MySQL also replicates from Xpand.  This is a more complex configuration, with some caveats, as discussed in Configuring Replication Failover.
  4. Configure MySQL as a slave from Xpand, using MySQL's CHANGE MASTER TO syntax, specifying the beginning (position 4) of the binlog created in step 2.
Reverting to MySQL

In the event that it becomes necessary to revert to MySQL, given the steps above have been taken, the following steps are necessary:

  1. Change Xpand to read only mode:

    master> SET GLOBAL read_only = true;
  2. Ensure slave has caught up by comparing binlog file and position shown by SHOW MASTER STATUS on Xpand and SHOW SLAVE STATUS on MySQL
  3. Recreate or re-enable Xpand slave from MySQL, specifying current binlog file and position shown in MySQL's SHOW MASTER STATUS
  4. Enable MySQL to take writes again:

    slave> SET GLOBAL read_only = false;
  5. Application servers can now be pointed back to MySQL.

Best practice during cutover

Configure read-only on the inactive side (slave and root users are exempted):

sql>   SET GLOBAL read_only = true;  

Cutover Caveats

Replication lag

Make sure that replication is caught up before cutting over. If Xpand is significantly behind, an auto-increment INSERT coming from the newly cut-over app server will conflict with a prior INSERT in the replication stream. In order to avoid getting into such issues, it may be necessary to quiesce the MySQL server for some period of time to ensure that the Xpand slave is caught up before cutting over.

Rogue servers/scripts

Post cutover there could still be some applications or scripts that are still attempting to write to the MySQL database.  These would be either failing as MySQL instance is set to read_only mode or silently manipulating data as root. Examples of such possibilities could be admin application deployed locally on MySQL server or some of the database admin kind of shell scripts that are executed locally as root by the DBAs and manipulates data. It is necessary to review and migrate those scripts to Xpand instance going forward as otherwise it would introduce data mismatch between Xpand and MySQL