Skip to content

Commit c89e6b3

Browse files
committed
This adds a global my.cnf parameter, rocksdb_use_range_locking.
When it is ON, MyRocks will: - initialize RocksDB to use range-locking lock manager - for all DML operations (including SELECT .. FOR UPDATE) will lock the scanned range before reading/modifying rows. - In range locking mode, there is no snapshot checking (cannot do that for ranges). Instead, MyRocks will read and modify latest committed data, just like InnoDB does (in the code, grep for (start|end) _ignore_snapshot) - Queries that do not have a finite range to scan, like UPDATE t1 .... ORDER BY t1.key LIMIT n will use a "Locking iterator" which will read rows, lock the range, and re-read the rows. See class LockingIterator.
1 parent 64a1f75 commit c89e6b3

File tree

73 files changed

+5674
-115
lines changed

Some content is hidden

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

73 files changed

+5674
-115
lines changed

mysql-test/suite/rocksdb/combinations

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ rocksdb_write_policy=write_prepared
77
[write_unprepared]
88
rocksdb_write_policy=write_unprepared
99
rocksdb_write_batch_flush_threshold=1
10+
11+
[range_locking]
12+
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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
--disable_query_log
16+
set @cf_id=(select column_family from information_schema.rocksdb_ddl
17+
where table_name='t1' and index_name='PRIMARY');
18+
set @rtrx_id=(select transaction_id from information_schema.rocksdb_trx
19+
where thread_id=connection_id());
20+
set @indexnr= (select lower(
21+
concat(
22+
lpad(hex(db_number),8,'0'),
23+
lpad(hex(index_number),8,'0')
24+
)
25+
)
26+
from information_schema.rocksdb_ddl
27+
where table_name='t1' and index_name='PRIMARY');
28+
29+
set @indexnr_next= (select lower(
30+
concat(
31+
lpad(hex(db_number),8,'0'),
32+
lpad(hex(index_number+1),8,'0')
33+
)
34+
)
35+
from information_schema.rocksdb_ddl
36+
where table_name='t1' and index_name='PRIMARY');
37+
38+
let $extra_where = where 1;
39+
40+
if ($select_from_is_rowlocks_current_trx_only)
41+
{
42+
let $extra_where = where transaction_id=(select transaction_id from information_schema.rocksdb_trx where connection_id()=thread_id);
43+
}
44+
45+
# If TRX1_ID is not specified, get the current transaction:
46+
let $transaction_col= replace(transaction_id, @rtrx_id, "\$trx_id");
47+
if ($TRX1_ID)
48+
{
49+
let $transaction_col = replace(transaction_id, '$TRX1_ID', "\$TRX1_ID");
50+
}
51+
52+
if ($TRX2_ID)
53+
{
54+
let $transaction_col = replace($transaction_col, '$TRX2_ID', "\$TRX2_ID");
55+
}
56+
57+
if ($order_by_rowkey)
58+
{
59+
let $extra_order_by = ORDER BY 3,2;
60+
}
61+
62+
if (!$order_by_rowkey)
63+
{
64+
--sorted_result
65+
}
66+
67+
eval select
68+
replace(column_family_id, @cf_id, "\$cf_id") as COLUMN_FAMILY_ID,
69+
$transaction_col as TRANSACTION_ID,
70+
replace(
71+
replace(`key`, @indexnr, '\${indexnr}'),
72+
@indexnr_next, '\${indexnr+1}'
73+
) as `KEY`,
74+
mode
75+
from information_schema.rocksdb_locks $extra_where $extra_order_by;
76+
77+
--enable_query_log

0 commit comments

Comments
 (0)