summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2018-01-24 11:09:22 -0500
committerBenety Goh <benety@mongodb.com>2018-02-09 12:47:15 -0500
commit862d39eec0130c16eb984f799911323df766177f (patch)
treee6c1eda219b84980763a03f21c26818473b41f6f
parentab9fbc6a90c65d228dd15973aa6706563c086106 (diff)
downloadmongo-862d39eec0130c16eb984f799911323df766177f.tar.gz
SERVER-32783 reduce unnecessary lock acqisition in RemoteCommandRetryScheduler::_remoteCommandCallback()
(cherry picked from commit 8b44a736464e31e2a38e40171cb34063f180171c)
-rw-r--r--src/mongo/client/remote_command_retry_scheduler.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/mongo/client/remote_command_retry_scheduler.cpp b/src/mongo/client/remote_command_retry_scheduler.cpp
index 08e8d4477a8..e3b1791b3ef 100644
--- a/src/mongo/client/remote_command_retry_scheduler.cpp
+++ b/src/mongo/client/remote_command_retry_scheduler.cpp
@@ -238,16 +238,17 @@ Status RemoteCommandRetryScheduler::_schedule_inlock() {
void RemoteCommandRetryScheduler::_remoteCommandCallback(
const executor::TaskExecutor::RemoteCommandCallbackArgs& rcba) {
- auto status = rcba.response.status;
- auto currentAttempt = _currentAttempt;
- {
+ const auto& status = rcba.response.status;
+
+ // Use a lambda to avoid unnecessary lock acquisition when checking conditions for termination.
+ auto getCurrentAttempt = [this]() {
stdx::lock_guard<stdx::mutex> lock(_mutex);
- currentAttempt = _currentAttempt;
- }
+ return _currentAttempt;
+ };
if (status.isOK() || status == ErrorCodes::CallbackCanceled ||
- currentAttempt == _retryPolicy->getMaximumAttempts() ||
- !_retryPolicy->shouldRetryOnError(status.code())) {
+ !_retryPolicy->shouldRetryOnError(status.code()) ||
+ getCurrentAttempt() == _retryPolicy->getMaximumAttempts()) {
_onComplete(rcba);
return;
}