diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index ab4afc03fac..15fa7d12b16 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -7854,8 +7854,7 @@ void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment, ulonglong first_value_part, max_first_value; handler **file= m_file; first_value_part= max_first_value= *first_value; - /* Must lock and find highest value among all partitions. */ - lock_auto_increment(); + /* Must find highest value among all partitions. */ do { /* Only nb_desired_values = 1 makes sense */ @@ -7866,7 +7865,6 @@ void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment, *first_value= first_value_part; /* log that the error was between table/partition handler */ sql_print_error("Partition failed to reserve auto_increment value"); - unlock_auto_increment(); DBUG_VOID_RETURN; } DBUG_PRINT("info", ("first_value_part: %lu", (ulong) first_value_part)); @@ -7874,7 +7872,6 @@ void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment, } while (*(++file)); *first_value= max_first_value; *nb_reserved_values= 1; - unlock_auto_increment(); } else { diff --git a/sql/handler.cc b/sql/handler.cc index efecd478019..086a6534120 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2819,15 +2819,10 @@ void handler::get_auto_increment(ulonglong offset, ulonglong increment, if (error) { if (error == HA_ERR_END_OF_FILE || error == HA_ERR_KEY_NOT_FOUND) - { - /* No entry found, start with 1. */ - nr= 1; - } + /* No entry found, that's fine */; else - { - DBUG_ASSERT(0); - nr= ULONGLONG_MAX; - } + print_error(error, MYF(0)); + nr= 1; } else nr= ((ulonglong) table->next_number_field-> diff --git a/storage/tokudb/mysql-test/tokudb_mariadb/r/autoinc.result b/storage/tokudb/mysql-test/tokudb_mariadb/r/autoinc.result new file mode 100644 index 00000000000..3d424357736 --- /dev/null +++ b/storage/tokudb/mysql-test/tokudb_mariadb/r/autoinc.result @@ -0,0 +1,36 @@ +create table t1 (a int auto_increment, b bigint(20), primary key (b,a)) engine=tokudb; +start transaction; +insert t1 (b) values (1); +set tokudb_lock_timeout=1; +insert t1 (b) values (1); +ERROR HY000: Lock wait timeout exceeded; try restarting transaction +set tokudb_lock_timeout=default; +insert t1 (b) values (1); +insert t1 (b) values (1); +commit; +commit; +select * from t1; +a b +1 1 +2 1 +3 1 +alter table t1 partition by range (b) (partition p0 values less than (9)); +start transaction; +insert t1 (b) values (2); +set tokudb_lock_timeout=1; +insert t1 (b) values (2); +ERROR HY000: Lock wait timeout exceeded; try restarting transaction +set tokudb_lock_timeout=default; +insert t1 (b) values (2); +insert t1 (b) values (2); +commit; +commit; +select * from t1; +a b +1 1 +2 1 +3 1 +1 2 +2 2 +3 2 +drop table t1; diff --git a/storage/tokudb/mysql-test/tokudb_mariadb/t/autoinc.test b/storage/tokudb/mysql-test/tokudb_mariadb/t/autoinc.test new file mode 100644 index 00000000000..99fd5333920 --- /dev/null +++ b/storage/tokudb/mysql-test/tokudb_mariadb/t/autoinc.test @@ -0,0 +1,51 @@ +# +# MDEV-6605 Multiple Clients Inserting Causing Error: Failed to read auto-increment value from storage engine +# + +--source include/have_partition.inc +create table t1 (a int auto_increment, b bigint(20), primary key (b,a)) engine=tokudb; + +# first, without partitions +start transaction; +insert t1 (b) values (1); + +--connect(con2,localhost,root) +set tokudb_lock_timeout=1; +# auto-inc value is locked +--error ER_LOCK_WAIT_TIMEOUT +insert t1 (b) values (1); +# but no deadlock +set tokudb_lock_timeout=default; +--send insert t1 (b) values (1) +--connection default +insert t1 (b) values (1); +commit; +--connection con2 +--reap +commit; +select * from t1; + +# now with partitions +--connection default +alter table t1 partition by range (b) (partition p0 values less than (9)); +start transaction; +insert t1 (b) values (2); + +--connection con2 +set tokudb_lock_timeout=1; +# auto-inc value is locked +--error ER_LOCK_WAIT_TIMEOUT +insert t1 (b) values (2); +# but no deadlock +set tokudb_lock_timeout=default; +--send insert t1 (b) values (2) +--connection default +insert t1 (b) values (2); +commit; +--connection con2 +--reap +commit; +select * from t1; + +drop table t1; +