Skip to content

Commit

Permalink
Fix super_read_only for DROP TRIGGER
Browse files Browse the repository at this point in the history
Summary:
Feature: Super Read-Only

This was contributed by: Laurynas Biveinis <[email protected]>

Fix for issue #10 (super read only does not prevent DROP TRIGGER).

- add super read only handling to mysql_create_and_drop_trigger;
- tweak error message in trans_begin to note whether regular or super
  read only is effective;
- add MTR tests for the above changes and for multi-table update which
  was implemented but not covered in MTR.

I will squash this commit, in future branches, with:
https://reviews.facebook.net/D16197

Test Plan:
mtr sys_vars.super_read_only_basic

I will run the automated tests on this diff now.

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

Reviewed By: pivanof

Subscribers: jtolmer

Differential Revision: https://reviews.facebook.net/D30309
  • Loading branch information
laurynas-biveinis authored and steaphangreene committed Jan 1, 2015
1 parent 91ab2ad commit b49b85b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
18 changes: 18 additions & 0 deletions mysql-test/suite/sys_vars/r/super_read_only_basic.result
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,27 @@ connection con1;
create table t1 (a int);
insert into t1 values(1);
create table t2 select * from t1;
update t1, t2 set t1.a=2, t2.a=2;
start transaction read write;
commit;
create trigger trig1 before insert on t1 for each row set new.a = new.a;
connection default;
#
# Make sure it blocks SUPER
#
set global super_read_only=1;
create trigger trig2 before insert on t2 for each row set new.a = new.a;
ERROR HY000: The MySQL server is running with the --read-only (super) option so it cannot execute this statement
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
update t1, t2 set t1.a=3, t2.a=3;
ERROR HY000: The MySQL server is running with the --read-only (super) option so it cannot execute this statement
start transaction read write;
ERROR HY000: The MySQL server is running with the --read-only (super) option so it cannot execute this statement
drop trigger trig1;
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
#
Expand All @@ -236,6 +248,12 @@ 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
update t1, t2 set t1.a=3, t2.a=3;
ERROR HY000: The MySQL server is running with the --read-only (super) option so it cannot execute this statement
start transaction read write;
ERROR HY000: The MySQL server is running with the --read-only (super) option so it cannot execute this statement
drop trigger trig1;
ERROR HY000: The MySQL server is running with the --read-only (super) option so it cannot execute this statement
#
# Cleanup
#
Expand Down
26 changes: 26 additions & 0 deletions mysql-test/suite/sys_vars/t/super_read_only_basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ insert into t1 values(1);

create table t2 select * from t1;

update t1, t2 set t1.a=2, t2.a=2;

start transaction read write;
commit;

create trigger trig1 before insert on t1 for each row set new.a = new.a;

--echo connection default;
connection default;

Expand All @@ -169,12 +176,23 @@ connection default;

set global super_read_only=1;

--error ER_OPTION_PREVENTS_STATEMENT
create trigger trig2 before insert on t2 for each row set new.a = new.a;

--error ER_OPTION_PREVENTS_STATEMENT
create table t3 (a int);

--error ER_OPTION_PREVENTS_STATEMENT
drop table t3;

--error ER_OPTION_PREVENTS_STATEMENT
update t1, t2 set t1.a=3, t2.a=3;

--error ER_OPTION_PREVENTS_STATEMENT
start transaction read write;

--error ER_OPTION_PREVENTS_STATEMENT
drop trigger trig1;

--echo #
--echo # Make sure it still blocks for non-super
Expand All @@ -192,6 +210,14 @@ create table t3 (a int);
--error ER_OPTION_PREVENTS_STATEMENT
insert into t1 values(1);

--error ER_OPTION_PREVENTS_STATEMENT
update t1, t2 set t1.a=3, t2.a=3;

--error ER_OPTION_PREVENTS_STATEMENT
start transaction read write;

--error ER_OPTION_PREVENTS_STATEMENT
drop trigger trig1;

--echo #
--echo # Cleanup
Expand Down
11 changes: 7 additions & 4 deletions sql/sql_trigger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
if (!create)
{
bool if_exists= thd->lex->drop_if_exists;
bool enforce_ro= true;
if (!opt_super_readonly)
enforce_ro= !(thd->security_ctx->master_access & SUPER_ACL);

/*
Protect the query table list from the temporary and potentially
Expand All @@ -458,11 +461,11 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
*/
thd->lex->sql_command= backup.sql_command;

if (opt_readonly && !(thd->security_ctx->master_access & SUPER_ACL) &&
!thd->slave_thread)
if (opt_readonly && enforce_ro && !thd->slave_thread)
{
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
goto end;
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0),
opt_super_readonly ? "--read-only (super)" : "--read-only");
goto end;
}

if (add_table_for_trigger(thd, thd->lex->spname, if_exists, & tables))
Expand Down
3 changes: 2 additions & 1 deletion sql/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ bool trans_begin(THD *thd, uint flags)
enforce_ro = !(thd->security_ctx->master_access & SUPER_ACL);
if (opt_readonly && enforce_ro)
{
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0),
opt_super_readonly ? "--read-only (super)" : "--read-only");
DBUG_RETURN(true);
}
thd->tx_read_only= false;
Expand Down

0 comments on commit b49b85b

Please sign in to comment.