mirror of
https://github.com/MariaDB/server.git
synced 2025-08-26 04:11:36 +02:00

The main purpose of this allow one to use the --read-only option to ensure that no one can issue a query that can block replication. The --read-only option can now take 4 different values: 0 No read only (as before). 1 Blocks changes for users without the 'READ ONLY ADMIN' privilege (as before). 2 Blocks in addition LOCK TABLES and SELECT IN SHARE MODE for not 'READ ONLY ADMIN' users. 3 Blocks in addition 'READ_ONLY_ADMIN' users for all the previous statements. read_only is changed to an enum and one can use the following names for the lock levels: OFF, ON, NO_LOCK, NO_LOCK_NO_ADMIN Too keep things compatible with older versions config files, one can still use values FALSE and TRUE, which are mapped to OFF and ON. The main visible changes are: - 'show variables like "read_only"' now returns a string instead of a number. - Error messages related to read_only violations now contains the current value off readonly. Other things: - is_read_only_ctx() renamed to check_read_only_with_error() - Moved TL_READ_SKIP_LOCKED to it's logical place Reviewed by: Sergei Golubchik <serg@mariadb.org>
169 lines
3.6 KiB
Text
169 lines
3.6 KiB
Text
include/master-slave.inc
|
|
[connection master]
|
|
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
|
|
connection master;
|
|
create user test;
|
|
grant all on test.* to test;
|
|
connection slave;
|
|
connect master2,127.0.0.1,test,,test,$MASTER_MYPORT,;
|
|
connect slave2,127.0.0.1,test,,test,$SLAVE_MYPORT,;
|
|
connection master1;
|
|
create table t1(a int) engine=InnoDB;
|
|
create table t2(a int) engine=MyISAM;
|
|
insert into t1 values(1001);
|
|
insert into t2 values(2001);
|
|
connection master;
|
|
set global read_only=1;
|
|
connection master1;
|
|
select @@read_only;
|
|
@@read_only
|
|
ON
|
|
select * from t1;
|
|
a
|
|
1001
|
|
select * from t2;
|
|
a
|
|
2001
|
|
connection slave;
|
|
select @@read_only;
|
|
@@read_only
|
|
OFF
|
|
select * from t1;
|
|
a
|
|
1001
|
|
select * from t2;
|
|
a
|
|
2001
|
|
connection master;
|
|
set global read_only=0;
|
|
connection master1;
|
|
BEGIN;
|
|
connection master2;
|
|
BEGIN;
|
|
connection master;
|
|
select @@read_only;
|
|
@@read_only
|
|
OFF
|
|
set global read_only=1;
|
|
connection master1;
|
|
*** On SUPER USER connection ***
|
|
insert into t1 values(1002);
|
|
insert into t2 values(2002);
|
|
connection master2;
|
|
*** On regular USER connection ***
|
|
insert into t1 values(1003);
|
|
ERROR HY000: The MariaDB server is running with the --read-only=ON option so it cannot execute this statement
|
|
insert into t2 values(2003);
|
|
ERROR HY000: The MariaDB server is running with the --read-only=ON option so it cannot execute this statement
|
|
connection master1;
|
|
*** SUPER USER COMMIT (must succeed) ***
|
|
COMMIT;
|
|
connection master2;
|
|
*** regular USER COMMIT (must succeed - nothing to commit) ***
|
|
COMMIT;
|
|
connection master;
|
|
select @@read_only;
|
|
@@read_only
|
|
ON
|
|
set global read_only=0;
|
|
connection master1;
|
|
insert into t1 values(1004);
|
|
insert into t2 values(2004);
|
|
select * from t1;
|
|
a
|
|
1001
|
|
1002
|
|
1004
|
|
select * from t2;
|
|
a
|
|
2001
|
|
2002
|
|
2004
|
|
connection slave;
|
|
select * from t1;
|
|
a
|
|
1001
|
|
1002
|
|
1004
|
|
select * from t2;
|
|
a
|
|
2001
|
|
2002
|
|
2004
|
|
connection slave1;
|
|
set global read_only=1;
|
|
connection slave;
|
|
select @@read_only;
|
|
@@read_only
|
|
ON
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`a` int(11) DEFAULT NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
show create table t2;
|
|
Table Create Table
|
|
t2 CREATE TABLE `t2` (
|
|
`a` int(11) DEFAULT NULL
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
connection master;
|
|
insert into t1 values(1005);
|
|
insert into t2 values(2005);
|
|
select * from t1;
|
|
a
|
|
1001
|
|
1002
|
|
1004
|
|
1005
|
|
select * from t2;
|
|
a
|
|
2001
|
|
2002
|
|
2004
|
|
2005
|
|
connection slave;
|
|
connection slave;
|
|
select * from t1;
|
|
a
|
|
1001
|
|
1002
|
|
1004
|
|
1005
|
|
select * from t2;
|
|
a
|
|
2001
|
|
2002
|
|
2004
|
|
2005
|
|
connection slave2;
|
|
insert into t1 values(1006);
|
|
ERROR HY000: The MariaDB server is running with the --read-only=ON option so it cannot execute this statement
|
|
insert into t2 values(2006);
|
|
ERROR HY000: The MariaDB server is running with the --read-only=ON option so it cannot execute this statement
|
|
#
|
|
# MDEV-30978: On slave XA COMMIT/XA ROLLBACK fail to return an error in read-only mode
|
|
#
|
|
# Where a read-only server permits writes through replication, it
|
|
# should not permit user connections to commit/rollback XA transactions
|
|
# prepared via replication. This test ensure this behavior is prohibited
|
|
#
|
|
connection master;
|
|
xa start '1';
|
|
insert into t1 values (1007);
|
|
xa end '1';
|
|
xa prepare '1';
|
|
connection slave;
|
|
connection slave2;
|
|
xa commit '1';
|
|
ERROR HY000: The MariaDB server is running with the --read-only=ON option so it cannot execute this statement
|
|
xa rollback '1';
|
|
ERROR HY000: The MariaDB server is running with the --read-only=ON option so it cannot execute this statement
|
|
connection master;
|
|
xa rollback '1';
|
|
connection master;
|
|
drop user test;
|
|
drop table t1;
|
|
drop table t2;
|
|
connection slave;
|
|
set global read_only=0;
|
|
include/rpl_end.inc
|