Skip to content

Commit 7a6cad5

Browse files
author
Nirbhay Choubey
committed
Backport fix for MDEV-7673, MDEV-7203 and MDEV-7192 from 10.0-galera
1 parent 07ff90e commit 7a6cad5

File tree

11 files changed

+198
-40
lines changed

11 files changed

+198
-40
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ i
2020
1
2121
DROP TABLE t1;
2222
SET @@GLOBAL.wsrep_forced_binlog_format=@wsrep_forced_binlog_format_saved;
23+
#
24+
# MDEV-7673: CREATE TABLE SELECT fails on Galera cluster
25+
#
26+
CREATE TABLE t1 (i INT) ENGINE=INNODB DEFAULT CHARSET=utf8 SELECT 1 as i;
27+
DROP TABLE t1;
2328
# End of tests
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# On node_2
2+
RESET MASTER;
3+
# On node_1
4+
RESET MASTER;
5+
CREATE TABLE t1(i INT)ENGINE=INNODB;
6+
INSERT INTO t1 VALUES(1);
7+
DELETE FROM t1 WHERE i = 1;
8+
# On node_2
9+
INSERT INTO t1 VALUES(2);
10+
DELETE FROM t1 WHERE i = 2;
11+
# On node_1
12+
SHOW BINLOG EVENTS IN 'mysqld-bin.000001' FROM <start_pos>;
13+
Log_name Pos Event_type Server_id End_log_pos Info
14+
mysqld-bin.000001 # Query 1 # use `test`; CREATE TABLE t1(i INT)ENGINE=INNODB
15+
mysqld-bin.000001 # Query 1 # BEGIN
16+
mysqld-bin.000001 # Annotate_rows 1 # INSERT INTO t1 VALUES(1)
17+
mysqld-bin.000001 # Table_map 1 # table_id: # (test.t1)
18+
mysqld-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
19+
mysqld-bin.000001 # Xid 1 # COMMIT /* xid= */
20+
mysqld-bin.000001 # Query 1 # BEGIN
21+
mysqld-bin.000001 # Annotate_rows 1 # DELETE FROM t1 WHERE i = 1
22+
mysqld-bin.000001 # Table_map 1 # table_id: # (test.t1)
23+
mysqld-bin.000001 # Delete_rows 1 # table_id: # flags: STMT_END_F
24+
mysqld-bin.000001 # Xid 1 # COMMIT /* xid= */
25+
mysqld-bin.000001 # Query 2 # BEGIN
26+
mysqld-bin.000001 # Annotate_rows 2 # INSERT INTO t1 VALUES(2)
27+
mysqld-bin.000001 # Table_map 2 # table_id: # (test.t1)
28+
mysqld-bin.000001 # Write_rows 2 # table_id: # flags: STMT_END_F
29+
mysqld-bin.000001 # Xid 2 # COMMIT /* xid= */
30+
mysqld-bin.000001 # Query 2 # BEGIN
31+
mysqld-bin.000001 # Annotate_rows 2 # DELETE FROM t1 WHERE i = 2
32+
mysqld-bin.000001 # Table_map 2 # table_id: # (test.t1)
33+
mysqld-bin.000001 # Delete_rows 2 # table_id: # flags: STMT_END_F
34+
mysqld-bin.000001 # Xid 2 # COMMIT /* xid= */
35+
# On node_2
36+
SHOW BINLOG EVENTS IN 'mysqld-bin.000001' FROM <start_pos>;
37+
Log_name Pos Event_type Server_id End_log_pos Info
38+
mysqld-bin.000001 # Query 1 # use `test`; CREATE TABLE t1(i INT)ENGINE=INNODB
39+
mysqld-bin.000001 # Query 1 # BEGIN
40+
mysqld-bin.000001 # Annotate_rows 1 # INSERT INTO t1 VALUES(1)
41+
mysqld-bin.000001 # Table_map 1 # table_id: # (test.t1)
42+
mysqld-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
43+
mysqld-bin.000001 # Xid 1 # COMMIT /* xid= */
44+
mysqld-bin.000001 # Query 1 # BEGIN
45+
mysqld-bin.000001 # Annotate_rows 1 # DELETE FROM t1 WHERE i = 1
46+
mysqld-bin.000001 # Table_map 1 # table_id: # (test.t1)
47+
mysqld-bin.000001 # Delete_rows 1 # table_id: # flags: STMT_END_F
48+
mysqld-bin.000001 # Xid 1 # COMMIT /* xid= */
49+
mysqld-bin.000001 # Query 2 # BEGIN
50+
mysqld-bin.000001 # Annotate_rows 2 # INSERT INTO t1 VALUES(2)
51+
mysqld-bin.000001 # Table_map 2 # table_id: # (test.t1)
52+
mysqld-bin.000001 # Write_rows 2 # table_id: # flags: STMT_END_F
53+
mysqld-bin.000001 # Xid 2 # COMMIT /* xid= */
54+
mysqld-bin.000001 # Query 2 # BEGIN
55+
mysqld-bin.000001 # Annotate_rows 2 # DELETE FROM t1 WHERE i = 2
56+
mysqld-bin.000001 # Table_map 2 # table_id: # (test.t1)
57+
mysqld-bin.000001 # Delete_rows 2 # table_id: # flags: STMT_END_F
58+
mysqld-bin.000001 # Xid 2 # COMMIT /* xid= */
59+
DROP TABLE t1;
60+
# End of test

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,13 @@ SELECT * FROM t1_temp;
2222
DROP TABLE t1;
2323
SET @@GLOBAL.wsrep_forced_binlog_format=@wsrep_forced_binlog_format_saved;
2424

