Skip to content

Commit 61daac5

Browse files
Daniele Sciasciasysprg
authored andcommitted
MDEV-27806 GTIDs diverge in Galera cluster after CTAS
Add OPTION_GTID_BEGIN to applying side thread. This is needed to avoid intermediate commits when CREATE TABLE AS SELECT is applied, causing one more GTID to be consumed with respect to executing node. Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
1 parent 9ab7dbc commit 61daac5

File tree

7 files changed

+120
-0
lines changed

7 files changed

+120
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
connection node_2;
2+
connection node_1;
3+
connection node_1;
4+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
5+
INSERT INTO t1 VALUES (1),(2),(3);
6+
CREATE TABLE ts1 AS SELECT * FROM t1;
7+
include/show_binlog_events.inc
8+
Log_name Pos Event_type Server_id End_log_pos Info
9+
mysqld-bin.000002 # Gtid # # BEGIN GTID #-#-#
10+
mysqld-bin.000002 # Query # # use `test`; CREATE TABLE `ts1` (
11+
`f1` int(11) NOT NULL
12+
)
13+
mysqld-bin.000002 # Annotate_rows # # CREATE TABLE ts1 AS SELECT * FROM t1
14+
mysqld-bin.000002 # Table_map # # table_id: # (test.ts1)
15+
mysqld-bin.000002 # Write_rows_v1 # # table_id: # flags: STMT_END_F
16+
mysqld-bin.000002 # Xid # # COMMIT /* XID */
17+
connection node_2;
18+
include/show_binlog_events.inc
19+
Log_name Pos Event_type Server_id End_log_pos Info
20+
mysqld-bin.000003 # Gtid # # BEGIN GTID #-#-#
21+
mysqld-bin.000003 # Query # # use `test`; CREATE TABLE `ts1` (
22+
`f1` int(11) NOT NULL
23+
)
24+
mysqld-bin.000003 # Annotate_rows # # CREATE TABLE ts1 AS SELECT * FROM t1
25+
mysqld-bin.000003 # Table_map # # table_id: # (test.ts1)
26+
mysqld-bin.000003 # Write_rows_v1 # # table_id: # flags: STMT_END_F
27+
mysqld-bin.000003 # Xid # # COMMIT /* XID */
28+
BINLOG_POSITIONS_MATCH
29+
1
30+
DROP TABLE t1,ts1;
31+
connection node_1;
32+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
33+
CREATE TABLE ts1 AS SELECT * FROM t1;
34+
include/show_binlog_events.inc
35+
Log_name Pos Event_type Server_id End_log_pos Info
36+
mysqld-bin.000002 # Gtid # # BEGIN GTID #-#-#
37+
mysqld-bin.000002 # Query # # use `test`; CREATE TABLE `ts1` (
38+
`f1` int(11) NOT NULL
39+
)
40+
mysqld-bin.000002 # Xid # # COMMIT /* XID */
41+
connection node_2;
42+
include/show_binlog_events.inc
43+
Log_name Pos Event_type Server_id End_log_pos Info
44+
mysqld-bin.000003 # Gtid # # BEGIN GTID #-#-#
45+
mysqld-bin.000003 # Query # # use `test`; CREATE TABLE `ts1` (
46+
`f1` int(11) NOT NULL
47+
)
48+
mysqld-bin.000003 # Query # # COMMIT
49+
BINLOG_POSITIONS_MATCH
50+
1
51+
DROP TABLE t1,ts1;
52+
CALL mtr.add_suppression("Ignoring server id for non bootstrap node");

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ DROP TABLE t1, t4;
5252
SET SQL_LOG_BIN=OFF;
5353
DROP TABLE t2, t3;
5454
connection node_3;
55+
BINLOG_POSITIONS_MATCH
56+
1
5557
STOP SLAVE;
5658
RESET SLAVE ALL;
5759
CALL mtr.add_suppression('You need to use --log-bin to make --binlog-format work');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--log-bin --log-slave-updates --gtid-strict-mode --wsrep_gtid_mode=on
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# MDEV-27806 GTIDs diverge after CTAS
3+
#
4+
--source include/galera_cluster.inc
5+
6+
--connection node_1
7+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
8+
INSERT INTO t1 VALUES (1),(2),(3);
9+
CREATE TABLE ts1 AS SELECT * FROM t1;
10+
--let binlog_pos= `SELECT @@gtid_binlog_pos`
11+
12+
--let $MASTER_MYPORT=$NODE_MYPORT_1
13+
--let $binlog_file=LAST
14+
--let $binlog_limit=8,20
15+
--source include/show_binlog_events.inc
16+
17+
--connection node_2
18+
--let $binlog_limit=7,20
19+
--source include/show_binlog_events.inc
20+
21+
--disable_query_log
22+
--eval SELECT STRCMP(@@gtid_binlog_pos, "$binlog_pos") = 0 AS BINLOG_POSITIONS_MATCH;
23+
--enable_query_log
24+
25+
DROP TABLE t1,ts1;
26+
27+
28+
#
29+
# Same as above, with empty CREATE TABLE AS SELECT
30+
#
31+
--connection node_1
32+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
33+
CREATE TABLE ts1 AS SELECT * FROM t1;
34+
--let binlog_pos= `SELECT @@gtid_binlog_pos`
35+
36+
--let $MASTER_MYPORT=$NODE_MYPORT_1
37+
--let $binlog_file=LAST
38+
--let $binlog_limit=18,20
39+
--source include/show_binlog_events.inc
40+
41+
--connection node_2
42+
--let $binlog_limit=17,20
43+
--source include/show_binlog_events.inc
44+
45+
--disable_query_log
46+
--eval SELECT STRCMP(@@gtid_binlog_pos, "$binlog_pos") = 0 AS BINLOG_POSITIONS_MATCH;
47+
--enable_query_log
48+
49+
DROP TABLE t1,ts1;
50+
51+
CALL mtr.add_suppression("Ignoring server id for non bootstrap node");

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,18 @@ DROP TABLE t1, t4;
5252
SET SQL_LOG_BIN=OFF;
5353
DROP TABLE t2, t3;
5454

