Reduce copies of LockInfo (#5172)
Summary: The LockInfo struct is not easy to copy because it contains std::vector. Reduce copies by using move constructor and `unordered_map::emplace`. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5172 Differential Revision: D14882053 Pulled By: lth fbshipit-source-id: 93999ec6ab1a5841fb5115abb764b6c1831a6de1
This commit is contained in:
parent
313e877285
commit
ef0fc1b461
@ -587,7 +587,7 @@ void TransactionBaseImpl::TrackKey(TransactionKeyMap* key_map, uint32_t cfh_id,
|
||||
auto& cf_key_map = (*key_map)[cfh_id];
|
||||
auto iter = cf_key_map.find(key);
|
||||
if (iter == cf_key_map.end()) {
|
||||
auto result = cf_key_map.insert({key, TransactionKeyMapInfo(seq)});
|
||||
auto result = cf_key_map.emplace(key, TransactionKeyMapInfo(seq));
|
||||
iter = result.first;
|
||||
} else if (seq < iter->second.seq) {
|
||||
// Now tracking this key with an earlier sequence number
|
||||
|
@ -311,14 +311,14 @@ Status TransactionLockMgr::TryLock(PessimisticTransaction* txn,
|
||||
int64_t timeout = txn->GetLockTimeout();
|
||||
|
||||
return AcquireWithTimeout(txn, lock_map, stripe, column_family_id, key, env,
|
||||
timeout, lock_info);
|
||||
timeout, std::move(lock_info));
|
||||
}
|
||||
|
||||
// Helper function for TryLock().
|
||||
Status TransactionLockMgr::AcquireWithTimeout(
|
||||
PessimisticTransaction* txn, LockMap* lock_map, LockMapStripe* stripe,
|
||||
uint32_t column_family_id, const std::string& key, Env* env,
|
||||
int64_t timeout, const LockInfo& lock_info) {
|
||||
int64_t timeout, LockInfo&& lock_info) {
|
||||
Status result;
|
||||
uint64_t end_time = 0;
|
||||
|
||||
@ -342,7 +342,7 @@ Status TransactionLockMgr::AcquireWithTimeout(
|
||||
// Acquire lock if we are able to
|
||||
uint64_t expire_time_hint = 0;
|
||||
autovector<TransactionID> wait_ids;
|
||||
result = AcquireLocked(lock_map, stripe, key, env, lock_info,
|
||||
result = AcquireLocked(lock_map, stripe, key, env, std::move(lock_info),
|
||||
&expire_time_hint, &wait_ids);
|
||||
|
||||
if (!result.ok() && timeout != 0) {
|
||||
@ -407,7 +407,7 @@ Status TransactionLockMgr::AcquireWithTimeout(
|
||||
}
|
||||
|
||||
if (result.ok() || result.IsTimedOut()) {
|
||||
result = AcquireLocked(lock_map, stripe, key, env, lock_info,
|
||||
result = AcquireLocked(lock_map, stripe, key, env, std::move(lock_info),
|
||||
&expire_time_hint, &wait_ids);
|
||||
}
|
||||
} while (!result.ok() && !timed_out);
|
||||
@ -526,7 +526,7 @@ bool TransactionLockMgr::IncrementWaiters(
|
||||
Status TransactionLockMgr::AcquireLocked(LockMap* lock_map,
|
||||
LockMapStripe* stripe,
|
||||
const std::string& key, Env* env,
|
||||
const LockInfo& txn_lock_info,
|
||||
LockInfo&& txn_lock_info,
|
||||
uint64_t* expire_time,
|
||||
autovector<TransactionID>* txn_ids) {
|
||||
assert(txn_lock_info.txn_ids.size() == 1);
|
||||
@ -578,7 +578,7 @@ Status TransactionLockMgr::AcquireLocked(LockMap* lock_map,
|
||||
result = Status::Busy(Status::SubCode::kLockLimit);
|
||||
} else {
|
||||
// acquire lock
|
||||
stripe->keys.insert({key, txn_lock_info});
|
||||
stripe->keys.emplace(key, std::move(txn_lock_info));
|
||||
|
||||
// Maintain lock count if there is a limit on the number of locks
|
||||
if (max_num_locks_) {
|
||||
|
@ -130,11 +130,11 @@ class TransactionLockMgr {
|
||||
Status AcquireWithTimeout(PessimisticTransaction* txn, LockMap* lock_map,
|
||||
LockMapStripe* stripe, uint32_t column_family_id,
|
||||
const std::string& key, Env* env, int64_t timeout,
|
||||
const LockInfo& lock_info);
|
||||
LockInfo&& lock_info);
|
||||
|
||||
Status AcquireLocked(LockMap* lock_map, LockMapStripe* stripe,
|
||||
const std::string& key, Env* env,
|
||||
const LockInfo& lock_info, uint64_t* wait_time,
|
||||
LockInfo&& lock_info, uint64_t* wait_time,
|
||||
autovector<TransactionID>* txn_ids);
|
||||
|
||||
void UnLockKey(const PessimisticTransaction* txn, const std::string& key,
|
||||
|
Loading…
Reference in New Issue
Block a user