Permalink
Browse files

Super Read-Only

Summary:
Feature: Super Read-Only

Implements super_read_only global, which activates read_only,
and also blocks writes by SUPER.

Linked to the read_only global as follows:
* Turning read_only off also turns off super_read_only.
* Turning super_read_only on also turns read_only on.
* All other changes to either one of these have no affect on the other.

Note: We ignore super_read_only when updating replication repositories.
Otherwise, "stop slave" and "change master to" would throw errors when
this setting is enabled.

Test Plan: New tests included, they all pass.

Reviewers: pivanof, inaam-rana, liang.guo.752

Reviewed By: pivanof

CC: jtolmer, MarkCallaghan, flamingcow, jeremycole, andrew-ford, santoshb

Differential Revision: https://reviews.facebook.net/D16197
  • Loading branch information...
steaphangreene committed Oct 19, 2012
1 parent d72b580 commit 4142091449dd439d473ab22f2e5d60b326e01dc7
@@ -912,6 +912,8 @@ The following options may be given as the first argument:
--stored-program-cache=#
The soft upper limit for number of cached stored routines
for one connection.
+ --super-read-only Enable read_only, and also block writes by users with the
+ SUPER privilege
-s, --symbolic-links
Enable symbolic link support.
--sync-binlog=# Synchronously flush binary log to disk after every #th
@@ -1244,6 +1246,7 @@ sort-buffer-size 262144
sporadic-binlog-dump-fail FALSE
sql-mode NO_ENGINE_SUBSTITUTION
stored-program-cache 256
+super-read-only FALSE
symbolic-links FALSE
sync-binlog 0
sync-frm TRUE
@@ -910,6 +910,8 @@ The following options may be given as the first argument:
--stored-program-cache=#
The soft upper limit for number of cached stored routines
for one connection.
+ --super-read-only Enable read_only, and also block writes by users with the
+ SUPER privilege
-s, --symbolic-links
Enable symbolic link support.
--sync-binlog=# Synchronously flush binary log to disk after every #th
@@ -1241,6 +1243,7 @@ sort-buffer-size 262144
sporadic-binlog-dump-fail FALSE
sql-mode NO_ENGINE_SUBSTITUTION
stored-program-cache 256
+super-read-only FALSE
symbolic-links FALSE
sync-binlog 0
sync-frm TRUE
@@ -0,0 +1,27 @@
+# This unit test is only to test super_read_only=1 doesn't cause
+# errors when executing "CHANGE MASTER".
+#
+# It is not intended to test general super_read_only functionality.
+#
+# Comprehensive super_read_only testing is in the
+# sys_vars.super_read_only_basic test.
+include/master-slave.inc
+Warnings:
+Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
+Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
+[connection master]
+create table t1(a int);
+insert into t1 values(1);
+set @@global.super_read_only=1;
+include/stop_slave.inc
+change master to master_connect_retry=20;
+include/start_slave.inc
+insert into t1 values(2);
+select * from t1;
+a
+1
+2
+set @@global.super_read_only=0;
+set @@global.read_only=0;
+drop table t1;
+include/rpl_end.inc
@@ -0,0 +1 @@
+--relay_log_info_repository='TABLE'
@@ -0,0 +1,32 @@
+--echo # This unit test is only to test super_read_only=1 doesn't cause
+--echo # errors when executing "CHANGE MASTER".
+--echo #
+--echo # It is not intended to test general super_read_only functionality.
+--echo #
+--echo # Comprehensive super_read_only testing is in the
+--echo # sys_vars.super_read_only_basic test.
+
+source include/master-slave.inc;
+
+connection master;
+create table t1(a int);
+insert into t1 values(1);
+sync_slave_with_master;
+
+set @@global.super_read_only=1;
+source include/stop_slave.inc;
+change master to master_connect_retry=20;
+source include/start_slave.inc;
+
+connection master;
+insert into t1 values(2);
+sync_slave_with_master;
+
+select * from t1;
+set @@global.super_read_only=0;
+set @@global.read_only=0;
+
+connection master;
+drop table t1;
+
+source include/rpl_end.inc;
@@ -0,0 +1,247 @@
+#
+# Setup
+#
+# Save original value
+set @start_read_only= @@global.read_only;
+set @start_super_read_only= @@global.super_read_only;
+grant CREATE, SELECT, DROP on *.* to test@localhost;
+# connect (con1,localhost,test,,test);
+# connection default;
+#
+# Test combinations of settings and changes
+#
+# ro,sro: 0,0: set ro->0: 0,0
+set global read_only=0;
+set global super_read_only=0;
+select @@global.read_only;
+@@global.read_only
+0
+select @@global.super_read_only;
+@@global.super_read_only
+0
+set global read_only=0;
+select @@global.read_only;
+@@global.read_only
+0
+select @@global.super_read_only;
+@@global.super_read_only
+0
+# ro,sro: 0,0: set ro->1: 1,0
+set global read_only=0;
+set global super_read_only=0;
+select @@global.read_only;
+@@global.read_only
+0
+select @@global.super_read_only;
+@@global.super_read_only
+0
+set global read_only=1;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+0
+# ro,sro: 0,0: set sro->0: 0,0
+set global read_only=0;
+set global super_read_only=0;
+select @@global.read_only;
+@@global.read_only
+0
+select @@global.super_read_only;
+@@global.super_read_only
+0
+set global super_read_only=0;
+select @@global.read_only;
+@@global.read_only
+0
+select @@global.super_read_only;
+@@global.super_read_only
+0
+# ro,sro: 0,0: set sro->1: 1,1
+set global read_only=0;
+set global super_read_only=0;
+select @@global.read_only;
+@@global.read_only
+0
+select @@global.super_read_only;
+@@global.super_read_only
+0
+set global super_read_only=1;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+1
+# ro,sro: 1,0: set ro->0: 0,0
+set global read_only=1;
+set global super_read_only=0;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+0
+set global read_only=0;
+select @@global.read_only;
+@@global.read_only
+0
+select @@global.super_read_only;
+@@global.super_read_only
+0
+# ro,sro: 1,0: set ro->1: 1,0
+set global read_only=1;
+set global super_read_only=0;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+0
+set global read_only=1;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+0
+# ro,sro: 1,0: set sro->0: 1,0
+set global read_only=1;
+set global super_read_only=0;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+0
+set global super_read_only=0;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+0
+# ro,sro: 1,0: set sro->1: 1,1
+set global read_only=1;
+set global super_read_only=0;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+0
+set global super_read_only=1;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+1
+# ro,sro: 1,1: set ro->0: 0,0
+set global read_only=1;
+set global super_read_only=1;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+1
+set global read_only=0;
+select @@global.read_only;
+@@global.read_only
+0
+select @@global.super_read_only;
+@@global.super_read_only
+0
+# ro,sro: 1,1: set ro->1: 1,1
+set global read_only=1;
+set global super_read_only=1;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+1
+set global read_only=1;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+1
+# ro,sro: 1,1: set sro->0: 1,0
+set global read_only=1;
+set global super_read_only=1;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+1
+set global super_read_only=0;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+0
+# ro,sro: 1,1: set sro->1: 1,1
+set global read_only=1;
+set global super_read_only=1;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+1
+set global super_read_only=1;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+1
+set global read_only=0;
+set global super_read_only=0;
+DROP TABLE IF EXISTS t1,t2,t3;
+#
+# Create tables/Make sure normal writes work
+#
+set global super_read_only=0;
+connection con1;
+create table t1 (a int);
+insert into t1 values(1);
+create table t2 select * from t1;
+connection default;
+#
+# Make sure it blocks SUPER
+#
+set global super_read_only=1;
+create table t3 (a int);
+ERROR HY000: The MySQL server is running with the --read-only (super) option so it cannot execute this statement
+drop table t3;
+ERROR HY000: The MySQL server is running with the --read-only (super) option so it cannot execute this statement
+#
+# Make sure it still blocks for non-super
+#
+connection con1;
+select @@global.read_only;
+@@global.read_only
+1
+select @@global.super_read_only;
+@@global.super_read_only
+1
+create table t3 (a int);
+ERROR HY000: The MySQL server is running with the --read-only (super) option so it cannot execute this statement
+insert into t1 values(1);
+ERROR HY000: The MySQL server is running with the --read-only (super) option so it cannot execute this statement
+#
+# Cleanup
+#
+connection default;
+set global super_read_only=0;
+drop table t1,t2;
+drop user test@localhost;
+set global read_only= @start_read_only;
+set global super_read_only= @start_super_read_only;
Oops, something went wrong.

0 comments on commit 4142091

Please sign in to comment.