Skip to content

Commit 6f3cc1f

Browse files
Add range locking support for MyRocks
- Add new sysvar, rocksdb_use_range_locking. When it's on: - RocksDB is initialized to used range-locking lock manager - For all DML operations (including SELECT ... FOR UPDATE), the scanned range will be locked before reading/modifying rows - For all DML operations, MyRocks will read and modify the latest committed data, just like InnoDB does, because there is no snapshot checking if range locking is used. - Introduce a RocksDB locking iterator, which reads the rows, locks the range, - and re-reads the rows. It is used for queries that do not have a finite range to scan, like UPDATE t1 ... ORDER BY t1.key LIMIT n - Add another new sysvar, rocksdb_use_range_lock_manager_as_point, which uses the point locking algorithm but the lock manager used is the range one. - Add enabled rocksdb_use_range_locking as another MTR rocksdb suite test combination. Co-authored-by: Sergei Petrunia <sergey@mariadb.com> Co-authored-by: Laurynas Biveinis <laurynas.biveinis@gmail.com>
1 parent 4874647 commit 6f3cc1f

File tree

91 files changed

+7654
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+7654
-117
lines changed

mysql-test/r/mysqld--help-notwin.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,9 @@ The following options may be given as the first argument:
23372337
and newtransaction will be started.
23382338
--rocksdb-max-latest-deadlocks=#
23392339
Maximum number of recent deadlocks to store
2340+
--rocksdb-max-lock-memory=#
2341+
Range-locking mode: Maximum amount of memory that locks
2342+
from all transactions can use at a time
23402343
--rocksdb-max-log-file-size=#
23412344
DBOptions::max_log_file_size for RocksDB
23422345
--rocksdb-max-manifest-file-size=#
@@ -2575,6 +2578,10 @@ The following options may be given as the first argument:
25752578
RocksDB
25762579
--rocksdb-use-io-uring
25772580
Use io_uring for RocksDB
2581+
--rocksdb-use-range-lock-manager-as-point
2582+
Use Range Lock Manager as point
2583+
--rocksdb-use-range-locking
2584+
Use Range Locking
25782585
--rocksdb-use-write-buffer-manager
25792586
For experiment only. Use write buffer manager
25802587
--rocksdb-validate-tables=#
@@ -3911,6 +3918,7 @@ rocksdb-max-compaction-history 64
39113918
rocksdb-max-file-opening-threads 16
39123919
rocksdb-max-intrinsic-tmp-table-write-count 1000
39133920
rocksdb-max-latest-deadlocks 5
3921+
rocksdb-max-lock-memory 1073741824
39143922
rocksdb-max-log-file-size 0
39153923
rocksdb-max-manifest-file-size 1073741824
39163924
rocksdb-max-manual-compactions 10
@@ -3990,6 +3998,8 @@ rocksdb-use-direct-reads FALSE
39903998
rocksdb-use-fsync FALSE
39913999
rocksdb-use-hyper-clock-cache FALSE
39924000
rocksdb-use-io-uring FALSE
4001+
rocksdb-use-range-lock-manager-as-point FALSE
4002+
rocksdb-use-range-locking FALSE
39934003
rocksdb-use-write-buffer-manager FALSE
39944004
rocksdb-validate-tables 1
39954005
rocksdb-vector-index ON

