Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-11308

Read_only Clarification

    XMLWordPrintable

Details

    Description

      The manual states this about read_only option:

      "Changing this to 1 will fail if you have table locks or transactions pending, while it will wait until other locks are released or transactions are completed."

      https://mariadb.com/kb/en/mariadb/server-system-variables/#read_only

      I have several issues with this sentence.

      1. It almost seems contradictory, but if not, then it needs some further clarification.

      For instance, it says, "Changing this to 1 will fail if you have ... transactions pending, while it will wait until other ... transactions are completed."

      I'm not quite sure what the difference in a pending transaction and a transaction that is not yet completed but is working on being completed (perhaps it means the COMMIT was already issued?).

      2. It says, "Changing this to 1 will fail if you have... transactions pending...".

      In my tests, if I have a transaction pending, and I issue the "SET @@GLOBAL.read_only=1", then the SET commands takes effect, and then if I try to COMMIT the pending transaction, it fails. Thus this is the opposite of what the manual states.

      I don't know if the manual is incorrect, or if the behavior from read_only is incorrect.

      3. It says, "Changing this to 1 will fail if you have table locks... pending..."

      Again, I tested this, and if I issue a TABLE LOCK on a table, and then issue SET @@GLOBAL.read_only=1" in another session, the SET command waits until you UNLOCK TABLES. So it does not fail either.

      Again, I don't know if the manual is incorrect, or if the behavior from read_only is incorrect.

      #2 test case:

      Session #1:

      mysql> select * from gtest;
      +------+
      | id   |
      +------+
      |    1 |
      |    2 |
      |    3 |
      |    4 |
      +------+
      4 rows in set (0.00 sec)
       
      mysql> begin;
      Query OK, 0 rows affected (0.00 sec)
       
      mysql> insert into gtest (id) values (5);
      Query OK, 1 row affected (0.03 sec)
      

      Session #2:

      mysql> set @@global.read_only=1;
      Query OK, 0 rows affected (0.00 sec)
      

      Session #1:

      mysql> commit;
      ERROR 1290 (HY000): The MariaDB server is running with the --read-only option so it cannot execute this statement
      mysql>
      mysql> select * from gtest;
      +------+
      | id   |
      +------+
      |    1 |
      |    2 |
      |    3 |
      |    4 |
      +------+
      4 rows in set (0.00 sec)
      

      #3 test case:

      Session #1:

      mysql> lock table gtest write;
      Query OK, 0 rows affected (0.00 sec)
      

      Session #2:

      mysql> set @@global.read_only=1;
      ...<hangs>...
      

      Session #1:

      mysql> insert into gtest (id) values (5);
      Query OK, 1 row affected (0.03 sec)
       
      mysql> commit;
      Query OK, 0 rows affected (0.00 sec)
       
      mysql> unlock tables;
      Query OK, 0 rows affected (0.00 sec)
      mysql> select * from gtest;
      +------+
      | id   |
      +------+
      |    1 |
      |    2 |
      |    3 |
      |    4 |
      |    5 |
      +------+
      5 rows in set (0.00 sec)
       
      mysql> select version();
      +-----------------+
      | version()       |
      +-----------------+
      | 10.0.26-MariaDB |
      +-----------------+
      1 row in set (0.03 sec)
      

      Session #2:

      Query OK, 0 rows affected (35.18 sec)
      

      (See how long it waited?)

      Attachments

        Activity

          People

            greenman Ian Gilfillan
            ccalender Chris Calender (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.