Refactor IsLockExpired (#6586)

Summary:
1. If expiration_time is non-positive, no need to call NowMicros, save a syscall.
2. expire_time should only be set when expired is false.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6586

Test Plan: make check

Reviewed By: lth

Differential Revision: D20673730

Pulled By: cheng-chang

fbshipit-source-id: a69e8d7b16dc6d0d00487bb1c19f0710d79482e2
main
Cheng Chang 5 years ago committed by Facebook GitHub Bot
parent 4246888101
commit 3881a678d5
  1. 14
      utilities/transactions/transaction_lock_mgr.cc

@ -255,12 +255,14 @@ std::shared_ptr<LockMap> TransactionLockMgr::GetLockMap(
bool TransactionLockMgr::IsLockExpired(TransactionID txn_id, bool TransactionLockMgr::IsLockExpired(TransactionID txn_id,
const LockInfo& lock_info, Env* env, const LockInfo& lock_info, Env* env,
uint64_t* expire_time) { uint64_t* expire_time) {
auto now = env->NowMicros(); if (lock_info.expiration_time == 0) {
*expire_time = 0;
bool expired = return false;
(lock_info.expiration_time > 0 && lock_info.expiration_time <= now); }
if (!expired && lock_info.expiration_time > 0) { auto now = env->NowMicros();
bool expired = lock_info.expiration_time <= now;
if (!expired) {
// return how many microseconds until lock will be expired // return how many microseconds until lock will be expired
*expire_time = lock_info.expiration_time; *expire_time = lock_info.expiration_time;
} else { } else {
@ -272,9 +274,9 @@ bool TransactionLockMgr::IsLockExpired(TransactionID txn_id,
bool success = txn_db_impl_->TryStealingExpiredTransactionLocks(id); bool success = txn_db_impl_->TryStealingExpiredTransactionLocks(id);
if (!success) { if (!success) {
expired = false; expired = false;
*expire_time = 0;
break; break;
} }
*expire_time = 0;
} }
} }

Loading…
Cancel
Save