Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: insert data with triggers lead to db crash #364

Closed
1 task done
DandreChen opened this issue Aug 4, 2022 · 1 comment · Fixed by #400
Closed
1 task done

bug: insert data with triggers lead to db crash #364

DandreChen opened this issue Aug 4, 2022 · 1 comment · Fixed by #400
Assignees
Labels
A-bug Something isn't working

Comments

@DandreChen
Copy link
Collaborator

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?

  • Yes, I will!
@duanfuxiang0
Copy link
Contributor

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);
}

@mergify mergify bot closed this as completed in #400 Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants