Skip to content

Commit f47124c

Browse files
author
Nirbhay Choubey
committed
Incorrect statements binlogged on slave with do_domain_ids=(...)
In domain ID based filtering, a flag is used to filter-out the events that belong to a particular domain. This flag gets set when IO thread receives a GTID_EVENT for the domain on filter list and its reset at the last event in the GTID group. The resetting, however, was wrongly done before the decision to write/filter the event from relay log is made. As a result, the last event in the group will always pass through the filter. Fixed by deferring the reset logic. Also added a test case.
1 parent 836275b commit f47124c

File tree

4 files changed

+188
-16
lines changed

4 files changed

+188
-16
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
include/rpl_init.inc [topology=1->2->3]
2+
include/stop_slave.inc
3+
CHANGE MASTER TO
4+
MASTER_USE_GTID = SLAVE_POS, IGNORE_SERVER_IDS = (2,3);
5+
CHANGE MASTER "M_3" TO
6+
MASTER_HOST = "127.0.0.1", MASTER_PORT = SERVER_MYPORT_3,
7+
MASTER_USER = "root", MASTER_USE_GTID = SLAVE_POS,
8+
IGNORE_SERVER_IDS = (1,2);
9+
START ALL SLAVES;
10+
Warnings:
11+
Note 1937 SLAVE 'M_3' started
12+
Note 1937 SLAVE '' started
13+
include/stop_slave.inc
14+
CHANGE MASTER "M_1" TO
15+
MASTER_HOST = "127.0.0.1", MASTER_PORT = MASTER_MYPORT,
16+
MASTER_USER = "root", MASTER_USE_GTID = SLAVE_POS,
17+
IGNORE_SERVER_IDS = (2,3);
18+
CHANGE MASTER TO
19+
MASTER_USE_GTID = SLAVE_POS, IGNORE_SERVER_IDS = (1,3);
20+
START ALL SLAVES;
21+
Warnings:
22+
Note 1937 SLAVE 'M_1' started
23+
Note 1937 SLAVE '' started
24+
CHANGE MASTER "M_2" TO
25+
MASTER_HOST = "127.0.0.1", MASTER_PORT = SLAVE_MYPORT,
26+
MASTER_USER = "root", MASTER_USE_GTID = SLAVE_POS,
27+
IGNORE_SERVER_IDS = (1,3);
28+
CHANGE MASTER "M_3" TO
29+
MASTER_HOST = "127.0.0.1", MASTER_PORT = SERVER_MYPORT_3,
30+
MASTER_USER = "root", MASTER_USE_GTID = SLAVE_POS,
31+
IGNORE_SERVER_IDS = (1,2);
32+
START ALL SLAVES;
33+
Warnings:
34+
Note 1937 SLAVE 'M_3' started
35+
Note 1937 SLAVE 'M_2' started
36+
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB;
37+
INSERT INTO t1 VALUES (1, "m1");
38+
INSERT INTO t1 VALUES (2, "m2"), (3, "m3"), (4, "m4");
39+
include/save_master_gtid.inc
40+
include/sync_with_master_gtid.inc
41+
SELECT * FROM t1 ORDER BY a;
42+
a b
43+
1 m1
44+
2 m2
45+
3 m3
46+
4 m4
47+
include/sync_with_master_gtid.inc
48+
SELECT * FROM t1 ORDER BY a;
49+
a b
50+
1 m1
51+
2 m2
52+
3 m3
53+
4 m4
54+
# Cleanup
55+
DROP TABLE t1;
56+
include/save_master_gtid.inc
57+
include/sync_with_master_gtid.inc
58+
include/sync_with_master_gtid.inc
59+
STOP SLAVE "M_3";
60+
RESET SLAVE "M_3" ALL;
61+
STOP SLAVE "M_1";
62+
RESET SLAVE "M_1" ALL;
63+
STOP SLAVE "M_2";
64+
RESET SLAVE "M_2" ALL;
65+
STOP SLAVE "M_3";
66+
RESET SLAVE "M_3" ALL;
67+
include/sync_with_master_gtid.inc
68+
STOP SLAVE;
69+
CHANGE MASTER TO MASTER_USE_GTID = NO, IGNORE_SERVER_IDS = ();
70+
include/sync_with_master_gtid.inc
71+
STOP SLAVE;
72+
CHANGE MASTER TO MASTER_USE_GTID = NO, IGNORE_SERVER_IDS = ();
73+
# End of test.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
!include ../my.cnf
2+
3+
[mysqld.1]
4+
log-slave-updates
5+
loose-innodb
6+
gtid_domain_id=1
7+
8+
[mysqld.2]
9+
log-slave-updates
10+
loose-innodb
11+
gtid_domain_id=2
12+
13+
[mysqld.3]
14+
log-slave-updates
15+
loose-innodb
16+
gtid_domain_id=3
17+
18+
[ENV]
19+
SERVER_MYPORT_3= @mysqld.3.port
20+
SERVER_MYSOCK_3= @mysqld.3.socket
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
--source include/have_innodb.inc
2+
--let $rpl_topology=1->2->3
3+
--source include/rpl_init.inc
4+
5+
--connection server_2
6+
--source include/stop_slave.inc
7+
eval CHANGE MASTER TO
8+
MASTER_USE_GTID = SLAVE_POS, IGNORE_SERVER_IDS = (2,3);
9+
--replace_result $SERVER_MYPORT_3 SERVER_MYPORT_3
10+
eval CHANGE MASTER "M_3" TO
11+
MASTER_HOST = "127.0.0.1", MASTER_PORT = $SERVER_MYPORT_3,
12+
MASTER_USER = "root", MASTER_USE_GTID = SLAVE_POS,
13+
IGNORE_SERVER_IDS = (1,2);
14+
START ALL SLAVES;
15+
16+
--connection server_3
17+
--source include/stop_slave.inc
18+
--replace_result $MASTER_MYPORT MASTER_MYPORT
19+
eval CHANGE MASTER "M_1" TO
20+
MASTER_HOST = "127.0.0.1", MASTER_PORT = $MASTER_MYPORT,
21+
MASTER_USER = "root", MASTER_USE_GTID = SLAVE_POS,
22+
IGNORE_SERVER_IDS = (2,3);
23+
eval CHANGE MASTER TO
24+
MASTER_USE_GTID = SLAVE_POS, IGNORE_SERVER_IDS = (1,3);
25+
START ALL SLAVES;
26+
27+
--connection server_1
28+
--replace_result $SLAVE_MYPORT SLAVE_MYPORT
29+
eval CHANGE MASTER "M_2" TO
30+
MASTER_HOST = "127.0.0.1", MASTER_PORT = $SLAVE_MYPORT,
31+
MASTER_USER = "root", MASTER_USE_GTID = SLAVE_POS,
32+
IGNORE_SERVER_IDS = (1,3);
33+
--replace_result $SERVER_MYPORT_3 SERVER_MYPORT_3
34+
eval CHANGE MASTER "M_3" TO
35+
MASTER_HOST = "127.0.0.1", MASTER_PORT = $SERVER_MYPORT_3,
36+
MASTER_USER = "root", MASTER_USE_GTID = SLAVE_POS,
37+
IGNORE_SERVER_IDS = (1,2);
38+
START ALL SLAVES;
39+
40+
connection server_1;
41+
42+
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB;
43+
INSERT INTO t1 VALUES (1, "m1");
44+
INSERT INTO t1 VALUES (2, "m2"), (3, "m3"), (4, "m4");
45+
46+
--source include/save_master_gtid.inc
47+
48+
connection server_2;
49+
--source include/sync_with_master_gtid.inc
50+
let $wait_condition=SELECT COUNT(*)=4 FROM t1;
51+
--source include/wait_condition.inc
52+
SELECT * FROM t1 ORDER BY a;
53+
54+
connection server_3;
55+
--source include/sync_with_master_gtid.inc
56+
--source include/wait_condition.inc
57+
SELECT * FROM t1 ORDER BY a;
58+
59+
--echo # Cleanup
60+
--connection server_1
61+
DROP TABLE t1;
62+
--source include/save_master_gtid.inc
63+
--connection server_2
64+
--source include/sync_with_master_gtid.inc
65+
--connection server_3
66+
--source include/sync_with_master_gtid.inc
67+
68+
--connection server_2
69+
STOP SLAVE "M_3";
70+
RESET SLAVE "M_3" ALL;
71+
72+
--connection server_3
73+
STOP SLAVE "M_1";
74+
RESET SLAVE "M_1" ALL;
75+
76+
--connection server_1
77+
STOP SLAVE "M_2";
78+
RESET SLAVE "M_2" ALL;
79+
STOP SLAVE "M_3";
80+
RESET SLAVE "M_3" ALL;
81+
82+
--connection server_2
83+
--source include/sync_with_master_gtid.inc
84+
STOP SLAVE;
85+
CHANGE MASTER TO MASTER_USE_GTID = NO, IGNORE_SERVER_IDS = ();
86+
87+
--connection server_3
88+
--source include/sync_with_master_gtid.inc
89+
STOP SLAVE;
90+
CHANGE MASTER TO MASTER_USE_GTID = NO, IGNORE_SERVER_IDS = ();
91+
92+
--echo # End of test.

