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,
const LockInfo& lock_info, Env* env,
uint64_t* expire_time) {
auto now = env->NowMicros();
bool expired =
(lock_info.expiration_time > 0 && lock_info.expiration_time <= now);
if (lock_info.expiration_time == 0) {
*expire_time = 0;
return false;
}
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
*expire_time = lock_info.expiration_time;
} else {
@ -272,9 +274,9 @@ bool TransactionLockMgr::IsLockExpired(TransactionID txn_id,
bool success = txn_db_impl_->TryStealingExpiredTransactionLocks(id);
if (!success) {
expired = false;
*expire_time = 0;
break;
}
*expire_time = 0;
}
}

Loading…
Cancel
Save