Skip to content

Commit d328705

Browse files
janlindstromsysprg
authored andcommitted
MDEV-34170 : table gtid_slave_pos entries never been deleted with wsrep_gtid_mode = 0
Problem was that updates to mysql.gtid_slave_pos table were replicated even when they were newer used and because that newer deleted. Avoid replication of mysql.gtid_slave_pos table if wsrep_gtid_mode=OFF. Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
1 parent a02773f commit d328705

File tree

7 files changed

+220
-23
lines changed

7 files changed

+220
-23
lines changed

mysql-test/suite/galera/r/galera_as_slave_gtid_myisam.result

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ EXPECT_1
2222
1
2323
gtid_binlog_state_equal
2424
0
25-
connection node_2;
26-
SELECT COUNT(*) AS EXPECT_1 FROM t1;
27-
EXPECT_1
28-
1
29-
gtid_binlog_state_equal
30-
0
3125
#cleanup
3226
connection node_3;
3327
DROP TABLE t1;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
connection node_2;
2+
connection node_1;
3+
connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3;
4+
create user repl@'%' identified by 'repl';
5+
grant all on *.* to repl@'%';
6+
flush privileges;
7+
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
8+
connection node_1;
9+
connection node_2;
10+
connection node_2;
11+
START SLAVE;
12+
connection node_3;
13+
CREATE TABLE t1 (id bigint primary key, msg varchar(100)) engine=innodb;
14+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
15+
EXPECT_10000
16+
10000
17+
connection node_2;
18+
SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos;
19+
EXPECT_1
20+
1
21+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
22+
EXPECT_10000
23+
10000
24+
connection node_1;
25+
SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos;
26+
EXPECT_0
27+
0
28+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
29+
EXPECT_10000
30+
10000
31+
connection node_2;
32+
# Verify that graceful shutdown succeeds.
33+
# Force SST
34+
connection node_1;
35+
# Waiting until node_2 is not part of cluster anymore
36+
connection node_2;
37+
# Start node_2 again
38+
¤ Wait until node_2 is back on cluster
39+
connection node_2;
40+
call mtr.add_suppression("Slave: Operation CREATE USER failed for .*");
41+
SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos;
42+
EXPECT_0
43+
0
44+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
45+
EXPECT_10000
46+
10000
47+
connection node_1;
48+
SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos;
49+
EXPECT_0
50+
0
51+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
52+
EXPECT_10000
53+
10000
54+
connection node_3;
55+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
56+
EXPECT_10000
57+
10000
58+
connection node_2;
59+
STOP SLAVE;
60+
RESET SLAVE ALL;
61+
connection node_3;
62+
RESET MASTER;
63+
drop table t1;
64+
connection node_2;
65+
DROP TABLE t1;
66+
connection node_1;
67+
connection node_1;
68+
disconnect node_3;
69+
disconnect node_2;
70+
disconnect node_1;
71+
# End of test

mysql-test/suite/galera/t/galera_as_slave_gtid_myisam.test

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,8 @@ SELECT LENGTH(@@global.gtid_binlog_state) > 1;
4646

4747
SELECT COUNT(*) AS EXPECT_1 FROM t1;
4848

49-
--disable_query_log
50-
--eval SELECT '$gtid_binlog_state_node1' = @@global.gtid_binlog_state AS gtid_binlog_state_equal;
51-
--enable_query_log
52-
53-
--connection node_2
54-
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
55-
--source include/wait_condition.inc
56-
57-
--let $wait_condition = SELECT COUNT(*) = 1 FROM t1;
58-
--source include/wait_condition.inc
59-
60-
SELECT COUNT(*) AS EXPECT_1 FROM t1;
49+
# Note that MyISAM tables are not replicated by Galera so we do not here
50+
# check node_2
6151

