Where the open source database community meets: Use code PERCONA75 and secure your spot for Percona Live.  Register

mydumper [less] locking

June 13, 2014
Author
Max Bubenick
Share this 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.

0 0 votes
Article Rating
Subscribe
Notify of
guest

7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Peter Zaitsev
Admin
11 years ago

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 Zaitsev
Admin
11 years ago

Wonderful Max, Thanks for explanation!

leafonsword
11 years ago

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!

caijinlong
caijinlong
9 years ago

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

caijinlong
caijinlong
9 years ago
Reply to  Max Bubenick

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

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved