From 4dffa7b5c5baadf95e01d7d595b4ae0dab5965cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 12 May 2022 15:17:37 +0300 Subject: [PATCH] MDEV-28546 : Possible to write/update with read_only=ON and not a SUPER privilege Function wsrep_read_only_option was already removed in commit d54bc3c0d1 because it could cause race condition on variable opt_readonly so that value OFF can become permanent. Removed function again and added test case. Note that writes to TEMPORARY tables are still allowed when read_only=ON. --- .../suite/galera/r/galera_read_only.result | 12 ++++++++++-- .../suite/galera/t/galera_read_only.test | 13 ++++++++++++- sql/sql_parse.cc | 18 +----------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/mysql-test/suite/galera/r/galera_read_only.result b/mysql-test/suite/galera/r/galera_read_only.result index fe8b45fa596..e7e18ca8145 100644 --- a/mysql-test/suite/galera/r/galera_read_only.result +++ b/mysql-test/suite/galera/r/galera_read_only.result @@ -17,10 +17,18 @@ connect foo_node_2,127.0.0.1,foo,,test,$port_2,; connection foo_node_2; INSERT INTO t1 VALUES (2); ERROR HY000: The MariaDB server is running with the --read-only option so it cannot execute this statement +CREATE TEMPORARY TABLE t2(id int not null primary key) engine=innodb; +INSERT INTO t2 values (1); +DROP TABLE t2; connection node_2; -SELECT COUNT(*) = 1 FROM t1; -COUNT(*) = 1 +SELECT COUNT(*) AS EXPECT_1 FROM t1; +EXPECT_1 1 +connection node_2; +SET GLOBAL read_only=TRUE; +CREATE TEMPORARY TABLE t2(id int not null primary key) engine=innodb; +INSERT INTO t2 values (1); +DROP TABLE t2; SET GLOBAL read_only=FALSE; DROP TABLE t1; DROP USER foo@localhost; diff --git a/mysql-test/suite/galera/t/galera_read_only.test b/mysql-test/suite/galera/t/galera_read_only.test index c0fa4af07e0..56fe2fdd910 100644 --- a/mysql-test/suite/galera/t/galera_read_only.test +++ b/mysql-test/suite/galera/t/galera_read_only.test @@ -28,9 +28,20 @@ CREATE USER foo@localhost; --connection foo_node_2 --error ER_OPTION_PREVENTS_STATEMENT INSERT INTO t1 VALUES (2); +# Writes to temporary tables are allowed +CREATE TEMPORARY TABLE t2(id int not null primary key) engine=innodb; +INSERT INTO t2 values (1); +DROP TABLE t2; --connection node_2 -SELECT COUNT(*) = 1 FROM t1; +SELECT COUNT(*) AS EXPECT_1 FROM t1; + +--connection node_2 +SET GLOBAL read_only=TRUE; +# Writes to temporary tables are allowed +CREATE TEMPORARY TABLE t2(id int not null primary key) engine=innodb; +INSERT INTO t2 values (1); +DROP TABLE t2; # Cleanup SET GLOBAL read_only=FALSE; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b5e6b6540c5..04c3450dd98 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1468,22 +1468,6 @@ static bool deny_updates_if_read_only_option(THD *thd, TABLE_LIST *all_tables) } #ifdef WITH_WSREP -static my_bool wsrep_read_only_option(THD *thd, TABLE_LIST *all_tables) -{ - int opt_readonly_saved = opt_readonly; - ulong flag_saved = (ulong)(thd->security_ctx->master_access & SUPER_ACL); - - opt_readonly = 0; - thd->security_ctx->master_access &= ~SUPER_ACL; - - my_bool ret = !deny_updates_if_read_only_option(thd, all_tables); - - opt_readonly = opt_readonly_saved; - thd->security_ctx->master_access |= flag_saved; - - return ret; -} - static void wsrep_copy_query(THD *thd) { thd->wsrep_retry_command = thd->get_command(); @@ -7807,7 +7791,7 @@ static bool wsrep_mysql_parse(THD *thd, char *rawbuf, uint length, { bool is_autocommit= !thd->in_multi_stmt_transaction_mode() && - wsrep_read_only_option(thd, thd->lex->query_tables); + !thd->wsrep_applier; bool retry_autocommit; do {