[Commits] 4229a7ee0a4: Post-merge fixes: adapt MyRocks to new Range-locking RocksDB interface
revision-id: 4229a7ee0a4e8f2b95ed7db7d87e9baf561dc88d (fb-prod8-202009-49-g4229a7ee0a4) parent(s): d8dcc6caacbb3658420322747b53d38efddf9977 author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2020-11-30 19:58:15 +0300 message: Post-merge fixes: adapt MyRocks to new Range-locking RocksDB interface Part#1: - Get to compile - Use the right GetLockStatusData call depending on the lock manager used --- rocksdb | 2 +- storage/rocksdb/ha_rocksdb.cc | 10 ++-- storage/rocksdb/ha_rocksdb.h | 2 + storage/rocksdb/rdb_i_s.cc | 107 ++++++++++++++++++++++++++++++------------ 4 files changed, 86 insertions(+), 35 deletions(-) diff --git a/rocksdb b/rocksdb index bb68c56f990..0e30dd985c7 160000 --- a/rocksdb +++ b/rocksdb @@ -1 +1 @@ -Subproject commit bb68c56f990da1531f1b84ae8488e5f3ccf416e7 +Subproject commit 0e30dd985c72b6f11576a2a2e43c62bcea01f9b9 diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 333e2370919..18e4809aa8a 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -767,7 +767,7 @@ static bool rocksdb_skip_locks_if_skip_unique_check = false; static ulonglong rocksdb_max_lock_memory; static bool rocksdb_use_range_locking = 0; -static std::shared_ptr<rocksdb::RangeLockMgrHandle> range_lock_mgr; +std::shared_ptr<rocksdb::RangeLockManagerHandle> range_lock_mgr; std::atomic<uint64_t> rocksdb_row_lock_deadlocks(0); std::atomic<uint64_t> rocksdb_row_lock_wait_timeouts(0); @@ -3604,7 +3604,7 @@ class Rdb_transaction_impl : public Rdb_transaction { rocksdb::Status lock_range(rocksdb::ColumnFamilyHandle *const cf, const rocksdb::Endpoint &start_endp, const rocksdb::Endpoint &end_endp) override { - ++m_lock_count; + ++m_row_lock_count; return m_rocksdb_tx->GetRangeLock(cf, start_endp, end_endp); } private: @@ -3846,7 +3846,7 @@ class Rdb_transaction_impl : public Rdb_transaction { if (use_locking_iterator) { locking_iter_created(); return GetLockingIterator(m_rocksdb_tx, options, column_family, - is_rev_cf, &m_lock_count); + is_rev_cf, &m_row_lock_count); } else return m_rocksdb_tx->GetIterator(options, column_family); @@ -6352,7 +6352,7 @@ static int rocksdb_init_internal(void *const p) { if (range_lock_mgr) { - range_lock_mgr->set_max_lock_memory(rocksdb_max_lock_memory); + range_lock_mgr->SetMaxLockMemory(rocksdb_max_lock_memory); sql_print_information("RocksDB: USING NEW RANGE LOCKING"); sql_print_information("RocksDB: Max lock memory=%llu", rocksdb_max_lock_memory); } @@ -15929,7 +15929,7 @@ void rocksdb_set_max_lock_memory(THD *thd, struct SYS_VAR*, void* /*var_ptr*/, const void *save) { const uint64_t new_val = *static_cast<const uint64_t *>(save); if (rocksdb_max_lock_memory != new_val) { - if (range_lock_mgr->set_max_lock_memory(new_val)) { + if (range_lock_mgr->SetMaxLockMemory(new_val)) { /* NO_LINT_DEBUG */ sql_print_warning("MyRocks: failed to set max_lock_memory"); push_warning_printf(thd, Sql_condition::SL_WARNING, diff --git a/storage/rocksdb/ha_rocksdb.h b/storage/rocksdb/ha_rocksdb.h index 81300833852..89a06a52d70 100644 --- a/storage/rocksdb/ha_rocksdb.h +++ b/storage/rocksdb/ha_rocksdb.h @@ -1250,4 +1250,6 @@ extern std::atomic<uint64_t> rocksdb_select_bypass_executed; extern std::atomic<uint64_t> rocksdb_select_bypass_rejected; extern std::atomic<uint64_t> rocksdb_select_bypass_failed; +extern std::shared_ptr<rocksdb::RangeLockManagerHandle> range_lock_mgr; + } // namespace myrocks diff --git a/storage/rocksdb/rdb_i_s.cc b/storage/rocksdb/rdb_i_s.cc index d6292343d32..765f432f0ce 100644 --- a/storage/rocksdb/rdb_i_s.cc +++ b/storage/rocksdb/rdb_i_s.cc @@ -1771,39 +1771,88 @@ static int rdb_i_s_lock_info_fill_table( } /* cf id -> rocksdb::KeyLockInfo */ - std::unordered_multimap<uint32_t, rocksdb::KeyLockInfo> lock_info = - rdb->GetLockStatusData(); - - for (const auto &lock : lock_info) { - const uint32_t cf_id = lock.first; - const auto &key_lock_info = lock.second; - 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); - } + if (range_lock_mgr) { + // Use Range Lock Manager's interface for obtaining more specific + // information about the acquired locks + auto lock_info = range_lock_mgr->GetRangeLockStatusData(); + + for (const auto &lock : lock_info) { + const uint32_t cf_id = lock.first; + const auto &range_lock_info = lock.second; + + std::string key_hexstr; + // For keys: :0 keys should look like point keys + if (!range_lock_info.start.inf_suffix && + !range_lock_info.end.inf_suffix && + (range_lock_info.start.slice == + range_lock_info.end.slice)) { + // Ok the lock is held on a single-point range. + // Show it like a single-point key + key_hexstr = rdb_hexdump(range_lock_info.start.slice.c_str(), + range_lock_info.start.slice.length(), + FN_REFLEN); + } else { + key_hexstr = rdb_hexdump(range_lock_info.start.slice.c_str(), + range_lock_info.start.slice.length(), + FN_REFLEN); + if (range_lock_info.start.inf_suffix) + key_hexstr.append(":1"); + + key_hexstr.append("-"); + + std::string key2 = rdb_hexdump(range_lock_info.end.slice.c_str(), + range_lock_info.end.slice.length(), + FN_REFLEN); + if (range_lock_info.end.inf_suffix) + key2.append(":1"); + key_hexstr.append(key2); + } - for (const auto &id : key_lock_info.ids) { - tables->table->field[RDB_LOCKS_FIELD::COLUMN_FAMILY_ID]->store(cf_id, - true); - tables->table->field[RDB_LOCKS_FIELD::TRANSACTION_ID]->store(id, true); + for (const auto &id : range_lock_info.ids) { + tables->table->field[RDB_LOCKS_FIELD::COLUMN_FAMILY_ID]->store(cf_id, + true); + tables->table->field[RDB_LOCKS_FIELD::TRANSACTION_ID]->store(id, true); - tables->table->field[RDB_LOCKS_FIELD::KEY]->store( - key_hexstr.c_str(), key_hexstr.size(), system_charset_info); - tables->table->field[RDB_LOCKS_FIELD::MODE]->store( - key_lock_info.exclusive ? "X" : "S", 1, system_charset_info); + tables->table->field[RDB_LOCKS_FIELD::KEY]->store( + key_hexstr.c_str(), key_hexstr.size(), system_charset_info); + tables->table->field[RDB_LOCKS_FIELD::MODE]->store( + range_lock_info.exclusive ? "X" : "S", 1, system_charset_info); - /* Tell MySQL about this row in the virtual table */ - ret = static_cast<int>( - my_core::schema_table_store_record(thd, tables->table)); + /* Tell MySQL about this row in the virtual table */ + ret = static_cast<int>( + my_core::schema_table_store_record(thd, tables->table)); - if (ret != 0) { - break; + if (ret != 0) { + break; + } + } + } + } else { + std::unordered_multimap<uint32_t, rocksdb::KeyLockInfo> lock_info = + rdb->GetLockStatusData(); + + for (const auto &lock : lock_info) { + const uint32_t cf_id = lock.first; + const auto &key_lock_info = lock.second; + auto key_hexstr = rdb_hexdump(key_lock_info.key.c_str(), + key_lock_info.key.length(), FN_REFLEN); + for (const auto &id : key_lock_info.ids) { + tables->table->field[RDB_LOCKS_FIELD::COLUMN_FAMILY_ID]->store(cf_id, + true); + tables->table->field[RDB_LOCKS_FIELD::TRANSACTION_ID]->store(id, true); + + tables->table->field[RDB_LOCKS_FIELD::KEY]->store( + key_hexstr.c_str(), key_hexstr.size(), system_charset_info); + tables->table->field[RDB_LOCKS_FIELD::MODE]->store( + key_lock_info.exclusive ? "X" : "S", 1, system_charset_info); + + /* Tell MySQL about this row in the virtual table */ + ret = static_cast<int>( + my_core::schema_table_store_record(thd, tables->table)); + + if (ret != 0) { + break; + } } } }
participants (1)
-
psergey