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

MyRocks-Gap-Lock: range locking bounds are incorrect for multi-part keys

    XMLWordPrintable

Details

    Description

      create table ten(a int);
      insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
      create table t4 (
        kp1 int not null,
        kp2 int not null,
        a int,
        primary key(kp1, kp2)
      ) engine=rocksdb;
       
      insert into t4 select 1,a, 1234 from ten;
      insert into t4 values (2, 3, 1234);
      insert into t4 values (2, 5, 1234);
      insert into t4 values (2, 7, 1234);
      insert into t4 select 3,a, 1234 from ten;
      

      First, a good example (when it does work):

      Connection1:

      mysql> begin;
      Query OK, 0 rows affected (0.00 sec)
       
      mysql> select * from t4 where kp1=2 and kp2 between 1 and 10 for update;
      +-----+-----+------+
      | kp1 | kp2 | a    |
      +-----+-----+------+
      |   2 |   3 | 1234 |
      |   2 |   5 | 1234 |
      |   2 |   7 | 1234 |
      +-----+-----+------+
      3 rows in set (0.01 sec)
       
      mysql> select * from information_schema.rocksdb_locks;
      +------------------+----------------+-----------------------------------------------------+------+
      | COLUMN_FAMILY_ID | TRANSACTION_ID | KEY                                                 | MODE |
      +------------------+----------------+-----------------------------------------------------+------+
      |                0 |             26 | 000001068000000280000001 - 00000106800000028000000a | X    |
      +------------------+----------------+-----------------------------------------------------+------+
      1 row in set (0.00 sec)
      

      Connection2:

      mysql> insert into t4 values ( 2,9,9999);
      ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction: Timeout on index: test.t4.PRIMARY
      

      This is expected.
      Now, bad example:
      Connection 1:

      mysql> begin;
      Query OK, 0 rows affected (0.00 sec)
       
      mysql> select * from t4 where kp1=2 for update;
      +-----+-----+------+
      | kp1 | kp2 | a    |
      +-----+-----+------+
      |   2 |   3 | 1234 |
      |   2 |   5 | 1234 |
      |   2 |   7 | 1234 |
      +-----+-----+------+
      3 rows in set (0.00 sec)
      

      mysql> select * from information_schema.rocksdb_locks;
      +------------------+----------------+--------------------------+------+
      | COLUMN_FAMILY_ID | TRANSACTION_ID | KEY                      | MODE |
      +------------------+----------------+--------------------------+------+
      |                0 |             28 | 000001068000000280000007 | X    |
      |                0 |             28 | 000001068000000280000005 | X    |
      |                0 |             28 | 000001068000000280000003 | X    |
      |                0 |             28 | 0000010680000002         | X    |
      +------------------+----------------+--------------------------+------+
      4 rows in set (0.00 sec)
      

      Note the last line. Is this the range lock ??

      Indeed, its bounds are wrong and it does not inhibit the INSERT:
      Connection2:

      mysql> insert into t4 values ( 2,9,9999);
      Query OK, 1 row affected (0.01 sec)
      

      Attachments

        Issue Links

          Activity

            People

              psergei Sergei Petrunia
              psergei Sergei Petrunia
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.