25+
--echo #
26+
--echo # MDEV-7673: CREATE TABLE SELECT fails on Galera cluster
27+
--echo #
28+
CREATE TABLE t1 (i INT) ENGINE=INNODB DEFAULT CHARSET=utf8 SELECT 1 as i;
29+
30+
# Cleanup
31+
DROP TABLE t1;
32+
2533
--echo # End of tests
2634

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
!include ../galera_2nodes.cnf
2+
3+
[mysqld]
4+
log-bin
5+
log-slave-updates
6+
binlog-annotate-row-events=ON
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--source include/galera_cluster.inc
2+
--source include/have_innodb.inc
3+
4+
--echo # On node_2
5+
--connection node_2
6+
RESET MASTER;
7+
8+
--echo # On node_1
9+
--connection node_1
10+
RESET MASTER;
11+
CREATE TABLE t1(i INT)ENGINE=INNODB;
12+
INSERT INTO t1 VALUES(1);
13+
DELETE FROM t1 WHERE i = 1;
14+
15+
--echo # On node_2
16+
--connection node_2
17+
INSERT INTO t1 VALUES(2);
18+
DELETE FROM t1 WHERE i = 2;
19+
20+
--echo # On node_1
21+
--connection node_1
22+
--source include/binlog_start_pos.inc
23+
let $start_pos= `select @binlog_start_pos`;
24+
--replace_column 2 # 5 #
25+
--replace_result $start_pos <start_pos>
26+
--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\//
27+
--eval SHOW BINLOG EVENTS IN 'mysqld-bin.000001' FROM $start_pos
28+
29+
--echo # On node_2
30+
--connection node_2
31+
--source include/binlog_start_pos.inc
32+
let $start_pos= `select @binlog_start_pos`;
33+
--replace_column 2 # 5 #
34+
--replace_result $start_pos <start_pos>
35+
--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\//
36+
--eval SHOW BINLOG EVENTS IN 'mysqld-bin.000001' FROM $start_pos
37+
38+
# Cleanup
39+
DROP TABLE t1;
40+
41+
--source include/galera_end.inc
42+
--echo # End of test

sql/rpl_rli.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,47 @@ void Relay_log_info::stmt_done(my_off_t event_master_log_pos,
12181218
}
12191219

12201220
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1221+
1222+
void
1223+
delete_or_keep_event_post_apply(Relay_log_info *rli,
1224+
Log_event_type typ, Log_event *ev)
1225+
{
1226+
switch (typ) {
1227+
case FORMAT_DESCRIPTION_EVENT:
1228+
/*
1229+
Format_description_log_event should not be deleted because it
1230+
will be used to read info about the relay log's format;
1231+
it will be deleted when the SQL thread does not need it,
1232+
i.e. when this thread terminates.
1233+
*/
1234+
break;
1235+
case ANNOTATE_ROWS_EVENT:
1236+
/*
1237+
Annotate_rows event should not be deleted because after it has
1238+
been applied, thd->query points to the string inside this event.
1239+
The thd->query will be used to generate new Annotate_rows event
1240+
during applying the subsequent Rows events.
1241+
*/
1242+
rli->set_annotate_event((Annotate_rows_log_event*) ev);
1243+
break;
1244+
case DELETE_ROWS_EVENT:
1245+
case UPDATE_ROWS_EVENT:
1246+
case WRITE_ROWS_EVENT:
1247+
/*
1248+
After the last Rows event has been applied, the saved Annotate_rows
1249+
event (if any) is not needed anymore and can be deleted.
1250+
*/
1251+
if (((Rows_log_event*)ev)->get_flags(Rows_log_event::STMT_END_F))
1252+
rli->free_annotate_event();
1253+
/* fall through */
1254+
default:
1255+
DBUG_PRINT("info", ("Deleting the event after it has been executed"));
1256+
if (!rli->is_deferred_event(ev))
1257+
delete ev;
1258+
break;
1259+
}
1260+
}
1261+
12211262
void Relay_log_info::cleanup_context(THD *thd, bool error)
12221263
{
12231264
DBUG_ENTER("Relay_log_info::cleanup_context");

sql/rpl_rli.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ class Relay_log_info : public Slave_reporting_capability
580580

581581
// Defined in rpl_rli.cc
582582
int init_relay_log_info(Relay_log_info* rli, const char* info_fname);
583-
583+
void delete_or_keep_event_post_apply(Relay_log_info *rli,
584+
Log_event_type typ, Log_event *ev);
584585

585586
#endif /* RPL_RLI_H */

sql/slave.cc

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,41 +2820,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli)
28202820

