diff options
author | ADAM David Alan Martin <adam.martin@10gen.com> | 2017-10-20 15:37:19 -0400 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2017-10-24 20:04:57 -0400 |
commit | 840ab4cdcbf9129ad59eb68f39e1cbded623fd0b (patch) | |
tree | 481b12d797581b8aaaa6e82aa585efb1f9d04c15 /src | |
parent | a4a94724dc82af8a314f98c2245d4e61233f56bf (diff) | |
download | mongo-840ab4cdcbf9129ad59eb68f39e1cbded623fd0b.tar.gz |
SERVER-29074 Avoid `AsyncOp::_request` in log text.
The `AsyncOp::_request` member is not always accurate, due to the
way that `NetworkInterfaceASIO` works. The member should not
be used in the generation of log message text -- the results
are incorrect and often misleading.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/executor/network_interface_asio.h | 14 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_asio_command.cpp | 28 |
2 files changed, 26 insertions, 16 deletions
diff --git a/src/mongo/executor/network_interface_asio.h b/src/mongo/executor/network_interface_asio.h index 8c86b4682b6..62f9f6a4829 100644 --- a/src/mongo/executor/network_interface_asio.h +++ b/src/mongo/executor/network_interface_asio.h @@ -200,6 +200,10 @@ private: Date_t now, rpc::EgressMetadataHook* metadataHook = nullptr); + HostAndPort target() const { + return this->_target; + } + private: NetworkInterfaceASIO::AsyncConnection* const _conn; @@ -211,7 +215,7 @@ private: const Date_t _start; - HostAndPort _target; + const HostAndPort _target; }; /** @@ -425,11 +429,9 @@ private: ErrorCodes::CallbackCanceled, "Callback canceled", now() - op->start()); return _completeOperation(op, rs); } else if (op->timedOut()) { - str::stream msg; - msg << "Operation timed out" - << ", request was " << op->_request.toString(); - auto rs = ResponseStatus( - ErrorCodes::NetworkInterfaceExceededTimeLimit, msg, now() - op->start()); + auto rs = ResponseStatus(ErrorCodes::NetworkInterfaceExceededTimeLimit, + "Operation timed out", + now() - op->start()); return _completeOperation(op, rs); } else if (ec) return _networkErrorCallback(op, ec); diff --git a/src/mongo/executor/network_interface_asio_command.cpp b/src/mongo/executor/network_interface_asio_command.cpp index 2799c350257..a09b45bc9d1 100644 --- a/src/mongo/executor/network_interface_asio_command.cpp +++ b/src/mongo/executor/network_interface_asio_command.cpp @@ -38,7 +38,6 @@ #include "mongo/db/dbmessage.h" #include "mongo/db/jsobj.h" #include "mongo/executor/async_stream_interface.h" -#include "mongo/executor/async_stream_interface.h" #include "mongo/executor/connection_pool_asio.h" #include "mongo/rpc/factory.h" #include "mongo/rpc/metadata/metadata_hook.h" @@ -60,6 +59,8 @@ namespace executor { namespace { +using namespace std::literals::string_literals; + MONGO_FP_DECLARE(NetworkInterfaceASIOasyncRunCommandFail); using asio::ip::tcp; @@ -299,7 +300,7 @@ void NetworkInterfaceASIO::_completeOperation(AsyncOp* op, ResponseStatus resp) MONGO_ASIO_INVARIANT(!resp.isOK(), "Failed to connect in setup", op); // If we fail during connection, we won't be able to access any of op's members after // calling finish(), so we return here. - log() << "Failed to connect to " << op->request().target << " - " << resp.status; + log() << "Failed to connect to " << op->request().target << " - " << redact(resp.status); op->finish(std::move(resp)); return; } @@ -309,7 +310,8 @@ void NetworkInterfaceASIO::_completeOperation(AsyncOp* op, ResponseStatus resp) MONGO_ASIO_INVARIANT(!resp.isOK(), "In refresh, but did not fail to heartbeat", op); // If we fail during heartbeating, we won't be able to access any of op's members after // calling finish(), so we return here. - log() << "Failed asio heartbeat to " << op->request().target << " - " + log() << "Failed asio heartbeat to " + << (op->command() ? op->command()->target().toString() : "unknown"s) << " - " << redact(resp.status); _numFailedOps.fetchAndAdd(1); op->finish(std::move(resp)); @@ -318,10 +320,16 @@ void NetworkInterfaceASIO::_completeOperation(AsyncOp* op, ResponseStatus resp) if (!resp.isOK()) { // In the case that resp is not OK, but _inSetup is false, we are using a connection - // that - // we got from the pool to execute a command, but it failed for some reason. - LOG(2) << "Failed to execute command: " << redact(op->request().toString()) - << " reason: " << redact(resp.status); + // that we got from the pool to execute a command, but it failed for some reason. + if (op->command()) { + LOG(2) << "Failed to send message: " + << redact(std::string(op->command()->toSend().buf(), + op->command()->toSend().buf() + + op->command()->toSend().size())) + << ". Reason: " << redact(resp.status); + } else { + LOG(2) << "Failed to execute a command. Reason: " << redact(resp.status); + } if (resp.status.code() != ErrorCodes::CallbackCanceled) { _numFailedOps.fetchAndAdd(1); @@ -392,7 +400,7 @@ void NetworkInterfaceASIO::_asyncRunCommand(AsyncOp* op, NetworkOpHandler handle auto cmd = op->command(); // Step 4 - auto recvMessageCallback = [this, cmd, handler, op](std::error_code ec, size_t bytes) { + auto recvMessageCallback = [this, cmd, handler](std::error_code ec, size_t bytes) { // We don't call _validateAndRun here as we assume the caller will. handler(ec, bytes); }; @@ -402,7 +410,7 @@ void NetworkInterfaceASIO::_asyncRunCommand(AsyncOp* op, NetworkOpHandler handle size_t bytes) { // The operation could have been canceled after starting the command, but before // receiving the header - _validateAndRun(op, ec, [this, op, recvMessageCallback, ec, bytes, cmd, handler] { + _validateAndRun(op, ec, [this, recvMessageCallback, ec, bytes, cmd, handler] { // validate response id uint32_t expectedId = cmd->toSend().header().getId(); uint32_t actualId = cmd->header().constView().getResponseToMsgId(); @@ -423,7 +431,7 @@ void NetworkInterfaceASIO::_asyncRunCommand(AsyncOp* op, NetworkOpHandler handle // Step 2 auto sendMessageCallback = [this, cmd, handler, recvHeaderCallback, op](std::error_code ec, size_t bytes) { - _validateAndRun(op, ec, [this, cmd, op, recvHeaderCallback] { + _validateAndRun(op, ec, [this, cmd, recvHeaderCallback] { asyncRecvMessageHeader( cmd->conn().stream(), &cmd->header(), std::move(recvHeaderCallback)); }); |