EmergencyEMERGENCY? Get 24/7 Help Now!

mydumper [less] locking

 | June 13, 2014 |  Posted In: Insight for DBAs, MySQL

PREVIOUS POST
NEXT POST
In this post I would like to review how my dumper for MySQL works from the point of view of locks. Since 0.6 serie we have different options, so I will try to explain how they work

As you may know mydumper is multithreaded and this adds a lot of complexity compared with other logical backup tools as it also needs to coordinate all threads with the same snapshot to be consistent. So let review how mydumper does this with the default settings.

By default mydumper uses 4 threads to dump data and 1 main thread

Main Thread
  • FLUSH TABLES WITH READ LOCK
Dump Thread X
  • START TRANSACTION WITH CONSISTENT SNAPSHOT;
  • dump non-InnoDB tables
Main Thread
  • UNLOCK TABLES
Dump Thread X
  • dump InnoDB tables
As you can see in this case we need FTWRL for two things, coordinate transaction’s snapshots and dump non-InnoDB tables in a consistent way. So we have have global read lock until we dumped all non-InnoDB tables.
What less locking does is this:
Main Thread
  • FLUSH TABLES WITH READ LOCK
Dump Thread X
  • START TRANSACTION WITH CONSISTENT SNAPSHOT;
 LL Dump Thread X
  • LOCK TABLES non-InnoDB
Main Thread
  • UNLOCK TABLES
 LL Dump Thread X
  • dump non-InnoDB tables
  • UNLOCK non-InnoDB
Dump Thread X
  • dump InnoDB tables

So now the global read lock its in place until less-locking threads lock non-InnoDB tables, and this is really fast. The only downsize is that it uses double the amount of threads, so for the default (4 threads) we will end up having 9 connections, but always 4 will be running at the same time.

Less-locking really helps when you have MyISAM or ARCHIVE that are not heavily updated by production workload, also you should know that LOCK TABLE … READ LOCAL allows non conflicting INSERTS on MyISAM so if you use that tables to keep logs (append only) you will not notice that lock at all.

For the next release we will implement backup locks that will avoid us to run FTWRL.

PREVIOUS POST
NEXT POST
Max Bubenick

Max Bubenick has been working with MySQL for more than 10 years. Before joining Percona's Remote DBA team in 2013 he worked as lead DBA for one of the biggest social gaming companies at that time. Also he maintains mydumper.

7 Comments

  • Max,

    In this case we’re locking all non-Innodb tables… I wonder what does it mean in practice and how it plays with servers which have very large amount of tables…. Do you do information_schema query as part of that logical operation to discover all those tables ? Do we when have one very large LOCK TABLES statement to lock them all ?

  • Peter,

    It get all tables from SHOW TABLE STATUS, then it add those to different queues, one for innodb (and tokudb was recently added) and other for non-innodb. Later all the non-innodb tables are distributed by the number of threads tacking care of their sizes, and then each thread lock it’s own tables at the beginning. So is not one LOCK TABLES but one per thread. After each thread got the locks FTWRL is released.

  • Why I didn’t use mydumper is mainly lack of ‘–single-transaction’ in mysqldump,since involving ‘–less-dumper’ option,I have no reason not institute mysqldump,haha!

  • I know the in the percona5.6,the server has global status Binlog_snapshot_file/Binlog_snapshot_position ,if we use mysqldump with –single-transaction,we just need the lock un-innodb tables to enure the consist data. if we don’t care about the un-innodb tables ,we don’t need lock tables at all.. So,I think we can dump data like this:
    Main Thread:
    LOCK UN-INNODB TABLES WITH READ

    Dump Thread X:
    START TRANSACTION WITH CONSISTENT SNAPSHOT;

    LL Dump Thread X
    dump non-InnoDB tables

    Main Thread
    UNLOCK TABLES

    Dump Thread X
    dump InnoDB tables

  • Hi caijinlong, is not so easy when you have multiple threads, as we need to coordinate them to be in the same position. This can be addressed with snapshot cloning which is also supported by PS 5.6. I just need to time to complete it.

    The other detail here is that we have status vars only from master status, mydumper also gets the position from the slave status which is really useful and the only option to do this is to stop slave while we are starting the transactions. But stoping a slave is not something I can add by default to run on a production environment.

    • Yes,I also think use snapshot cloning is the best less lock method,multi thread share same transaction ! I also plan test the snapshot cloning replace the FTWRL。Very expect the next version mydumper use no-lock with innodb tables 。 haha

Leave a Reply