Sep
30
2012
--

Blog Year 1: My top 10 posts

I started this blog one year ago. My first post was September 12, 2011. Since then I’ve written 54 posts.

I thought it might be fun to look back and select my top 10 favourites, so here they are (in chronological order).

Enjoy!

 

 

Written by in: Zend Developer |
Sep
29
2012
--

Percona team at MySQL Connect today

Attending MySQL Connect ? Do not miss our talks!

Peter Zaitsev is doing “Optimizing MySQL Configuration” talk at 2:30 PM in Golden Gate 4 room
Vadim Tkachenko is talking about “MySQL and Solid-State Drives: Usage and Tuning” at 4:00 PM in the same room.

See you around !

Sep
27
2012
--

Logging Foreign Key errors

In the last blog post I wrote about how to log deadlock errors using Percona Toolkit. Foreign key errors have the same problems. InnoDB only logs the last error in the output of SHOW ENGINE INNODB STATUS, so we need another similar tool in order to have historical data.

pt-fk-error-logger

This is a tool very similar to pt-deadlock-logger that will help us to log those errors. It can log them to a table, file or just show them on STDOUT. Let’s see how to use it:

1- Create the table

First we create the table where we are going to store the information:

CREATE TABLE foreign_key_errors (
  ts datetime NOT NULL,
  error text NOT NULL,
  PRIMARY KEY (ts)
);

2- Run the tool as a daemon and store it on that recently created table

# pt-fk-error-logger --daemonize --run-time=3600 --interval=10 --dest h=10.0.0.5,D=test,t=foreign_key_errors h=127.0.0.1

We are monitoring the MySQL on host 127.0.0.1 and storing all the errors on the host 10.0.05, database test and table foreign_key_errors. It will run as a daemon for 3600 seconds and will check the last error every 10 seconds.

3- Cause an error

I run a SQL command that shows this error:

ERROR 1025 (HY000): Error on rename of './employees10/#sql-3da_2a' to './employees10/employees' (errno: 150)

Ok, not very informative. It's not very clear where is the error. Let's see the explanation with perror:

# perror 150
MySQL error code 150: Foreign key constraint is incorrectly formed

Still difficult to know what the problem is.

4- Let's check what the tool has logged:

mysql> select * from test.foreign_key_errors\G
*************************** 1. row ***************************
   ts: 2012-09-26 14:28:31
error: Error in foreign key constraint of table employees10/dept_emp:
there is no index in referenced table which would contain
the columns as the first columns, or the data types in the
referenced table do not match the ones in table. Constraint:
,
  CONSTRAINT "dept_emp_ibfk_1" FOREIGN KEY ("emp_no") REFERENCES "employees" ("emp_no") ON DELETE CASCADE
The index in the foreign key in table is "PRIMARY"
See http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
for correct foreign key definition.
InnoDB: Renaming table `employees10`.`#sql-3da_2b` to `employees10`.`employees` failed!

So, we have the timestamp when the error happened and the text of the error. We can see here that it was caused by an index that was referenced by the FK, a PRIMARY KEY. So, the command that causes the error was:

mysql> ALTER TABLE employees DROP PRIMARY KEY;

Conclusion

If you are having too many deadlock or foreign key errors log them. Just reading the last error happened on the databases is not enough information to dig into the code and solve the problem. These tools are easy to use and make your life easier.

Sep
26
2012
--

Percona Toolkit version 2.1.4 released

The Percona Toolkit team is happy to announce the release of Percona Toolkit version 2.1.4. This is the fifth stable release in the 2.1 series, and primarily a bug-fix release; We suggest that users upgrade to the latest version of the tools.

The complete list of changes is on the Launchpad milestone for 2.1.4, but here are some highlights the release:

  • pt-table-checksum now works with Percona XtraDB Cluster
  • The “Version Check” feature, explained at length here.
  • –defaults-file is now used when connecting to discovered slaves in pt-table-checksum

All in all, a solid bug-fix release, with the addition of some new features too.

Remember that if you need help with Percona Toolkit, we provide flat-fee, unlimited support services with rapid 24×7 response on a commercial basis via our Support contracts. Links to the downloads, documentation, bug reports, mailing list, and more are available from the Percona Toolkit project homepage.

Sep
25
2012
--

Timezone and pt-table-checksum

I recently worked through an issue with a client trying to detect data drift across some servers that were located in different timezones.  Unfortunately, several of the tables had timestamp fields and were set to a default value of CURRENT_TIMESTAMP.  From the manual, here is how MySQL handles timezone locality with timestamp fields:

