Commit 5b71e042 authored by Jan Lindström's avatar Jan Lindström

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.
parent f8488370
connection node_2;
connection node_1;
connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3;
connection node_1;
connection node_1;
connection node_2;
connection node_3;
SHOW CREATE TABLE mysql.wsrep_cluster;
Table Create Table
wsrep_cluster CREATE TABLE `wsrep_cluster` (
`cluster_uuid` char(36) NOT NULL,
`view_id` bigint(20) NOT NULL,
`view_seqno` bigint(20) NOT NULL,
`protocol_version` int(11) NOT NULL,
`capabilities` int(11) NOT NULL,
PRIMARY KEY (`cluster_uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SHOW CREATE TABLE mysql.wsrep_cluster_members;
Table Create Table
wsrep_cluster_members CREATE TABLE `wsrep_cluster_members` (
`node_uuid` char(36) NOT NULL,
`cluster_uuid` char(36) NOT NULL,
`node_name` char(32) NOT NULL,
`node_incoming_address` varchar(256) NOT NULL,
PRIMARY KEY (`node_uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SELECT @@sql_safe_updates;
@@sql_safe_updates
1
SELECT COUNT(*) = 1 FROM mysql.wsrep_cluster;
COUNT(*) = 1
1
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster;
cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid')
1
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
COUNT(*) = 3
1
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size')
1
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');
COUNT(*) = 1
1
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
node_incoming_address LIKE '127.0.0.1:%'
1
1
1
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid')
1
1
1
connection node_2;
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
COUNT(*) = 3
1
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size')
1
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');
COUNT(*) = 1
1
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
node_incoming_address LIKE '127.0.0.1:%'
1
1
1
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid')
1
1
1
connection node_3;
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
COUNT(*) = 3
1
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size')
1
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');
COUNT(*) = 1
1
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
node_incoming_address LIKE '127.0.0.1:%'
1
1
1
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid')
1
1
1
!include ../galera_3nodes.cnf
[mysqld]
sql-safe-updates=1
wsrep-debug=1
#
# This test performs basic checks on the contents of the wsrep_schema
#
# wsrep_members_history checks are temporarily disabled until it
# can be made configurable.
#
--source include/galera_cluster.inc
--source include/have_innodb.inc
--connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3
--connection node_1
# Save original auto_increment_offset values.
--let $node_1=node_1
--let $node_2=node_2
--let $node_3=node_3
--source ../galera/include/auto_increment_offset_save.inc
# Make the test fail if table structure has changed
SHOW CREATE TABLE mysql.wsrep_cluster;
SHOW CREATE TABLE mysql.wsrep_cluster_members;
#disabled SHOW CREATE TABLE mysql.wsrep_member_history;
SELECT @@sql_safe_updates;
# Checks for the wsrep_cluster table
SELECT COUNT(*) = 1 FROM mysql.wsrep_cluster;
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster;
# Checks for the wsrep_cluster_members table
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
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');
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
--connection node_2
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
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');
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
--connection node_3
SELECT COUNT(*) = 3 FROM mysql.wsrep_cluster_members;
SELECT COUNT(*) = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size') FROM mysql.wsrep_cluster_members;
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');
SELECT node_incoming_address LIKE '127.0.0.1:%' from mysql.wsrep_cluster_members;
SELECT cluster_uuid = (SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_state_uuid') FROM mysql.wsrep_cluster_members;
--source ../galera/include/auto_increment_offset_restore.inc
......@@ -159,6 +159,24 @@ class thd_context_switch
THD *m_cur_thd;
};
class sql_safe_updates
{
public:
sql_safe_updates(THD* thd)
: m_thd(thd)
, m_option_bits(thd->variables.option_bits)
{
thd->variables.option_bits&= ~OPTION_SAFE_UPDATES;
}
~sql_safe_updates()
{
m_thd->variables.option_bits= m_option_bits;
}
private:
THD* m_thd;
ulonglong m_option_bits;
};
static int execute_SQL(THD* thd, const char* sql, uint length) {
DBUG_ENTER("Wsrep_schema::execute_SQL()");
int err= 0;
......@@ -603,13 +621,15 @@ static void wsrep_init_thd_for_schema(THD *thd)
thd->prior_thr_create_utime= thd->start_utime= thd->thr_create_utime;
/* */
thd->variables.wsrep_on = 0;
/* No Galera replication */
thd->variables.wsrep_on= 0;
/* No binlogging */
thd->variables.sql_log_bin = 0;
thd->variables.option_bits &= ~OPTION_BIN_LOG;
thd->variables.sql_log_bin= 0;
thd->variables.option_bits&= ~OPTION_BIN_LOG;
/* No safe updates */
thd->variables.option_bits&= ~OPTION_SAFE_UPDATES;
/* No general log */
thd->variables.option_bits |= OPTION_LOG_OFF;
thd->variables.option_bits|= OPTION_LOG_OFF;
/* Read committed isolation to avoid gap locking */
thd->variables.tx_isolation= ISO_READ_COMMITTED;
wsrep_assign_from_threadvars(thd);
......@@ -664,6 +684,7 @@ int Wsrep_schema::store_view(THD* thd, const Wsrep_view& view)
Wsrep_schema_impl::wsrep_off wsrep_off(thd);
Wsrep_schema_impl::binlog_off binlog_off(thd);
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd);
/*
Clean up cluster table and members table.
......@@ -918,6 +939,7 @@ int Wsrep_schema::append_fragment(THD* thd,
thd->lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
Wsrep_schema_impl::binlog_off binlog_off(thd);
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd);
Wsrep_schema_impl::init_stmt(thd);
TABLE* frag_table= 0;
......@@ -967,6 +989,7 @@ int Wsrep_schema::update_fragment_meta(THD* thd,
thd->lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
Wsrep_schema_impl::binlog_off binlog_off(thd);
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd);
int error;
uchar *key=NULL;
key_part_map key_map= 0;
......@@ -1089,6 +1112,7 @@ int Wsrep_schema::remove_fragments(THD* thd,
WSREP_DEBUG("Removing %zu fragments", fragments.size());
Wsrep_schema_impl::wsrep_off wsrep_off(thd);
Wsrep_schema_impl::binlog_off binlog_off(thd);
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd);
Query_tables_list query_tables_list_backup;
Open_tables_backup open_tables_backup;
......@@ -1156,6 +1180,7 @@ int Wsrep_schema::replay_transaction(THD* orig_thd,
Wsrep_schema_impl::wsrep_off wsrep_off(&thd);
Wsrep_schema_impl::binlog_off binlog_off(&thd);
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(&thd);
Wsrep_schema_impl::thd_context_switch thd_context_switch(orig_thd, &thd);
int ret= 1;
......@@ -1270,6 +1295,7 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd)
Wsrep_storage_service storage_service(&storage_thd);
Wsrep_schema_impl::binlog_off binlog_off(&storage_thd);
Wsrep_schema_impl::wsrep_off wsrep_off(&storage_thd);
Wsrep_schema_impl::sql_safe_updates sql_safe_updates(&storage_thd);
Wsrep_schema_impl::thd_context_switch thd_context_switch(orig_thd,
&storage_thd);
Wsrep_server_state& server_state(Wsrep_server_state::instance());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment