New --mysql-stop option for ec2-consistent-snapshot

| 6 Comments | 0 TrackBacks

The ec2-consistent-snapshot software tries its best to flush and lock a MySQL database on an EC2 instance while it initiates the EBS snapshot, and for many environments it does a pretty good job.

However, there are situations where the database may spend time performing crash recovery from the log file when it is started from a copy of the snapshot. We are seeing this behavior at CampusExplorer.com where the database is constantly active and we have innodb_log_file_size set (probably too) high. The delay is doubtless exacerbated by the fact that the blocks on the new EBS volume are being recovered from S3 as it is being built from the snapshot.

Google has created an innodb_disallow_writes MySQL patch which I think points out the problem we may be hitting.

“Note that it is not sufficient to run FLUSH TABLES WITH READ LOCK as there are background IO threads used by InnoDB that may still do IO.”

It would be very nice to have this patch incorporated in MySQL on Ubuntu. It looks like the OurDelta folks have already incorporated the patch. [Update: See rsimmons’ comment below which explains why this particular patch might not be the answer.]

In any case, when we bring up a database using an EBS volume created from an EBS snapshot of an active database, it can take up to 45 minutes recovering before it lets normal clients connect. This is too long for us so we’re trying a new approach.

The ec2-consistent-snapshot now has a --mysql-stop option which shuts down the MySQL server, initiates the snapshot, and then restarts the database. Our hope is that this will get us a snapshot which can be restored and run without delay. If any MySQL experts can point out the potential flaws in this, please do.

Since we obviously can’t stop and start our production database every hour, we are performing this snapshot activity on a replication slave that is dedicated to snapshots and backups.

We continue to perform occasional snapshots on the production database EBS volume just to help keep it reliable per Amazon’s instructions, but we don’t expect to be able to restore it without crash recovery.

If you’d like to test the new --mysql-stop option, please upgrade your ec2-consistent-snapshot package from the Alestic PPA and let me know how it goes.

No TrackBacks

TrackBack URL: http://alestic.com/mt/mt-tb.cgi/57

6 Comments

It would be great to get an option for mysql_socket. I have a non-standard socket location in my setup and I've had to modify ec2-consistent-snapshot so that mysql_host was "localhost:mysql_socket=/path/to/mysql.sock". I don't know enough Perl, or I'd do it myself.

Thanks for all the great tools and articles
-David

I don't think there's a way for you to avoid doing a recovery or clean shutdown. If I understand correctly, the innodb log is basically a way of borrowing against the future, by doing fast sequential writes to the end of a log file instead of random writes to the data files. But eventually the writes need to be applied to the data files. A typical busy mysql server will have plenty of dirty blocks in the buffer pool, which means they have been written to the log but not the data files. At some point you will need to apply these changes to the data files, whether through clean shutdown or recovery. As far as I know the standard options for a _hot_ consistent backup are:

1) filesystem level snapshot and then recovery. you can do the recovery on a spare host immediately after the snapshot so you can quickly restore later in case of disaster
2) percona xtrabackup. this cleverly avoids needs a FS level snapshot, but requires doing a "log apply" step (basically recovery) before being able to use the backup.

You should definitely experiment with reducing innodb_log_file_size as far as you can before it has a negative performance impact. Your recovery time should be directly proportional to it.

As far as I understand, the innodb_disallow_writes patch is just an alternative when you can't do a filesystem level snapshot. It allows you to get a clean copy of the data and logs without shutting down the server, but since it doesn't flush dirty pages you would still need to do a recovery after copying the files.

Performing backups from a slave is fine, but there are some bugs I have encountered with replication that can cause the slave to accumulate small differences from the master over time. So I would recommend checking for that (mk-table-checksum) and/or periodically resyncing the slave from the master.

David: Can you just set the complete value using the --mysql-host option? Please add comments to this ticket: https://bugs.launchpad.net/ec2-consistent-snapshot/+bug/481477

rsimmons: Thanks. A lot of useful information! We'll try reducing innodb_log_file_size and will keep an eye on the replication issues which we've also heard about.

Without the work Eric has done, a lot of us would not be using AWS as much as we do because Eric has made it so much easier.