Values for TIMESTAMP columns are converted from the current time zone to UTC for storage, and from UTC to the current time zone for retrieval.

This can result in every row being deemed out of sync when each server is using in it’s own timezone.  Fortunately, there is a workaround for this as a result of how pt-table-checksum/pt-table-sync calculate their checksums.  Lets look at an example:

Node1 > PDT > select timediff(now(),convert_tz(
 -> now(),
 -> @@session.time_zone,'+00:00'
 -> )) as tz_offset;
+-----------+
| tz_offset |
+-----------+
| -07:00:00 |
+-----------+
Node2 > EDT > select timediff(now(),convert_tz(
 -> now(),
 -> @@session.time_zone,'+00:00'
 -> )) as tz_offset;
+-----------+
| tz_offset |
+-----------+
| -04:00:00 |
+-----------+

Node1 is configured in PDT time while node2 is configured in EDT time.  Now, lets insert some rows into a table with timestamp field configured to use CURRENT_TIMESTAMP as the default and verify that they look different when no timezone manipulation takes place:

Node1 > PDT > select * from foo.bar;
+----+-------------+---------------------+
| id | data        | date_created        |
+----+-------------+---------------------+
| 1  | node1, row1 | 2012-09-24 09:38:49 |
| 2  | node1, row2 | 2012-09-24 09:38:49 |
| 3  | node1, row3 | 2012-09-24 09:38:49 |
+----+-------------+---------------------+
Node2 > EDT > select * from foo.bar;
+----+-------------+---------------------+
| id | data        | date_created        |
+----+-------------+---------------------+
| 1  | node1, row1 | 2012-09-24 12:38:49 |
| 2  | node1, row2 | 2012-09-24 12:38:49 |
| 3  | node1, row3 | 2012-09-24 12:38:49 |
+----+-------------+---------------------+

So, when we run pt-table-checksum against node1, we see that even though MySQL is storing these values in UTC internally, we have “data drift” on both nodes:

pt-table-checksum –replicate=percona.checksums –databases=foo h=localhost

Node1 > PDT > select this_crc, master_crc from percona.checksums;
+----------+------------+
| this_crc | master_crc |
+----------+------------+
| 763d97f1 | 763d97f1   |
+----------+------------+
Node2 > EDT > select this_crc, master_crc from percona.checksums;
+----------+------------+
| this_crc | master_crc |
+----------+------------+
| b890c395 | 763d97f1   |
+----------+------------+

Naturally, pt-table-sync finds this and reports that all 3 rows in this chunk are different and gives the REPLACE INTO statements bring node2 in sync:

[root@test-master mbenshoof]# pt-table-sync --print --replicate percona.checksums --sync-to-master h=node2
REPLACE INTO `foo`.`bar`(`id`, `data`, `date_created`) VALUES ('1', 'node1, row1', '2012-09-24 09:38:49') /*percona-toolkit src_db:foo src_tbl:bar src_dsn:P=3306,h=192.168.1.45,p=...,u=percona dst_db:foo dst_tbl:bar dst_dsn:h=192.168.1.46,p=...,u=percona lock:1 transaction:1 changing_src:percona.checksums replicate:percona.checksums bidirectional:0 pid:1821 user:root host:test-master*/;
REPLACE INTO `foo`.`bar`(`id`, `data`, `date_created`) VALUES ('2', 'node1, row2', '2012-09-24 09:38:49') /*percona-toolkit src_db:foo src_tbl:bar src_dsn:P=3306,h=192.168.1.45,p=...,u=percona dst_db:foo dst_tbl:bar dst_dsn:h=192.168.1.46,p=...,u=percona lock:1 transaction:1 changing_src:percona.checksums replicate:percona.checksums bidirectional:0 pid:1821 user:root host:test-master*/;
REPLACE INTO `foo`.`bar`(`id`, `data`, `date_created`) VALUES ('3', 'node1, row3', '2012-09-24 09:38:49') /*percona-toolkit src_db:foo src_tbl:bar src_dsn:P=3306,h=192.168.1.45,p=...,u=percona dst_db:foo dst_tbl:bar dst_dsn:h=192.168.1.46,p=...,u=percona lock:1 transaction:1 changing_src:percona.checksums replicate:percona.checksums bidirectional:0 pid:1821 user:root host:test-master*/;

