summaryrefslogtreecommitdiff
path: root/src/mongo/db/dbdirectclient.cpp
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-08-18 11:58:07 -0400
committerMathias Stearn <mathias@10gen.com>2017-08-28 19:09:18 -0400
commita3a02da6327b4995a75912c4fde4022b089d4947 (patch)
tree0657fbea3ec55f201754cd7a34b1a0658a5eb8a9 /src/mongo/db/dbdirectclient.cpp
parentc246ae62641c3559c38830f6f5f4981e0acffa0c (diff)
downloadmongo-a3a02da6327b4995a75912c4fde4022b089d4947.tar.gz
SERVER-30735 Make DBDirectClient use its own LastError
Diffstat (limited to 'src/mongo/db/dbdirectclient.cpp')
-rw-r--r--src/mongo/db/dbdirectclient.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/mongo/db/dbdirectclient.cpp b/src/mongo/db/dbdirectclient.cpp
index b6df5ab4dd3..76f389b8434 100644
--- a/src/mongo/db/dbdirectclient.cpp
+++ b/src/mongo/db/dbdirectclient.cpp
@@ -32,15 +32,17 @@
#include "mongo/db/dbdirectclient.h"
+#include <boost/core/swap.hpp>
+
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/curop.h"
-#include "mongo/db/lasterror.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/wire_version.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/transport/service_entry_point.h"
#include "mongo/util/log.h"
+#include "mongo/util/scopeguard.h"
namespace mongo {
@@ -122,9 +124,14 @@ QueryOptions DBDirectClient::_lookupAvailableOptions() {
}
namespace {
-DbResponse loopbackBuildResponse(OperationContext* const opCtx, Message& toSend) {
+DbResponse loopbackBuildResponse(OperationContext* const opCtx,
+ LastError* lastError,
+ Message& toSend) {
DirectClientScope directClientScope(opCtx);
- LastError::get(opCtx->getClient()).startDirectClientRequest();
+ boost::swap(*lastError, LastError::get(opCtx->getClient()));
+ ON_BLOCK_EXIT([&] { boost::swap(*lastError, LastError::get(opCtx->getClient())); });
+
+ LastError::get(opCtx->getClient()).startRequest();
CurOp curOp(opCtx);
toSend.header().setId(nextMessageId());
@@ -134,7 +141,7 @@ DbResponse loopbackBuildResponse(OperationContext* const opCtx, Message& toSend)
} // namespace
bool DBDirectClient::call(Message& toSend, Message& response, bool assertOk, string* actualServer) {
- auto dbResponse = loopbackBuildResponse(_opCtx, toSend);
+ auto dbResponse = loopbackBuildResponse(_opCtx, &_lastError, toSend);
invariant(!dbResponse.response.empty());
response = std::move(dbResponse.response);
@@ -142,7 +149,7 @@ bool DBDirectClient::call(Message& toSend, Message& response, bool assertOk, str
}
void DBDirectClient::say(Message& toSend, bool isRetry, string* actualServer) {
- auto dbResponse = loopbackBuildResponse(_opCtx, toSend);
+ auto dbResponse = loopbackBuildResponse(_opCtx, &_lastError, toSend);
invariant(dbResponse.response.empty());
}