sql/slave.cc

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5875,22 +5875,6 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
58755875
}
58765876
};);
58775877

5878-
if (mi->using_gtid != Master_info::USE_GTID_NO &&
5879-
mi->domain_id_filter.is_group_filtered() &&
5880-
mi->events_queued_since_last_gtid > 0 &&
5881-
((mi->last_queued_gtid_standalone &&
5882-
!Log_event::is_part_of_group((Log_event_type)(uchar)
5883-
buf[EVENT_TYPE_OFFSET])) ||
5884-
(!mi->last_queued_gtid_standalone &&
5885-
((uchar)buf[EVENT_TYPE_OFFSET] == XID_EVENT ||
5886-
((uchar)buf[EVENT_TYPE_OFFSET] == QUERY_EVENT &&
5887-
Query_log_event::peek_is_commit_rollback(buf, event_len,
5888-
checksum_alg))))))
5889-
{
5890-
/* Reset the domain_id_filter flag. */
5891-
mi->domain_id_filter.reset_filter();
5892-
}
5893-
58945878
if (mi->using_gtid != Master_info::USE_GTID_NO && mi->gtid_event_seen)
58955879
{
58965880
if (unlikely(mi->gtid_reconnect_event_skip_count))
@@ -6076,6 +6060,9 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
60766060
*/
60776061
mi->gtid_current_pos.update(&mi->last_queued_gtid);
60786062
mi->events_queued_since_last_gtid= 0;
6063+
6064+
/* Reset the domain_id_filter flag. */
6065+
mi->domain_id_filter.reset_filter();
60796066
}
60806067

60816068
skip_relay_logging:

0 commit comments

Comments
 (0)