This is where we can use the @@session.time_zone variable to our advantage.  If both servers were set up using UTC as the timezone (which is the recommended practice – store everything in UTC and then perform the timezone logic in the application), we wouldn’t see any data drift.  And as explained above, the timestamps are actually stored in UTC on the server regardless of the timezone.  So, to overcome the timezone inconsistencies, we can use the –set-vars option with pt-table-checksum like this:

pt-table-checksum –replicate percona.checksums –databases=foo –set-vars=”time_zone=’+00:00′” h=localhost

This effectively sets both servers to UTC (in terms of display logic) and the checksums are calculated in the same locality:

Node1 > PDT > select this_crc, master_crc from percona.checksums;
+----------+------------+
| this_crc | master_crc |
+----------+------------+
| 4cdfe786 | 4cdfe786   |
+----------+------------+
Node2 > EDT > select this_crc, master_crc from percona.checksums;
+----------+------------+
| this_crc | master_crc |
+----------+------------+
| 4cdfe786 | 4cdfe786   |
+----------+------------+

This same option can and should be applied to pt-table-sync as well, especially if the checksums were created without it.  Since it uses the checksum table to find the chunks but still recalculates the checksums on the fly to get the actual rows in need of syncing, it will not find those rows even though pt-table-checksum reported the chunk as out of sync.  You can verify this yourself looking at the actual SQL generated by pt-table-sync when looking at rows:

