Skip to content

Commit c9d222b

Browse files
author
Daogang Qu
committed
Bug #20748502 ASSERTION `THD->VARIABLES.GTID_NEXT.TYPE== ANONYMOUS_GROUP' FAILED.
Problem 1: In row binlog format, when autocommit is disabled and @@GLOBAL.GTID_MODE=OFF_PERMISSIVE, setting GTID_NEXT='UUID:NUMBER' was causing the assertion failure, right afte committing the single statement 'CREATE TEMPORARY TABLE' transaction. The root cause is that the statement 'CREATE TEMPORARY TABLE' sets has_gtid_consistency_violation to true, so that we call end_gtid_violating_transaction(...) to check a possible violation of gtid consistency and set it back to false on committing the transaction later, but the single statement transaction missed to call end_gtid_violating_transaction(...), since the binlog transaction cache is empty on committing the transaction. Which causes the next transaction to cause the assertion failure. Problem 2: When autocommit is disabled, the statement 'CREATE TEMPORARY TABLE' does not start a transaction, so setting GTID_NEXT='UUID:NUMBER' can not cause an error right after it. To fix the first problem, A transaction with an empty owned gtid should call end_gtid_violating_transaction(...) to check a possible violation of gtid consistency and set has_gtid_consistency_violation back to false on commit, if it has set has_gtid_consistency_violation to true. To fix the second problem, when autocommit is disabled, 'CREATE/DROP TEMPORARY TABLE' sets SERVER_STATUS_IN_TRANS to start transaction in any case (regardless of binlog=on/off, binlog format and transactional/non-transactional engine) to make behavior consistent. Which is changing user-visible behavior when binary log is disabled.
1 parent 5bf44cf commit c9d222b

12 files changed

+332
-80
lines changed

mysql-test/extra/binlog_tests/enforce_gtid_consistency_tmp_consistent.test

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ SET AUTOCOMMIT = 0;
6767
--source extra/binlog_tests/enforce_gtid_consistency_statement.inc
6868
COMMIT;
6969
DROP TEMPORARY TABLE t1;
70+
COMMIT;
7071

7172
--echo ---- CREATE TEMPORARY in trx, SQL_LOG_BIN=0 (MyISAM, AUTOCOMMIT=0) ----
7273
--let $statement= CREATE TEMPORARY TABLE t1 (a INT) ENGINE = MyISAM
@@ -94,12 +95,14 @@ SET AUTOCOMMIT = 0;
9495

9596
--echo ---- DROP TEMPORARY in trx, SQL_LOG_BIN=0 (InnoDB, AUTOCOMMIT=0) ----
9697
CREATE TEMPORARY TABLE t1 (a INT) ENGINE = InnoDB;
98+
COMMIT;
9799
--let $statement= DROP TEMPORARY TABLE t1
98100
--source extra/binlog_tests/enforce_gtid_consistency_statement.inc
99101
COMMIT;
100102

101103
--echo ---- DROP TEMPORARY in trx, SQL_LOG_BIN=0 (MyISAM, AUTOCOMMIT=0) ----
102104
CREATE TEMPORARY TABLE t1 (a INT) ENGINE = MyISAM;
105+
COMMIT;
103106
--let $statement= DROP TEMPORARY TABLE t1
104107
--source extra/binlog_tests/enforce_gtid_consistency_statement.inc
105108
COMMIT;

mysql-test/include/check-warnings.test

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#
2+
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3+
#
24
# This test is executed once after each test to check the servers
35
# for unexpected warnings found in the servers error log
46
#
@@ -27,6 +29,7 @@ create temporary table error_log (
2729
file_name varchar(255),
2830
line varchar(1024) default null
2931
) engine=myisam;
32+
COMMIT;
3033

3134
# Get the name of servers error log
3235
let $log_error= $MTR_LOG_ERROR;

mysql-test/r/gtids_anonymous_trxs_violations.result

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ SET @@GLOBAL.GTID_MODE=OFF_PERMISSIVE;
22
CREATE TABLE t2 (c1 INT);
33
set @@autocommit=0;
44
CREATE TEMPORARY TABLE t1(a INT key);
5+
COMMIT;
56
SET SESSION GTID_NEXT='AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE:1';
67
INSERT INTO t2 VALUES(1);
78
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
RESET MASTER;
2+
CREATE TABLE t1 (c1 INT);
3+
SET @@GLOBAL.GTID_MODE = OFF_PERMISSIVE;
4+
SET SESSION autocommit = 0;
5+
CREATE TEMPORARY TABLE Temp1 SELECT RAND();
6+
SET SESSION GTID_NEXT = '11111111-AAAA-2222-BBBB-000000000000:1';
7+
ERROR HY000: The system variable gtid_next cannot be set when there is an ongoing transaction.
8+
COMMIT;
9+
CREATE TEMPORARY TABLE Temp2(c1 INT);
10+
SET SESSION GTID_NEXT = '11111111-AAAA-2222-BBBB-000000000000:2';
11+
ERROR HY000: The system variable gtid_next cannot be set when there is an ongoing transaction.
12+
COMMIT;
13+
CREATE TEMPORARY TABLE Temp3 LIKE Temp2;
14+
SET SESSION GTID_NEXT = '11111111-AAAA-2222-BBBB-000000000000:3';
15+
ERROR HY000: The system variable gtid_next cannot be set when there is an ongoing transaction.
16+
COMMIT;
17+
SET SESSION GTID_NEXT = '11111111-AAAA-2222-BBBB-000000000000:4';
18+
DROP TABLE t1;
19+
SET SESSION GTID_NEXT = 'automatic';
20+
DROP TEMPORARY TABLE Temp1,Temp2,Temp3;
21+
SET SESSION GTID_NEXT='11111111-AAAA-2222-BBBB-000000000000:5';
22+
ERROR HY000: The system variable gtid_next cannot be set when there is an ongoing transaction.
23+
COMMIT;
24+
SET SESSION autocommit = 1;
25+
SET @@GLOBAL.GTID_MODE = OFF;

0 commit comments

Comments
 (0)