[Commits] d099340b910: MyRocksm, Range Locking, Shared point locks: got basic cases to work

Sergei Petrunia psergey at askmonty.org
Mon May 13 17:15:11 EEST 2019


revision-id: d099340b9105d4fd5397c5a8548218372f963083 (fb-prod201801-233-gd099340b910)
parent(s): a679ed01453c1898ec9d1fac95d8d4d149607b81
author: Sergei Petrunia
committer: Sergei Petrunia
timestamp: 2019-05-13 17:15:11 +0300
message:

MyRocksm, Range Locking, Shared point locks: got basic cases to work

- Point rocksdb submodule to the shared locks revision
- Add testcases
- (No changes were necessary on MyRocks side so far)

---
 .../rocksdb/include/select_from_rocksdb_locks.inc  | 35 ++++++++++++++
 .../rocksdb/r/range_locking_shared_locks.result    | 55 ++++++++++++++++++++++
 .../rocksdb/t/range_locking_shared_locks.test      | 54 +++++++++++++++++++++
 rocksdb                                            |  2 +-
 4 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/mysql-test/suite/rocksdb/include/select_from_rocksdb_locks.inc b/mysql-test/suite/rocksdb/include/select_from_rocksdb_locks.inc
new file mode 100644
index 00000000000..31280b0510c
--- /dev/null
+++ b/mysql-test/suite/rocksdb/include/select_from_rocksdb_locks.inc
@@ -0,0 +1,35 @@
+--echo # select * from information_schema.rocksdb_locks; # With replacements by select_from_rocksdb_locks.inc
+--disable_query_log
+set @cf_id=(select column_family from information_schema.rocksdb_ddl
+            where table_name='t1' and index_name='PRIMARY');
+set @indexnr= (select lpad(hex(index_number),6,'0') from information_schema.rocksdb_ddl
+               where table_name='t1' and index_name='PRIMARY');
+
+let $extra_where = where 1;
+
+if ($select_from_is_rowlocks_current_trx_only) 
+{
+  let $extra_where = where transaction_id=(select transaction_id from information_schema.rocksdb_trx where connection_id()=thread_id);
+}
+
+let $transaction_col= transaction_id;
+
+if ($TRX1_ID)
+{
+  let $transaction_col = replace($transaction_col, '$TRX1_ID', "\$TRX1_ID");
+}
+
+if ($TRX2_ID)
+{
+  let $transaction_col = replace($transaction_col, '$TRX2_ID', "\$TRX2_ID");
+}
+
+--sorted_result
+eval select 
+  replace(column_family_id, @cf_id, "\$cf_id") as COLUMN_FAMILY_ID,
+  $transaction_col as TRANSACTION_ID,
+  replace(`key`, @indexnr, '\${indexnr}') as `KEY`,
+  mode
+from information_schema.rocksdb_locks $extra_where;
+
+--enable_query_log
diff --git a/mysql-test/suite/rocksdb/r/range_locking_shared_locks.result b/mysql-test/suite/rocksdb/r/range_locking_shared_locks.result
new file mode 100644
index 00000000000..33c7b421f9b
--- /dev/null
+++ b/mysql-test/suite/rocksdb/r/range_locking_shared_locks.result
@@ -0,0 +1,55 @@
+create table t1 (
+pk int primary key,
+a int
+) engine=rocksdb;
+insert into t1 values
+(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
+# A basic test for shared locks
+begin;
+select * from t1 where pk=3 for update;
+pk	a
+3	3
+select * from t1 where pk=5 lock in share mode;
+pk	a
+5	5
+connect  con1,localhost,root,,;
+connection con1;
+begin;
+select * from t1 where pk=5 lock in share mode;
+pk	a
+5	5
+# Now for pk=5 we should see two locks by TRX1 and TRX2 with mode=S:
+# select * from information_schema.rocksdb_locks; # With replacements by select_from_rocksdb_locks.inc
+COLUMN_FAMILY_ID	TRANSACTION_ID	KEY	mode
+$cf_id	$TRX1_ID	0000${indexnr}80000003	X
+$cf_id	$TRX1_ID	0000${indexnr}80000005	S
+$cf_id	$TRX2_ID	0000${indexnr}80000005	S
+rollback;
+# Now, TRX2_ID should be gone:
+# select * from information_schema.rocksdb_locks; # With replacements by select_from_rocksdb_locks.inc
+COLUMN_FAMILY_ID	TRANSACTION_ID	KEY	mode
+$cf_id	$TRX1_ID	0000${indexnr}80000003	X
+$cf_id	$TRX1_ID	0000${indexnr}80000005	S
+connection default;
+# Get a read lock on pk=3 (where we have a write lock).
+#  The result should be that we will still have a write lock
+select * from t1 where pk=3 for update;
+pk	a
+3	3
+# select * from information_schema.rocksdb_locks; # With replacements by select_from_rocksdb_locks.inc
+COLUMN_FAMILY_ID	TRANSACTION_ID	KEY	mode
+$cf_id	$TRX1_ID	0000${indexnr}80000003	X
+$cf_id	$TRX1_ID	0000${indexnr}80000005	S
+# Get a write lock on pk=5 (where we have a read lock).
+#  The result should be that we will have a write lock.
+select * from t1 where pk=5 for update;
+pk	a
+5	5
+# select * from information_schema.rocksdb_locks; # With replacements by select_from_rocksdb_locks.inc
+COLUMN_FAMILY_ID	TRANSACTION_ID	KEY	mode
+$cf_id	$TRX1_ID	0000${indexnr}80000003	X
+$cf_id	$TRX1_ID	0000${indexnr}80000005	X
+connection default;
+rollback;
+disconnect con1;
+drop table t1;
diff --git a/mysql-test/suite/rocksdb/t/range_locking_shared_locks.test b/mysql-test/suite/rocksdb/t/range_locking_shared_locks.test
new file mode 100644
index 00000000000..372ced5bfac
--- /dev/null
+++ b/mysql-test/suite/rocksdb/t/range_locking_shared_locks.test
@@ -0,0 +1,54 @@
+#
+# Test for shared lock support for range locking
+#
+--source include/have_rocksdb.inc
+--source suite/rocksdb/include/have_range_locking.inc
+--enable_connect_log
+
+create table t1 (
+  pk int primary key,
+  a int
+) engine=rocksdb;
+
+
+insert into t1 values
+(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
+
+--echo # A basic test for shared locks
+
+begin;
+select * from t1 where pk=3 for update;
+select * from t1 where pk=5 lock in share mode;
+let $TRX1_ID=`select transaction_id from information_schema.rocksdb_trx where thread_id=connection_id()`;
+
+connect (con1,localhost,root,,);
+connection con1;
+begin;
+select * from t1 where pk=5 lock in share mode;
+let $TRX2_ID=`select transaction_id from information_schema.rocksdb_trx where thread_id=connection_id()`;
+--echo # Now for pk=5 we should see two locks by TRX1 and TRX2 with mode=S:
+--source suite/rocksdb/include/select_from_rocksdb_locks.inc
+
+rollback;
+--echo # Now, TRX2_ID should be gone:
+--source suite/rocksdb/include/select_from_rocksdb_locks.inc
+
+connection default;
+
+--echo # Get a read lock on pk=3 (where we have a write lock).
+--echo #  The result should be that we will still have a write lock
+select * from t1 where pk=3 for update;
+--source suite/rocksdb/include/select_from_rocksdb_locks.inc
+
+--echo # Get a write lock on pk=5 (where we have a read lock).
+--echo #  The result should be that we will have a write lock.
+select * from t1 where pk=5 for update;
+--source suite/rocksdb/include/select_from_rocksdb_locks.inc
+
+connection default;
+rollback;
+
+disconnect con1;
+
+drop table t1;
+
diff --git a/rocksdb b/rocksdb
index 1b423e3954d..2f0ee897552 160000
--- a/rocksdb
+++ b/rocksdb
@@ -1 +1 @@
-Subproject commit 1b423e3954d932c4624337308e3e1cd98481a495
+Subproject commit 2f0ee897552bb4a8aa66b933c0d6f8529a82e2e8


More information about the commits mailing list