forked from percona/percona-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug 1486747 / 76872 (InnoDB AUTO_INCREMENT produces same value tw…
…ice) The issue is ha_innobase::get_auto_increment not honoring increment and offset parameters for the first value in the interval. This results in the reserved autoinc interval having slightly lesser bounds than it should. ha_innobase::get_auto_increment sets the next value after this interval as the next table autoinc value. Then its caller handler::update_auto_increment will bump the interval start value so that increment and offset are honored. The bumped value, while correct, will conflict with the next autoinc value for this table. This conflict will be resolved at the end of ha_innobase::write_row, which will update the autoinc value according to the actual inserted value used, but before then a parallel inserting thread will get a duplicate key error. Fix by pulling the next value computation function compute_next_insert_id from handler.cc to handler.h, and calling it from ha_innobase::get_auto_increment so that the interval is correct there before further processing. Assert in handler::update_auto_increment that its own rounding is a no-op in case of InnoDB. Add a testcase. Re-record the existing testcases to account for ER_AUTOINC_READ_FAILED being returned instead of ER_WARN_DATA_OUT_OF_RANGE. Moreover, out-of-range auto increment keys insert now can fail instead of being truncated.
- Loading branch information
1 parent
59dc74e
commit bd9d2eb
Showing
11 changed files
with
117 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
SELECT @@innodb_autoinc_lock_mode; | ||
@@innodb_autoinc_lock_mode | ||
1 | ||
CREATE TABLE `test` ( | ||
`test_id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
`testcol` varchar(256) | ||
) ENGINE=InnoDB; | ||
INSERT INTO `test` (`testcol`) VALUES ('aldsldjfhasjk'); | ||
SET SESSION auto_increment_increment = 2; | ||
SET DEBUG_SYNC="ib_after_row_insert SIGNAL insert_1_ready WAIT_FOR insert_1_finish"; | ||
INSERT INTO `test` (`testcol`) VALUES ('aldsldjfhasjk'); | ||
SET SESSION auto_increment_increment = 2; | ||
SET DEBUG_SYNC="now WAIT_FOR insert_1_ready"; | ||
SET DEBUG_SYNC="ib_before_row_insert SIGNAL insert_1_finish WAIT_FOR insert_2_finish"; | ||
INSERT INTO `test` (`testcol`) VALUES ('aldsldjfhasjk'); | ||
SET DEBUG_SYNC="now SIGNAL insert_2_finish"; | ||
SELECT * FROM test; | ||
test_id testcol | ||
1 aldsldjfhasjk | ||
3 aldsldjfhasjk | ||
5 aldsldjfhasjk | ||
DROP TABLE test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# Test for bug #76872: InnoDB AUTO_INCREMENT produces same value twice | ||
# | ||
--source include/have_innodb.inc | ||
--source include/have_debug_sync.inc | ||
--source include/count_sessions.inc | ||
|
||
# Should be != 0 | ||
SELECT @@innodb_autoinc_lock_mode; | ||
|
||
CREATE TABLE `test` ( | ||
`test_id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
`testcol` varchar(256) | ||
) ENGINE=InnoDB; | ||
|
||
INSERT INTO `test` (`testcol`) VALUES ('aldsldjfhasjk'); | ||
|
||
SET SESSION auto_increment_increment = 2; | ||
SET DEBUG_SYNC="ib_after_row_insert SIGNAL insert_1_ready WAIT_FOR insert_1_finish"; | ||
send INSERT INTO `test` (`testcol`) VALUES ('aldsldjfhasjk'); | ||
--connect(con1,localhost,root,,) | ||
--connection con1 | ||
SET SESSION auto_increment_increment = 2; | ||
SET DEBUG_SYNC="now WAIT_FOR insert_1_ready"; | ||
SET DEBUG_SYNC="ib_before_row_insert SIGNAL insert_1_finish WAIT_FOR insert_2_finish"; | ||
send INSERT INTO `test` (`testcol`) VALUES ('aldsldjfhasjk'); | ||
--connection default | ||
reap; | ||
SET DEBUG_SYNC="now SIGNAL insert_2_finish"; | ||
--connection con1 | ||
reap; | ||
--disconnect con1 | ||
--connection default | ||
|
||
SELECT * FROM test; | ||
|
||
DROP TABLE test; | ||
--source include/wait_until_count_sessions.inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters