revision-id: d8dcc6caacbb3658420322747b53d38efddf9977 (fb-prod8-202009-48-gd8dcc6caacb) parent(s): 7e916290e883c42ae3aab8fb2bb954b7b8537076 78674a3d77089376d8f511566c697077ff1bdb5d author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2020-11-30 18:10:09 +0300 message: Merge branch 'fb-mysql-8.0.17-range-locking-sept20' into fb-mysql-8.0.17 .gitmodules | 2 +- mysql-test/suite/rocksdb/combinations | 3 + .../suite/rocksdb/include/not_range_locking.inc | 5 + mysql-test/suite/rocksdb/r/rocksdb.result | 2 + .../rocksdb/r/rocksdb_timeout_rollback.result | 3 + mysql-test/suite/rocksdb/r/unique_sec.result | 4 + .../suite/rocksdb/r/unique_sec_rev_cf.result | 4 + mysql-test/suite/rocksdb/t/deadlock_tracking.test | 7 +- .../t/drop_cf_before_show_deadlock_info.test | 4 + mysql-test/suite/rocksdb/t/hermitage.inc | 14 +- mysql-test/suite/rocksdb/t/hermitage.test | 3 + mysql-test/suite/rocksdb/t/i_s_deadlock.test | 4 + mysql-test/suite/rocksdb/t/issue111.test | 4 + .../rocksdb/t/issue243_transactionStatus.test | 4 + .../suite/rocksdb/t/level_repeatable_read.test | 3 + mysql-test/suite/rocksdb/t/lock_info.test | 3 + mysql-test/suite/rocksdb/t/locking_issues.test | 3 + mysql-test/suite/rocksdb/t/max_row_locks.test | 1 + mysql-test/suite/rocksdb/t/rocksdb.test | 3 + .../suite/rocksdb/t/rocksdb_concurrent_delete.test | 4 + mysql-test/suite/rocksdb/t/rocksdb_locks.test | 3 + .../suite/rocksdb/t/rocksdb_timeout_rollback.test | 2 + mysql-test/suite/rocksdb/t/rpl_row_not_found.inc | 2 + .../suite/rocksdb/t/select_lock_in_share_mode.test | 3 + mysql-test/suite/rocksdb/t/unique_check.test | 5 + mysql-test/suite/rocksdb/t/unique_sec.inc | 10 +- mysql-test/suite/rocksdb/t/varbinary_format.test | 4 + mysql-test/suite/rocksdb/t/varchar_format.test | 2 + .../r/rocksdb_max_lock_memory_basic.result | 7 + .../r/rocksdb_use_range_locking_basic.result | 7 + .../t/rocksdb_max_lock_memory_basic.test | 5 + .../t/rocksdb_use_range_locking_basic.test | 5 + rocksdb | 2 +- storage/rocksdb/CMakeLists.txt | 8 +- storage/rocksdb/ha_rocksdb.cc | 572 +++++++++++++++++++-- storage/rocksdb/ha_rocksdb.h | 14 +- storage/rocksdb/rdb_i_s.cc | 12 +- storage/rocksdb/rdb_locking_iter.cc | 108 ++++ storage/rocksdb/rdb_locking_iter.h | 190 +++++++ 39 files changed, 988 insertions(+), 53 deletions(-) diff --cc storage/rocksdb/ha_rocksdb.cc index 52ded9a7206,d19c07bc611..333e2370919 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@@ -752,7 -739,14 +759,15 @@@ static uint32_t rocksdb_select_bypass_r static uint32_t rocksdb_select_bypass_debug_row_delay = 0; static unsigned long long // NOLINT(runtime/int) rocksdb_select_bypass_multiget_min = 0; +static bool rocksdb_skip_locks_if_skip_unique_check = false; + // Range locking: how much memory to use. + // (note that this is different from rocksdb_max_row_locks as + // that one is a hard per-thread count limit, and this one is a + // global memory limit) + static ulonglong rocksdb_max_lock_memory; + + static bool rocksdb_use_range_locking = 0; + static std::shared_ptr<rocksdb::RangeLockMgrHandle> range_lock_mgr; std::atomic<uint64_t> rocksdb_row_lock_deadlocks(0); std::atomic<uint64_t> rocksdb_row_lock_wait_timeouts(0); @@@ -2905,8 -2881,20 +2965,20 @@@ class Rdb_transaction virtual void set_sync(bool sync) = 0; - virtual void release_lock(rocksdb::ColumnFamilyHandle *const column_family, + virtual void release_lock(const Rdb_key_def &key_descr, const std::string &rowkey) = 0; + virtual + rocksdb::Status lock_range(rocksdb::ColumnFamilyHandle *const cf, + const rocksdb::Endpoint &start, + const rocksdb::Endpoint &end) = 0; + + rocksdb::Status lock_singlepoint_range(rocksdb::ColumnFamilyHandle *const cf, + const rocksdb::Slice &point) { + // Normally, one needs to "flip" the endpoint type for reverse-ordered CFs. + // But here we are locking just one point so this is not necessary. + rocksdb::Endpoint endp(point, false); + return lock_range(cf, endp, endp); + } virtual bool prepare(const rocksdb::TransactionName &name) = 0; diff --cc storage/rocksdb/ha_rocksdb.h index 72f1202d0a2,ab0c3df2865..81300833852 --- a/storage/rocksdb/ha_rocksdb.h +++ b/storage/rocksdb/ha_rocksdb.h @@@ -346,14 -346,24 +346,24 @@@ class ha_rocksdb : public my_core::hand rocksdb::Slice *lower_bound_slice, rocksdb::Slice *upper_bound_slice); void setup_scan_iterator(const Rdb_key_def &kd, rocksdb::Slice *slice, - const bool use_all_keys, const uint eq_cond_len) + const bool use_all_keys, const uint eq_cond_len, + bool use_locking_iterator) MY_ATTRIBUTE((__nonnull__)); + + int set_range_lock(Rdb_transaction *tx, + const Rdb_key_def &kd, + const enum ha_rkey_function &find_flag, + const rocksdb::Slice &slice, + const key_range *const end_key, + bool flip_rev_cf, + bool *use_locking_iterator); + void release_scan_iterator(void); - rocksdb::Status get_for_update( - Rdb_transaction *const tx, - rocksdb::ColumnFamilyHandle *const column_family, - const rocksdb::Slice &key, rocksdb::PinnableSlice *value) const; + rocksdb::Status get_for_update(Rdb_transaction *const tx, + const Rdb_key_def &kd, + const rocksdb::Slice &key, + rocksdb::PinnableSlice *value) const; int get_row_by_rowid(uchar *const buf, const char *const rowid, const uint rowid_size, const bool skip_lookup = false,