1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

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>
This commit is contained in:
Monty
2025-03-31 20:07:13 +03:00
parent 595e834946
commit ce8a74f235
37 changed files with 455 additions and 171 deletions

View File

@@ -41,15 +41,16 @@ enum thr_lock_type { TL_IGNORE=-1,
modify tables.
*/
TL_READ_DEFAULT,
/* READ, but skip locks if found */
TL_READ_SKIP_LOCKED,
TL_READ, /* Read lock */
/* Get shared locks on all read rows */
TL_READ_WITH_SHARED_LOCKS,
/* High prior. than TL_WRITE. Allow concurrent insert */
TL_READ_HIGH_PRIORITY,
/* READ, Don't allow concurrent insert */
TL_READ_NO_INSERT,
/* READ, but skip locks if found */
TL_READ_SKIP_LOCKED,
/*
/*
Write lock, but allow other threads to read / write.
Used by BDB tables in MySQL to mark that someone is
reading/writing to the table.
@@ -85,6 +86,9 @@ enum thr_lock_type { TL_IGNORE=-1,
*/
#define TL_FIRST_WRITE TL_WRITE_ALLOW_WRITE
/* First lock that can block readonly slaves using InnoDB tables */
#define TL_BLOCKS_READONLY TL_READ_WITH_SHARED_LOCKS
enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 };