Bug #44568 | Online backup 'waiting' while load executed | ||
---|---|---|---|
Submitted: | 30 Apr 2009 6:59 | Modified: | 25 Feb 2010 0:04 |
Reporter: | Omer Barnir (OCA) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Backup | Severity: | S3 (Non-critical) |
Version: | 6.0.11 | OS: | Any |
Assigned to: | Jørgen Løland | CPU Architecture: | Any |
[30 Apr 2009 6:59]
Omer Barnir
[30 Apr 2009 7:03]
Omer Barnir
Observed with 6.0.11 but likely to have been there before
[30 Apr 2009 7:05]
Omer Barnir
scripts and data for reproducing the bug
Attachment: bug_test.tar.gz (application/x-gzip, text), 453.93 KiB.
[30 Apr 2009 8:11]
Rafal Somla
When running tests for BUG#42338 I have not observed that BACKUP is blocked by concurrent load. I was testing with InnoDB tables only.
[30 Apr 2009 8:12]
Jørgen Løland
In myisam, read locks have lower priority than write locks. This could also be the reason for the backup starvation. To increase the priority in normal sql, one would use the HIGH_PRIORITY option (See http://dev.mysql.com/doc/refman/6.0/en/select.html).
[30 Apr 2009 10:39]
Rafal Somla
I'd like to look at this if no one objects.
[30 Apr 2009 10:41]
Rafal Somla
Sorry, was thinking about 44569 :P
[30 Apr 2009 15:13]
Omer Barnir
This is observed with Innodb tables. Changing title back.
[30 Apr 2009 18:43]
Omer Barnir
Also observed with Falcon, but Falcon seems to handle it better and in order to see the above you need to use a larger table (such as the one in bug#44569
[4 Jun 2009 13:50]
Jørgen Løland
A very unofficial test running backup of the flightstats database in innodb tables in parallel with mysql-stress-test: 0 concurrent threads: 16 seconds 1 concurrent thread: 17 seconds 2 concurrent threads: 19 seconds 3 concurrent threads: 34 seconds (but huge deviation; 21, 27 and 54) 4 concurrent threads: never completes All results are averages over 3 test executions.
[4 Jun 2009 14:08]
Jørgen Løland
I reproduced as suggested above and attached gdb. Here's the stack I get for the BACKUP thread: #0 0xb7f1f430 in __kernel_vsyscall () #1 0xb7ef20e5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/tls/i686/cmov/libpthread.so.0 #2 0x088964be in safe_cond_wait (cond=0x8c281c0, mp=0x8c27b80, file=0x899d7b7 "lock.cc", line=1161) at thr_mutex.c:423 #3 0x082ed8e5 in lock_global_read_lock (thd=0xaa9d9a8) at lock.cc:1161 #4 0x08947661 in backup::block_commits (thd=0xaa9d9a8, tables=0x0) at data_backup.cc:395 #5 0x08947cef in backup::write_table_data (thd=0xaa9d9a8, info=@0xab1e7b8, s=@0xaaa58d8) at data_backup.cc:690 #6 0x0893db55 in Backup_restore_ctx::do_backup (this=0xa88f8b68) at kernel.cc:1249 #7 0x089406fe in execute_backup_command (thd=0xaa9d9a8, lex=0xaa9e8ec, backupdir=0xa88f9140, overwrite=false, skip_gap_event=false) at kernel.cc:202 #8 0x0830b300 in mysql_execute_command (thd=0xaa9d9a8) at sql_parse.cc:2491 #9 0x08313ca3 in mysql_parse (thd=0xaa9d9a8, inBuf=0xaa5d748 "BACKUP DATABASE FlightStats_test TO '/home/jl208045/mysql/wl4769/flightstat/flight.bak'", length=87, found_semicolon=0xa88f9bd4) at sql_parse.cc:5999 #10 0x08314825 in dispatch_command (command=COM_QUERY, thd=0xaa9d9a8, packet=0xaa577b1 "BACKUP DATABASE FlightStats_test TO '/home/jl208045/mysql/wl4769/flightstat/flight.bak'", packet_length=87) at sql_parse.cc:1064
[5 Jun 2009 6:44]
Jørgen Løland
The reason for this bug is starvation when the backup code tries to set the global read lock. The global read lock is implemented so that you won't be able to set it if there is an ongoing commit. The reason for the starvation is that there's nothing preventing new threads from going into the commit phase while the backup thread waits for the global read lock. Related to the global read lock, commits do this (abstracted from wait_if_global_read_lock): if (!global_read_lock) { protect_against_global_readlock++; <do commit things> protect_against_global_readlock--; } To set the global read lock, the code does this: while (protect_against_global_readlock) wait; global_read_lock=true; The starvation can be avoided if the commit code has to wait if another thread *tries* to set the global read lock. E.g., global_read_lock can be set to true before "while (protect_against_global_readlock) wait;", effectively making new commits wait.
[5 Jun 2009 8:46]
Jørgen Løland
A worklog for refining the backup commit blocker exists: WL#4610. Implementing that WL should fix this bug.
[18 Jun 2009 8:46]
Jørgen Løland
Not planned fixed this quarter. Setting state to Analyzing
[18 Nov 2009 8:34]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/90796 2894 Jorgen Loland 2009-11-18 Bug#44568: Online backup 'waiting' while load executed To make a transaction consistent backup image across all tables and storage engines, backup needs to block commits during the synchronization phase. Previously, this was achieved by using global_read_lock. However, GRL was not intended for this usage and has some serious disadvantages: - backup did not use it as it was meant to be used, and GRL will therefore starve backup even with few concurrent transactions - backup only needs to block commits/be blocked by commits. Backup's usage of GRL blocked DMLs. This patch contains a temporary solution to the problem. It changes the backup metadata locking to a more generic backup shared/exclusive locking mechanism that is used for both BML and commit blocking. Compared to using GRL for commit blocking, much fewer operations are blocked (only commits vs whole transactions starting from it's first DML statement). Further, the starvation of backup by concurrent transactions is removed because the locking mechanism orders lock requests FIFO. The patch is a temporary solution because the locking mechanism will most likely be replaced by MetaDataLocking later. There are e.g. plans for scoped locks in MDL, which will make backup block commits only in the tables being backed up. @ mysql-test/suite/backup/include/backup_vp_nontx.inc Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/include/bml_test.inc Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/r/backup_bml_block.result Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/r/backup_bml_not_falcon.result Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/r/backup_errors.result Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/r/backup_errors_compression.result Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/r/backup_snapshot.result Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/r/backup_timeout.result Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/r/backup_triggers_and_events.result Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/r/backup_vp_nontx_memory.result Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/r/backup_vp_nontx_myisam.result Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/r/backup_vp_tx.result Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/t/backup_bml.test Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/t/backup_bml_block.test Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/t/backup_errors.test Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/t/backup_snapshot.test Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/t/backup_timeout.test Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/t/backup_triggers_and_events.test Change test and sync points to work with new commit blocker @ mysql-test/suite/backup/t/backup_vp_tx.test Change test and sync points to work with new commit blocker @ sql/backup/be_default.cc Incorrect optimization removed. Caused too early lock release because locking thread was killed. @ sql/backup/data_backup.cc Change backup to use new commit blocker instead of GRL @ sql/bml.cc Refactor BML to become more generic backup shared/exclusive locking mechanism. This will be used both for backup metadata locking and commit blocking. @ sql/bml.h Refactor BML to become more generic backup shared/exclusive locking mechanism. This will be used both for backup metadata locking and commit blocking. @ sql/handler.cc Acquire and release shared backup commit blocker lock when committing. @ sql/mysqld.cc Instanciate backup metadata locks and backup commit blocker locking instances. @ sql/si_objects.cc Add functions for setting and releasing backup commit blocker @ sql/si_objects.h Add functions for setting and releasing backup commit blocker @ sql/sql_parse.cc BML changed name to Backup_sx_lock
[18 Nov 2009 16:42]
Chuck Bell
Approved with changes.
[19 Nov 2009 10:50]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/90941 2890 Jorgen Loland 2009-11-19 Bug#44568: Online backup 'waiting' while load executed To make a transaction consistent backup image across all tables and storage engines, backup needs to block commits during the synchronization phase. Previously, this was achieved by using global read lock (GRL). However, GRL was not intended for this usage and has some serious disadvantages: - backup did not use it as it was meant to be used, and GRL will therefore starve backup even with few concurrent transactions - backup only needs to block commits/be blocked by commits. Backup's usage of GRL blocked DMLs. This patch contains a temporary solution to the problem. It changes the backup metadata locking to a more generic backup shared/exclusive locking mechanism that is used for both BML and commit blocking. Compared to using GRL for commit blocking, much fewer operations are blocked (only commits vs whole transactions starting from it's first DML statement). Further, the starvation of backup by concurrent transactions is removed because the locking mechanism orders lock requests FIFO. The patch is a temporary solution because the locking mechanism will most likely be replaced by MetaDataLocking later. There are plans for scoped locks in MDL, which will make backup block commits only in the tables being backed up. @ mysql-test/suite/backup/include/backup_vp_nontx.inc Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/include/bml_test.inc Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/r/backup_bml_block.result Recorded new test output. @ mysql-test/suite/backup/r/backup_bml_not_falcon.result Recorded new test output. @ mysql-test/suite/backup/r/backup_errors.result Recorded new test output. @ mysql-test/suite/backup/r/backup_errors_compression.result Recorded new test output. @ mysql-test/suite/backup/r/backup_snapshot.result Recorded new test output. @ mysql-test/suite/backup/r/backup_timeout.result Recorded new test output. @ mysql-test/suite/backup/r/backup_triggers_and_events.result Recorded new test output. @ mysql-test/suite/backup/r/backup_vp_nontx_memory.result Recorded new test output. @ mysql-test/suite/backup/r/backup_vp_nontx_myisam.result Recorded new test output. @ mysql-test/suite/backup/r/backup_vp_tx.result Recorded new test output. @ mysql-test/suite/backup/t/backup_bml.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_bml_block.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_errors.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_snapshot.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_timeout.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_triggers_and_events.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_vp_tx.test Change test and sync points to work with new commit blocker. @ sql/backup/be_default.cc Incorrect optimization removed. Caused too early lock release because locking thread was killed. @ sql/backup/data_backup.cc Change backup to use new commit blocker instead of GRL @ sql/bml.cc Refactor BML to become more generic backup shared/exclusive locking mechanism. This will be used both for backup metadata locking and commit blocking. @ sql/bml.h Refactor BML to become more generic backup shared/exclusive locking mechanism. This will be used both for backup metadata locking and commit blocking. @ sql/handler.cc Acquire and release shared backup commit blocker lock when committing. @ sql/mysqld.cc Instanciate backup metadata locks and backup commit blocker locking instances. @ sql/si_objects.cc Add functions for setting and releasing backup commit blocker. @ sql/si_objects.h Add functions for setting and releasing backup commit blocker. @ sql/sql_parse.cc BML changed name to Backup_sx_lock
[20 Nov 2009 14:27]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/91108 2892 Jorgen Loland 2009-11-20 Bug#44568: Online backup 'waiting' while load executed To make a transaction consistent backup image across all tables and storage engines, backup needs to block commits during the synchronization phase. Previously, this was achieved by using global read lock (GRL). However, GRL was not intended for this usage and has some serious disadvantages: - backup did not use it as it was meant to be used, and GRL will therefore starve backup even with few concurrent transactions - backup only needs to block commits/be blocked by commits. Backup's usage of GRL blocked DMLs. This patch contains a temporary solution to the problem. It changes the backup metadata locking to a more generic backup shared/exclusive locking mechanism that is used for both BML and commit blocking. Compared to using GRL for commit blocking, much fewer operations are blocked (only commits vs whole transactions starting from it's first DML statement). Further, the starvation of backup by concurrent transactions is removed because the locking mechanism orders lock requests FIFO. The patch is a temporary solution because the locking mechanism will most likely be replaced by MetaDataLocking later. There are plans for scoped locks in MDL, which will make backup block commits only in the tables being backed up. @ mysql-test/suite/backup/include/backup_vp_nontx.inc Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/include/bml_test.inc Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/r/backup_bml_block.result Recorded new test output. @ mysql-test/suite/backup/r/backup_bml_not_falcon.result Recorded new test output. @ mysql-test/suite/backup/r/backup_errors.result Recorded new test output. @ mysql-test/suite/backup/r/backup_errors_compression.result Recorded new test output. @ mysql-test/suite/backup/r/backup_snapshot.result Recorded new test output. @ mysql-test/suite/backup/r/backup_timeout.result Recorded new test output. @ mysql-test/suite/backup/r/backup_triggers_and_events.result Recorded new test output. @ mysql-test/suite/backup/r/backup_vp_nontx_memory.result Recorded new test output. @ mysql-test/suite/backup/r/backup_vp_nontx_myisam.result Recorded new test output. @ mysql-test/suite/backup/r/backup_vp_tx.result Recorded new test output. @ mysql-test/suite/backup/t/backup_bml.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_bml_block.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_errors.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_snapshot.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_timeout.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_triggers_and_events.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_vp_tx.test Change test and sync points to work with new commit blocker. @ sql/backup/be_default.cc Incorrect optimization removed. Caused too early lock release because locking thread was killed. @ sql/backup/data_backup.cc Change backup to use new commit blocker instead of GRL @ sql/bml.cc Refactor BML to become more generic backup shared/exclusive locking mechanism. This will be used both for backup metadata locking and commit blocking. @ sql/bml.h Refactor BML to become more generic backup shared/exclusive locking mechanism. This will be used both for backup metadata locking and commit blocking. @ sql/handler.cc Acquire and release shared backup commit blocker lock when committing. @ sql/mysqld.cc Instanciate backup metadata locks and backup commit blocker locking instances. @ sql/si_objects.cc Add functions for setting and releasing backup commit blocker. Also removed BML_exception since Backup_sx_locks allows the thread owning X lock to set S lock, thus making BML_exception redundant. @ sql/si_objects.h Add functions for setting and releasing backup commit blocker. Also removed BML_exception since Backup_sx_locks allows the thread owning X lock to set S lock, thus making BML_exception redundant. @ sql/sql_class.cc Removed BML_exception flag since Backup_sx_locks allows the thread owning X lock to set S lock, thus making BML_exception redundant. @ sql/sql_class.h Removed BML_exception flag since Backup_sx_locks allows the thread owning X lock to set S lock, thus making BML_exception redundant. @ sql/sql_parse.cc BML_class changed name to Backup_sx_lock
[25 Nov 2009 17:14]
Rafal Somla
Good to push.
[26 Nov 2009 9:51]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/91756 2896 Jorgen Loland 2009-11-26 Bug#44568: Online backup 'waiting' while load executed To make a transaction consistent backup image across all tables and storage engines, backup needs to block commits during the synchronization phase. Previously, this was achieved by using global read lock (GRL). However, GRL was not intended for this usage and has some serious disadvantages: - backup did not use it as it was meant to be used, and GRL will therefore starve backup even with few concurrent transactions - backup only needs to block commits/be blocked by commits. Backup's usage of GRL blocked DMLs. This patch contains a temporary solution to the problem. It changes the backup metadata locking to a more generic backup shared/exclusive locking mechanism that is used for both BML and commit blocking. Compared to using GRL for commit blocking, much fewer operations are blocked (only commits vs whole transactions starting from it's first DML statement). Further, the starvation of backup by concurrent transactions is removed because the locking mechanism orders lock requests FIFO. The patch is a temporary solution because the locking mechanism will most likely be replaced by MetaDataLocking later. There are plans for scoped locks in MDL, which will make backup block commits only in the tables being backed up. @ mysql-test/suite/backup/include/backup_vp_nontx.inc Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/include/bml_test.inc Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/r/backup_bml_block.result Recorded new test output. @ mysql-test/suite/backup/r/backup_bml_not_falcon.result Recorded new test output. @ mysql-test/suite/backup/r/backup_errors.result Recorded new test output. @ mysql-test/suite/backup/r/backup_errors_compression.result Recorded new test output. @ mysql-test/suite/backup/r/backup_snapshot.result Recorded new test output. @ mysql-test/suite/backup/r/backup_timeout.result Recorded new test output. @ mysql-test/suite/backup/r/backup_triggers_and_events.result Recorded new test output. @ mysql-test/suite/backup/r/backup_vp_nontx_memory.result Recorded new test output. @ mysql-test/suite/backup/r/backup_vp_nontx_myisam.result Recorded new test output. @ mysql-test/suite/backup/r/backup_vp_tx.result Recorded new test output. @ mysql-test/suite/backup/t/backup_bml.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_bml_block.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_errors.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_snapshot.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_timeout.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_triggers_and_events.test Change test and sync points to work with new commit blocker. @ mysql-test/suite/backup/t/backup_vp_tx.test Change test and sync points to work with new commit blocker. @ sql/backup/be_default.cc Incorrect optimization removed. Caused too early lock release because locking thread was killed. @ sql/backup/data_backup.cc Change backup to use new commit blocker instead of GRL @ sql/bml.cc Refactor BML to become more generic backup shared/exclusive locking mechanism. This will be used both for backup metadata locking and commit blocking. @ sql/bml.h Refactor BML to become more generic backup shared/exclusive locking mechanism. This will be used both for backup metadata locking and commit blocking. @ sql/handler.cc Acquire and release shared backup commit blocker lock when committing. @ sql/mysqld.cc Instanciate backup metadata locks and backup commit blocker locking instances. @ sql/si_objects.cc Add functions for setting and releasing backup commit blocker. Also removed BML_exception since Backup_sx_locks allows the thread owning X lock to set S lock, thus making BML_exception redundant. @ sql/si_objects.h Add functions for setting and releasing backup commit blocker. Also removed BML_exception since Backup_sx_locks allows the thread owning X lock to set S lock, thus making BML_exception redundant. @ sql/sql_class.cc Removed BML_exception flag since Backup_sx_locks allows the thread owning X lock to set S lock, thus making BML_exception redundant. @ sql/sql_class.h Removed BML_exception flag since Backup_sx_locks allows the thread owning X lock to set S lock, thus making BML_exception redundant. @ sql/sql_parse.cc BML_class changed name to Backup_sx_lock
[26 Nov 2009 9:53]
Jørgen Løland
Pushed to mysql-6.0-backup
[22 Dec 2009 9:01]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/95341 2925 Jorgen Loland 2009-12-22 BUG#44568 - followup patch. '#include "bml.h"' was incorrectly placed inside an ifdef. The patch moves include outside ifdef. @ sql/handler.cc '#include "bml.h"' was incorrectly placed inside an ifdef. Patch moves include outside ifdef.
[15 Jan 2010 14:53]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/97103 3067 Chuck Bell 2010-01-15 BUG#44568 - followup patch. '#include "bml.h"' was incorrectly placed inside an ifdef. The patch moves include outside ifdef. original changeset: 2925 (mysql-6.0-backup) @ sql/handler.cc '#include "bml.h"' was incorrectly placed inside an ifdef. Patch moves include outside ifdef.
[20 Feb 2010 9:16]
Bugs System
Pushed into 6.0.14-alpha (revid:ingo.struewing@sun.com-20100218152520-s4v1ld76bif06eqn) (version source revid:ingo.struewing@sun.com-20100119103538-wtp5alpz4p2jayl5) (merge vers: 6.0.14-alpha) (pib:16)
[25 Feb 2010 0:04]
Paul DuBois
Noted in 6.0.14 changelog. BACKUP DATABASE was too conservative about blocking for current transactions before beginning to back up, and was sometimes blocking when it did not need to.