Skip to content

Commit 5b71e04

Browse files
author
Jan Lindström
committed
MDEV-21402 : sql_safe_updates breaks Galera 4
Added handling for sql_safe_updated i.e. we disable it while we do wsrep_schema operations.
1 parent f848837 commit 5b71e04

File tree

4 files changed

+188
-5
lines changed

4 files changed

+188
-5
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
connection node_2;
2+
connection node_1;
3+
connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3;
4+
connection node_1;
5+
connection node_1;
6+
connection node_2;
7+
connection node_3;
8+
SHOW CREATE TABLE mysql.wsrep_cluster;
9+
Table Create Table
10+
wsrep_cluster CREATE TABLE `wsrep_cluster` (
11+
`cluster_uuid` char(36) NOT NULL,
12+
`view_id` bigint(20) NOT NULL,
13+
`view_seqno` bigint(20) NOT NULL,
14+
`protocol_version` int(11) NOT NULL,
15+
`capabilities` int(11) NOT NULL,
16+
PRIMARY KEY (`cluster_uuid`)
17+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
18+
SHOW CREATE TABLE mysql.wsrep_cluster_members;
19+
Table Create Table
20+
wsrep_cluster_members CREATE TABLE `wsrep_cluster_members` (
21+
`node_uuid` char(36) NOT NULL,
22+
`cluster_uuid` char(36) NOT NULL,
23+
`node_name` char(32) NOT NULL,
24+
`node_incoming_address` varchar(256) NOT NULL,
25+
PRIMARY KEY (`node_uuid`)
26+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
27+
SELECT @@sql_safe_updates;
28+
@@sql_safe_updates
29+
1
30+
SELECT COUNT(*) = 1 FROM mysql.wsrep_cluster;
31+
COUNT(*) = 1
32+
1
33+
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster;
34+
cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid')
35+
1
36+
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
37+
COUNT(*) = 3
38+
1
39+
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
40+
COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size')
41+
1
42+
SELECT COUNT(*) = 1 FROM mysql.wsrep_cluster_members WHERE node_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_gcomm_uuid');
43+
COUNT(*) = 1
44+
1
45+
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
46+
node_incoming_address LIKE '127.0.0.1:%'
47+
1
48+
1
49+
1
50+
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
51+
cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid')
52+
1
53+
1
54+
1
55+
connection node_2;
56+
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
57+
COUNT(*) = 3
58+
1
59+
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
60+
COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size')
61+
1
62+
SELECT COUNT(*) = 1 FROM mysql.wsrep_cluster_members WHERE node_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_gcomm_uuid');
63+
COUNT(*) = 1
64+
1
65+
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
66+
node_incoming_address LIKE '127.0.0.1:%'
67+
1
68+
1
69+
1
70+
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
71+
cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid')
72+
1
73+
1
74+
1
75+
connection node_3;
76+
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
77+
COUNT(*) = 3
78+
1
79+
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
80+
COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size')
81+
1
82+
SELECT COUNT(*) = 1 FROM mysql.wsrep_cluster_members WHERE node_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_gcomm_uuid');
83+
COUNT(*) = 1
84+
1
85+
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
86+
node_incoming_address LIKE '127.0.0.1:%'
87+
1
88+
1
89+
1
90+
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
91+
cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid')
92+
1
93+
1
94+
1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
!include ../galera_3nodes.cnf
2+
3+
[mysqld]
4+
sql-safe-updates=1
5+
wsrep-debug=1
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#
2+
# This test performs basic checks on the contents of the wsrep_schema
3+
#
4+
# wsrep_members_history checks are temporarily disabled until it
5+
# can be made configurable.
6+
#
7+
8+
--source include/galera_cluster.inc
9+
--source include/have_innodb.inc
10+
11+
--connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3
12+
--connection node_1
13+
# Save original auto_increment_offset values.
14+
--let $node_1=node_1
15+
--let $node_2=node_2
16+
--let $node_3=node_3
17+
--source ../galera/include/auto_increment_offset_save.inc
18+
19+
# Make the test fail if table structure has changed
20+
21+
SHOW CREATE TABLE mysql.wsrep_cluster;
22+
SHOW CREATE TABLE mysql.wsrep_cluster_members;
23+
#disabled SHOW CREATE TABLE mysql.wsrep_member_history;
24+
SELECT @@sql_safe_updates;
25+
26+
# Checks for the wsrep_cluster table
27+
28+
SELECT COUNT(*) = 1 FROM mysql.wsrep_cluster;
29+
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster;
30+
31+
# Checks for the wsrep_cluster_members table
32+
33+
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
34+
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
35+
SELECT COUNT(*) = 1 FROM mysql.wsrep_cluster_members WHERE node_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_gcomm_uuid');
36+
37+
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
38+
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
39+
40+
--connection node_2
41+
42+
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
43+
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
44+
SELECT COUNT(*) = 1 FROM mysql.wsrep_cluster_members WHERE node_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_gcomm_uuid');
45+
46+
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
47+
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
48+
49+
--connection node_3
50+
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
51+
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
52+
SELECT COUNT(*) = 1 FROM mysql.wsrep_cluster_members WHERE node_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_gcomm_uuid');
53+
54+
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
55+
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
56+
57+
--source ../galera/include/auto_increment_offset_restore.inc
58+

sql/wsrep_schema.cc

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@ class thd_context_switch
159159
THD *m_cur_thd;
160160
};
161161

162+
class sql_safe_updates
163+
{
164+
public:
165+
sql_safe_updates(THD* thd)
166+
: m_thd(thd)
167+
, m_option_bits(thd->variables.option_bits)
168+
{
169+
thd->variables.option_bits&= ~OPTION_SAFE_UPDATES;
170+
}
171+
~sql_safe_updates()
172+
{
173+
m_thd->variables.option_bits= m_option_bits;
174+
}
175+
private:
176+
THD* m_thd;
177+
ulonglong m_option_bits;
178+
};
179+
162180
static int execute_SQL(THD* thd, const char* sql, uint length) {
163181
DBUG_ENTER("Wsrep_schema::execute_SQL()");
164182
int err= 0;
@@ -603,13 +621,15 @@ static void wsrep_init_thd_for_schema(THD *thd)
603621

604622
thd->prior_thr_create_utime= thd->start_utime= thd->thr_create_utime;
605623

606-
/* */
607-
thd->variables.wsrep_on = 0;
624+
/* No Galera replication */
625+
thd->variables.wsrep_on= 0;
608626
/* No binlogging */
609-
thd->variables.sql_log_bin = 0;
610-
thd->variables.option_bits &= ~OPTION_BIN_LOG;
627+
thd->variables.sql_log_bin= 0;
628+
thd->variables.option_bits&= ~OPTION_BIN_LOG;
629+
/* No safe updates */
630+
thd->variables.option_bits&= ~OPTION_SAFE_UPDATES;
611631
/* No general log */
612-
thd->variables.option_bits |= OPTION_LOG_OFF;
632+
thd->variables.option_bits|= OPTION_LOG_OFF;
613633
/* Read committed isolation to avoid gap locking */
614634
thd->variables.tx_isolation= ISO_READ_COMMITTED;
615635
wsrep_assign_from_threadvars(thd);
@@ -664,6 +684,7 @@ int Wsrep_schema::store_view(THD* thd, const Wsrep_view& view)
664684

665685
Wsrep_schema_impl::wsrep_off wsrep_off(thd);
666686
Wsrep_schema_impl::binlog_off binlog_off(thd);
687+
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd);
667688

668689
/*
669690
Clean up cluster table and members table.
@@ -918,6 +939,7 @@ int Wsrep_schema::append_fragment(THD* thd,
918939
thd->lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
919940

920941
Wsrep_schema_impl::binlog_off binlog_off(thd);
942+
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd);
921943
Wsrep_schema_impl::init_stmt(thd);
922944

923945
TABLE* frag_table= 0;
@@ -967,6 +989,7 @@ int Wsrep_schema::update_fragment_meta(THD* thd,
967989
thd->lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
968990

969991
Wsrep_schema_impl::binlog_off binlog_off(thd);
992+
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd);
970993
int error;
971994
uchar *key=NULL;
972995
key_part_map key_map= 0;
@@ -1089,6 +1112,7 @@ int Wsrep_schema::remove_fragments(THD* thd,
10891112
WSREP_DEBUG("Removing %zu fragments", fragments.size());
10901113
Wsrep_schema_impl::wsrep_off wsrep_off(thd);
10911114
Wsrep_schema_impl::binlog_off binlog_off(thd);
1115+
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd);
10921116

10931117
Query_tables_list query_tables_list_backup;
10941118
Open_tables_backup open_tables_backup;
@@ -1156,6 +1180,7 @@ int Wsrep_schema::replay_transaction(THD* orig_thd,
11561180

11571181
Wsrep_schema_impl::wsrep_off wsrep_off(&thd);
11581182
Wsrep_schema_impl::binlog_off binlog_off(&thd);
1183+
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(&thd);
11591184
Wsrep_schema_impl::thd_context_switch thd_context_switch(orig_thd, &thd);
11601185

11611186
int ret= 1;
@@ -1270,6 +1295,7 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd)
12701295
Wsrep_storage_service storage_service(&storage_thd);
12711296
Wsrep_schema_impl::binlog_off binlog_off(&storage_thd);
12721297
Wsrep_schema_impl::wsrep_off wsrep_off(&storage_thd);
1298+
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(&storage_thd);
12731299
Wsrep_schema_impl::thd_context_switch thd_context_switch(orig_thd,
12741300
&storage_thd);
12751301
Wsrep_server_state& server_state(Wsrep_server_state::instance());

0 commit comments

Comments
 (0)