diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-08-18 11:58:07 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-08-28 19:09:18 -0400 |
commit | a3a02da6327b4995a75912c4fde4022b089d4947 (patch) | |
tree | 0657fbea3ec55f201754cd7a34b1a0658a5eb8a9 /src/mongo/db | |
parent | c246ae62641c3559c38830f6f5f4981e0acffa0c (diff) | |
download | mongo-a3a02da6327b4995a75912c4fde4022b089d4947.tar.gz |
SERVER-30735 Make DBDirectClient use its own LastError
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/dbdirectclient.cpp | 17 | ||||
-rw-r--r-- | src/mongo/db/dbdirectclient.h | 2 | ||||
-rw-r--r-- | src/mongo/db/lasterror.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/lasterror.h | 9 | ||||
-rw-r--r-- | src/mongo/db/service_entry_point_mongod.cpp | 2 |
5 files changed, 18 insertions, 19 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()); } diff --git a/src/mongo/db/dbdirectclient.h b/src/mongo/db/dbdirectclient.h index c5d4bc78f6f..4432d775e23 100644 --- a/src/mongo/db/dbdirectclient.h +++ b/src/mongo/db/dbdirectclient.h @@ -30,6 +30,7 @@ #include "mongo/client/dbclientinterface.h" #include "mongo/db/dbmessage.h" +#include "mongo/db/lasterror.h" #include "mongo/util/net/hostandport.h" namespace mongo { @@ -102,6 +103,7 @@ public: private: OperationContext* _opCtx; + LastError _lastError; // This LastError will be used for all operations on this client. }; } // namespace mongo diff --git a/src/mongo/db/lasterror.cpp b/src/mongo/db/lasterror.cpp index 2521fa99466..c9d9aca453e 100644 --- a/src/mongo/db/lasterror.cpp +++ b/src/mongo/db/lasterror.cpp @@ -110,15 +110,10 @@ void LastError::disable() { _nPrev--; // caller is a command that shouldn't count as an operation } -void LastError::startTopLevelRequest() { +void LastError::startRequest() { _disabled = false; ++_nPrev; _hadNotMasterError = false; } -void LastError::startDirectClientRequest() { - _disabled = false; - ++_nPrev; -} - } // namespace mongo diff --git a/src/mongo/db/lasterror.h b/src/mongo/db/lasterror.h index ee450089595..8c5a5d3bfb3 100644 --- a/src/mongo/db/lasterror.h +++ b/src/mongo/db/lasterror.h @@ -50,14 +50,9 @@ public: void reset(bool valid = false); /** - * when db receives a top level message/request, call this + * when db receives a message/request, call this */ - void startTopLevelRequest(); - - /** - * when DBDirectClient receives a message/request, call this - */ - void startDirectClientRequest(); + void startRequest(); /** * Disables error recording for the current operation. diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp index f8ddfda6ec3..37b3d4e51fc 100644 --- a/src/mongo/db/service_entry_point_mongod.cpp +++ b/src/mongo/db/service_entry_point_mongod.cpp @@ -1039,7 +1039,7 @@ DbResponse ServiceEntryPointMongod::handleRequest(OperationContext* opCtx, const if (c.isInDirectClient()) { invariant(!opCtx->lockState()->inAWriteUnitOfWork()); } else { - LastError::get(c).startTopLevelRequest(); + LastError::get(c).startRequest(); AuthorizationSession::get(c)->startRequest(opCtx); // We should not be holding any locks at this point |