Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression in tidb_restricted_read_only - can not disable after enabling #33003

Closed
morgo opened this issue Mar 10, 2022 · 11 comments
Closed

regression in tidb_restricted_read_only - can not disable after enabling #33003

morgo opened this issue Mar 10, 2022 · 11 comments
Labels
sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@morgo
Copy link
Contributor

morgo commented Mar 10, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

SET GLOBAL tidb_restricted_read_only=1;
SET GLOBAL tidb_restricted_read_only=0;
CREATE TABLE test.t1 (a int);

2. What did you expect to see? (Required)

The create table statement should succeed.

This is a regression bisected to #31746

3. What did you see instead (Required)

mysql> CREATE TABLE test.t1 (a int);
ERROR 1836 (HY000): Running in read-only mode

4. What is your TiDB version? (Required)

tidb> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v6.0.0-alpha-56-g9a4ca3ca6
Edition: Community
Git Commit Hash: 9a4ca3ca6919699fb4f0da72edd7151c56f84edd
Git Branch: master
UTC Build Time: 2022-03-10 20:12:59
GoVersion: go1.16.15
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)
@morgo morgo added the type/bug The issue is confirmed as a bug. label Mar 10, 2022
@morgo
Copy link
Contributor Author

morgo commented Mar 10, 2022

@ichn-hu PTAL :-)

@ChenPeng2013 ChenPeng2013 added the sig/sql-infra SIG: SQL Infra label Mar 11, 2022
@bb7133 bb7133 added sig/execution SIG execution and removed sig/sql-infra SIG: SQL Infra labels Mar 11, 2022
@ichn-hu
Copy link
Contributor

ichn-hu commented Mar 14, 2022

I suppose this is the by-design behavior of tidb_restricted_read_only, as the transmissibility requirements in #31746 (review) states.

@ichn-hu
Copy link
Contributor

ichn-hu commented Mar 14, 2022

we need to update the docs though

@morgo
Copy link
Contributor Author

morgo commented Mar 14, 2022

I suppose this is the by-design behavior of tidb_restricted_read_only, as the transmissibility requirements in #31746 (review) states.

The design has a usability problem if it allows the value to be changed, but not effective. If this is the intended case, then attempting to set it to 0 again should return an error saying that another value must be modified first.

@ichn-hu
Copy link
Contributor

ichn-hu commented Mar 14, 2022

I think this might be against the original design requirements, as it is for cloud replication scenario, where the cloud service DBA turns on the restricted read-only variable and implicitly turned on super read-only before the replication started, and when it is done, she would turn off the restricted read-only and it is upon to the user to turn off super read-only.

cc @SunRunAway please take a look as this is your design.

@SunRunAway
Copy link
Contributor

Another reference is that the behavior is similar like MySQL’s super_read_only and read_only.

@morgo
Copy link
Contributor Author

morgo commented Mar 14, 2022

Another reference is that the behavior is similar like MySQL’s super_read_only and read_only.

See the test-case above. I'm not touching the value of super_read_only: I'm just toggling tidb_restricted_read_only on and then off. If it's not supported, there should be an error?

@SunRunAway
Copy link
Contributor

SunRunAway commented Mar 14, 2022

When I change super_read_only from on to off, the read_only will continue to be kept as on.

tidb_restricted_read_only and tidb_super_read_only follow this behaviour.

@morgo
Copy link
Contributor Author

morgo commented Mar 14, 2022

Here is my suggestion:

morgo@ubuntu:~/go/src/github.com/morgo/tidb$ git diff
diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go
index bdc9150f5..227172955 100644
--- a/sessionctx/variable/sysvar.go
+++ b/sessionctx/variable/sysvar.go
@@ -1063,13 +1063,29 @@ var defaultSysVars = []*SysVar{
        {Scope: ScopeGlobal, Name: TiDBRestrictedReadOnly, Value: BoolToOnOff(DefTiDBRestrictedReadOnly), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error {
                on := TiDBOptOn(val)
                if on {
-                       err := s.GlobalVarsAccessor.SetGlobalSysVar(TiDBSuperReadOnly, "ON")
+                       // Set SuperReadOnly to ON as well
+                       err := s.GlobalVarsAccessor.SetGlobalSysVarOnly(TiDBSuperReadOnly, "ON")
                        if err != nil {
                                return err
                        }
                }
                RestrictedReadOnly.Store(on)
                return nil
+       }, Validation: func(vars *SessionVars, normalizedValue string, _ string, _ ScopeFlag) (string, error) {
+               // Because setting ON also enables SuperReadOnly, we need to at least WARN
+               // that SETTING ON->OFF won't take effect when SuperReadOnly is ON.
+               // Another option is that we could also toggle SuperReadOnly OFF,
+               // but we don't currently do this.
+               if !TiDBOptOn(normalizedValue) {
+                       result, err := vars.GlobalVarsAccessor.GetGlobalSysVar(TiDBSuperReadOnly)
+                       if err != nil {
+                               return normalizedValue, err
+                       }
+                       if TiDBOptOn(result) {
+                               vars.StmtCtx.AppendWarning(errors.New("you need to set super_read_only OFF too, otherwise this doesn't make sense."))
+                       }
+               }
+               return normalizedValue, nil
        }},
        {Scope: ScopeGlobal, Name: TiDBSuperReadOnly, Value: BoolToOnOff(DefTiDBSuperReadOnly), Type: TypeBool, Validation: func(vars *SessionVars, normalizedValue string, _ string, _ ScopeFlag) (string, error) {
                on := TiDBOptOn(normalizedValue)

@SunRunAway
Copy link
Contributor

SunRunAway commented Mar 14, 2022

It does make sense.
cloudAdmin uses tidb_restricted_read_only while customer(root user) only uses tidb_super_read_only.

When cloudAdmin sets tidb_restricted_read_only to ON, it tells that customer can not write into the database, and any root user can not change this situation.
When cloudAdmin sets tidb_restricted_read_only to OFF, it tells that the customer now has right to change tidb_super_read_only to OFF to make their cluster writable.

@morgo
Copy link
Contributor Author

morgo commented Aug 2, 2022

Closing as not required. If users use tidb_super_read_only as documented, there is no problem.

@morgo morgo closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

5 participants