28212821
exec_res= apply_event_and_update_pos(ev, thd, rli);
28222822

2823-
switch (ev->get_type_code()) {
2824-
case FORMAT_DESCRIPTION_EVENT:
2825-
/*
2826-
Format_description_log_event should not be deleted because it
2827-
will be used to read info about the relay log's format;
2828-
it will be deleted when the SQL thread does not need it,
2829-
i.e. when this thread terminates.
2830-
*/
2831-
break;
2832-
case ANNOTATE_ROWS_EVENT:
2833-
/*
2834-
Annotate_rows event should not be deleted because after it has
2835-
been applied, thd->query points to the string inside this event.
2836-
The thd->query will be used to generate new Annotate_rows event
2837-
during applying the subsequent Rows events.
2838-
*/
2839-
rli->set_annotate_event((Annotate_rows_log_event*) ev);
2840-
break;
2841-
case DELETE_ROWS_EVENT:
2842-
case UPDATE_ROWS_EVENT:
2843-
case WRITE_ROWS_EVENT:
2844-
/*
2845-
After the last Rows event has been applied, the saved Annotate_rows
2846-
event (if any) is not needed anymore and can be deleted.
2847-
*/
2848-
if (((Rows_log_event*)ev)->get_flags(Rows_log_event::STMT_END_F))
2849-
rli->free_annotate_event();
2850-
/* fall through */
2851-
default:
2852-
DBUG_PRINT("info", ("Deleting the event after it has been executed"));
2853-
if (!rli->is_deferred_event(ev))
2854-
delete ev;
2855-
break;
2856-
}
2857-
2823+
delete_or_keep_event_post_apply(rli, ev->get_type_code(), ev);
28582824

28592825
/*
28602826
update_log_pos failed: this should not happen, so we don't

sql/sql_parse.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,6 +2913,14 @@ case SQLCOM_PREPARE:
29132913
if (create_info.options & HA_LEX_CREATE_TMP_TABLE)
29142914
thd->variables.option_bits|= OPTION_KEEP_LOG;
29152915

2916+
#ifdef WITH_WSREP
2917+
if (WSREP(thd) &&
2918+
(!thd->is_current_stmt_binlog_format_row() ||
2919+
!(create_info.options & HA_LEX_CREATE_TMP_TABLE)))
2920+
WSREP_TO_ISOLATION_BEGIN(create_table->db, create_table->table_name,
2921+
NULL)
2922+
#endif
2923+
29162924
/*
29172925
select_create is currently not re-execution friendly and
29182926
needs to be created for every execution of a PS/SP.

sql/wsrep_applier.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static wsrep_cb_status_t wsrep_apply_events(THD* thd,
7373
char *buf= (char *)events_buf;
7474
int rcode= 0;
7575
int event= 1;
76+
Log_event_type typ;
7677

7778
DBUG_ENTER("wsrep_apply_events");
7879

@@ -106,7 +107,10 @@ static wsrep_cb_status_t wsrep_apply_events(THD* thd,
106107
rcode= 1;
107108
goto error;
108109
}
109-
switch (ev->get_type_code()) {
110+
111+
typ= ev->get_type_code();
112+
113+
switch (typ) {
110114
case WRITE_ROWS_EVENT:
111115
case UPDATE_ROWS_EVENT:
112116
case DELETE_ROWS_EVENT:
@@ -117,14 +121,20 @@ static wsrep_cb_status_t wsrep_apply_events(THD* thd,
117121
break;
118122
}
119123

120-
thd->server_id = ev->server_id; // use the original server id for logging
121-
thd->set_time(); // time the query
124+
/* Use the original server id for logging. */
125+
thd->set_server_id(ev->server_id);
126+
thd->set_time(); // time the query
122127
wsrep_xid_init(&thd->transaction.xid_state.xid,
123128
&thd->wsrep_trx_meta.gtid.uuid,
124129
thd->wsrep_trx_meta.gtid.seqno);
125130
thd->lex->current_select= 0;
126131
if (!ev->when)
127132
ev->when = time(NULL);
133+
134+
thd->variables.option_bits=
135+
(thd->variables.option_bits & ~OPTION_SKIP_REPLICATION) |
136+
(ev->flags & LOG_EVENT_SKIP_REPLICATION_F ? OPTION_SKIP_REPLICATION : 0);
137+
128138
ev->thd = thd;
129139
exec_res = ev->apply_event(thd->wsrep_rli);
130140
DBUG_PRINT("info", ("exec_event result: %d", exec_res));
@@ -172,7 +182,8 @@ static wsrep_cb_status_t wsrep_apply_events(THD* thd,
172182
WSREP_ERROR("Error in %s event: commit of row events failed: %lld",
173183
ev->get_type_str(), (long long)wsrep_thd_trx_seqno(thd));
174184
}
175-
delete ev;
185+
186+
delete_or_keep_event_post_apply(thd->wsrep_rli, typ, ev);
176187
}
177188

178189
error:

0 commit comments

Comments
 (0)