[Commits] 0320154e8: Support PessimisticTransactionDB::GetLockStatusData() in RangeLockMgr, too
revision-id: 0320154e8fa4a3a24f1a65fec2487e490dfb8507 (v5.8-1017-g0320154e8) parent(s): 2a1882e24b51074ead248ad445bedbe336e0ecd3 author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2018-11-26 18:04:29 +0300 message: Support PessimisticTransactionDB::GetLockStatusData() in RangeLockMgr, too --- include/rocksdb/utilities/transaction_db.h | 2 + .../transactions/pessimistic_transaction_db.cc | 11 +- utilities/transactions/transaction_lock_mgr.cc | 37 ++++++ utilities/transactions/transaction_lock_mgr.h | 142 +++++++++++---------- 4 files changed, 121 insertions(+), 71 deletions(-) diff --git a/include/rocksdb/utilities/transaction_db.h b/include/rocksdb/utilities/transaction_db.h index 57b5d2767..16fa8a4a7 100644 --- a/include/rocksdb/utilities/transaction_db.h +++ b/include/rocksdb/utilities/transaction_db.h @@ -164,8 +164,10 @@ struct TransactionDBWriteOptimizations { struct KeyLockInfo { std::string key; + std::string key2; // Used when range locking is used std::vector<TransactionID> ids; bool exclusive; + bool has_key2 = false; // TRUE <=> key2 has a value }; struct DeadlockInfo { diff --git a/utilities/transactions/pessimistic_transaction_db.cc b/utilities/transactions/pessimistic_transaction_db.cc index a74bf3e6b..c5635cf05 100644 --- a/utilities/transactions/pessimistic_transaction_db.cc +++ b/utilities/transactions/pessimistic_transaction_db.cc @@ -40,7 +40,8 @@ PessimisticTransactionDB::PessimisticTransactionDB( txn_db_options_.custom_mutex_factory ? txn_db_options_.custom_mutex_factory : std::shared_ptr<TransactionDBMutexFactory>( - new TransactionDBMutexFactoryImpl())) { + new TransactionDBMutexFactoryImpl())), + range_lock_mgr_(this) { assert(db_impl_ != nullptr); info_log_ = db_impl_->GetDBOptions().info_log; } @@ -71,7 +72,8 @@ PessimisticTransactionDB::PessimisticTransactionDB( txn_db_options_.custom_mutex_factory ? txn_db_options_.custom_mutex_factory : std::shared_ptr<TransactionDBMutexFactory>( - new TransactionDBMutexFactoryImpl())) { + new TransactionDBMutexFactoryImpl())), + range_lock_mgr_(this) { assert(db_impl_ != nullptr); } @@ -619,7 +621,10 @@ void PessimisticTransactionDB::GetAllPreparedTransactions( TransactionLockMgr::LockStatusData PessimisticTransactionDB::GetLockStatusData() { - return lock_mgr_.GetLockStatusData(); + if (use_range_locking) + return range_lock_mgr_.GetLockStatusData(); + else + return lock_mgr_.GetLockStatusData(); } std::vector<DeadlockPath> PessimisticTransactionDB::GetDeadlockInfoBuffer() { diff --git a/utilities/transactions/transaction_lock_mgr.cc b/utilities/transactions/transaction_lock_mgr.cc index 4b2a66235..ae317742e 100644 --- a/utilities/transactions/transaction_lock_mgr.cc +++ b/utilities/transactions/transaction_lock_mgr.cc @@ -848,6 +848,43 @@ void TransactionLockMgr::UnLock(const PessimisticTransaction* txn, } } +struct LOCK_PRINT_CONTEXT { + TransactionLockMgr::LockStatusData *data; + // this will not be needed when locks are per-column-family: + uint32_t cfh_id; +}; + +static +void push_into_lock_status_data(void* param, const DBT *left, + const DBT *right, TXNID txnid) +{ + struct LOCK_PRINT_CONTEXT *ctx= (LOCK_PRINT_CONTEXT*)param; + struct KeyLockInfo info; + + info.key.append((const char*)left->data, (size_t)left->size); + info.exclusive= true; + + if (!(left->size == right->size && + !memcmp(left->data, right->data, left->size))) + { + // not a single-point lock + info.has_key2= true; + info.key2.append((const char*)right->data, right->size); + } + + info.ids.push_back(txnid); + ctx->data->insert({ctx->cfh_id, info}); +} + + +TransactionLockMgr::LockStatusData RangeLockMgr::GetLockStatusData() { + TransactionLockMgr::LockStatusData data; + LOCK_PRINT_CONTEXT ctx = {&data, GetColumnFamilyID(my_txn_db->DefaultColumnFamily()) }; + lt->dump_locks((void*)&ctx, push_into_lock_status_data); + return data; +} + + TransactionLockMgr::LockStatusData TransactionLockMgr::GetLockStatusData() { LockStatusData data; // Lock order here is important. The correct order is lock_map_mutex_, then diff --git a/utilities/transactions/transaction_lock_mgr.h b/utilities/transactions/transaction_lock_mgr.h index cbbb12579..9f7f61db7 100644 --- a/utilities/transactions/transaction_lock_mgr.h +++ b/utilities/transactions/transaction_lock_mgr.h @@ -76,74 +76,6 @@ class BaseLockMgr { virtual ~BaseLockMgr(){} }; -using namespace toku; - - -/* - A lock manager that supports Range-based locking. -*/ -class RangeLockMgr : - public BaseLockMgr, - public RangeLockMgrControl -{ - public: - void AddColumnFamily(uint32_t column_family_id) override { /* do nothing */ } - void RemoveColumnFamily(uint32_t column_family_id) override { /* do nothing */ } - - Status TryLock(PessimisticTransaction* txn, uint32_t column_family_id, - const std::string& key, Env* env, bool exclusive) override ; - - // Get a lock on a range - // (TODO: this allows to acquire exclusive range locks although they are not - // used ATM) - Status TryRangeLock(PessimisticTransaction* txn, - uint32_t column_family_id, - const rocksdb::Slice &start_key, - const rocksdb::Slice &end_key, - bool exclusive); - - void UnLock(const PessimisticTransaction* txn, const TransactionKeyMap* keys, - Env* env) override ; - /* - Same as above, but *keys is guaranteed to hold all the locks obtained by - the transaction. - */ - void UnLockAll(const PessimisticTransaction* txn, const TransactionKeyMap* keys, - Env* env); - void UnLock(PessimisticTransaction* txn, uint32_t column_family_id, - const std::string& key, Env* env) override ; - - RangeLockMgr() - { - ltm.create(on_create, on_destroy, on_escalate, NULL); - toku::comparator cmp; - cmp.create(toku_builtin_compare_fun, NULL); - DICTIONARY_ID dict_id = { .dictid = 1 }; - lt= ltm.get_lt(dict_id, cmp , /* on_create_extra*/nullptr); - - } - - void KillLockWait(void *cdata); - - int set_max_lock_memory(size_t max_lock_memory) override - { - return ltm.set_max_lock_memory(max_lock_memory); - } - - uint64_t get_escalation_count() override; - - private: - toku::locktree_manager ltm; - toku::locktree *lt; // only one tree for now - - // Callbacks - static int on_create(locktree *lt, void *extra) { return 0; /* no error */ } - static void on_destroy(locktree *lt) {} - static void on_escalate(TXNID txnid, const locktree *lt, - const range_buffer &buffer, void *extra) {} - -}; - class TransactionLockMgr { public: @@ -248,5 +180,79 @@ class TransactionLockMgr { void operator=(const TransactionLockMgr&); }; + +using namespace toku; + +/* + A lock manager that supports Range-based locking. +*/ +class RangeLockMgr : + public BaseLockMgr, + public RangeLockMgrControl +{ + public: + void AddColumnFamily(uint32_t column_family_id) override { /* do nothing */ } + void RemoveColumnFamily(uint32_t column_family_id) override { /* do nothing */ } + + Status TryLock(PessimisticTransaction* txn, uint32_t column_family_id, + const std::string& key, Env* env, bool exclusive) override ; + + // Get a lock on a range + // (TODO: this allows to acquire exclusive range locks although they are not + // used ATM) + Status TryRangeLock(PessimisticTransaction* txn, + uint32_t column_family_id, + const rocksdb::Slice &start_key, + const rocksdb::Slice &end_key, + bool exclusive); + + void UnLock(const PessimisticTransaction* txn, const TransactionKeyMap* keys, + Env* env) override ; + /* + Same as above, but *keys is guaranteed to hold all the locks obtained by + the transaction. + */ + void UnLockAll(const PessimisticTransaction* txn, const TransactionKeyMap* keys, + Env* env); + void UnLock(PessimisticTransaction* txn, uint32_t column_family_id, + const std::string& key, Env* env) override ; + + RangeLockMgr(TransactionDB* txn_db) : my_txn_db(txn_db) + { + ltm.create(on_create, on_destroy, on_escalate, NULL); + toku::comparator cmp; + cmp.create(toku_builtin_compare_fun, NULL); + DICTIONARY_ID dict_id = { .dictid = 1 }; + lt= ltm.get_lt(dict_id, cmp , /* on_create_extra*/nullptr); + + } + + void KillLockWait(void *cdata); + + int set_max_lock_memory(size_t max_lock_memory) override + { + return ltm.set_max_lock_memory(max_lock_memory); + } + + uint64_t get_escalation_count() override; + + TransactionLockMgr::LockStatusData GetLockStatusData(); + + private: + toku::locktree_manager ltm; + toku::locktree *lt; // only one tree for now + + TransactionDB* my_txn_db; + + // Callbacks + static int on_create(locktree *lt, void *extra) { return 0; /* no error */ } + static void on_destroy(locktree *lt) {} + static void on_escalate(TXNID txnid, const locktree *lt, + const range_buffer &buffer, void *extra) {} + +}; + + + } // namespace rocksdb #endif // ROCKSDB_LITE
participants (1)
-
Sergei Petrunia