Skip to content

Commit

Permalink
This adds a global my.cnf parameter, rocksdb_use_range_locking.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
spetrunia committed May 17, 2021
1 parent 64a1f75 commit c89e6b3
Show file tree
Hide file tree
Showing 73 changed files with 5,674 additions and 115 deletions.
3 changes: 3 additions & 0 deletions mysql-test/suite/rocksdb/combinations
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ rocksdb_write_policy=write_prepared
[write_unprepared]
rocksdb_write_policy=write_unprepared
rocksdb_write_batch_flush_threshold=1

[range_locking]
rocksdb_use_range_locking=1
3 changes: 3 additions & 0 deletions mysql-test/suite/rocksdb/include/have_range_locking.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (`select count(*) = 0 from performance_schema.session_variables where variable_name = 'rocksdb_use_range_locking' and variable_value = 'ON';`) {
--skip Test requires range locking
}
5 changes: 5 additions & 0 deletions mysql-test/suite/rocksdb/include/not_range_locking.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--let $_use_range_locking= `select @@rocksdb_use_range_locking`
if ($_use_range_locking == 1)
{
--skip Test doesn't support range locking
}
77 changes: 77 additions & 0 deletions mysql-test/suite/rocksdb/include/select_from_is_rowlocks.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
--echo # select * from information_schema.rocksdb_locks; # With replacements by select_from_is_rowlocks.inc
#
# An include to print contents of I_S.ROCKSB_LOCKS
#
# Implicit "parameters"
# - Currently it prints locks on t1.PRIMARY
#
# Explicit "parameter" variables:
# - $TRX1_ID - print this transaction as "TRX1"
# - $TRX2_ID - print this transaction as "TRX2"
#
# - $select_from_is_rowlocks_current_trx_only
# - $order_by_rowkey

--disable_query_log
set @cf_id=(select column_family from information_schema.rocksdb_ddl
where table_name='t1' and index_name='PRIMARY');
set @rtrx_id=(select transaction_id from information_schema.rocksdb_trx
where thread_id=connection_id());
set @indexnr= (select lower(
concat(
lpad(hex(db_number),8,'0'),
lpad(hex(index_number),8,'0')
)
)
from information_schema.rocksdb_ddl
where table_name='t1' and index_name='PRIMARY');

set @indexnr_next= (select lower(
concat(
lpad(hex(db_number),8,'0'),
lpad(hex(index_number+1),8,'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);
}

# If TRX1_ID is not specified, get the current transaction:
let $transaction_col= replace(transaction_id, @rtrx_id, "\$trx_id");
if ($TRX1_ID)
{
let $transaction_col = replace(transaction_id, '$TRX1_ID', "\$TRX1_ID");
}

if ($TRX2_ID)
{
let $transaction_col = replace($transaction_col, '$TRX2_ID', "\$TRX2_ID");
}

if ($order_by_rowkey)
{
let $extra_order_by = ORDER BY 3,2;
}

if (!$order_by_rowkey)
{
--sorted_result
}

eval select
replace(column_family_id, @cf_id, "\$cf_id") as COLUMN_FAMILY_ID,
$transaction_col as TRANSACTION_ID,
replace(
replace(`key`, @indexnr, '\${indexnr}'),
@indexnr_next, '\${indexnr+1}'
) as `KEY`,
mode
from information_schema.rocksdb_locks $extra_where $extra_order_by;

--enable_query_log
Loading

0 comments on commit c89e6b3

Please sign in to comment.