One thing I am still struggling with is how to set up some form of MySQL replication, Multi-Master and/or Master-Slave configuration on EC2.

It would be wonderful if you could share some of the techniques / best practices you have discovered if not some code!

In any case, thanks for all the stuff you do to help all of us.
Rob

Rob: I learned most of what I know about setting up master-slave replication here:
http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html

Leave a comment

Stay Updated

Subscribe with email address:
 Subscribe with a reader
Join the EC2 Ubuntu Google Group
Follow Eric Hammond on Twitter

More Entries

Ubuntu Karmic Desktop on EC2
As Thilo Maier pointed out in comments on my request for UDS input, I have been publishing both server and…
Ubuntu Developer Summit - EC2 Lucid
For the last year I have been working with Canonical and the Ubuntu server team, helping to migrate over to…
New --mysql-stop option for ec2-consistent-snapshot
The ec2-consistent-snapshot software tries its best to flush and lock a MySQL database on an EC2 instance while it initiates…
Understanding Access Credentials for AWS/EC2
Amazon Web Services (AWS) has a dizzying proliferation of credentials, keys, ids, usernames, certificates, passwords, and codes which are used…
How *Not* to Upgrade to Ubuntu 9.10 Karmic on Amazon EC2
WARNING! Though most Ubuntu 9.04 Jaunty systems can upgrade to 9.10 Karmic in place, this is not possible on EC2…
1 TB of Memory in 1 Minute with 1 Command
Amazon Web Services just announced the release of two new instance types for EC2. These new types have 34.2 GB…
New Releases of Ubuntu and Debian Images for Amazon EC2 (Kernel, Security, PPA, runurl, Tools)
New updates have been released for the Ubuntu and Debian AMIs (EC2 images) published on: http://alestic.com The following notes apply…
Encrypting Ephemeral Storage and EBS Volumes on Amazon EC2
Over the years, Amazon has repeatedly recommended that customers who care about the security of their data should consider encrypting…
Creating Consistent EBS Snapshots with MySQL and XFS on EC2
In the article Running MySQL on Amazon EC2 with Elastic Block Store I describe the principles involved in using EBS…
Hidden Dangers in Creating Public EBS Snapshots on EC2
Amazon EC2 recently released a feature which lets you share an EBS snapshot so that other accounts can access it.…
Solving: "I can't connect to my server on Amazon EC2"
Help! I can’t connect to my EC2 instance! Woah! My box just stopped talking to me! Hey! I can’t access…
runurl - A Tool and Approach for Simplifying user-data Scripts on EC2
Many Ubuntu and Debian images for Amazon EC2 include a hook where scripts passed as user-data will be run as…
Presentation: Building Custom Linux Images for Amazon EC2
At the end of July, I gave a presentation at O’Reilly’s Open Source Convention (OSCON 2009) in San Jose. The…
New Releases of Ubuntu and Debian Images for Amazon EC2 (Tools, Security)
New updates have been released for the Ubuntu and Debian AMIs (EC2 images) published on: http://alestic.com The following notes apply…
Poll: Verifying ssh Fingerprint on EC2 Instances
When you ssh to a new EC2 instance, you are presented with the challenge: The authenticity of host 'XXX' can't…
EBS Snapshots of a MySQL Slave Database on EC2
At our company, CampusExplorer.com, we regularly snapshot the EBS volume which holds our MySQL database using the basic procedure I…
Matching EC2 Availability Zones Across AWS Accounts
Summary: EC2 availability zone names in different accounts do not match to the same underlying physical infrastructure. This article explains…
Does Your Product Help Users Build AMIs for Amazon EC2?
I will be speaking at the O’Reilly Open Source Convention (OSCON 2009) next week, giving a presentation on building custom…
Creating a New Image for EC2 by Rebundling a Running Instance
When you start up an instance (server) on Amazon EC2, you need to pick the image or AMI (Amazon Machine…
New Releases of Ubuntu Images for Amazon EC2 2009-06-23 (Karmic Koala Alpha released)
Ubuntu Karmic Koala Alpha is being developed and will be released as Ubuntu 9.10 in October. If you want to…