In the recently released TokuDB 7.5.5 the implementation of TokuDB hot-backup moved from a patch to the MySQL Server, to MySQL Plugin. Why did we make this change?
TokuDB hot backup makes a transactionally consistent copy of the TokuDB files while applications continue to read and write these files. Christian Rober wrote a nice series of blogs about how hot backup works. See TokuDB hot backup 1 and TokuDB hot backup 2 for details. In summary, the TokuDB hot backup library intercepts system calls that write files and duplicates the writes on backup files. It does this while copying files to the backup directory.
There are two changes made to MySQL to get TokuDB hot backup working.
First, the hot backup library must be loaded into the mysqld server so that it can intercept system calls. One could use LD_PRELOAD to solve the system call intercept problem. In contrast, Tokutek builds of MySQL link the hot backup library into mysqld so that is it automatically loaded when mysqld is started.
Second, there must be a user interface that can be used to start a backup, track its progress, and determine whether or not the backup succeeded. We have patched the MySQL server to include a new SQL command (backup to ‘/my/backup/2015/2/1’) to initiate a backup. We also defined some session variables that are used to monitor and control the backup. The patch changed the SQL parser and added code to handle the new command.
We want to use TokuDB hot backup with enterprise AND community builds of MySQL, MariaDB, and Percona Server. As a result, we replaced the patch with a plugin. The patch would have been nearly impossible to get integrated into the various MySQL forks.
The TokuDB backup plugin kicks off a backup as a side effect of setting a backup session variable to the name of the destination directory. In addition, we use session variables to monitor and control the backup process. Here is how it works. Lets suppose that we want to backup the MySQL data files into a backup directory called ‘/my/backup/2015/2/1’.
To limit the copy rate to 10 MB per second, run the ‘set tokudb_backup_throttle=10000000’ command.
To start the backup, run the ‘set tokudb_backup_dir=’/my/backup/2015/2/1’ command. This command blocks until the backup is complete. The entire backup is done by the check function attached to the ‘tokudb_backup_dir’ session variable. It is really cool that we can execute code when a session variable is updated.
The backup progress can be monitored with ‘show processlist’ from another MySQL client. The TokuDB hot backup will update the state of the backup periodically.
When the backup completes, the ‘set tokudb_backup_dir’ command returns.
Please refer to the TokuDB backup plugin github repository for further details.
Resources
RELATED POSTS