DeNA / HandlerSocket-Plugin-for-MySQL

HandlerSocket is a NoSQL plugin for MySQL, working as a daemon inside the mysqld process, to accept tcp connections, and execute requests from clients. HandlerSocket does not support SQL queries; instead it supports simple CRUD operations on tables.
Other
1.13k stars 150 forks source link

InnoDB's get_auto_increment() is error where insert three rows with two tables in a epoll_wait time #77

Open zephyrleaves opened 12 years ago

zephyrleaves commented 12 years ago

When insert three rows with two tables in a epoll_wait time , it will make "update_auto_increment()" failed and return "HA_ERR_AUTOINC_ERANGE" ,becase the nr will be 0.

Like table: CREATE TABLE testx ( id int(20) unsigned NOT NULL AUTO_INCREMENT, data varchar(200) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=1DEFAULT;

exeucte commands like sql below in a epoll_wait time twice: insert into test1 (data) values ('1'); insert into test1 (data) values ('2'); insert into test2 (data) values ('3'); It will return HA_ERR_AUTOINC_ERANGE(167).

Because the "trx" is in THD and two table has two "prebuilt" ,it will make mistake on "trx->n_autoinc_rows" and "prebuilt->autoinc_last_value".

I think should use "hnd->start_stmt(thd,TL_WRITE)" in "dbcontext::cmd_insert_internal() " before the "const int r = hnd->ha_write_row(buf)" ,this will reset the "trx->n_autoinc_rows" ,and make "update_auto_increment()" success!

ahiguti commented 12 years ago

I tried executing multiple inserts within a single transaction, and it worked fine. I have no idea how to reproduce your problem. Please provide a working script reproducing the error.

zephyrleaves commented 12 years ago

The multiple inserts must be in 2 tables and the variable innodb_autoinc_lock_mode should be 1. In one transaction,the script need like insert into test1 (data) values ('1'); insert into test1 (data) values ('2'); insert into test2 (data) values ('3'); 2 inserts in test1 and then 1 insert in test2,it will reproduce .