Commit dbe2c506 authored by unknown's avatar unknown

MDEV-4591:Setting gtid* values from inside a transaction might cause unexpected results

Now we give an error on attempts to set @@SESSION.gtid_domain_id or
@@SESSION.gtid_seq_no when a transaction is active.
parent 7b6ab563
......@@ -29,6 +29,29 @@ include/start_slave.inc
SELECT * FROM t1;
a
1
*** Test that setting @@gtid_domain_id or @@gtid_seq_no is not allowed inside a transaction. ***
BEGIN;
INSERT INTO t1 VALUES (100);
SET SESSION gtid_domain_id= 100;
ERROR HY000: Cannot modify @@session.gtid_domain_id or @@session.gtid_seq_no inside a transaction
SET SESSION gtid_seq_no= 100;
ERROR HY000: Cannot modify @@session.gtid_domain_id or @@session.gtid_seq_no inside a transaction
SET @old_domain= @@GLOBAL.gtid_domain_id;
SET GLOBAL gtid_domain_id= 100;
SELECT @@SESSION.gtid_domain_id;
@@SESSION.gtid_domain_id
0
SET GLOBAL gtid_domain_id= @old_domain;
INSERT INTO t1 VALUES (101);
SELECT * FROM t1 ORDER BY a;
a
1
100
101
ROLLBACK;
SELECT * FROM t1 ORDER BY a;
a
1
*** Test requesting an explicit GTID position that conflicts with newer GTIDs of our own in the binlog. ***
include/stop_slave.inc
RESET MASTER;
......
......@@ -52,6 +52,23 @@ ALTER TABLE mysql.gtid_slave_pos ADD PRIMARY KEY (domain_id, sub_id);
SELECT * FROM t1;
--echo *** Test that setting @@gtid_domain_id or @@gtid_seq_no is not allowed inside a transaction. ***
BEGIN;
INSERT INTO t1 VALUES (100);
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO
SET SESSION gtid_domain_id= 100;
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO
SET SESSION gtid_seq_no= 100;
SET @old_domain= @@GLOBAL.gtid_domain_id;
SET GLOBAL gtid_domain_id= 100;
SELECT @@SESSION.gtid_domain_id;
SET GLOBAL gtid_domain_id= @old_domain;
INSERT INTO t1 VALUES (101);
SELECT * FROM t1 ORDER BY a;
ROLLBACK;
SELECT * FROM t1 ORDER BY a;
--echo *** Test requesting an explicit GTID position that conflicts with newer GTIDs of our own in the binlog. ***
--connection slave
--source include/stop_slave.inc
......
......@@ -6551,3 +6551,7 @@ ER_GTID_START_FROM_BINLOG_HOLE
eng "The binlog on the master is missing the GTID %u-%u-%llu requested by the slave (even though both a prior and a subsequent sequence number does exist), and GTID strict mode is enabled"
ER_SLAVE_UNEXPECTED_MASTER_SWITCH
eng "Unexpected GTID received from master after reconnect. This normally indicates that the master server was replaced without restarting the slave threads. %s"
ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO
eng "Cannot modify @@session.gtid_domain_id or @@session.gtid_seq_no inside a transaction"
ER_STORED_FUNCTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO
eng "Cannot modify @@session.gtid_domain_id or @@session.gtid_seq_no inside a stored function or trigger"
......@@ -1203,6 +1203,21 @@ static Sys_var_ulong Sys_pseudo_thread_id(
BLOCK_SIZE(1), NO_MUTEX_GUARD, IN_BINLOG,
ON_CHECK(check_has_super));
static bool
check_gtid_domain_id(sys_var *self, THD *thd, set_var *var)
{
if (check_has_super(self, thd, var))
return true;
if (var->type != OPT_GLOBAL &&
error_if_in_trans_or_substatement(thd,
ER_STORED_FUNCTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO,
ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO))
return true;
return false;
}
static Sys_var_uint Sys_gtid_domain_id(
"gtid_domain_id",
"Used with global transaction ID to identify logically independent "
......@@ -1213,7 +1228,7 @@ static Sys_var_uint Sys_gtid_domain_id(
SESSION_VAR(gtid_domain_id),
CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, UINT_MAX32), DEFAULT(0),
BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG,
ON_CHECK(check_has_super));
ON_CHECK(check_gtid_domain_id));
static bool check_gtid_seq_no(sys_var *self, THD *thd, set_var *var)
......@@ -1223,6 +1238,11 @@ static bool check_gtid_seq_no(sys_var *self, THD *thd, set_var *var)
if (check_has_super(self, thd, var))
return true;
if (error_if_in_trans_or_substatement(thd,
ER_STORED_FUNCTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO,
ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO))
return true;
domain_id= thd->variables.gtid_domain_id;
server_id= thd->variables.server_id;
seq_no= (uint64)var->value->val_uint();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment