Wednesday, 23 October 2013

MySQL Community Dinner

Dear Community,

it is my pleasure to announce that there will be a community dinner on the evening of Monday the 11th of November in London coinciding with the Percona Live Conference. In the same spirit as the community dinner in Santa Clara, the event will be `pay your own way` so it's important to bring some cash on the evening so that splitting the bill is as painless as possible.

The venue is Masala Zone in Earl's Court, which is a short walk from the Millenium Gloucester. For anyone that would like to walk over we will meet in the foyer of the hotel at ~7pm and walk over. 

Please make your way over to our eventbrite page to register your attendance so that we can give the guys at Masala Zone good notice of how many to expect.

The link above will take you to the Masala Zone site where you can see what's on the menu. 

http://www.eventbrite.co.uk/event/8935216473

Please let me know if you've got any questions in the comments.

Looking forward to seeing you there!

Monday, 14 October 2013

MySQL Replication Filters: replicate-ignore-table & ON DELETE CASCADE

It's no secret that you shouldn't rely on replication filtering. Recently a customer asked if an `ON DELETE CASCADE` would still affect the data on a slave if the table was being ignored through replication filtering. It was one of those occasions that I couldn't give a confident answer without a quick test but alas the gut was right and the obvious answer is yes, "ON DELETE|UPDATE CASCADE" will change data even if you replicate using replication filters.

I tested using RBR and SBR. If anything I was questioning the behaviour of RBR here but it turns out to be consistent with SBR. I had a master-slave setup already deployed for some other testing so it was easy to implement the FKs needed for this. The dataset is the trusty world db available from dev.mysql.com and I needed to change the constraints on the table to match the conditions proposed.

Master

mysql> ALTER TABLE City DROP FOREIGN KEY City_ibfk_1;
Query OK, 5000 rows affected (0.06 sec)
Records: 5000 Duplicates: 0 Warnings: 0

mysql> ALTER TABLE City ADD CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `Country` (`Code`)
ON DELETE CASCADE;
Query OK, 5000 rows affected (0.06 sec)
Records: 5000 Duplicates: 0 Warnings: 0

mysql> SELECT COUNT(*) FROM City WHERE CountryCode = 'UKR';
+----------+
| COUNT(*) |
+----------+
| 57 |
+----------+
1 row in set (0.00 sec)

Slave

mysql> SELECT COUNT(*) FROM City WHERE CountryCode = 'UKR';
+----------+
| COUNT(*) |
+----------+
| 57 |
+----------+
1 row in set (0.00 sec)

So our row counts match. I'll update the my.cnf file for the replication filtering.

Slave

cat /etc/my.cnf
...
replicate-ignore-table = "world.City"
...

Restart MySQL on the slave and check the status;
mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.101
Master_User: repl
Master_Port: 3306
...
Replicate_Ignore_Table: world.City
...
1 row in set (0.00 sec)

Filter exists, lets test it. Update a row on the master and compare the values between the instances;

Master

mysql> UPDATE City SET population=90000 WHERE ID = 3482;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> SELECT * FROM City WHERE ID = 3482;
+------+------------+-------------+---------------+------------+
| id | Name | CountryCode | District | Population |
+------+------------+-------------+---------------+------------+
| 3482 | Mukatševe | UKR | Taka-Karpatia | 90000 |
+------+------------+-------------+---------------+------------+
1 row in set (0.00 sec)

Checking the slave we can see that it remains the old value;

Slave

mysql> SELECT * FROM City WHERE ID = 3482;
+------+------------+-------------+---------------+------------+
| ID | Name | CountryCode | District | Population |
+------+------------+-------------+---------------+------------+
| 3482 | Mukatševe | UKR | Taka-Karpatia | 89000 |
+------+------------+-------------+---------------+------------+
1 row in set (0.00 sec)

Now if we delete the parent record in the Country table we can see that the CASCADE affects the 'ignored' table on the Slave too.

Master

mysql> DELETE FROM Country WHERE Code = 'UKR';
Query OK, 1 row affected (0.00 sec)

mysql> SELECT COUNT(*) FROM City WHERE CountryCode = 'UKR';
+----------+
| COUNT(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)

Slave

mysql> SELECT COUNT(*) FROM City WHERE CountryCode = 'UKR';
+----------+
| COUNT(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)

If you're running with FK Constraints with ON DELETE|UPDATE CASCADE and replication filtering on your slaves you might not have the data you think you have.

Tuesday, 8 October 2013

Bristol MySQL Meetup

The next Bristol (and surrounding areas) MySQL meetup will take place on Thursday 10th of October in Bristol (currently) scheduled for 7.00pm at the Watershed. I say currently because it might be moved if we can find a quieter place. I personally found the Watershed pretty noisy. The topic of the night will be tools. We'll have a 50,000ft overview of some of the tools and then make some time for some demos. According to the RSVP list there's a nice mix of Dev and Ops so there should be a mixture of experience and hopefully some inspirational use cases for tools being used in the wild. Right this moment the agenda of tools will be some from the following;
  • pt-toolkit
  • openark-toolkit
  • Oracle's MySQL Utilities
  • Xtrabackup
  • Mydumper
  • Common_schema
  • AOT
To give you guys and girls further incentive to attend the meetup, we have some swag to unload. There will be some Pythian and Percona t-shirts, some Oracle/MySQL usb drives & stickers and a ticket to Percona Live London to unburden myself of. I'd like to pass out some swag for participation over chance so make sure to bring a tasty question or story about how you use DBA/Dev tools. The Percona Live UK ticket is a very kind donation from Percona, so a HUGE `thank you` goes to Kortney and Tom for arranging that for us. The caveat to bagging swag/ticket: it's limited to attendees only and there will be a photo of the proud owners posted on the meetup page (with you permission of course). We will also have a discount code made available for anyone looking to attend PLUK. Follow the latest news for Percona Live London using the #perconalive hashtag or via Percona.com. Please post any questions or suggestions for Thursday night topic/venue.