Bug #70673 | Restored backup is different from original | ||
---|---|---|---|
Submitted: | 21 Oct 2013 12:17 | Modified: | 14 Nov 2013 19:48 |
Reporter: | Kevin Rogers | Email Updates: | |
Status: | Can't repeat | Impact on me: | |
Category: | MySQL Server: Command-line Clients | Severity: | S2 (Serious) |
Version: | 5.0.95 | OS: | Linux (Red Hat Enterprise Linux Server 5.9) |
Assigned to: | CPU Architecture: | Any | |
Tags: | mysqldump |
[21 Oct 2013 12:17]
Kevin Rogers
[21 Oct 2013 13:05]
Peter Laursen
I doubt very much that this is related to the --single-transaction option. I believe the dump is likely OK, and what goes wrong here, happens on the 5.1 target server (and not the 5.0 source server as it seems that you assume). First step to debug this would be to find out it what is in existence after restore is in conformance with the INSERTS in the dump/.sql-file or not. Does the unexpected behaviour occur when exporting from 5.0 or when importing to 5.1? Also interesting questions are 1) what is the 5.1 server sql_mode? Probably it is 'empty'? 2) 'innodb_autoinc_lock_mode' variable is 0 or 1 on the 5.1 server where you import? Refer http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#sysvar_innodb_autoinc_lock_m.... Default is "1" in MySQL 5.1 (and MySQL 5.0 behaves like setting was "0"). Setting 'innodb_autoinc_lock_mode' to "0" while importing the dump may resolve the problem if my assuption is right. Basically my assumption is that the correct iutoincrement value cannot be inserted because of the lock behaviour when innodb_autoinc_lock_mode = 1 and the server will then silently insert next possible value. 'silently' (= no errors returned) because of 'empty' sql_mode. Undoubtedly the dump uses BULK INSERTS? Anyway I may be wrong here and something else could be happening that I am not able to imagine. Peter (not a MySQL/Oracle person)
[21 Oct 2013 15:13]
Kevin Rogers
Thanks for the reply Peter. 1) Yes, sql_mode is empty on both servers. 2) innodb_autoinc_lock_mode is 1 on the new server. If you look at the the dump in step 5 of my steps to reproduce, you'll see that the CREATE TABLE statement for table b has an AUTO_INCREMENT value of 405, but no data is present in the data dump below. This SQL dump implies that from the perspective of the mysqldump (step 3) the AUTO_INCREMENT value for table b was increasing even though the insert (step 4) was running in a different transaction. It seems that by the time the mysqldump (step 3) got to exporting table b, the insert (step 4) had inserted 404 rows into table b. This is reflected in the AUTO_INCREMENT value, but there is no corresponding 404 rows of data in the export for table b. I've been looking at this for days, as the new server in one table has different values in the auto increment column for records added since I turned on replication - I may be getting tied up in knots, but something really doesn't seem right. So far, the above steps to reproduce are the closest I've got to showing the problem. I have a suspicion that this somehow interacts with bug #45677 which means that old versions of MySQL do not properly replicate auto increment values from INSERT statements in triggers - as the table showing differences in the auto increment column (and not just the auto increment value) is updated from a trigger...
[21 Oct 2013 16:44]
Kevin Rogers
I've managed to narrow the problem a little further. The problem affects multiple tables, but one table more significantly than the others. The affected table, lets call is "t2", has a "hole" in it on the new server (the slave of the old server). Table "t2" has records inserted into it from an ON UPDATE TRIGGER on another table "t1". On the slave, table t2 has a gap of 54,210 in it's auto-increment id column, but table t1 has contiguous id's. The data before the gap matches on both servers, but it's as if t2.id = t1.id + 54210 after the gap. This appears to correspond exactly to the period of time while I was running the mysqldump that I initialised the new slave server with. It's like the auto_increment id that was in the dump file carried on incrementing while the dump was running, and the value written to the dump file was not the value at the time the dump started, but the value at the time the dump got to the table t2. It took at least an hour for the mysqldump to get to table t2. It then looks like replication started up ok, but when data was inserted into t2 it used the auto increment value from the create table statement.
[14 Nov 2013 19:47]
Sveta Smirnova
Thank you for the report. This is actually known problem: see bug #20786 for discussion and few patches for mysqldump which can solve this issue(especially "[28 Jun 19:54] Sveta Smirnova"). Your case is not easy to solve in 5.0 and 5.1, because this is not mysqldump bug, but the fact that table definition (*frm) is not transactional and InnoDB is transactional. In version 5.5 and up, where transactional DDL was introduced, this issue does not exist.