55+
--let binlog_pos=`SELECT @@gtid_binlog_pos;`
56+
5557
--connection node_3
5658
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
5759
--source include/wait_condition.inc
5860
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't4';
5961
--source include/wait_condition.inc
6062

63+
--disable_query_log
64+
--eval SELECT STRCMP(@@gtid_binlog_pos, "$binlog_pos") = 0 AS BINLOG_POSITIONS_MATCH;
65+
--enable_query_log
66+
6167
STOP SLAVE;
6268
RESET SLAVE ALL;
6369

sql/wsrep_applier.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ int wsrep_apply_events(THD* thd,
196196
(thd->variables.option_bits & ~OPTION_SKIP_REPLICATION) |
197197
(ev->flags & LOG_EVENT_SKIP_REPLICATION_F ? OPTION_SKIP_REPLICATION : 0);
198198

199+
if (ev->get_type_code() == GTID_EVENT)
200+
{
201+
thd->variables.option_bits &= ~OPTION_GTID_BEGIN;
202+
}
203+
199204
ev->thd= thd;
200205
exec_res= ev->apply_event(thd->wsrep_rgi);
201206
DBUG_PRINT("info", ("exec_event result: %d", exec_res));

sql/wsrep_high_priority_service.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ int Wsrep_applier_service::apply_write_set(const wsrep::ws_meta& ws_meta,
534534
THD* thd= m_thd;
535535

536536
thd->variables.option_bits |= OPTION_BEGIN;
537+
thd->variables.option_bits |= OPTION_GTID_BEGIN;
537538
thd->variables.option_bits |= OPTION_NOT_AUTOCOMMIT;
538539
DBUG_ASSERT(thd->wsrep_trx().active());
539540
DBUG_ASSERT(thd->wsrep_trx().state() == wsrep::transaction::s_executing);
@@ -570,6 +571,8 @@ int Wsrep_applier_service::apply_write_set(const wsrep::ws_meta& ws_meta,
570571
thd->wsrep_cs().fragment_applied(ws_meta.seqno());
571572
}
572573
thd_proc_info(thd, "wsrep applied write set");
574+
575+
thd->variables.option_bits &= ~OPTION_GTID_BEGIN;
573576
DBUG_RETURN(ret);
574577
}
575578

0 commit comments

Comments
 (0)