1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00
Files
mariadb/mysql-test/suite/sys_vars/t/read_only_basic.test
Monty ce8a74f235 MDEV-36425 Extend read_only to also block share locks and super user
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>
2025-04-28 12:59:39 +03:00

169 lines
6.7 KiB
Plaintext

############## mysql-test\t\read_only_basic.test ###############
# #
# Variable Name: read_only #
# Scope: GLOBAL #
# Access Type: Dynamic #
# Data Type: numeric #
# Default Value: 0 #
# Range: - #
# #
# #
# Creation Date: 2008-02-07 #
# Author: Salman #
# #
# Description: Test Cases of Dynamic System Variable read_only #
# that checks the behavior of this variable in the following ways#
# * Default Value #
# * Valid & Invalid values #
# * Scope & Access method #
# * Data Integrity #
# #
# Reference: http://dev.mysql.com/doc/refman/5.1/en/ #
# server-system-variables.html #
# #
###############################################################################
--source include/load_sysvars.inc
################################################################
# START OF read_only TESTS #
################################################################
################################################################
# Saving initial value of read_only in a temporary variable #
################################################################
SET @start_value = @@global.read_only;
SELECT @start_value;
--echo '#--------------------FN_DYNVARS_139_01------------------------#'
################################################################
# Display the DEFAULT value of read_only #
################################################################
SET @@global.read_only = 1;
SET @@global.read_only = DEFAULT;
SELECT @@global.read_only;
--echo '#---------------------FN_DYNVARS_139_02-------------------------#'
###############################################
# Verify default value of variable #
###############################################
SET @@global.read_only = @start_value;
SELECT @@global.read_only = 0;
--echo '#--------------------FN_DYNVARS_139_03------------------------#'
#################################################################
# Change the value of read_only to a valid value #
#################################################################
SET @@global.read_only = 0;
SELECT @@global.read_only;
SET @@global.read_only = 1;
SELECT @@global.read_only;
SET @@global.read_only = TRUE;
SELECT @@global.read_only;
SET @@global.read_only = FALSE;
SELECT @@global.read_only;
SET @@global.read_only = ON;
SELECT @@global.read_only;
SET @@global.read_only = OFF;
SELECT @@global.read_only;
--echo '#--------------------FN_DYNVARS_139_04-------------------------#'
####################################################################
# Change the value of read_only to invalid value #
####################################################################
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.read_only = -1;
SELECT @@global.read_only;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.read_only = 4294967296;
SELECT @@global.read_only;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.read_only = 10240022115;
SELECT @@global.read_only;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.read_only = 10000.01;
SELECT @@global.read_only;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.read_only = -1024;
SELECT @@global.read_only;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.read_only = 42949672950;
SELECT @@global.read_only;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.read_only = 'test';
SELECT @@global.read_only;
--echo '#-------------------FN_DYNVARS_139_05----------------------------#'
####################################################################
# Test if accessing session read_only gives error #
####################################################################
--Error ER_GLOBAL_VARIABLE
SET @@session.read_only = 0;
SELECT @@read_only;
--echo '#----------------------FN_DYNVARS_139_06------------------------#'
##############################################################################
# Check if the value in GLOBAL & SESSION Tables matches values in variable #
##############################################################################
SELECT @@global.read_only = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='read_only';
SELECT @@global.read_only = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='read_only';
--echo '#---------------------FN_DYNVARS_139_07----------------------#'
########################################################################################################
# Check if accessing variable with SESSION,LOCAL and without SCOPE points to same session variable #
########################################################################################################
SET @@global.read_only = 1;
SELECT @@read_only = @@global.read_only;
--echo '#---------------------FN_DYNVARS_139_08----------------------#'
###################################################################
# Check if read_only can be accessed with and without @@ sign #
###################################################################
--Error ER_GLOBAL_VARIABLE
SET read_only = 1;
SELECT @@read_only;
--Error ER_UNKNOWN_TABLE
SELECT local.read_only;
--Error ER_UNKNOWN_TABLE
SELECT global.read_only;
--Error ER_BAD_FIELD_ERROR
SELECT read_only = @@session.read_only;
##############################
# Restore initial value #
##############################
SET @@global.read_only = @start_value;
SELECT @@global.read_only;
#################################################################
# END OF read_only TESTS #
#################################################################