diff options
author | Waley Chen <waleycz@gmail.com> | 2016-08-03 15:54:57 -0400 |
---|---|---|
committer | Waley Chen <waleycz@gmail.com> | 2016-08-03 15:54:57 -0400 |
commit | 05e1c33649e08ec3736121254da7b29a73934788 (patch) | |
tree | 591de8a744ed1e31535038474247102e540c209d /src/mongo/executor/network_interface_mock.cpp | |
parent | 1aeb9f04c0cdaaa4832ada812797b50456986baf (diff) | |
download | mongo-05e1c33649e08ec3736121254da7b29a73934788.tar.gz |
SERVER-24067 TaskExecutor RemoteCommandCallbackArgs should include elapsedMS and metadata
Diffstat (limited to 'src/mongo/executor/network_interface_mock.cpp')
-rw-r--r-- | src/mongo/executor/network_interface_mock.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/mongo/executor/network_interface_mock.cpp b/src/mongo/executor/network_interface_mock.cpp index 2ebd1244e47..2c84a34071a 100644 --- a/src/mongo/executor/network_interface_mock.cpp +++ b/src/mongo/executor/network_interface_mock.cpp @@ -149,8 +149,8 @@ void NetworkInterfaceMock::cancelCommand(const CallbackHandle& cbHandle) { invariant(!inShutdown()); stdx::lock_guard<stdx::mutex> lk(_mutex); - ResponseStatus response(ErrorCodes::CallbackCanceled, "Network operation canceled"); - _cancelCommand_inlock(cbHandle, response); + ResponseStatus rs(ErrorCodes::CallbackCanceled, "Network operation canceled", Milliseconds(0)); + _cancelCommand_inlock(cbHandle, rs); } @@ -216,7 +216,7 @@ void NetworkInterfaceMock::shutdown() { lk.unlock(); for (NetworkOperationIterator iter = todo.begin(); iter != todo.end(); ++iter) { iter->setResponse( - now, ResponseStatus(ErrorCodes::ShutdownInProgress, "Shutting down mock network")); + now, {ErrorCodes::ShutdownInProgress, "Shutting down mock network", Milliseconds(0)}); iter->finishResponse(); } lk.lock(); @@ -298,7 +298,7 @@ void NetworkInterfaceMock::scheduleResponse(NetworkOperationIterator noi, // If no RemoteCommandResponse was returned (for example, on a simulated network error), then // do not attempt to run the metadata hook, since there is no returned metadata. if (_metadataHook && response.isOK()) { - _metadataHook->readReplyMetadata(noi->getRequest().target, response.getValue().metadata); + _metadataHook->readReplyMetadata(noi->getRequest().target, response.metadata); } noi->setResponse(when, response); @@ -307,7 +307,7 @@ void NetworkInterfaceMock::scheduleResponse(NetworkOperationIterator noi, RemoteCommandRequest NetworkInterfaceMock::scheduleSuccessfulResponse(const BSONObj& response) { BSONObj metadata; - return scheduleSuccessfulResponse(RemoteCommandResponse(response, metadata)); + return scheduleSuccessfulResponse(RemoteCommandResponse(response, metadata, Milliseconds(0))); } RemoteCommandRequest NetworkInterfaceMock::scheduleSuccessfulResponse( @@ -330,6 +330,12 @@ RemoteCommandRequest NetworkInterfaceMock::scheduleErrorResponse(const Status& r return scheduleErrorResponse(getNextReadyRequest(), response); } +RemoteCommandRequest NetworkInterfaceMock::scheduleErrorResponse(const ResponseStatus response) { + auto noi = getNextReadyRequest(); + scheduleResponse(noi, now(), response); + return noi->getRequest(); +} + RemoteCommandRequest NetworkInterfaceMock::scheduleErrorResponse(NetworkOperationIterator noi, const Status& response) { return scheduleErrorResponse(noi, now(), response); @@ -426,9 +432,9 @@ void NetworkInterfaceMock::_enqueueOperation_inlock( if (op.getRequest().timeout != RemoteCommandRequest::kNoTimeout) { invariant(op.getRequest().timeout >= Milliseconds(0)); - ResponseStatus response(ErrorCodes::NetworkTimeout, "Network timeout"); + ResponseStatus rs(ErrorCodes::NetworkTimeout, "Network timeout", Milliseconds(0)); auto action = stdx::bind( - &NetworkInterfaceMock::_cancelCommand_inlock, this, op.getCallbackHandle(), response); + &NetworkInterfaceMock::_cancelCommand_inlock, this, op.getCallbackHandle(), rs); _alarms.emplace(_now_inlock() + op.getRequest().timeout, action); } } @@ -470,17 +476,15 @@ void NetworkInterfaceMock::_connectThenEnqueueOperation_inlock(const HostAndPort } // The completion handler for the postconnect command schedules the original command. - auto postconnectCompletionHandler = [this, - op](StatusWith<RemoteCommandResponse> response) mutable { + auto postconnectCompletionHandler = [this, op](ResponseStatus rs) mutable { stdx::lock_guard<stdx::mutex> lk(_mutex); - if (!response.isOK()) { - op.setResponse(_now_inlock(), response.getStatus()); + if (!rs.isOK()) { + op.setResponse(_now_inlock(), rs); op.finishResponse(); return; } - auto handleStatus = - _hook->handleReply(op.getRequest().target, std::move(response.getValue())); + auto handleStatus = _hook->handleReply(op.getRequest().target, std::move(rs)); if (!handleStatus.isOK()) { op.setResponse(_now_inlock(), handleStatus); @@ -585,8 +589,8 @@ bool NetworkInterfaceMock::_isExecutorThreadRunnable_inlock() { return _waitingToRunMask & kExecutorThread; } -static const StatusWith<RemoteCommandResponse> kUnsetResponse( - ErrorCodes::InternalError, "NetworkOperation::_response never set"); +static const ResponseStatus kUnsetResponse(ErrorCodes::InternalError, + "NetworkOperation::_response never set"); NetworkInterfaceMock::NetworkOperation::NetworkOperation() : _requestDate(), @@ -612,9 +616,8 @@ NetworkInterfaceMock::NetworkOperation::~NetworkOperation() {} std::string NetworkInterfaceMock::NetworkOperation::getDiagnosticString() const { return str::stream() << "NetworkOperation -- request:'" << _request.toString() - << "', responseStatus: '" << _response.getStatus().toString() - << "', responseBody: '" - << (_response.getStatus().isOK() ? _response.getValue().toString() : "") + << "', responseStatus: '" << _response.status.toString() + << "', responseBody: '" << (_response.isOK() ? _response.toString() : "") << "', reqDate: " << _requestDate.toString() << ", nextConsiderDate: " << _nextConsiderationDate.toString() << ", respDate: " << _responseDate.toString(); |