6252
--disable_query_log
6353
--eval SELECT '$gtid_binlog_state_node1' = @@global.gtid_binlog_state AS gtid_binlog_state_equal;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
!include ../galera_2nodes_as_slave.cnf
2+
3+
[mysqld]
4+
wsrep-debug=1
5+
server_id=15
6+
wsrep_gtid_mode=OFF
7+
wsrep_gtid_domain_id=16
8+
gtid_domain_id=11
9+
gtid_strict_mode=OFF
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#
2+
# Test Galera as a replica to a MySQL async replication
3+
#
4+
# The galera/galera_2node_slave.cnf describes the setup of the nodes
5+
#
6+
--source include/force_restart.inc
7+
--source include/galera_cluster.inc
8+
--source include/have_innodb.inc
9+
--source include/have_sequence.inc
10+
11+
# As node #3 is not a Galera node, and galera_cluster.inc does not open connetion to it
12+
# we open the node_3 connection here
13+
--connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3
14+
15+
create user repl@'%' identified by 'repl';
16+
grant all on *.* to repl@'%';
17+
flush privileges;
18+
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
19+
20+
--let $node_1 = node_1
21+
--let $node_2 = node_2
22+
--source include/auto_increment_offset_save.inc
23+
24+
--connection node_2
25+
--disable_query_log
26+
--eval CHANGE MASTER TO master_host='127.0.0.1', master_user='repl', master_password='repl', master_port=$NODE_MYPORT_3, master_use_gtid=slave_pos;
27+
--enable_query_log
28+
START SLAVE;
29+
30+
--connection node_3
31+
32+
CREATE TABLE t1 (id bigint primary key, msg varchar(100)) engine=innodb;
33+
--disable_query_log
34+
INSERT INTO t1 SELECT seq, 'test' from seq_1_to_10000;
35+
--enable_query_log
36+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
37+
38+
--connection node_2
39+
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
40+
--source include/wait_condition.inc
41+
42+
--let $wait_condition = SELECT COUNT(*) = 10000 FROM t1;
43+
--source include/wait_condition.inc
44+
45+
#
46+
# Node_2 is slave so mysql.gtid_slave_pos table is also replicated
47+
#
48+
SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos;
49+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
50+
51+
--connection node_1
52+
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
53+
--source include/wait_condition.inc
54+
55+
--let $wait_condition = SELECT COUNT(*) = 10000 FROM t1;
56+
--source include/wait_condition.inc
57+
58+
#
59+
# mysql-gtid_slave_pos table should not be replicated by Galera
60+
#
61+
SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos;
62+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
63+
64+
--connection node_2
65+
--echo # Verify that graceful shutdown succeeds.
66+
--source include/shutdown_mysqld.inc
67+
--echo # Force SST
68+
--remove_file $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat
69+
70+
--connection node_1
71+
--echo # Waiting until node_2 is not part of cluster anymore
72+
--let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
73+
--source include/wait_condition.inc
74+
--let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status';
75+
--source include/wait_condition.inc
76+
77+
--connection node_2
78+
--echo # Start node_2 again
79+
--source include/start_mysqld.inc
80+
81+
--echo ¤ Wait until node_2 is back on cluster
82+
--let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status';
83+
--source include/wait_condition.inc
84+
--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
85+
--source include/wait_condition.inc
86+
--let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready';
87+
--source include/wait_condition.inc
88+
89+
--connection node_2
90+
call mtr.add_suppression("Slave: Operation CREATE USER failed for .*");
91+
SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos;
92+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
93+
94+
--connection node_1
95+
SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos;
96+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
97+
98+
--connection node_3
99+
SELECT COUNT(*) AS EXPECT_10000 FROM t1;
100+
101+
#
102+
# Cleanup
103+
#
104+
--connection node_2
105+
STOP SLAVE;
106+
RESET SLAVE ALL;
107+
108+
--connection node_3
109+
RESET MASTER;
110+
drop table t1;
111+
112+
--connection node_2
113+
DROP TABLE t1;
114+
115+
--connection node_1
116+
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
117+
--source include/wait_condition.inc
118+
119+
--connection node_1
120+
--disconnect node_3
121+
122+
--source include/auto_increment_offset_restore.inc
123+
--source include/galera_end.inc
124+
--echo # End of test

sql/log_event_server.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,11 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi,
17261726
thd->variables.pseudo_thread_id= thread_id; // for temp tables
17271727
DBUG_PRINT("query",("%s", thd->query()));
17281728

1729+
#ifdef WITH_WSREP
1730+
WSREP_DEBUG("Query_log_event thread=%llu for query=%s",
1731+
thd_get_thread_id(thd), wsrep_thd_query(thd));
1732+
#endif
1733+
17291734
if (unlikely(!(expected_error= error_code)) ||
17301735
ignored_error_code(expected_error) ||
17311736
!unexpected_error_code(expected_error))

sql/rpl_gtid.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,11 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id,
697697

698698
#ifdef WITH_WSREP
699699
/*
700-
We should replicate local gtid_slave_pos updates to other nodes.
700+
We should replicate local gtid_slave_pos updates to other nodes if
701+
wsrep gtid mode is set.
701702
In applier we should not append them to galera writeset.
702703
*/
703-
if (WSREP_ON_ && wsrep_thd_is_local(thd))
704+
if (WSREP_ON_ && wsrep_gtid_mode && wsrep_thd_is_local(thd))
704705
{
705706
thd->wsrep_ignore_table= false;
706707
table->file->row_logging= 1; // replication requires binary logging
@@ -877,10 +878,12 @@ rpl_slave_state::gtid_delete_pending(THD *thd,
877878

878879
#ifdef WITH_WSREP
879880
/*
880-
We should replicate local gtid_slave_pos updates to other nodes.
881+
We should replicate local gtid_slave_pos updates to other nodes if
882+
wsrep gtid mode is set.
881883
In applier we should not append them to galera writeset.
882884
*/
883-
if (WSREP_ON_ && wsrep_thd_is_local(thd) &&
885+
if (WSREP_ON_ && wsrep_gtid_mode &&
886+
wsrep_thd_is_local(thd) &&
884887
thd->wsrep_cs().state() != wsrep::client_state::s_none)
885888
{
886889
if (thd->wsrep_trx().active() == false)
@@ -891,7 +894,8 @@ rpl_slave_state::gtid_delete_pending(THD *thd,
891894
}
892895
thd->wsrep_ignore_table= false;
893896
}
894-
thd->wsrep_ignore_table= true;
897+
else
898+
thd->wsrep_ignore_table= true;
895899
#endif
896900

897901
thd_saved_option= thd->variables.option_bits;

0 commit comments

Comments
 (0)