SELECT /*foo.bar:1/1*/ 0 AS chunk_num, COUNT(*) AS cnt, COALESCE(LOWER(CONV(BIT_XOR(CAST(CRC32(CONCAT_WS(‘#’, `id`, `data`, `date_created` + 0, CONCAT(ISNULL(`data`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `foo`.`bar` FORCE INDEX (`PRIMARY`) WHERE (1=1) FOR UPDATE;

When you update your session timezone (SET @@session.time_zone = “+01:00″ for example), you will see different output for this.  Experiment with different timezones and each time, the checksum will change.  However, the underlying data isn’t touched and remains the same.

In general, it is safest to always use UTC as your timezone for MySQL to prevent this extra logic from being required, but the use of –set-vars can be a very powerful tool when you need to influence the session variables on different servers for whatever reason.

Sep
24
2012
--

Percona Server tree with support of Fusion-io atomic writes and DirectFS

Not so long ago Fusion-io announced an SDK which provides direct API access to Fusion ioMemory(tm) in addition to providing a native filesystem (directFS) with a goal to avoid overhead from kernel and regular Linux filesystems: ext4 and xfs. This requires a support from application, it should use special calls for IO. With help from Fusion-io, we provide source code of Percona Server which uses direct API access. The main idea that with this functionality you can disable “innodb-doublewrite”, retain ACID compliance by using atomic writes, and in IO intensive workloads gain an additional 30-50% in throughput when compared to workloads on the same ioMemory™ device using an unmodified Percona Server. Further benchmarking results on latency variability reduction expected soon.
Percona Server 5.5.27 with Fusion-io atomic writes is available from Launchpad repository: lp:~percona-core/percona-server/percona-server-5.5.27-fusion-io-atomic,
and the patch itself is the revision 300.
To compile it you need access to Fusion-io SDK, which is currently available to early-access partners prior to general release. Contact Fusion-io at developer.fusionio.com for details, or speak with Fusion-io in New York at their Percona Live! presentation.

Sep
20
2012
--

A (prototype) lower impact slow query log

Yesterday, over at my personal blog, I blogged about the impact of the MySQL slow query log. Since we’re working on Percona Server 5.6, I did wonder if this was a good opportunity to re-examine how we could provide slow query log type functionality to our users.

The slow query log code inside the MySQL server does several things that aren’t good for concurrency on modern systems. For starters, it takes a mutex while both doing formatting of what to write and while doing the write(2) system call itself. This is, in fact, entirely unneccesary.

From the man page for the write system call:

If the file was open(2)ed with O_APPEND, the file offset is first set to the end of the file before writing. The adjustment of the file offset and the write operation are performed as an atomic step.

So we can pretty easily see that for our case of writing the slow query log, if we had a buffer that was the log entry, we could just call write(2) and never take a mutex. We trade some memory usage (for the buffer) for concurrency – pushing all the concurrency problems down into the operating system.

The main challenge with this strategy is log file rotation, as if you just close(2) a file descriptor that others may be write(2)ing to then bad things may happen (namely that the file descriptor gets reused for something else.. say an innodb data file, and writing part of your slow query log as an innodb page will not end in hugs and puppies).

So, in order to test my theory, I sat down and wrote an audit plugin. It turns out I had to extend the MySQL plugin API to be able to reproduce all the information in the slow query log. The code for my prototype can be found at lp:~stewart/percona-server/5.6-slow-query-plugin-prototype (this revision) – this will probably build fine against 5.5 too, but I haven’t tested. To build it you’ll need the Intel Threading Building Blocks headers installed as I used their tbb::atomic<> implementation.

My solution to log file rotation is to basically count how many people may be using it and waiting until this drops to zero before closing the file descriptor. This avoids taking any locks around calling write(), which is the most time consuming part of writing the log. I’m not convinced if this is the best solution or not, but it appears to work and I think it’s race free.

No improvement like this is complete without benchmarks. My benchmarks (“mysqlslap -q ‘select 1;’ –number-of-queries=1000000 –concurrency=64″ on my laptop) come out at the following:

  • straight MySQL (no slow query log): 13 seconds
  • MySQL with slow query log enabled: 18 seconds
  • My audit plugin slow query log: 15 seconds
  • straight Drizzle (no slow query log): 8 seconds

So that’s a quite promising start.

Sep
20
2012
--

Fusion-io atomic writes and DirectFS

Not so far ago Fusion-io announced SDK which provides direct API access to Fusion ioMemory(tm) in addition to providing a native filesystem (directFS) with a goal to avoid overhead from kernel and regular Linux filesystems: ext4 and xfs. Fusion-io will explain these features during our Percona Live New York conference and share performance numbers.

It is not too late to register for conference and talk with Fusion-io engineers directly. “PerconaNY” registration will give you 15% discount.

Sep
20
2012
--

Upcoming webinar on PRM

Just a reminder that Wednesday the 26th at 10am Pacific time, I’ll give a webinar on PRM, the Percona replication manager. During the webinar, I’ll walk you through the setup of a PRM cluster and show you how to perform some basic management tasks. If you are interested, click here to register.

See you Wednesday!

Regards,

Yves

Written by in: MySQL,Zend Developer |
Sep
19
2012
--

What attendees are saying about Percona Live NYC ?

With Percona Live NYC right around the corner I decide some of attendees what did they like on the last year event and what they are looking forward to in 2012. Here are some responses I got. If you’ve attended in 2011 or planning to join us in 2012 please feel free to comment with your feedback!

Ori Herrnstadt, CTO, Akiban Technologies says:
“I truly appreciated the opportunity to present at Percona Live NY last year and can’t wait to show how Akiban has progressed since then. As the founder of a company that is eliminating data complexity while preserving SQL and embracing new development paradigms, Percona Live offers the right mix of savvy technologists.”

Ryan Lowe, Production Engineer at Square Inc. says:
“This will be the fifth Percona Live event that I have attended, with each one being better than the last. Next month in New York, I’m most looking forward to the scaling, big data, and high availability talks being offered by the likes of Facebook, Tumblr, and (of course) Percona engineers. Percona Live goes above and beyond simply a MySQL conference. I can always count on enjoying presentations on surrounding technologies including flash storage, hadoop, the cloud, and a variety of other topics. I’m looking forward to another great event and hope to see you there!”

Sean Hull, Senior MySQL EC2 & Scalability Lead have written while essay on the topic:
“What I loved about Percona Live NY 2011

Last year I was excited to go to Percona Live for the first time in NYC. I arrived just in time to hear Harrison Fisk from Facebook speak about some of the awesome tweaks they’re running with MySQL there. It’s not everyday that you get to hear from top MySQL engineers how they’re using the technology and what their biggest challenges are. If they can make MySQL hum, so can the rest of us!

Afterward, outside in the foyer, I ran into all sorts of luminaries in the MySQL space. Percona folks like Peter Zaitsev & Vadim Tkachenko, plus other big names like Baron Schwartz, Harrison, and Ronald Bradford. I ran into people from firms like Yahoo, Google, Daniweb, Pythian, SkySQL & Palomino.

This years event next month features rockstar engineers from an incredible lineup of firms including Etsy, New Relic, Youtube, Paypal, Tumblr, SugarCRM, Square, and of course a few from Percona themselves. I promise you this, these talks won’t be salesy or in any way a waste of your time and money. They will be thoroughly technical talks, with cutting edge insights and advice from those in the trenches using the technology everyday.

If I wasn’t heading to Oracle Open World for the publishers seminar & MySQL Connect, I would most certainly be there. In fact I had originally been slated to talk about point-in-time recovery in MySQL. Oh well, I’m sure I’ll catch you at the Percona Live in April 2013.”

Looking forward seeing all of you in NY in less than 2 weeks!

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com