mysql-test/suite/rocksdb/combinations

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
[rocksdb_ddse]
44
default_dd_system_storage_engine = rocksdb
5+
6+
[range_locking]
7+
rocksdb_use_range_locking=1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (`select count(*) = 0 from performance_schema.session_variables where variable_name = 'rocksdb_use_range_locking' and variable_value = 'ON';`) {
2+
--skip Test requires range locking
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--let $_use_range_locking= `select @@rocksdb_use_range_locking`
2+
if ($_use_range_locking == 1)
3+
{
4+
--skip Test doesn't support range locking
5+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
--echo # select * from information_schema.rocksdb_locks; # With replacements by select_from_is_rowlocks.inc
2+
#
3+
# An include to print contents of I_S.ROCKSB_LOCKS
4+
#
5+
# Implicit "parameters"
6+
# - Currently it prints locks on t1.PRIMARY
7+
#
8+
# Explicit "parameter" variables:
9+
# - $TRX1_ID - print this transaction as "TRX1"
10+
# - $TRX2_ID - print this transaction as "TRX2"
11+
#
12+
# - $select_from_is_rowlocks_current_trx_only
13+
# - $order_by_rowkey
14+
#
15+
# - $SECOND_INDEX_NAME
16+
17+
--disable_query_log
18+
set @cf_id=(select column_family from information_schema.rocksdb_ddl
19+
where table_name='t1' and index_name='PRIMARY');
20+
set @rtrx_id=(select transaction_id from information_schema.rocksdb_trx
21+
where thread_id=connection_id());
22+
set @indexnr= (select lower(lpad(hex(index_number),8,'0')) from information_schema.rocksdb_ddl
23+
where table_name='t1' and index_name='PRIMARY');
24+
25+
set @indexnr_next= (select lower(lpad(hex(index_number+1),8,'0'))
26+
from information_schema.rocksdb_ddl
27+
where table_name='t1' and index_name='PRIMARY');
28+
29+
let $extra_where = where 1;
30+
31+
if ($select_from_is_rowlocks_current_trx_only)
32+
{
33+
let $extra_where = where transaction_id=(select transaction_id from information_schema.rocksdb_trx where connection_id()=thread_id);
34+
}
35+
36+
## transaction column
37+
38+
# If TRX1_ID is not specified, get the current transaction:
39+
let $transaction_col= replace(transaction_id, @rtrx_id, "\$trx_id");
40+
if ($TRX1_ID)
41+
{
42+
let $transaction_col = replace(transaction_id, '$TRX1_ID', "\$TRX1_ID");
43+
}
44+
45+
if ($TRX2_ID)
46+
{
47+
let $transaction_col = replace($transaction_col, '$TRX2_ID', "\$TRX2_ID");
48+
}
49+
50+
## CF_ID column
51+
let $cf_id_col= column_family_id;
52+
53+
if ($SECOND_INDEX_NAME)
54+
{
55+
eval set @cf2_id=(select column_family from information_schema.rocksdb_ddl
56+
where table_name='t1' and index_name='$SECOND_INDEX_NAME');
57+
58+
let $cf_id_col= replace($cf_id_col, @cf2_id, "\$cf2_id");
59+
}
60+
let $cf_id_col= replace($cf_id_col, @cf_id, "\$cf_id");
61+
62+
## KEY column
63+
let $key_col= (`key`);
64+
if ($SECOND_INDEX_NAME)
65+
{
66+
eval set @indexnr2= (select lower(lpad(hex(index_number),8,'0'))
67+
from information_schema.rocksdb_ddl
68+
where table_name='t1' and index_name='$SECOND_INDEX_NAME');
69+
70+
eval set @indexnr2_next= (select lower(lpad(hex(index_number+1),8,'0'))
71+
from information_schema.rocksdb_ddl
72+
where table_name='t1' and index_name='$SECOND_INDEX_NAME');
73+
74+
let $key_col = replace($key_col, @indexnr2, '\${indexnr2}');
75+
let $key_col = replace($key_col, @indexnr2_next, '\${indexnr2+1}');
76+
}
77+
78+
let $key_col = replace($key_col, @indexnr, '\${indexnr}');
79+
let $key_col = replace($key_col, @indexnr_next, '\${indexnr+1}');
80+
81+
## ORDER BY
82+
if ($order_by_rowkey)
83+
{
84+
let $extra_order_by = ORDER BY 3,2;
85+
}
86+
87+
if (!$order_by_rowkey)
88+
{
89+
--sorted_result
90+
}
91+
92+
eval select
93+
$cf_id_col as COLUMN_FAMILY_ID,
94+
$transaction_col as TRANSACTION_ID,
95+
$key_col as `KEY`,
96+
mode
97+
from information_schema.rocksdb_locks $extra_where $extra_order_by;
98+
99+
--enable_query_log

0 commit comments

Comments
 (0)