stonedb
stonedb copied to clipboard
bug: insert data with triggers lead to db crash
Describe the problem
Create two tables t_ test1、t_ test2, the storage engine is tianmu, and then create triggers to intsert data to table t_test1, the data is synchronized to table t_test2. When the insert is executed, the database instance crashes. When the tables are stored in InnoDB, there is no such failure.
Expected behavior
insert success
How To Reproduce
CREATE TABLE t_test1(
id INT NOT NULL AUTO_INCREMENT,
first_name VARCHAR(10) NOT NULL,
last_name VARCHAR(10) NOT NULL,
sex VARCHAR(5) NOT NULL,
score INT NOT NULL,
copy_id INT NOT NULL,
PRIMARY KEY (id
)
) ENGINE=stonedb;
CREATE TABLE t_test2(
id INT NOT NULL AUTO_INCREMENT,
first_name VARCHAR(10) NOT NULL,
last_name VARCHAR(10) NOT NULL,
sex VARCHAR(5) NOT NULL,
score INT NOT NULL,
copy_id INT NOT NULL,
PRIMARY KEY (id
)
) ENGINE=stonedb;
DELIMITER // create trigger insert_trigger_t_test2 after insert on t_test1 for each row BEGIN insert into test.t_test2(id,first_name,last_name,sex,score,copy_id) VALUES(new.id,new.first_name,new.last_name,new.sex,new.score,new.copy_id); end // DELIMITER ;
insert into t_test1 values(1,'张','三','1',100,1);
Environment
centos 7.9
Are you interested in submitting a PR to solve the problem?
- [X] Yes, I will!
After checking the code, it was found that after auto-commit was turned on, the transaction could not be registered at the session level, but only at the statement level, and here we can refer to the processing flow of mysql 5.7 (innodb).
// trans_register_ha(thd, FALSE, hton, &trx_id); for statement level
// trans_register_ha(thd, TRUE, hton, &trx_id); for session level
innobase_register_trx() {
const ulonglong trx_id = static_cast<ulonglong>(trx_get_id_for_print(trx));
trans_register_ha(thd, FALSE, hton, &trx_id);
if (!trx_is_registered_for_2pc(trx)
&& thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
trans_register_ha(thd, TRUE, hton, &trx_id);
}
trx_register_for_2pc(trx);
}