From f174778e9be263568286b30404a8a7b0cdc30035 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) Upstream commit ID : fb-mysql-5.6.35/8cb1dc836b68f1f13e8b2655b2b8cb2d57f400b3 PS-5217 : Merge fb-prod201803 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: c36c164e06c --- 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 3f811b2ef698..1a707131c105 100644 --- a/mysql-test/suite/rocksdb/r/lock.result +++ b/mysql-test/suite/rocksdb/r/lock.result @@ -114,3 +114,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 0bc8e6401e15..80969cb3c730 100644 --- a/mysql-test/suite/rocksdb/t/lock.test +++ b/mysql-test/suite/rocksdb/t/lock.test @@ -210,6 +210,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 1e8f1be8c0d0..d62d7874d66f 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -9885,7 +9885,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)) { /*