From d023b1f34b93bb1cdefdb33d4997f9ad7192e870 Mon Sep 17 00:00:00 2001 From: Ming Lin Date: Wed, 22 Aug 2018 09:09:43 -0700 Subject: [PATCH] Ignore setting m_lock_rows if lock_type == TL_IGNORE (#871) Summary: Original report: https://jira.mariadb.org/browse/MDEV-15816 To reproduce this bug just following below steps, client 1: USE test; CREATE TABLE t1 (i INT) ENGINE=MyISAM; HANDLER t1 OPEN h; CREATE TABLE t2 (i INT) ENGINE=RocksDB; LOCK TABLES t2 WRITE; client 2: FLUSH TABLES WITH READ LOCK; client 1: INSERT INTO t2 VALUES (1); So client 1 acquired the lock and set m_lock_rows = RDB_LOCK_WRITE. Then client 2 calls store_lock(TL_IGNORE) and m_lock_rows was wrongly set to RDB_LOCK_NONE, as below ``` #0 myrocks::ha_rocksdb::store_lock (this=0x7fffbc03c7c8, thd=0x7fffc0000ba0, to=0x7fffc0011220, lock_type=TL_IGNORE) #1 get_lock_data (thd=0x7fffc0000ba0, table_ptr=0x7fffe84b7d20, count=1, flags=2) #2 mysql_lock_abort_for_thread (thd=0x7fffc0000ba0, table=0x7fffbc03bbc0) #3 THD::notify_shared_lock (this=0x7fffc0000ba0, ctx_in_use=0x7fffbc000bd8, needs_thr_lock_abort=true) #4 MDL_lock::notify_conflicting_locks (this=0x555557a82380, ctx=0x7fffc0000cc8) #5 MDL_context::acquire_lock (this=0x7fffc0000cc8, mdl_request=0x7fffe84b8350, lock_wait_timeout=2) #6 Global_read_lock::lock_global_read_lock (this=0x7fffc0003fe0, thd=0x7fffc0000ba0) ``` Finally, client 1 "INSERT INTO..." hits the Assertion 'm_lock_rows == RDB_LOCK_WRITE' failed in myrocks::ha_rocksdb::write_row() Fix this bug by not setting m_locks_rows if lock_type == TL_IGNORE. Closes https://github.com/facebook/mysql-5.6/issues/838 Pull Request resolved: https://github.com/facebook/mysql-5.6/pull/871 Differential Revision: D9417382 Pulled By: lth fbshipit-source-id: 5ab26549a28 --- mysql-test/suite/rocksdb/r/lock.result | 15 +++++++++++++++ mysql-test/suite/rocksdb/t/lock.test | 22 ++++++++++++++++++++++ storage/rocksdb/ha_rocksdb.cc | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/rocksdb/r/lock.result b/mysql-test/suite/rocksdb/r/lock.result index 8c89fa1b934a..60fe5ebe3a8b 100644 --- a/mysql-test/suite/rocksdb/r/lock.result +++ b/mysql-test/suite/rocksdb/r/lock.result @@ -106,3 +106,18 @@ SELECT a,b FROM t1; a b UNLOCK TABLES; DROP TABLE t1, t2; +CREATE TABLE t1 (i INT) ENGINE=MyISAM; +HANDLER t1 OPEN h; +CREATE TABLE t2 (i INT) ENGINE=RocksDB; +LOCK TABLES t2 WRITE; +connect con1,localhost,root,,test; +connection con1; +FLUSH TABLES WITH READ LOCK; +connection default; +INSERT INTO t2 VALUES (1); +UNLOCK TABLES; +HANDLER h CLOSE; +connection con1; +disconnect con1; +connection default; +DROP TABLE t1, t2; diff --git a/mysql-test/suite/rocksdb/t/lock.test b/mysql-test/suite/rocksdb/t/lock.test index 015a08bef573..9ce5e5665053 100644 --- a/mysql-test/suite/rocksdb/t/lock.test +++ b/mysql-test/suite/rocksdb/t/lock.test @@ -196,6 +196,28 @@ SELECT a,b FROM t1; UNLOCK TABLES; DROP TABLE t1, t2; +CREATE TABLE t1 (i INT) ENGINE=MyISAM; +HANDLER t1 OPEN h; +CREATE TABLE t2 (i INT) ENGINE=RocksDB; +LOCK TABLES t2 WRITE; + +--connect (con1,localhost,root,,test) +--connection con1 +--send +FLUSH TABLES WITH READ LOCK; + +--connection default +INSERT INTO t2 VALUES (1); +UNLOCK TABLES; +HANDLER h CLOSE; + +--connection con1 +--reap +--disconnect con1 + +--connection default +DROP TABLE t1, t2; + # Check that all connections opened by test cases in this file are really # gone so execution of other tests won't be affected by their presence. --source include/wait_until_count_sessions.inc diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index e12b39e18b47..6ddc24686916 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -10402,7 +10402,7 @@ THR_LOCK_DATA **ha_rocksdb::store_lock(THD *const thd, THR_LOCK_DATA **to, m_lock_rows = RDB_LOCK_WRITE; } else if (lock_type == TL_READ_WITH_SHARED_LOCKS) { m_lock_rows = RDB_LOCK_READ; - } else { + } else if (lock_type != TL_IGNORE) { m_lock_rows = RDB_LOCK_NONE; if (THDVAR(thd, lock_scanned_rows)) { /*