[Commits] 9447f482b2d: Add support for printing range locks to information_schema.rocksdb_locks
revision-id: 9447f482b2d086ee644f02caba9ce0d225bdd514 (fb-prod201801-168-g9447f482b2d) parent(s): 77b5ff58f83734a6925b76ec498f60fd85390035 author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2018-11-26 18:08:31 +0300 message: Add support for printing range locks to information_schema.rocksdb_locks Also disable rocksdb.lock_info with range locking as the output is different in range locking mode. --- mysql-test/suite/rocksdb/r/range_locking.result | 30 ++++++++++++++++++++++ mysql-test/suite/rocksdb/t/lock_info.test | 3 +++ mysql-test/suite/rocksdb/t/range_locking.test | 28 ++++++++++++++++++++ rocksdb | 2 +- storage/rocksdb/range_locking/locktree/locktree.cc | 28 ++++++++++++++++++++ storage/rocksdb/range_locking/locktree/locktree.h | 4 ++- storage/rocksdb/rdb_i_s.cc | 12 +++++++-- 7 files changed, 103 insertions(+), 4 deletions(-) diff --git a/mysql-test/suite/rocksdb/r/range_locking.result b/mysql-test/suite/rocksdb/r/range_locking.result index 621a1c6a93a..964458b783f 100644 --- a/mysql-test/suite/rocksdb/r/range_locking.result +++ b/mysql-test/suite/rocksdb/r/range_locking.result @@ -75,3 +75,33 @@ connection default; disconnect con1; disconnect con2; drop table t1; +# +# Test INFORMATION_SCHEMA.lock_info in range-locking mode +# +create table t1 ( +pk int primary key, +a int +) engine=rocksdb; +insert into t1 values +(10,10),(20,20),(30,30); +begin; +select * from t1 where pk=10 for update; +pk a +10 10 +select * from information_schema.rocksdb_locks; +COLUMN_FAMILY_ID TRANSACTION_ID KEY MODE +0 15 000001078000000a X +delete from t1 where pk between 25 and 40; +select * from information_schema.rocksdb_locks; +COLUMN_FAMILY_ID TRANSACTION_ID KEY MODE +0 15 0000010780000019 - 0000010780000028 X +0 15 000001078000000a X +rollback; +begin; +select * from t1 where pk between 2 and 9 for update; +pk a +select * from information_schema.rocksdb_locks; +COLUMN_FAMILY_ID TRANSACTION_ID KEY MODE +0 16 0000010780000002 - 0000010780000009 X +rollback; +drop table t1; diff --git a/mysql-test/suite/rocksdb/t/lock_info.test b/mysql-test/suite/rocksdb/t/lock_info.test index 1b624cf38c0..cd7359c8547 100644 --- a/mysql-test/suite/rocksdb/t/lock_info.test +++ b/mysql-test/suite/rocksdb/t/lock_info.test @@ -1,5 +1,8 @@ --source include/have_rocksdb.inc +# Range Locking supports I_S.lock_info but its printout is different (see range_locking.test) +#--source suite/rocksdb/include/not_range_locking.inc + --disable_warnings DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t2; diff --git a/mysql-test/suite/rocksdb/t/range_locking.test b/mysql-test/suite/rocksdb/t/range_locking.test index e3a88b18210..4cf6f079ebe 100644 --- a/mysql-test/suite/rocksdb/t/range_locking.test +++ b/mysql-test/suite/rocksdb/t/range_locking.test @@ -93,3 +93,31 @@ disconnect con1; disconnect con2; drop table t1; +--echo # +--echo # Test INFORMATION_SCHEMA.lock_info in range-locking mode +--echo # +create table t1 ( + pk int primary key, + a int +) engine=rocksdb; + +insert into t1 values +(10,10),(20,20),(30,30); + +begin; +select * from t1 where pk=10 for update; + +select * from information_schema.rocksdb_locks; + +delete from t1 where pk between 25 and 40; +select * from information_schema.rocksdb_locks; + +rollback; +begin; +select * from t1 where pk between 2 and 9 for update; +select * from information_schema.rocksdb_locks; +rollback; + +drop table t1; + + diff --git a/rocksdb b/rocksdb index 2a1882e24b5..0320154e8fa 160000 --- a/rocksdb +++ b/rocksdb @@ -1 +1 @@ -Subproject commit 2a1882e24b51074ead248ad445bedbe336e0ecd3 +Subproject commit 0320154e8fa4a3a24f1a65fec2487e490dfb8507 diff --git a/storage/rocksdb/range_locking/locktree/locktree.cc b/storage/rocksdb/range_locking/locktree/locktree.cc index 75f78305214..625535a8e18 100644 --- a/storage/rocksdb/range_locking/locktree/locktree.cc +++ b/storage/rocksdb/range_locking/locktree/locktree.cc @@ -412,6 +412,34 @@ int locktree::acquire_write_lock(TXNID txnid, const DBT *left_key, const DBT *ri return try_acquire_lock(true, txnid, left_key, right_key, conflicts, big_txn); } +// typedef void (*dump_callback)(void *cdata, const DBT *left, const DBT *right, TXNID txnid); +void locktree::dump_locks(void *cdata, dump_callback cb) +{ + concurrent_tree::locked_keyrange lkr; + keyrange range; + range.create(toku_dbt_negative_infinity(), + toku_dbt_positive_infinity()); + + lkr.prepare(m_rangetree); + lkr.acquire(range); + + GrowableArray<row_lock> all_locks; + all_locks.init(); + iterate_and_get_overlapping_row_locks(&lkr, &all_locks); + + const size_t n_locks = all_locks.get_size(); + for (size_t i = 0; i < n_locks; i++) { + const row_lock lock = all_locks.fetch_unchecked(i); + (*cb)(cdata, + lock.range.get_left_key(), + lock.range.get_right_key(), + lock.txnid); + } + lkr.release(); + all_locks.deinit(); + range.destroy(); +} + void locktree::get_conflicts(bool is_write_request, TXNID txnid, const DBT *left_key, const DBT *right_key, txnid_set *conflicts) { diff --git a/storage/rocksdb/range_locking/locktree/locktree.h b/storage/rocksdb/range_locking/locktree/locktree.h index 0e6b5d6ee9d..28fe8cc99ab 100644 --- a/storage/rocksdb/range_locking/locktree/locktree.h +++ b/storage/rocksdb/range_locking/locktree/locktree.h @@ -320,7 +320,9 @@ namespace toku { // abstraction and code complexity. It is still fairly abstract // since the lock_request object is opaque struct lt_lock_request_info *get_lock_request_info(void); - + + typedef void (*dump_callback)(void *cdata, const DBT *left, const DBT *right, TXNID txnid); + void dump_locks(void *cdata, dump_callback cb); private: locktree_manager *m_mgr; DICTIONARY_ID m_dict_id; diff --git a/storage/rocksdb/rdb_i_s.cc b/storage/rocksdb/rdb_i_s.cc index 147ad7f1b76..7972f79a06d 100644 --- a/storage/rocksdb/rdb_i_s.cc +++ b/storage/rocksdb/rdb_i_s.cc @@ -1448,8 +1448,16 @@ static int rdb_i_s_lock_info_fill_table( for (const auto &lock : lock_info) { const uint32_t cf_id = lock.first; const auto &key_lock_info = lock.second; - const auto key_hexstr = rdb_hexdump(key_lock_info.key.c_str(), - key_lock_info.key.length(), FN_REFLEN); + auto key_hexstr = rdb_hexdump(key_lock_info.key.c_str(), + key_lock_info.key.length(), FN_REFLEN); + if (key_lock_info.has_key2) + { + const auto key2_hexstr = rdb_hexdump(key_lock_info.key2.c_str(), + key_lock_info.key2.length(), + FN_REFLEN - key_hexstr.size() - 3); + key_hexstr.append(" - "); + key_hexstr.append(key2_hexstr); + } for (const auto &id : key_lock_info.ids) { tables->table->field[RDB_LOCKS_FIELD::COLUMN_FAMILY_ID]->store(cf_id,
participants (1)
-
Sergei Petrunia