Skip to content

Commit

Permalink
fix(tianmu): Fix crashes caused by transaction errors when autocommit…
Browse files Browse the repository at this point in the history
…=ON (#400)

Co-authored-by: dfx <duanfuxiang>
  • Loading branch information
duanfuxiang0 authored Aug 15, 2022
1 parent c8fd9a5 commit f52441b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
30 changes: 30 additions & 0 deletions mysql-test/suite/tianmu/r/issue364.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
USE test;
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=tianmu;
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=tianmu;
CREATE TRIGGER insert_trigger_t_test2 AFTER INSERT ON t_test1 FOR EACH ROW
BEGIN
INSERT INTO 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|
INSERT INTO t_test1 values(1,'张','三','1',100,1);
SELECT id FROM t_test2;
id
1
DROP TRIGGER insert_trigger_t_test2;
DROP TABLE t_test2;
DROP TABLE t_test1;
30 changes: 30 additions & 0 deletions mysql-test/suite/tianmu/t/issue364.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
USE test;
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=tianmu;
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=tianmu;
DELIMITER |;
CREATE TRIGGER insert_trigger_t_test2 AFTER INSERT ON t_test1 FOR EACH ROW
BEGIN
INSERT INTO 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);
SELECT id FROM t_test2;
DROP TRIGGER insert_trigger_t_test2;
DROP TABLE t_test2;
DROP TABLE t_test1;
5 changes: 4 additions & 1 deletion storage/tianmu/handler/tianmu_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,11 @@ int TianmuHandler::extra(enum ha_extra_function operation) {
int TianmuHandler::start_stmt(THD *thd, thr_lock_type lock_type) {
try {
if (lock_type == TL_WRITE_CONCURRENT_INSERT || lock_type == TL_WRITE_DEFAULT || lock_type == TL_WRITE) {
trans_register_ha(thd, true, rcbase_hton,NULL);
trans_register_ha(thd, false, rcbase_hton,NULL);
if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
trans_register_ha(thd, true, rcbase_hton,NULL);
}
current_txn_ = ha_rcengine_->GetTx(thd);
current_txn_->AddTableWRIfNeeded(share);
}
} catch (std::exception &e) {
Expand Down

0 comments on commit f52441b

Please sign in to comment.