diff --git a/src/mongo/client/async_client.cpp b/src/mongo/client/async_client.cpp index f0b0172ed3b66..62d1222784ec0 100644 --- a/src/mongo/client/async_client.cpp +++ b/src/mongo/client/async_client.cpp @@ -280,7 +280,8 @@ Future AsyncDBClient::initWireVersion(const std::string& appName, auto cmdReply = rpc::makeReply(&response); _parseHelloResponse(requestObj, cmdReply); if (hook) { - executor::RemoteCommandResponse cmdResp(*cmdReply, timer.elapsed()); + executor::RemoteCommandResponse cmdResp( + _peer, cmdReply->getCommandReply(), timer.elapsed()); uassertStatusOK(hook->validateHost(_peer, requestObj, cmdResp)); } }); @@ -401,7 +402,8 @@ Future AsyncDBClient::runCommandRequest( std::move(fromConnAcquiredTimer), token) .then([this, startTimer = std::move(startTimer)](rpc::UniqueReply response) { - return executor::RemoteCommandResponse(*response, startTimer.elapsed()); + return executor::RemoteCommandResponse( + _peer, response->getCommandReply(), startTimer.elapsed()); }); } @@ -414,8 +416,11 @@ Future AsyncDBClient::_continueReceiveExhaustRe .then([stopwatch, msgId, baton, this](Message responseMsg) mutable { bool isMoreToComeSet = OpMsg::isFlagSet(responseMsg, OpMsg::kMoreToCome); rpc::UniqueReply response = rpc::UniqueReply(responseMsg, rpc::makeReply(&responseMsg)); - auto rcResponse = executor::RemoteCommandResponse( - *response, duration_cast(stopwatch.elapsed()), isMoreToComeSet); + auto rcResponse = + executor::RemoteCommandResponse(_peer, + response->getCommandReply(), + duration_cast(stopwatch.elapsed()), + isMoreToComeSet); return rcResponse; }); } diff --git a/src/mongo/client/dbclient_session.cpp b/src/mongo/client/dbclient_session.cpp index e956a3bf1d06b..2244568f450ce 100644 --- a/src/mongo/client/dbclient_session.cpp +++ b/src/mongo/client/dbclient_session.cpp @@ -198,7 +198,7 @@ executor::RemoteCommandResponse initWireVersion( if (auto status = DBClientSession::appendClientMetadata(applicationName, &bob); !status.isOK()) { - return status; + return {conn->getServerHostAndPort(), status}; } conn->getCompressorManager().clientBegin(&bob); @@ -229,10 +229,11 @@ executor::RemoteCommandResponse initWireVersion( conn->getCompressorManager().clientFinish(helloObj); - return executor::RemoteCommandResponse{std::move(helloObj), finish - start}; + return executor::RemoteCommandResponse{ + conn->getServerHostAndPort(), std::move(helloObj), finish - start}; } catch (...) { - return exceptionToStatus(); + return {conn->getServerHostAndPort(), exceptionToStatus()}; } boost::optional clampTimeout(double timeoutInSec) { diff --git a/src/mongo/client/fetcher_test.cpp b/src/mongo/client/fetcher_test.cpp index 1cd6642c37ec8..d46df1e461ae6 100644 --- a/src/mongo/client/fetcher_test.cpp +++ b/src/mongo/client/fetcher_test.cpp @@ -164,7 +164,7 @@ void FetcherTest::processNetworkResponse(const BSONObj& obj, ReadyQueueState readyQueueStateAfterProcessing, FetcherState fetcherStateAfterProcessing) { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); - getNet()->scheduleSuccessfulResponse({obj, elapsed}); + getNet()->scheduleSuccessfulResponse(ResponseStatus::make_forTest(obj, elapsed)); finishProcessingNetworkResponse(readyQueueStateAfterProcessing, fetcherStateAfterProcessing); } @@ -563,7 +563,8 @@ TEST_F(FetcherTest, ScheduleButShutdown) { TEST_F(FetcherTest, ScheduleAfterCompletionReturnsShutdownInProgress) { ASSERT_EQUALS(Fetcher::State::kPreStart, fetcher->getState_forTest()); ASSERT_OK(fetcher->schedule()); - auto rs = ResponseStatus(ErrorCodes::OperationFailed, "find command failed", Milliseconds(0)); + auto rs = ResponseStatus::make_forTest( + Status(ErrorCodes::OperationFailed, "find command failed"), Milliseconds(0)); processNetworkResponse(rs, ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::OperationFailed, status.code()); @@ -573,7 +574,8 @@ TEST_F(FetcherTest, ScheduleAfterCompletionReturnsShutdownInProgress) { TEST_F(FetcherTest, FindCommandFailed1) { ASSERT_OK(fetcher->schedule()); - auto rs = ResponseStatus(ErrorCodes::BadValue, "bad hint", Milliseconds(0)); + auto rs = + ResponseStatus::make_forTest(Status(ErrorCodes::BadValue, "bad hint"), Milliseconds(0)); processNetworkResponse(rs, ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::BadValue, status.code()); ASSERT_EQUALS("bad hint", status.reason()); @@ -1089,7 +1091,8 @@ TEST_F(FetcherTest, UpdateNextActionAfterSecondBatch) { ASSERT_EQUALS(cursorId, cursors.front().numberLong()); // Failed killCursors command response should be logged. - getNet()->scheduleSuccessfulResponse(noi, {BSON("ok" << false), Milliseconds(0)}); + getNet()->scheduleSuccessfulResponse( + noi, ResponseStatus::make_forTest(BSON("ok" << false), Milliseconds(0))); getNet()->runReadyNetworkOperations(); } @@ -1197,9 +1200,11 @@ TEST_F(FetcherTest, FetcherAppliesRetryPolicyToFirstCommandButNotToGetMoreReques // Retry policy is applied to find command. const BSONObj doc = BSON("_id" << 1); - auto rs = ResponseStatus(ErrorCodes::HostUnreachable, "first", Milliseconds(0)); + auto rs = + ResponseStatus::make_forTest(Status(ErrorCodes::HostUnreachable, "first"), Milliseconds(0)); processNetworkResponse(rs, ReadyQueueState::kHasReadyRequests, FetcherState::kActive); - rs = ResponseStatus(ErrorCodes::SocketException, "second", Milliseconds(0)); + rs = ResponseStatus::make_forTest(Status(ErrorCodes::SocketException, "second"), + Milliseconds(0)); processNetworkResponse(rs, ReadyQueueState::kHasReadyRequests, FetcherState::kActive); processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" @@ -1214,7 +1219,8 @@ TEST_F(FetcherTest, FetcherAppliesRetryPolicyToFirstCommandButNotToGetMoreReques ASSERT_BSONOBJ_EQ(doc, documents.front()); ASSERT_TRUE(Fetcher::NextAction::kGetMore == nextAction); - rs = ResponseStatus(ErrorCodes::OperationFailed, "getMore failed", Milliseconds(0)); + rs = ResponseStatus::make_forTest(Status(ErrorCodes::OperationFailed, "getMore failed"), + Milliseconds(0)); // No retry policy for subsequent getMore commands. processNetworkResponse(rs, ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::OperationFailed, status); diff --git a/src/mongo/client/remote_command_retry_scheduler.cpp b/src/mongo/client/remote_command_retry_scheduler.cpp index f0d0797a27ee5..20633522d2a4f 100644 --- a/src/mongo/client/remote_command_retry_scheduler.cpp +++ b/src/mongo/client/remote_command_retry_scheduler.cpp @@ -198,7 +198,10 @@ void RemoteCommandRetryScheduler::_remoteCommandCallback( }(); if (!scheduleStatus.isOK()) { - _onComplete({rcba.executor, rcba.myHandle, rcba.request, scheduleStatus}); + _onComplete({rcba.executor, + rcba.myHandle, + rcba.request, + executor::RemoteCommandResponse(rcba.request.target, scheduleStatus)}); return; } } diff --git a/src/mongo/client/remote_command_retry_scheduler_test.cpp b/src/mongo/client/remote_command_retry_scheduler_test.cpp index 756a7a8967fae..4b04a772597dd 100644 --- a/src/mongo/client/remote_command_retry_scheduler_test.cpp +++ b/src/mongo/client/remote_command_retry_scheduler_test.cpp @@ -361,7 +361,9 @@ TEST_F(RemoteCommandRetrySchedulerTest, runReadyNetworkOperations(); checkCompletionStatus( - &scheduler, callback, {ErrorCodes::CallbackCanceled, "executor shutdown"}); + &scheduler, + callback, + ResponseStatus::make_forTest(Status(ErrorCodes::CallbackCanceled, "executor shutdown"))); } TEST_F(RemoteCommandRetrySchedulerTest, @@ -379,7 +381,9 @@ TEST_F(RemoteCommandRetrySchedulerTest, runReadyNetworkOperations(); checkCompletionStatus( - &scheduler, callback, {ErrorCodes::CallbackCanceled, "scheduler shutdown"}); + &scheduler, + callback, + ResponseStatus::make_forTest(Status(ErrorCodes::CallbackCanceled, "scheduler shutdown"))); } TEST_F(RemoteCommandRetrySchedulerTest, SchedulerInvokesCallbackOnNonRetryableErrorInResponse) { @@ -393,7 +397,8 @@ TEST_F(RemoteCommandRetrySchedulerTest, SchedulerInvokesCallbackOnNonRetryableEr start(&scheduler); // This should match one of the non-retryable error codes in the policy. - ResponseStatus rs(ErrorCodes::OperationFailed, "injected error", Milliseconds(0)); + ResponseStatus rs = ResponseStatus::make_forTest( + Status(ErrorCodes::OperationFailed, "injected error"), Milliseconds(0)); processNetworkResponse(rs); checkCompletionStatus(&scheduler, callback, rs); @@ -412,7 +417,8 @@ TEST_F(RemoteCommandRetrySchedulerTest, SchedulerInvokesCallbackOnFirstSuccessfu start(&scheduler); // Elapsed time in response is ignored on successful responses. - ResponseStatus response(BSON("ok" << 1 << "x" << 123 << "z" << 456), Milliseconds(100)); + ResponseStatus response = ResponseStatus::make_forTest( + BSON("ok" << 1 << "x" << 123 << "z" << 456), Milliseconds(100)); processNetworkResponse(response); checkCompletionStatus(&scheduler, callback, response); @@ -435,10 +441,11 @@ TEST_F(RemoteCommandRetrySchedulerTest, SchedulerIgnoresEmbeddedErrorInSuccessfu // Scheduler does not parse document in a successful response for embedded errors. // This is the case with some commands (e.g. find) which do not always return errors using the // wire protocol. - ResponseStatus response(BSON("ok" << 0 << "code" << int(ErrorCodes::FailedToParse) << "errmsg" - << "injected error" - << "z" << 456), - Milliseconds(100)); + ResponseStatus response = ResponseStatus::make_forTest( + BSON("ok" << 0 << "code" << int(ErrorCodes::FailedToParse) << "errmsg" + << "injected error" + << "z" << 456), + Milliseconds(100)); processNetworkResponse(response); checkCompletionStatus(&scheduler, callback, response); @@ -456,15 +463,19 @@ TEST_F(RemoteCommandRetrySchedulerTest, badExecutor.get(), request, std::ref(callback), std::move(policy)); start(&scheduler); - processNetworkResponse({ErrorCodes::HostNotFound, "first", Milliseconds(0)}); + processNetworkResponse( + ResponseStatus::make_forTest(Status(ErrorCodes::HostNotFound, "first"), Milliseconds(0))); // scheduleRemoteCommand() will fail with ErrorCodes::ShutdownInProgress when trying to send // third remote command request after processing second failed response. badExecutor->scheduleRemoteCommandFailPoint = true; - processNetworkResponse({ErrorCodes::HostNotFound, "second", Milliseconds(0)}); + processNetworkResponse( + ResponseStatus::make_forTest(Status(ErrorCodes::HostNotFound, "second"), Milliseconds(0))); checkCompletionStatus( - &scheduler, callback, {ErrorCodes::ShutdownInProgress, "", Milliseconds(0)}); + &scheduler, + callback, + ResponseStatus::make_forTest(Status(ErrorCodes::ShutdownInProgress, ""), Milliseconds(0))); } TEST_F(RemoteCommandRetrySchedulerTest, @@ -478,10 +489,13 @@ TEST_F(RemoteCommandRetrySchedulerTest, &getExecutor(), request, std::ref(callback), std::move(policy)); start(&scheduler); - processNetworkResponse({ErrorCodes::HostNotFound, "first", Milliseconds(0)}); - processNetworkResponse({ErrorCodes::HostUnreachable, "second", Milliseconds(0)}); + processNetworkResponse( + ResponseStatus::make_forTest(Status(ErrorCodes::HostNotFound, "first"), Milliseconds(0))); + processNetworkResponse(ResponseStatus::make_forTest( + Status(ErrorCodes::HostUnreachable, "second"), Milliseconds(0))); - ResponseStatus response(ErrorCodes::NetworkTimeout, "last", Milliseconds(0)); + ResponseStatus response = + ResponseStatus::make_forTest(Status(ErrorCodes::NetworkTimeout, "last"), Milliseconds(0)); processNetworkResponse(response); checkCompletionStatus(&scheduler, callback, response); } @@ -496,9 +510,11 @@ TEST_F(RemoteCommandRetrySchedulerTest, SchedulerShouldRetryUntilSuccessfulRespo &getExecutor(), request, std::ref(callback), std::move(policy)); start(&scheduler); - processNetworkResponse({ErrorCodes::HostNotFound, "first", Milliseconds(0)}); + processNetworkResponse( + ResponseStatus::make_forTest(Status(ErrorCodes::HostNotFound, "first"), Milliseconds(0))); - ResponseStatus response(BSON("ok" << 1 << "x" << 123 << "z" << 456), Milliseconds(100)); + ResponseStatus response = ResponseStatus::make_forTest( + BSON("ok" << 1 << "x" << 123 << "z" << 456), Milliseconds(100)); processNetworkResponse(response); checkCompletionStatus(&scheduler, callback, response); } @@ -546,13 +562,15 @@ TEST_F(RemoteCommandRetrySchedulerTest, policyPtr->scheduler = &scheduler; start(&scheduler); - processNetworkResponse({ErrorCodes::HostNotFound, "first", Milliseconds(0)}); + processNetworkResponse( + ResponseStatus::make_forTest(Status(ErrorCodes::HostNotFound, "first"), Milliseconds(0))); - checkCompletionStatus(&scheduler, - callback, - {ErrorCodes::CallbackCanceled, - "scheduler was shut down before retrying command", - Milliseconds(0)}); + checkCompletionStatus( + &scheduler, + callback, + ResponseStatus::make_forTest( + Status(ErrorCodes::CallbackCanceled, "scheduler was shut down before retrying command"), + Milliseconds(0))); } bool sharedCallbackStateDestroyed = false; @@ -590,7 +608,8 @@ TEST_F(RemoteCommandRetrySchedulerTest, sharedCallbackData.reset(); ASSERT_FALSE(sharedCallbackStateDestroyed); - processNetworkResponse({ErrorCodes::OperationFailed, "command failed", Milliseconds(0)}); + processNetworkResponse(ResponseStatus::make_forTest( + Status(ErrorCodes::OperationFailed, "command failed"), Milliseconds(0))); scheduler.join(); ASSERT_EQUALS(ErrorCodes::OperationFailed, result); diff --git a/src/mongo/client/server_discovery_monitor_test.cpp b/src/mongo/client/server_discovery_monitor_test.cpp index cd0e778e8e9d7..0acb6d465c4fe 100644 --- a/src/mongo/client/server_discovery_monitor_test.cpp +++ b/src/mongo/client/server_discovery_monitor_test.cpp @@ -202,7 +202,8 @@ class ServerDiscoveryMonitorTestFixture : public unittest::Test { const auto opmsg = OpMsgRequestBuilder::create( auth::ValidatedTenancyScope::kNotRequired, request.dbname, request.cmdObj); const auto reply = node->runCommand(request.id, opmsg)->getCommandReply(); - _net->scheduleSuccessfulResponse(noi, RemoteCommandResponse(reply, Milliseconds(0))); + _net->scheduleSuccessfulResponse( + noi, RemoteCommandResponse::make_forTest(reply, Milliseconds(0))); } else { _net->scheduleErrorResponse(noi, Status(ErrorCodes::HostUnreachable, "")); } diff --git a/src/mongo/client/server_ping_monitor_test.cpp b/src/mongo/client/server_ping_monitor_test.cpp index f86de1839b7fb..87337602870f3 100644 --- a/src/mongo/client/server_ping_monitor_test.cpp +++ b/src/mongo/client/server_ping_monitor_test.cpp @@ -148,7 +148,8 @@ class ServerPingMonitorTestFixture : public unittest::Test { if (node->isRunning()) { const auto opmsg = static_cast(request); const auto reply = node->runCommand(request.id, opmsg)->getCommandReply(); - _net->scheduleSuccessfulResponse(noi, RemoteCommandResponse(reply, Milliseconds(0))); + _net->scheduleSuccessfulResponse( + noi, RemoteCommandResponse::make_forTest(reply, Milliseconds(0))); } else { _net->scheduleErrorResponse(noi, Status(ErrorCodes::HostUnreachable, "")); } diff --git a/src/mongo/db/query/search/mongot_cursor.cpp b/src/mongo/db/query/search/mongot_cursor.cpp index 0b41e4bf9d92d..449b03f03edfc 100644 --- a/src/mongo/db/query/search/mongot_cursor.cpp +++ b/src/mongo/db/query/search/mongot_cursor.cpp @@ -155,15 +155,20 @@ long long computeInitialBatchSize(const boost::intrusive_ptr& } } // namespace +HostAndPort getMongotAddress() { + auto swHostAndPort = HostAndPort::parse(globalMongotParams.host); + // This host and port string is configured and validated at startup. + invariant(swHostAndPort.getStatus()); + + return swHostAndPort.getValue(); +} + executor::RemoteCommandRequest getRemoteCommandRequest(OperationContext* opCtx, const NamespaceString& nss, const BSONObj& cmdObj) { doThrowIfNotRunningWithMongotHostConfigured(); - auto swHostAndPort = HostAndPort::parse(globalMongotParams.host); - // This host and port string is configured and validated at startup. - invariant(swHostAndPort.getStatus()); executor::RemoteCommandRequest rcr( - executor::RemoteCommandRequest(swHostAndPort.getValue(), nss.dbName(), cmdObj, opCtx)); + executor::RemoteCommandRequest(getMongotAddress(), nss.dbName(), cmdObj, opCtx)); rcr.sslMode = transport::ConnectSSLMode::kDisableSSL; return rcr; } @@ -385,8 +390,9 @@ executor::RemoteCommandResponse runSearchCommandWithRetries( std::function retryPolicy) { using namespace fmt::literals; auto taskExecutor = executor::getMongotTaskExecutor(expCtx->opCtx->getServiceContext()); - executor::RemoteCommandResponse response = - Status(ErrorCodes::InternalError, "Internal error running search command"); + executor::RemoteCommandResponse response = { + getMongotAddress(), + Status(ErrorCodes::InternalError, "Internal error running search command")}; for (;;) { Status err = Status::OK(); do { diff --git a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp index 2231dc1515f68..161124c283744 100644 --- a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp +++ b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp @@ -207,9 +207,10 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSeveralDownNodes) { const Date_t startDate = getNet()->now(); const int numCommandsExpected = config.getNumMembers() - 1; for (int i = 0; i < numCommandsExpected; ++i) { - getNet()->scheduleResponse(getNet()->getNextReadyRequest(), - startDate + Milliseconds(10), - {ErrorCodes::HostUnreachable, "No reply"}); + getNet()->scheduleResponse( + getNet()->getNextReadyRequest(), + startDate + Milliseconds(10), + RemoteCommandResponse::make_forTest(Status(ErrorCodes::HostUnreachable, "No reply"))); } getNet()->runUntil(startDate + Milliseconds(10)); getNet()->exitNetwork(); @@ -258,7 +259,7 @@ executor::RemoteCommandResponse makeHeartbeatResponse(const ReplSetConfig& rsCon hbResp.setDurableOpTimeAndWallTime({opTime, wallTime}); auto bob = BSONObjBuilder(hbResp.toBSON()); bob.appendElements(extraFields); - return RemoteCommandResponse(bob.obj(), duration_cast(millis)); + return RemoteCommandResponse::make_forTest(bob.obj(), duration_cast(millis)); } TEST_F(CheckQuorumForInitiate, QuorumCheckSuccessForFiveNodes) { @@ -341,8 +342,10 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToOneDownNode) { ASSERT(seenHosts.insert(request.target).second) << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h2", 1)) { - getNet()->scheduleResponse( - noi, startDate + Milliseconds(10), {ErrorCodes::HostUnreachable, "No response"}); + getNet()->scheduleResponse(noi, + startDate + Milliseconds(10), + RemoteCommandResponse::make_forTest( + Status(ErrorCodes::HostUnreachable, "No response"))); } else { getNet()->scheduleResponse(noi, startDate + Milliseconds(10), @@ -401,14 +404,15 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetNameMismatch) { getNet()->scheduleResponse( noi, startDate + Milliseconds(10), - (RemoteCommandResponse( + (RemoteCommandResponse::make_forTest( BSON("ok" << 0 << "code" << ErrorCodes::InconsistentReplicaSetNames << "errmsg" << "replica set name doesn't match."), Milliseconds(8)))); } else { - getNet()->scheduleResponse(noi, - startDate + Milliseconds(10), - RemoteCommandResponse(BSON("ok" << 1), Milliseconds(8))); + getNet()->scheduleResponse( + noi, + startDate + Milliseconds(10), + RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(8))); } } getNet()->runUntil(startDate + Milliseconds(10)); @@ -586,13 +590,15 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckVetoedDueToIncompatibleSetName) { getNet()->scheduleResponse( noi, startDate + Milliseconds(10), - (RemoteCommandResponse( + (RemoteCommandResponse::make_forTest( BSON("ok" << 0 << "code" << ErrorCodes::InconsistentReplicaSetNames << "errmsg" << "replica set name doesn't match."), Milliseconds(8)))); } else { - getNet()->scheduleResponse( - noi, startDate + Milliseconds(10), {ErrorCodes::HostUnreachable, "No response"}); + getNet()->scheduleResponse(noi, + startDate + Milliseconds(10), + RemoteCommandResponse::make_forTest( + Status(ErrorCodes::HostUnreachable, "No response"))); } } getNet()->runUntil(startDate + Milliseconds(10)); @@ -647,8 +653,10 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToInsufficientVoters) { startDate + Milliseconds(10), makeHeartbeatResponse(rsConfig, Milliseconds(8))); } else { - getNet()->scheduleResponse( - noi, startDate + Milliseconds(10), {ErrorCodes::HostUnreachable, "No response"}); + getNet()->scheduleResponse(noi, + startDate + Milliseconds(10), + RemoteCommandResponse::make_forTest( + Status(ErrorCodes::HostUnreachable, "No response"))); } } getNet()->runUntil(startDate + Milliseconds(10)); @@ -703,8 +711,10 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToNoElectableNodeResponding) { startDate + Milliseconds(10), makeHeartbeatResponse(rsConfig, Milliseconds(8))); } else { - getNet()->scheduleResponse( - noi, startDate + Milliseconds(10), {ErrorCodes::HostUnreachable, "No response"}); + getNet()->scheduleResponse(noi, + startDate + Milliseconds(10), + RemoteCommandResponse::make_forTest( + Status(ErrorCodes::HostUnreachable, "No response"))); } } getNet()->runUntil(startDate + Milliseconds(10)); @@ -800,11 +810,13 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckProcessesCallbackCanceledResponse) { getNet()->scheduleResponse( noi, startDate + Milliseconds(10), - (RemoteCommandResponse(ErrorCodes::CallbackCanceled, "Testing canceled callback"))); + (RemoteCommandResponse::make_forTest( + Status(ErrorCodes::CallbackCanceled, "Testing canceled callback")))); } else { - getNet()->scheduleResponse(noi, - startDate + Milliseconds(10), - RemoteCommandResponse(BSON("ok" << 0), Milliseconds(8))); + getNet()->scheduleResponse( + noi, + startDate + Milliseconds(10), + RemoteCommandResponse::make_forTest(BSON("ok" << 0), Milliseconds(8))); } } getNet()->runUntil(startDate + Milliseconds(10)); diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp index c6c1eb4d91acb..08cfe1ecb98f7 100644 --- a/src/mongo/db/repl/initial_syncer_test.cpp +++ b/src/mongo/db/repl/initial_syncer_test.cpp @@ -243,7 +243,7 @@ class InitialSyncerTest : public executor::ThreadPoolExecutorTest, const BSONObj& obj) { NetworkInterfaceMock* net = getNet(); Milliseconds millis(0); - RemoteCommandResponse response(obj, millis); + RemoteCommandResponse response = RemoteCommandResponse::make_forTest(obj, millis); LOGV2(24159, "Sending response for network request", "dbname"_attr = noi->getRequest().dbname, @@ -261,7 +261,9 @@ class InitialSyncerTest : public executor::ThreadPoolExecutorTest, "errorStatus"_attr = errorStatus); } verifyNextRequestCommandName(cmdName); - net->scheduleResponse(net->getNextReadyRequest(), net->now(), errorStatus); + net->scheduleResponse(net->getNextReadyRequest(), + net->now(), + RemoteCommandResponse::make_forTest(errorStatus)); } void processNetworkResponse(std::string cmdName, const BSONObj& obj) { @@ -655,7 +657,7 @@ RemoteCommandResponse makeCursorResponse(CursorId cursorId, } ASSERT_OK(oqMetadata.writeToMetadata(&bob)); bob.append("ok", 1); - return {bob.obj(), Milliseconds()}; + return RemoteCommandResponse::make_forTest(bob.obj(), Milliseconds()); } /** @@ -1833,8 +1835,8 @@ TEST_F(InitialSyncerTest, InitialSyncerPassesThroughFCVFetcherCallbackError_Mock _mock ->expect(BSON("find" << "system.version"), - RemoteCommandResponse(ErrorCodes::OperationFailed, - "find command failed at sync source")) + RemoteCommandResponse::make_forTest( + Status(ErrorCodes::OperationFailed, "find command failed at sync source"))) .times(1); // Start the real work. @@ -1926,10 +1928,10 @@ TEST_F(InitialSyncerTest, InitialSyncerResendsFindCommandIfFCVFetcherReturnsRetr // Respond to the first FCV attempt with a retriable error. _mock - ->expect( - BSON("find" - << "system.version"), - RemoteCommandResponse(ErrorCodes::HostUnreachable, "host unreachable network error")) + ->expect(BSON("find" + << "system.version"), + RemoteCommandResponse::make_forTest( + Status(ErrorCodes::HostUnreachable, "host unreachable network error"))) .times(1); ASSERT_OK(initialSyncer->startup(opCtx.get(), maxAttempts)); @@ -2502,9 +2504,9 @@ TEST_F(InitialSyncerTest, _mock ->expect(BSON("find" << "oplog.rs"), - RemoteCommandResponse( - ErrorCodes::OperationFailed, - "Oplog entry fetcher associated with the stopTimestamp failed")) + RemoteCommandResponse::make_forTest( + Status(ErrorCodes::OperationFailed, + "Oplog entry fetcher associated with the stopTimestamp failed"))) .times(1); } diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index d9e271449f66d..bb243afc2fc36 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -2965,7 +2965,7 @@ BSONObj ReplicationCoordinatorImpl::runCmdOnPrimaryAndAwaitResponse( // provide additional management when trying to cancel the request with differing clients. executor::RemoteCommandRequest request(primaryHostAndPort, dbName, cmdObj, nullptr); executor::RemoteCommandResponse cbkResponse( - Status{ErrorCodes::InternalError, "Uninitialized value"}); + primaryHostAndPort, Status{ErrorCodes::InternalError, "Uninitialized value"}); // Schedule the remote command. auto&& scheduleResult = _replExecutor->scheduleRemoteCommand( diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp index f5608a032cfc0..3560f5f7da49f 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp @@ -2683,7 +2683,8 @@ TEST_F(PrimaryCatchUpTest, CannotSeeAllNodes) { const RemoteCommandRequest& request = noi->getRequest(); if (request.target.host() == "node2") { auto status = Status(ErrorCodes::HostUnreachable, "Can't reach remote host"); - getNet()->scheduleResponse(noi, getNet()->now(), status); + getNet()->scheduleResponse( + noi, getNet()->now(), RemoteCommandResponse::make_forTest(status)); } else { getNet()->scheduleResponse(noi, getNet()->now(), makeHeartbeatResponse(time1)); } @@ -2954,7 +2955,8 @@ TEST_F(PrimaryCatchUpTest, FreshestNodeBecomesAvailableLater) { const RemoteCommandRequest& request = noi->getRequest(); if (request.target.host() == "node2") { auto status = Status(ErrorCodes::HostUnreachable, "Can't reach remote host"); - getNet()->scheduleResponse(noi, getNet()->now(), status); + getNet()->scheduleResponse( + noi, getNet()->now(), RemoteCommandResponse::make_forTest(status)); } else { getNet()->scheduleResponse(noi, getNet()->now(), makeHeartbeatResponse(time3)); } diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp index b3264e97a8ce5..3f022b62d52ff 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp @@ -222,7 +222,7 @@ void ReplicationCoordinatorImpl::handleHeartbeatResponse_forTest(BSONObj respons replSetNameString = replSetName.toString(); } - executor::TaskExecutor::ResponseStatus status(response, ping); + executor::TaskExecutor::ResponseStatus status(request.target, response, ping); executor::TaskExecutor::RemoteCommandCallbackArgs cbData( _replExecutor.get(), handle, request, status); diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp index b85431836059f..1888e11db12c4 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp @@ -1651,7 +1651,8 @@ TEST_F(ReplCoordHBV1Test, IgnoreTheContentsOfMetadataWhenItsReplicaSetIdDoesNotM // Prepare heartbeat response. OID unexpectedId = OID::gen(); OpTime opTime{Timestamp{10, 10}, 10}; - RemoteCommandResponse heartbeatResponse(ErrorCodes::InternalError, "not initialized"); + RemoteCommandResponse heartbeatResponse = + RemoteCommandResponse::make_forTest(Status(ErrorCodes::InternalError, "not initialized")); { ReplSetHeartbeatResponse hbResp; hbResp.setSetName(rsConfig.getReplSetName()); diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index 160dfb7f6b5a8..3464f500a633d 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -471,9 +471,10 @@ TEST_F(ReplCoordTest, NodeReturnsNodeNotFoundWhenQuorumCheckFailsWhileInitiating ASSERT_EQUALS(HostAndPort("node2", 54321), noi->getRequest().target); ASSERT_EQUALS(DatabaseName::kAdmin, noi->getRequest().dbname); ASSERT_BSONOBJ_EQ(hbArgs.toBSON(), noi->getRequest().cmdObj); - getNet()->scheduleResponse(noi, - startDate + Milliseconds(10), - RemoteCommandResponse(ErrorCodes::NoSuchKey, "No response")); + getNet()->scheduleResponse( + noi, + startDate + Milliseconds(10), + RemoteCommandResponse::make_forTest(Status(ErrorCodes::NoSuchKey, "No response"))); getNet()->runUntil(startDate + Milliseconds(10)); getNet()->exitNetwork(); ASSERT_EQUALS(startDate + Milliseconds(10), getNet()->now()); @@ -519,7 +520,9 @@ TEST_F(ReplCoordTest, InitiateSucceedsWhenQuorumCheckPasses) { hbResp.setWrittenOpTimeAndWallTime({OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)}); hbResp.setDurableOpTimeAndWallTime({OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)}); getNet()->scheduleResponse( - noi, startDate + Milliseconds(10), RemoteCommandResponse(hbResp.toBSON(), Milliseconds(8))); + noi, + startDate + Milliseconds(10), + RemoteCommandResponse::make_forTest(hbResp.toBSON(), Milliseconds(8))); getNet()->runUntil(startDate + Milliseconds(10)); getNet()->exitNetwork(); ASSERT_EQUALS(startDate + Milliseconds(10), getNet()->now()); @@ -1257,7 +1260,9 @@ TEST_F(ReplCoordTest, NodeCalculatesDefaultWriteConcernOnStartupNewConfigMajorit hbResp.setWrittenOpTimeAndWallTime({OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)}); hbResp.setDurableOpTimeAndWallTime({OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)}); getNet()->scheduleResponse( - noi, startDate + Milliseconds(10), RemoteCommandResponse(hbResp.toBSON(), Milliseconds(8))); + noi, + startDate + Milliseconds(10), + RemoteCommandResponse::make_forTest(hbResp.toBSON(), Milliseconds(8))); getNet()->runUntil(startDate + Milliseconds(10)); getNet()->exitNetwork(); ASSERT_EQUALS(startDate + Milliseconds(10), getNet()->now()); @@ -1320,7 +1325,9 @@ TEST_F(ReplCoordTest, NodeCalculatesDefaultWriteConcernOnStartupNewConfigNoMajor hbResp.setWrittenOpTimeAndWallTime({OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)}); hbResp.setDurableOpTimeAndWallTime({OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)}); getNet()->scheduleResponse( - noi, startDate + Milliseconds(10), RemoteCommandResponse(hbResp.toBSON(), Milliseconds(8))); + noi, + startDate + Milliseconds(10), + RemoteCommandResponse::make_forTest(hbResp.toBSON(), Milliseconds(8))); getNet()->runUntil(startDate + Milliseconds(10)); getNet()->exitNetwork(); ASSERT_EQUALS(startDate + Milliseconds(10), getNet()->now()); diff --git a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp index a6fbf06eb9275..d7d08ed760df1 100644 --- a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp +++ b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp @@ -269,7 +269,7 @@ executor::RemoteCommandResponse ReplCoordTest::makeResponseStatus(const BSONObj& "Responding with {doc} (elapsed: {millis})", "doc"_attr = doc, "millis"_attr = millis); - return RemoteCommandResponse(doc, millis); + return RemoteCommandResponse::make_forTest(doc, millis); } void ReplCoordTest::simulateEnoughHeartbeatsForAllNodesUp() { diff --git a/src/mongo/db/repl/reporter_test.cpp b/src/mongo/db/repl/reporter_test.cpp index 0906cd042456b..a317c209c6f13 100644 --- a/src/mongo/db/repl/reporter_test.cpp +++ b/src/mongo/db/repl/reporter_test.cpp @@ -393,7 +393,8 @@ TEST_F(ReporterTestNoTriggerAtSetUp, IsNotActiveAfterUpdatePositionTimeoutExpire // Schedule a response to the updatePosition command at a time that exceeds the timeout. Then // make sure the reporter shut down due to a remote command timeout. auto updatePosRequest = net->getNextReadyRequest(); - RemoteCommandResponse response(BSON("ok" << 1), Milliseconds(0)); + RemoteCommandResponse response = + RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(0)); executor::TaskExecutor::ResponseStatus responseStatus(response); net->scheduleResponse( updatePosRequest, net->now() + updatePositionTimeout + Milliseconds(1), responseStatus); @@ -413,7 +414,8 @@ TEST_F(ReporterTest, TaskExecutorAndNetworkErrorsStopTheReporter) { ASSERT_TRUE(reporter->isActive()); ASSERT_TRUE(reporter->isWaitingToSendReport()); - processNetworkResponse({ErrorCodes::NoSuchKey, "waaaah", Milliseconds(0)}); + processNetworkResponse(RemoteCommandResponse::make_forTest( + Status(ErrorCodes::NoSuchKey, "waaaah"), Milliseconds(0))); ASSERT_EQUALS(ErrorCodes::NoSuchKey, reporter->join()); assertReporterDone(); @@ -544,7 +546,8 @@ TEST_F(ReporterTest, CommandPreparationFailureDuringRescheduleStopsTheReporter) } TEST_F(ReporterTest, FailedUpdateShouldNotRescheduleUpdate) { - processNetworkResponse({ErrorCodes::OperationFailed, "update failed", Milliseconds(0)}); + processNetworkResponse(RemoteCommandResponse::make_forTest( + Status(ErrorCodes::OperationFailed, "update failed"), Milliseconds(0))); ASSERT_EQUALS(ErrorCodes::OperationFailed, reporter->join()); assertReporterDone(); @@ -559,7 +562,8 @@ TEST_F(ReporterTest, SuccessfulUpdateShouldRescheduleUpdate) { runUntil(until, true); - processNetworkResponse({ErrorCodes::OperationFailed, "update failed", Milliseconds(0)}); + processNetworkResponse(RemoteCommandResponse::make_forTest( + Status(ErrorCodes::OperationFailed, "update failed"), Milliseconds(0))); ASSERT_EQUALS(ErrorCodes::OperationFailed, reporter->join()); assertReporterDone(); @@ -763,7 +767,10 @@ TEST_F(ReporterTest, BackupChannelFailureAlsoCauseReporterFailure) { ASSERT_TRUE(reporter->isBackupActive()); processNetworkResponse(BSON("ok" << 1), true); - processNetworkResponse({ErrorCodes::OperationFailed, "update failed", Milliseconds(0)}, false); + processNetworkResponse( + RemoteCommandResponse::make_forTest(Status(ErrorCodes::OperationFailed, "update failed"), + Milliseconds(0)), + false); ASSERT_EQUALS(ErrorCodes::OperationFailed, reporter->getStatus_forTest().code()); // We need to explicitly shutdown the reporter here because we need to ask the main channel to diff --git a/src/mongo/db/repl/scatter_gather_test.cpp b/src/mongo/db/repl/scatter_gather_test.cpp index a77394e5db459..fefd36ad2ec1c 100644 --- a/src/mongo/db/repl/scatter_gather_test.cpp +++ b/src/mongo/db/repl/scatter_gather_test.cpp @@ -188,18 +188,21 @@ TEST_F(ScatterGatherTest, DeleteAlgorithmAfterItHasCompleted) { NetworkInterfaceMock* net = getNet(); net->enterNetwork(); NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); - net->scheduleResponse( - noi, net->now() + Seconds(2), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + net->scheduleResponse(noi, + net->now() + Seconds(2), + (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); ASSERT_FALSE(ranCompletion); noi = net->getNextReadyRequest(); - net->scheduleResponse( - noi, net->now() + Seconds(2), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + net->scheduleResponse(noi, + net->now() + Seconds(2), + (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); ASSERT_FALSE(ranCompletion); noi = net->getNextReadyRequest(); - net->scheduleResponse( - noi, net->now() + Seconds(5), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + net->scheduleResponse(noi, + net->now() + Seconds(5), + (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); ASSERT_FALSE(ranCompletion); net->runUntil(net->now() + Seconds(2)); @@ -228,19 +231,21 @@ TEST_F(ScatterGatherTest, DeleteAlgorithmBeforeItCompletes) { net->enterNetwork(); NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); net->scheduleResponse( - noi, net->now(), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + noi, net->now(), (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); ASSERT_FALSE(ranCompletion); // Get and process the response from the first node immediately. net->runReadyNetworkOperations(); noi = net->getNextReadyRequest(); - net->scheduleResponse( - noi, net->now() + Seconds(2), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + net->scheduleResponse(noi, + net->now() + Seconds(2), + (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); ASSERT_FALSE(ranCompletion); noi = net->getNextReadyRequest(); - net->scheduleResponse( - noi, net->now() + Seconds(5), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + net->scheduleResponse(noi, + net->now() + Seconds(5), + (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); ASSERT_FALSE(ranCompletion); sga.reset(); @@ -266,8 +271,9 @@ TEST_F(ScatterGatherTest, DeleteAlgorithmAfterCancel) { NetworkInterfaceMock* net = getNet(); net->enterNetwork(); NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); - net->scheduleResponse( - noi, net->now() + Seconds(2), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + net->scheduleResponse(noi, + net->now() + Seconds(2), + (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); ASSERT_FALSE(ranCompletion); // Cancel the runner so following responses won't change the result. All pending requests @@ -364,18 +370,21 @@ TEST_F(ScatterGatherTest, DoNotProcessMoreThanSufficientResponses) { NetworkInterfaceMock* net = getNet(); net->enterNetwork(); NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); - net->scheduleResponse( - noi, net->now() + Seconds(2), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + net->scheduleResponse(noi, + net->now() + Seconds(2), + (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); ASSERT_FALSE(ranCompletion); noi = net->getNextReadyRequest(); - net->scheduleResponse( - noi, net->now() + Seconds(2), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + net->scheduleResponse(noi, + net->now() + Seconds(2), + (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); ASSERT_FALSE(ranCompletion); noi = net->getNextReadyRequest(); - net->scheduleResponse( - noi, net->now() + Seconds(5), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + net->scheduleResponse(noi, + net->now() + Seconds(5), + (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); ASSERT_FALSE(ranCompletion); net->runUntil(net->now() + Seconds(2)); @@ -404,15 +413,16 @@ TEST_F(ScatterGatherTest, AlgorithmProcessesCallbackCanceledResponse) { NetworkInterfaceMock* net = getNet(); net->enterNetwork(); NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); - net->scheduleResponse( - noi, net->now() + Seconds(2), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + net->scheduleResponse(noi, + net->now() + Seconds(2), + (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); ASSERT_FALSE(ranCompletion); noi = net->getNextReadyRequest(); - net->scheduleResponse( - noi, - net->now() + Seconds(2), - (RemoteCommandResponse(ErrorCodes::CallbackCanceled, "Testing canceled callback"))); + net->scheduleResponse(noi, + net->now() + Seconds(2), + (RemoteCommandResponse::make_forTest( + Status(ErrorCodes::CallbackCanceled, "Testing canceled callback")))); ASSERT_FALSE(ranCompletion); // We don't schedule a response from one node to make sure the response with the @@ -468,7 +478,7 @@ TEST_F(ScatterGatherTest, DoNotCreateCallbacksIfHasSufficientResponsesReturnsTru NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); net->scheduleResponse(noi, net->now(), - (RemoteCommandResponse( + (RemoteCommandResponse::make_forTest( BSON("ok" << 1), boost::posix_time::milliseconds(10)))); net->runReadyNetworkOperations(); @@ -477,7 +487,7 @@ TEST_F(ScatterGatherTest, DoNotCreateCallbacksIfHasSufficientResponsesReturnsTru noi = net->getNextReadyRequest(); net->scheduleResponse(noi, net->now(), - (RemoteCommandResponse( + (RemoteCommandResponse::make_forTest( BSON("ok" << 1), boost::posix_time::milliseconds(10)))); net->runReadyNetworkOperations(); @@ -486,7 +496,7 @@ TEST_F(ScatterGatherTest, DoNotCreateCallbacksIfHasSufficientResponsesReturnsTru noi = net->getNextReadyRequest(); net->scheduleResponse(noi, net->now(), - (RemoteCommandResponse( + (RemoteCommandResponse::make_forTest( BSON("ok" << 1), boost::posix_time::milliseconds(10)))); net->runReadyNetworkOperations(); @@ -506,7 +516,7 @@ TEST_F(ScatterGatherTest, SuccessfulScatterGatherViaRun) { net->enterNetwork(); NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); net->scheduleResponse( - noi, net->now(), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + noi, net->now(), (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); net->runReadyNetworkOperations(); noi = net->getNextReadyRequest(); @@ -515,7 +525,7 @@ TEST_F(ScatterGatherTest, SuccessfulScatterGatherViaRun) { noi = net->getNextReadyRequest(); net->scheduleResponse( - noi, net->now(), (RemoteCommandResponse(BSON("ok" << 1), Milliseconds(10)))); + noi, net->now(), (RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(10)))); net->runReadyNetworkOperations(); net->exitNetwork(); diff --git a/src/mongo/db/repl/shard_merge_recipient_service_test.cpp b/src/mongo/db/repl/shard_merge_recipient_service_test.cpp index 423dc1f1254c6..236347b048269 100644 --- a/src/mongo/db/repl/shard_merge_recipient_service_test.cpp +++ b/src/mongo/db/repl/shard_merge_recipient_service_test.cpp @@ -450,19 +450,19 @@ class ShardMergeRecipientServiceTest : public ServiceContextMongoDTest { MockNetwork::InSequence seq(*_mockNet); _mockNet ->expect(backupCursorRequest, - RemoteCommandResponse( - {cursorDataMock.getBackupCursorBatches(0), Milliseconds()})) + RemoteCommandResponse::make_forTest( + cursorDataMock.getBackupCursorBatches(0), Milliseconds())) .times(1); _mockNet ->expect(getMoreRequest, - RemoteCommandResponse( - {cursorDataMock.getBackupCursorBatches(1), Milliseconds()})) + RemoteCommandResponse::make_forTest( + cursorDataMock.getBackupCursorBatches(1), Milliseconds())) .times(1); _mockNet ->expect(getMoreRequest, - RemoteCommandResponse( - {cursorDataMock.getBackupCursorBatches(-1), Milliseconds()})) + RemoteCommandResponse::make_forTest( + cursorDataMock.getBackupCursorBatches(-1), Milliseconds())) .times(1); } @@ -471,18 +471,18 @@ class ShardMergeRecipientServiceTest : public ServiceContextMongoDTest { void expectSuccessfulKillBackupCursorCall() { _mockNet - ->expect( - killBackupCursorRequest, - RemoteCommandResponse({cursorDataMock.getkillBackupCursorReply(), Milliseconds()})) + ->expect(killBackupCursorRequest, + RemoteCommandResponse::make_forTest(cursorDataMock.getkillBackupCursorReply(), + Milliseconds())) .times(1); _mockNet->runUntilExpectationsSatisfied(); } void expectSuccessfulBackupCursorEmptyGetMore() { _mockNet - ->expect( - getMoreRequest, - RemoteCommandResponse({cursorDataMock.getBackupCursorBatches(-1), Milliseconds()})) + ->expect(getMoreRequest, + RemoteCommandResponse::make_forTest(cursorDataMock.getBackupCursorBatches(-1), + Milliseconds())) .times(1); _mockNet->runUntilExpectationsSatisfied(); } @@ -743,30 +743,31 @@ TEST_F(ShardMergeRecipientServiceTest, OpenBackupCursorRetriesIfBackupCursorIsTo { MockNetwork::InSequence seq(*getMockNet()); getMockNet() - ->expect(backupCursorRequest, - RemoteCommandResponse({cursorDataMock.getBackupCursorBatches( - 0, TSOlderThanCursorDataMockCheckpointTS), - Milliseconds()})) + ->expect( + backupCursorRequest, + RemoteCommandResponse::make_forTest( + cursorDataMock.getBackupCursorBatches(0, TSOlderThanCursorDataMockCheckpointTS), + Milliseconds())) .times(1); getMockNet() - ->expect( - killBackupCursorRequest, - RemoteCommandResponse({cursorDataMock.getkillBackupCursorReply(), Milliseconds()})) + ->expect(killBackupCursorRequest, + RemoteCommandResponse::make_forTest(cursorDataMock.getkillBackupCursorReply(), + Milliseconds())) .times(1); getMockNet() - ->expect( - backupCursorRequest, - RemoteCommandResponse({cursorDataMock.getBackupCursorBatches(0), Milliseconds()})) + ->expect(backupCursorRequest, + RemoteCommandResponse::make_forTest(cursorDataMock.getBackupCursorBatches(0), + Milliseconds())) .times(1); getMockNet() - ->expect( - getMoreRequest, - RemoteCommandResponse({cursorDataMock.getBackupCursorBatches(1), Milliseconds()})) + ->expect(getMoreRequest, + RemoteCommandResponse::make_forTest(cursorDataMock.getBackupCursorBatches(1), + Milliseconds())) .times(1); getMockNet() - ->expect( - getMoreRequest, - RemoteCommandResponse({cursorDataMock.getBackupCursorBatches(-1), Milliseconds()})) + ->expect(getMoreRequest, + RemoteCommandResponse::make_forTest(cursorDataMock.getBackupCursorBatches(-1), + Milliseconds())) .times(1); } getMockNet()->runUntilExpectationsSatisfied(); @@ -802,11 +803,13 @@ TEST_F(ShardMergeRecipientServiceTest, MergeFailsIfBackupCursorIsAlreadyActiveOn auto backupCursorConflictErrorCode = 50886; getMockNet() - ->expect(backupCursorRequest, - RemoteCommandResponse( - ErrorCodes::Error(backupCursorConflictErrorCode), - "The existing backup cursor must be closed before $backupCursor can succeed.", - Milliseconds())) + ->expect( + backupCursorRequest, + RemoteCommandResponse::make_forTest( + Status( + ErrorCodes::Error(backupCursorConflictErrorCode), + "The existing backup cursor must be closed before $backupCursor can succeed."), + Milliseconds())) .times(1); getMockNet()->runUntilExpectationsSatisfied(); @@ -838,9 +841,10 @@ TEST_F(ShardMergeRecipientServiceTest, MergeFailsIfDonorIsFsyncLocked) { auto backupCursorConflictWithFsyncErrorCode = 50887; getMockNet() ->expect(backupCursorRequest, - RemoteCommandResponse(ErrorCodes::Error(backupCursorConflictWithFsyncErrorCode), - "The node is currently fsyncLocked.", - Milliseconds())) + RemoteCommandResponse::make_forTest( + Status(ErrorCodes::Error(backupCursorConflictWithFsyncErrorCode), + "The node is currently fsyncLocked."), + Milliseconds())) .times(1); getMockNet()->runUntilExpectationsSatisfied(); @@ -872,9 +876,10 @@ TEST_F(ShardMergeRecipientServiceTest, MergeFailsIfBackupCursorNotSupportedOnDon auto backupCursorNotSupportedErrorCode = 40324; getMockNet() ->expect(backupCursorRequest, - RemoteCommandResponse(ErrorCodes::Error(backupCursorNotSupportedErrorCode), - "Unrecognized pipeline stage name: '$backupCursor'", - Milliseconds())) + RemoteCommandResponse::make_forTest( + Status(ErrorCodes::Error(backupCursorNotSupportedErrorCode), + "Unrecognized pipeline stage name: '$backupCursor'"), + Milliseconds())) .times(1); getMockNet()->runUntilExpectationsSatisfied(); diff --git a/src/mongo/db/repl/vote_requester_test.cpp b/src/mongo/db/repl/vote_requester_test.cpp index 518f8b4eb1fa3..e63739d9ea765 100644 --- a/src/mongo/db/repl/vote_requester_test.cpp +++ b/src/mongo/db/repl/vote_requester_test.cpp @@ -171,18 +171,20 @@ class VoteRequesterTest : public mongo::unittest::Test { } RemoteCommandResponse badRemoteCommandResponse() { - return RemoteCommandResponse(ErrorCodes::NodeNotFound, "not on my watch"); + return RemoteCommandResponse::make_forTest( + Status(ErrorCodes::NodeNotFound, "not on my watch")); } RemoteCommandResponse callbackCanceledCommandResponse() { - return RemoteCommandResponse(ErrorCodes::CallbackCanceled, "Testing canceled callback"); + return RemoteCommandResponse::make_forTest( + Status(ErrorCodes::CallbackCanceled, "Testing canceled callback")); } RemoteCommandResponse votedYes() { ReplSetRequestVotesResponse response; response.setVoteGranted(true); response.setTerm(1); - return RemoteCommandResponse(response.toBSON(), Milliseconds(10)); + return RemoteCommandResponse::make_forTest(response.toBSON(), Milliseconds(10)); } RemoteCommandResponse votedYesStatusNotOkBecauseFailedToStoreLastVote() { @@ -194,7 +196,7 @@ class VoteRequesterTest : public mongo::unittest::Test { auto status = Status(ErrorCodes::InterruptedDueToReplStateChange, "operation was interrupted"); CommandHelpers::appendCommandStatusNoThrow(result, status); - return RemoteCommandResponse(result.obj(), Milliseconds(10)); + return RemoteCommandResponse::make_forTest(result.obj(), Milliseconds(10)); } RemoteCommandResponse votedNoBecauseConfigVersionDoesNotMatch() { @@ -202,7 +204,7 @@ class VoteRequesterTest : public mongo::unittest::Test { response.setVoteGranted(false); response.setTerm(1); response.setReason("candidate's config version differs from mine"); - return RemoteCommandResponse(response.toBSON(), Milliseconds(10)); + return RemoteCommandResponse::make_forTest(response.toBSON(), Milliseconds(10)); } RemoteCommandResponse votedNoBecauseSetNameDiffers() { @@ -210,7 +212,7 @@ class VoteRequesterTest : public mongo::unittest::Test { response.setVoteGranted(false); response.setTerm(1); response.setReason("candidate's set name differs from mine"); - return RemoteCommandResponse(response.toBSON(), Milliseconds(10)); + return RemoteCommandResponse::make_forTest(response.toBSON(), Milliseconds(10)); } RemoteCommandResponse votedNoBecauseLastOpTimeIsGreater() { @@ -218,7 +220,7 @@ class VoteRequesterTest : public mongo::unittest::Test { response.setVoteGranted(false); response.setTerm(1); response.setReason("candidate's data is staler than mine"); - return RemoteCommandResponse(response.toBSON(), Milliseconds(10)); + return RemoteCommandResponse::make_forTest(response.toBSON(), Milliseconds(10)); } RemoteCommandResponse votedNoBecauseTermIsGreater() { @@ -226,7 +228,7 @@ class VoteRequesterTest : public mongo::unittest::Test { response.setVoteGranted(false); response.setTerm(3); response.setReason("candidate's term is lower than mine"); - return RemoteCommandResponse(response.toBSON(), Milliseconds(10)); + return RemoteCommandResponse::make_forTest(response.toBSON(), Milliseconds(10)); } RemoteCommandResponse votedNoBecauseAlreadyVoted() { @@ -234,7 +236,7 @@ class VoteRequesterTest : public mongo::unittest::Test { response.setVoteGranted(false); response.setTerm(2); response.setReason("already voted for another candidate this term"); - return RemoteCommandResponse(response.toBSON(), Milliseconds(10)); + return RemoteCommandResponse::make_forTest(response.toBSON(), Milliseconds(10)); } std::unique_ptr _requester; diff --git a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp index 6eb1bd7eb2a9c..949698a024a7d 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp @@ -398,8 +398,8 @@ StatusWith ShardingCatalogManager::_runCommandForAddShar executor::RemoteCommandRequest request( host, dbName, cmdObj, rpc::makeEmptyMetadata(), opCtx, kRemoteCommandTimeout); - executor::RemoteCommandResponse response = - Status(ErrorCodes::InternalError, "Internal error running command"); + executor::RemoteCommandResponse response( + host, Status(ErrorCodes::InternalError, "Internal error running command")); auto swCallbackHandle = _executorForAddShard->scheduleRemoteCommand( request, [&response](const executor::TaskExecutor::RemoteCommandCallbackArgs& args) { diff --git a/src/mongo/db/s/migration_chunk_cloner_source.cpp b/src/mongo/db/s/migration_chunk_cloner_source.cpp index defe224ced3b1..bb476aec4b691 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source.cpp +++ b/src/mongo/db/s/migration_chunk_cloner_source.cpp @@ -978,7 +978,7 @@ void MigrationChunkClonerSource::_cleanup(bool wasSuccessful) { StatusWith MigrationChunkClonerSource::_callRecipient(OperationContext* opCtx, const BSONObj& cmdObj) { executor::RemoteCommandResponse responseStatus( - Status{ErrorCodes::InternalError, "Uninitialized value"}); + _recipientHost, Status{ErrorCodes::InternalError, "Uninitialized value"}); auto executor = Grid::get(getGlobalServiceContext())->getExecutorPool()->getFixedExecutor(); auto scheduleStatus = executor->scheduleRemoteCommand( diff --git a/src/mongo/db/s/transaction_coordinator_futures_util.cpp b/src/mongo/db/s/transaction_coordinator_futures_util.cpp index 4f0c166748874..4310700aa96dd 100644 --- a/src/mongo/db/s/transaction_coordinator_futures_util.cpp +++ b/src/mongo/db/s/transaction_coordinator_futures_util.cpp @@ -152,9 +152,10 @@ Future AsyncWorkScheduler::scheduleRemot } return false; }))) { - return ResponseStatus{BSON("code" << failPointErrorCode << "ok" << false << "errmsg" - << "fail point"), - Milliseconds(1)}; + return ResponseStatus::make_forTest(BSON("code" << failPointErrorCode << "ok" << false + << "errmsg" + << "fail point"), + Milliseconds(1)); } if (isSelfShard) { @@ -195,7 +196,9 @@ Future AsyncWorkScheduler::scheduleRemot // 'ResponseStatus' is the response format of a remote request sent over the network // so we simulate that format manually here, since we sent the request over the // loopback. - return ResponseStatus{replyOpMsg.body.getOwned(), _executor->now() - start}; + return ResponseStatus{HostAndPort("localhost", serverGlobalParams.port), + replyOpMsg.body.getOwned(), + _executor->now() - start}; }); } diff --git a/src/mongo/db/serverless/shard_split_donor_service_test.cpp b/src/mongo/db/serverless/shard_split_donor_service_test.cpp index a06d60e8b9d73..81519fad9824e 100644 --- a/src/mongo/db/serverless/shard_split_donor_service_test.cpp +++ b/src/mongo/db/serverless/shard_split_donor_service_test.cpp @@ -334,7 +334,7 @@ bool processReplSetStepUpRequest(executor::NetworkInterfaceMock* net, const auto opmsg = static_cast(request); const auto reply = node->runCommand(request.id, opmsg)->getCommandReply(); net->scheduleSuccessfulResponse( - noi, executor::RemoteCommandResponse(reply, Milliseconds(0))); + noi, executor::RemoteCommandResponse::make_forTest(reply, Milliseconds(0))); } } else { net->scheduleErrorResponse(noi, Status(ErrorCodes::HostUnreachable, "generated by test")); @@ -368,7 +368,8 @@ void processIncomingRequest(executor::NetworkInterfaceMock* net, const auto opmsg = static_cast(request); const auto reply = node->runCommand(request.id, opmsg)->getCommandReply(); - net->scheduleSuccessfulResponse(noi, executor::RemoteCommandResponse(reply, Milliseconds(0))); + net->scheduleSuccessfulResponse( + noi, executor::RemoteCommandResponse::make_forTest(reply, Milliseconds(0))); } void waitForReadyRequest(executor::NetworkInterfaceMock* net) { diff --git a/src/mongo/executor/async_rpc.cpp b/src/mongo/executor/async_rpc.cpp index dc8abf091c324..9f8666067b6c2 100644 --- a/src/mongo/executor/async_rpc.cpp +++ b/src/mongo/executor/async_rpc.cpp @@ -133,21 +133,21 @@ class AsyncRPCRunnerImpl : public AsyncRPCRunner { }) .then([targeter](TaskExecutor::RemoteCommandCallbackArgs cbargs) { auto r = cbargs.response; - auto s = makeErrorIfNeeded(r, r.target); + auto s = makeErrorIfNeeded(r); // Update targeter for errors. - if (!s.isOK() && s.code() == ErrorCodes::RemoteCommandExecutionError && r.target) { + if (!s.isOK() && s.code() == ErrorCodes::RemoteCommandExecutionError) { auto extraInfo = s.extraInfo(); if (extraInfo->isLocal()) { - targeter->onRemoteCommandError(*(r.target), extraInfo->asLocal()).get(); + targeter->onRemoteCommandError(r.target, extraInfo->asLocal()).get(); } else { targeter - ->onRemoteCommandError(*(r.target), + ->onRemoteCommandError(r.target, extraInfo->asRemote().getRemoteCommandResult()) .get(); } } uassertStatusOK(s); - return AsyncRPCInternalResponse{r.data, r.target.get(), *r.elapsed}; + return AsyncRPCInternalResponse{r.data, r.target, *r.elapsed}; }); } }; diff --git a/src/mongo/executor/async_rpc.h b/src/mongo/executor/async_rpc.h index a39a0533ffbbd..ebadcf350ac46 100644 --- a/src/mongo/executor/async_rpc.h +++ b/src/mongo/executor/async_rpc.h @@ -183,14 +183,13 @@ class AsyncRPCRunner { * Returns a RemoteCommandExecutionError with ErrorExtraInfo populated to contain * details about any error, local or remote, contained in `r`. */ -inline Status makeErrorIfNeeded(TaskExecutor::ResponseStatus r, - boost::optional targetAttempted) { +inline Status makeErrorIfNeeded(TaskExecutor::ResponseStatus r) { if (r.status.isOK() && getStatusFromCommandResult(r.data).isOK() && getWriteConcernStatusFromCommandResult(r.data).isOK() && getFirstWriteErrorStatusFromCommandResult(r.data).isOK()) { return Status::OK(); } - return {AsyncRPCErrorInfo(r, targetAttempted), "Remote command execution failed"}; + return {AsyncRPCErrorInfo(r), "Remote command execution failed"}; } /** diff --git a/src/mongo/executor/async_rpc_error_info.h b/src/mongo/executor/async_rpc_error_info.h index fd21e30672360..40f5af9aa04f7 100644 --- a/src/mongo/executor/async_rpc_error_info.h +++ b/src/mongo/executor/async_rpc_error_info.h @@ -72,7 +72,7 @@ class AsyncRPCErrorInfo final : public ErrorExtraInfo { _remoteCommandResult{getStatusFromCommandResult(_error)}, _remoteCommandWriteConcernError{getWriteConcernStatusFromCommandResult(_error)}, _remoteCommandFirstWriteError{getFirstWriteErrorStatusFromCommandResult(_error)}, - _targetUsed{*rcr.target}, + _targetUsed{rcr.target}, _elapsed{*rcr.elapsed} { // The buffer backing the default empty BSONObj has static duration so it is effectively // owned. @@ -138,7 +138,7 @@ class AsyncRPCErrorInfo final : public ErrorExtraInfo { * Construct the relevant extra info from the RemoteCommandResponse provided by the TaskExecutor * used to invoke the remote command. */ - AsyncRPCErrorInfo(RemoteCommandResponse rcr, boost::optional target) + AsyncRPCErrorInfo(RemoteCommandResponse rcr) : _prov{[&] { if (!rcr.status.isOK()) return CommandErrorProvenance::kLocal; @@ -151,7 +151,7 @@ class AsyncRPCErrorInfo final : public ErrorExtraInfo { return RemoteError(rcr); } }()}, - _targetAttempted{target} {} + _targetAttempted{rcr.target} {} /** * Construct the relevant extra info from an error status - used if a remote command invokation * attempt fails before it reaches the TaskExecutor level. diff --git a/src/mongo/executor/exhaust_response_reader_tl.cpp b/src/mongo/executor/exhaust_response_reader_tl.cpp index b6c68512c3033..0ce5420f816af 100644 --- a/src/mongo/executor/exhaust_response_reader_tl.cpp +++ b/src/mongo/executor/exhaust_response_reader_tl.cpp @@ -170,7 +170,8 @@ SemiFuture ExhaustResponseReaderTL::next() { if (swResp.isOK()) { return swResp; } - return RemoteCommandResponse(std::move(swResp.getStatus())); + return RemoteCommandResponse(_originatingRequest.target, + std::move(swResp.getStatus())); }) .tapAll( [this, anchor = shared_from_this()](const StatusWith& swResp) { diff --git a/src/mongo/executor/mock_async_rpc.h b/src/mongo/executor/mock_async_rpc.h index 51d94cd1c1c51..6d6a1322450cf 100644 --- a/src/mongo/executor/mock_async_rpc.h +++ b/src/mongo/executor/mock_async_rpc.h @@ -153,19 +153,17 @@ class SyncMockAsyncRPCRunner : public detail::AsyncRPCRunner { stdx::lock_guard lg{_m}; _requests.emplace_back(cmdBSON, dbName, targets[0], std::move(p)); _hasRequestsCV.notify_one(); - return std::move(f).onCompletion([targetUsed = - targets[0]](StatusWith resp) { - if (!resp.isOK()) { - uassertStatusOK(Status{AsyncRPCErrorInfo(resp.getStatus(), targetUsed), - "Remote command execution failed"}); - } - Status maybeError( - detail::makeErrorIfNeeded(executor::RemoteCommandResponse( - targetUsed, resp.getValue(), Microseconds(1)), - targetUsed)); - uassertStatusOK(maybeError); - return detail::AsyncRPCInternalResponse{resp.getValue(), targetUsed}; - }); + return std::move(f).onCompletion( + [targetUsed = targets[0]](StatusWith resp) { + if (!resp.isOK()) { + uassertStatusOK(Status{AsyncRPCErrorInfo(resp.getStatus(), targetUsed), + "Remote command execution failed"}); + } + Status maybeError(detail::makeErrorIfNeeded(executor::RemoteCommandResponse( + targetUsed, resp.getValue(), Microseconds(1)))); + uassertStatusOK(maybeError); + return detail::AsyncRPCInternalResponse{resp.getValue(), targetUsed}; + }); }); } @@ -281,8 +279,7 @@ class AsyncMockAsyncRPCRunner : public detail::AsyncRPCRunner { "Remote command execution failed"}); } Status maybeError(detail::makeErrorIfNeeded( - executor::RemoteCommandResponse(targets[0], ans.getValue(), Microseconds(1)), - targets[0])); + executor::RemoteCommandResponse(targets[0], ans.getValue(), Microseconds(1)))); uassertStatusOK(maybeError); return detail::AsyncRPCInternalResponse{ans.getValue(), targets[0]}; }); diff --git a/src/mongo/executor/mock_network_fixture.h b/src/mongo/executor/mock_network_fixture.h index 9664aea8c9451..42551e8f314dc 100644 --- a/src/mongo/executor/mock_network_fixture.h +++ b/src/mongo/executor/mock_network_fixture.h @@ -151,7 +151,7 @@ class MockNetwork { Action(const BSONObj& response) { _actionFunc = [=](const BSONObj& request) { - return RemoteCommandResponse(response, Milliseconds(0)); + return RemoteCommandResponse::make_forTest(response, Milliseconds(0)); }; } diff --git a/src/mongo/executor/network_interface_mock.cpp b/src/mongo/executor/network_interface_mock.cpp index 80b8ac9824623..3bdf52646fa0e 100644 --- a/src/mongo/executor/network_interface_mock.cpp +++ b/src/mongo/executor/network_interface_mock.cpp @@ -156,7 +156,8 @@ void NetworkInterfaceMock::cancelCommand(const CallbackHandle& cbHandle, const B invariant(!inShutdown()); stdx::lock_guard lk(_mutex); - ResponseStatus rs(ErrorCodes::CallbackCanceled, "Network operation canceled", Milliseconds(0)); + ResponseStatus rs = ResponseStatus::make_forTest( + Status(ErrorCodes::CallbackCanceled, "Network operation canceled"), Milliseconds(0)); _interruptWithResponse_inlock(cbHandle, rs); } @@ -241,11 +242,12 @@ void NetworkInterfaceMock::shutdown() { _waitingToRunMask |= kExecutorThread; // Prevents network thread from scheduling. lk.unlock(); for (auto& op : todo) { - auto response = NetworkResponse{{}, - now, - ResponseStatus{ErrorCodes::ShutdownInProgress, - "Shutting down mock network", - Milliseconds(0)}}; + auto response = + NetworkResponse{{}, + now, + ResponseStatus::make_forTest(Status(ErrorCodes::ShutdownInProgress, + "Shutting down mock network"), + Milliseconds(0))}; if (op.fulfillResponse(std::move(response))) { LOGV2_WARNING(22590, "Mock network interface shutting down with outstanding request", @@ -371,7 +373,7 @@ void NetworkInterfaceMock::scheduleResponse(NetworkOperationIterator noi, } RemoteCommandRequest NetworkInterfaceMock::scheduleSuccessfulResponse(const BSONObj& response) { - return scheduleSuccessfulResponse(RemoteCommandResponse(response, Milliseconds(0))); + return scheduleSuccessfulResponse(ResponseStatus::make_forTest(response, Milliseconds(0))); } RemoteCommandRequest NetworkInterfaceMock::scheduleSuccessfulResponse( @@ -408,7 +410,7 @@ RemoteCommandRequest NetworkInterfaceMock::scheduleErrorResponse(NetworkOperatio RemoteCommandRequest NetworkInterfaceMock::scheduleErrorResponse(NetworkOperationIterator noi, Date_t when, const Status& response) { - scheduleResponse(noi, when, response); + scheduleResponse(noi, when, ResponseStatus::make_forTest(response)); return noi->getRequest(); } @@ -495,8 +497,9 @@ void NetworkInterfaceMock::_enqueueOperation_inlock(NetworkOperation&& op) { if (!status.isOK()) { return; } - auto response = ResponseStatus( - ErrorCodes::NetworkInterfaceExceededTimeLimit, "Network timeout", Milliseconds(0)); + auto response = ResponseStatus::make_forTest( + Status(ErrorCodes::NetworkInterfaceExceededTimeLimit, "Network timeout"), + Milliseconds(0)); _interruptWithResponse_inlock(cbh, std::move(response)); }); } @@ -511,11 +514,11 @@ void NetworkInterfaceMock::_connectThenEnqueueOperation_inlock(const HostAndPort auto handshakeReply = (handshakeReplyIter != std::end(_handshakeReplies)) ? handshakeReplyIter->second - : RemoteCommandResponse(BSONObj(), Milliseconds(0)); + : ResponseStatus::make_forTest(BSONObj(), Milliseconds(0)); auto valid = _hook->validateHost(target, op.getRequest().cmdObj, handshakeReply); if (!valid.isOK()) { - auto response = NetworkResponse{{}, _now_inlock(), valid}; + auto response = NetworkResponse{{}, _now_inlock(), ResponseStatus::make_forTest(valid)}; op.fulfillResponse(std::move(response)); return; } @@ -523,7 +526,8 @@ void NetworkInterfaceMock::_connectThenEnqueueOperation_inlock(const HostAndPort auto swHookPostconnectCommand = _hook->makeRequest(target); if (!swHookPostconnectCommand.isOK()) { - auto response = NetworkResponse{{}, _now_inlock(), swHookPostconnectCommand.getStatus()}; + auto response = NetworkResponse{ + {}, _now_inlock(), ResponseStatus::make_forTest(swHookPostconnectCommand.getStatus())}; op.fulfillResponse(std::move(response)); return; } @@ -557,7 +561,8 @@ void NetworkInterfaceMock::_connectThenEnqueueOperation_inlock(const HostAndPort auto handleStatus = _hook->handleReply(op.getRequest().target, std::move(rs)); if (!handleStatus.isOK()) { - auto response = NetworkResponse{{}, _now_inlock(), handleStatus}; + auto response = + NetworkResponse{{}, _now_inlock(), ResponseStatus::make_forTest(handleStatus)}; op.fulfillResponse(std::move(response)); return; } diff --git a/src/mongo/executor/network_interface_mock_test.cpp b/src/mongo/executor/network_interface_mock_test.cpp index c6ac849c6e33c..1ba28cdf13454 100644 --- a/src/mongo/executor/network_interface_mock_test.cpp +++ b/src/mongo/executor/network_interface_mock_test.cpp @@ -82,19 +82,20 @@ TEST_F(NetworkInterfaceMockTest, ConnectionHook) { << "stuff"), nullptr}; - RemoteCommandResponse expectedResponse{BSON("foo" - << "bar" - << "baz" - << "garply" - << "bar" - << "baz"), - Milliseconds(30)}; + RemoteCommandResponse expectedResponse = RemoteCommandResponse::make_forTest(BSON("foo" + << "bar" + << "baz" + << "garply" + << "bar" + << "baz"), + Milliseconds(30)); // need to copy as it will be moved auto helloReplyData = BSON("iamyour" << "father"); - RemoteCommandResponse helloReply{helloReplyData.copy(), Milliseconds(20)}; + RemoteCommandResponse helloReply = + RemoteCommandResponse::make_forTest(helloReplyData.copy(), Milliseconds(20)); net().setHandshakeReplyForHost(testHost(), std::move(helloReply)); diff --git a/src/mongo/executor/network_interface_tl.cpp b/src/mongo/executor/network_interface_tl.cpp index ff0c2f87ce835..f71e65ac22f89 100644 --- a/src/mongo/executor/network_interface_tl.cpp +++ b/src/mongo/executor/network_interface_tl.cpp @@ -631,7 +631,7 @@ void NetworkInterfaceTL::ExhaustCommandState::continueExhaustRequest( StatusWith swResponse) { RemoteCommandResponse response; if (!swResponse.isOK()) { - response = RemoteCommandResponse(std::move(swResponse.getStatus())); + response = RemoteCommandResponse(request.target, std::move(swResponse.getStatus())); } else { response = std::move(swResponse.getValue()); } @@ -1016,7 +1016,8 @@ ExecutorFuture NetworkInterfaceTL::_runCommand( if (swResponse.isOK()) { return swResponse.getValue(); } else { - return RemoteCommandResponse(std::move(swResponse.getStatus()), + return RemoteCommandResponse(cmdState->request.target, + std::move(swResponse.getStatus()), cmdState->stopwatch.elapsed()); } }(); diff --git a/src/mongo/executor/network_test_env.cpp b/src/mongo/executor/network_test_env.cpp index ffcd5ea58f62f..398e35d2ae76a 100644 --- a/src/mongo/executor/network_test_env.cpp +++ b/src/mongo/executor/network_test_env.cpp @@ -66,12 +66,15 @@ void NetworkTestEnv::onCommands(std::vector funcs) { } else if (resultStatus.isOK()) { BSONObjBuilder result(std::move(resultStatus.getValue())); CommandHelpers::appendCommandStatusNoThrow(result, resultStatus.getStatus()); - const RemoteCommandResponse response(result.obj(), Milliseconds(1)); + const RemoteCommandResponse response = + RemoteCommandResponse::make_forTest(result.obj(), Milliseconds(1)); _mockNetwork->scheduleResponse(noi, _mockNetwork->now(), response); } else { _mockNetwork->scheduleResponse( - noi, _mockNetwork->now(), {resultStatus.getStatus(), Milliseconds(0)}); + noi, + _mockNetwork->now(), + RemoteCommandResponse::make_forTest(resultStatus.getStatus(), Milliseconds(0))); } } @@ -91,11 +94,15 @@ void NetworkTestEnv::onCommandWithMetadata(OnCommandWithMetadataFunction func) { } else if (cmdResponseStatus.isOK()) { BSONObjBuilder result(std::move(cmdResponseStatus.data)); CommandHelpers::appendCommandStatusNoThrow(result, cmdResponseStatus.status); - const RemoteCommandResponse response(result.obj(), Milliseconds(1)); + const RemoteCommandResponse response = + RemoteCommandResponse::make_forTest(result.obj(), Milliseconds(1)); _mockNetwork->scheduleResponse(noi, _mockNetwork->now(), response); } else { - _mockNetwork->scheduleResponse(noi, _mockNetwork->now(), cmdResponseStatus.status); + _mockNetwork->scheduleResponse( + noi, + _mockNetwork->now(), + RemoteCommandResponse::make_forTest(cmdResponseStatus.status)); } _mockNetwork->runReadyNetworkOperations(); @@ -128,7 +135,7 @@ void NetworkTestEnv::onFindWithMetadataCommand(OnFindCommandWithMetadataFunction const auto& resultStatus = func(request); if (!resultStatus.isOK()) { - return resultStatus.getStatus(); + return RemoteCommandResponse::make_forTest(resultStatus.getStatus()); } std::vector result; @@ -145,7 +152,7 @@ void NetworkTestEnv::onFindWithMetadataCommand(OnFindCommandWithMetadataFunction BSONObjBuilder resultBuilder(std::move(metadata)); appendCursorResponseObject(0LL, nss, arr.arr(), boost::none, &resultBuilder); - return RemoteCommandResponse(resultBuilder.obj(), Milliseconds(1)); + return RemoteCommandResponse::make_forTest(resultBuilder.obj(), Milliseconds(1)); }); } diff --git a/src/mongo/executor/pinned_connection_task_executor.cpp b/src/mongo/executor/pinned_connection_task_executor.cpp index a194d4d678f5c..bd6f37065d700 100644 --- a/src/mongo/executor/pinned_connection_task_executor.cpp +++ b/src/mongo/executor/pinned_connection_task_executor.cpp @@ -90,7 +90,7 @@ class PinnedConnectionTaskExecutor::CallbackState : public TaskExecutor::Callbac TaskExecutor* exec) { CallbackHandle cbHandle; setCallbackForHandle(&cbHandle, rcb.second); - auto errorResponse = RemoteCommandResponse(boost::none, kCallbackCanceledErrorStatus); + auto errorResponse = RemoteCommandResponse(rcb.first.target, kCallbackCanceledErrorStatus); TaskExecutor::RemoteCommandCallbackFn callback; using std::swap; swap(rcb.second->callback, callback); @@ -102,12 +102,11 @@ class PinnedConnectionTaskExecutor::CallbackState : public TaskExecutor::Callbac static void runCallbackFinished(stdx::unique_lock& lk, RequestAndCallback rcb, TaskExecutor* exec, - const StatusWith& result, - boost::optional targetUsed) { + const StatusWith& result) { // Convert the result into a RemoteCommandResponse unconditionally. - RemoteCommandResponse asRcr = - result.isOK() ? result.getValue() : RemoteCommandResponse(result.getStatus()); - asRcr.target = targetUsed; + RemoteCommandResponse asRcr = result.isOK() + ? result.getValue() + : RemoteCommandResponse(rcb.first.target, result.getStatus()); CallbackHandle cbHandle; setCallbackForHandle(&cbHandle, rcb.second); TaskExecutor::RemoteCommandCallbackFn callback; @@ -344,12 +343,7 @@ void PinnedConnectionTaskExecutor::_doNetworking(stdx::unique_lock& // stream. In any case, we first complete the current request // by invoking it's callback: state = CallbackState::State::kDone; - // Get the target if we successfully acquired a stream. - boost::optional target = boost::none; - if (_stream) { - target = _stream->getClient()->remote(); - } - CallbackState::runCallbackFinished(lk, req, this, result, target); + CallbackState::runCallbackFinished(lk, req, this, result); } // If we weren't able to acquire a stream, shut-down. if (!_stream) { diff --git a/src/mongo/executor/remote_command_response.cpp b/src/mongo/executor/remote_command_response.cpp index 4fe4db15e35db..6ad1fc825e1ef 100644 --- a/src/mongo/executor/remote_command_response.cpp +++ b/src/mongo/executor/remote_command_response.cpp @@ -44,82 +44,46 @@ namespace mongo { namespace executor { -RemoteCommandResponseBase::RemoteCommandResponseBase(ErrorCodes::Error code, std::string reason) - : status(code, reason){}; - -RemoteCommandResponseBase::RemoteCommandResponseBase(ErrorCodes::Error code, - std::string reason, - Microseconds elapsed) - : elapsed(elapsed), status(code, reason) {} - -RemoteCommandResponseBase::RemoteCommandResponseBase(Status s) : status(std::move(s)) { +RemoteCommandResponse::RemoteCommandResponse(HostAndPort hp, Status s) + : status(std::move(s)), target(std::move(hp)) { invariant(!isOK()); -}; +} -RemoteCommandResponseBase::RemoteCommandResponseBase(Status s, Microseconds elapsed) - : elapsed(elapsed), status(std::move(s)) { +RemoteCommandResponse::RemoteCommandResponse(HostAndPort hp, Status s, Microseconds elapsed) + : elapsed(elapsed.count() == 0 ? boost::none : boost::make_optional(elapsed)), + status(std::move(s)), + target(std::move(hp)) { invariant(!isOK()); -}; +} -RemoteCommandResponseBase::RemoteCommandResponseBase(BSONObj dataObj, - Microseconds elapsed, - bool moreToCome) - : data(std::move(dataObj)), elapsed(elapsed), moreToCome(moreToCome) { +RemoteCommandResponse::RemoteCommandResponse(HostAndPort hp, + BSONObj dataObj, + Microseconds elapsed, + bool moreToCome) + : data(std::move(dataObj)), elapsed(elapsed), moreToCome(moreToCome), target(std::move(hp)) { // The buffer backing the default empty BSONObj has static duration so it is effectively // owned. invariant(data.isOwned() || data.objdata() == BSONObj().objdata()); -}; - -// TODO(amidvidy): we currently discard output docs when we use this constructor. We should -// have RCR hold those too, but we need more machinery before that is possible. -RemoteCommandResponseBase::RemoteCommandResponseBase(const rpc::ReplyInterface& rpcReply, - Microseconds elapsed, - bool moreToCome) - : RemoteCommandResponseBase(rpcReply.getCommandReply(), std::move(elapsed), moreToCome) {} - -bool RemoteCommandResponseBase::isOK() const { - return status.isOK(); } -RemoteCommandResponse::RemoteCommandResponse(boost::optional hp, - ErrorCodes::Error code, - std::string reason) - : RemoteCommandResponseBase(code, std::move(reason)), target(std::move(hp)) {} - -RemoteCommandResponse::RemoteCommandResponse(boost::optional hp, - ErrorCodes::Error code, - std::string reason, - Microseconds elapsed) - : RemoteCommandResponseBase(code, std::move(reason), elapsed), target(std::move(hp)) {} - -RemoteCommandResponse::RemoteCommandResponse(boost::optional hp, Status s) - : RemoteCommandResponseBase(std::move(s)), target(std::move(hp)) {} - -RemoteCommandResponse::RemoteCommandResponse(boost::optional hp, - Status s, - Microseconds elapsed) - : RemoteCommandResponseBase(std::move(s), elapsed), target(std::move(hp)) {} - -RemoteCommandResponse::RemoteCommandResponse(HostAndPort hp, BSONObj dataObj, Microseconds elapsed) - : RemoteCommandResponseBase(std::move(dataObj), elapsed), target(std::move(hp)) {} - -RemoteCommandResponse::RemoteCommandResponse(HostAndPort hp, - const rpc::ReplyInterface& rpcReply, - Microseconds elapsed) - : RemoteCommandResponseBase(rpcReply, elapsed), target(std::move(hp)) {} - std::string RemoteCommandResponse::toString() const { - return format(FMT_STRING("RemoteResponse --" + return format(FMT_STRING("RemoteResponse -- " " cmd: {}" + " target: {}" " status: {}" - " elapsed: {}" + " elapsedMicros: {}" " moreToCome: {}"), data.toString(), + target.toString(), status.toString(), elapsed ? StringData(elapsed->toString()) : "n/a"_sd, moreToCome); } +bool RemoteCommandResponse::isOK() const { + return status.isOK(); +} + bool RemoteCommandResponse::operator==(const RemoteCommandResponse& rhs) const { if (this == &rhs) { return true; @@ -136,5 +100,33 @@ std::ostream& operator<<(std::ostream& os, const RemoteCommandResponse& response return os << response.toString(); } +RemoteCommandResponse RemoteCommandResponse::make_forTest(Status s) { + return RemoteCommandResponse(std::move(s)); +} + +RemoteCommandResponse RemoteCommandResponse::make_forTest(Status s, Microseconds elapsed) { + return RemoteCommandResponse(std::move(s), elapsed); +} + +RemoteCommandResponse RemoteCommandResponse::make_forTest(BSONObj dataObj, + Microseconds elapsed, + bool moreToCome) { + return RemoteCommandResponse(std::move(dataObj), elapsed, moreToCome); +} + +RemoteCommandResponse::RemoteCommandResponse(Status s) : status(std::move(s)) { + invariant(!isOK()); +} + +RemoteCommandResponse::RemoteCommandResponse(Status s, Microseconds elapsed) + : elapsed(elapsed.count() == 0 ? boost::none : boost::make_optional(elapsed)), + status(std::move(s)) { + invariant(!isOK()); +} + +RemoteCommandResponse::RemoteCommandResponse(BSONObj dataObj, Microseconds elapsed, bool moreToCome) + : data(std::move(dataObj)), elapsed(elapsed), moreToCome(moreToCome) {} + + } // namespace executor } // namespace mongo diff --git a/src/mongo/executor/remote_command_response.h b/src/mongo/executor/remote_command_response.h index 2674075cebd66..7e6db95ef85d8 100644 --- a/src/mongo/executor/remote_command_response.h +++ b/src/mongo/executor/remote_command_response.h @@ -56,82 +56,49 @@ namespace executor { /** * Type of object describing the response of previously sent RemoteCommandRequest. - */ -struct RemoteCommandResponseBase { - RemoteCommandResponseBase() = default; - - RemoteCommandResponseBase(ErrorCodes::Error code, std::string reason); - - RemoteCommandResponseBase(ErrorCodes::Error code, std::string reason, Microseconds elapsed); - - RemoteCommandResponseBase(Status s); - - RemoteCommandResponseBase(Status s, Microseconds elapsed); - - RemoteCommandResponseBase(BSONObj dataObj, Microseconds elapsed, bool moreToCome = false); - - RemoteCommandResponseBase(const rpc::ReplyInterface& rpcReply, - Microseconds elapsed, - bool moreToCome = false); - - bool isOK() const; - - BSONObj data; // Always owned. May point into message. - boost::optional elapsed; - Status status = Status::OK(); - bool moreToCome = false; // Whether or not the moreToCome bit is set on an exhaust message. - -protected: - ~RemoteCommandResponseBase() = default; -}; - -/** - * This type is a RemoteCommandResponseBase + the target that the origin request was actually run - * on. * * The target member may be used by callers to associate a HostAndPort with the remote or * local error that the RemoteCommandResponse holds. The "status" member will be populated - * with possible local errors, while the "data" member may hold any remote errors. For local - * errors that are not caused by the remote (for example, local shutdown), the target member will - * not be filled. + * with possible local errors, while the "data" member may hold any remote errors. * - * For local errors, the response is associated (by the network interface) with a remote - * HostAndPort for these cases: - * 1. When acquiring a connection to the remote from the pool. - * 2. When using the connection to the remote. - * 3. Enforcing a timeout (propagated or internal) while using the connection to the remote. */ -struct RemoteCommandResponse : RemoteCommandResponseBase { - using RemoteCommandResponseBase::RemoteCommandResponseBase; - - RemoteCommandResponse(boost::optional hp, - ErrorCodes::Error code, - std::string reason); +struct RemoteCommandResponse { + RemoteCommandResponse() = default; - RemoteCommandResponse(boost::optional hp, - ErrorCodes::Error code, - std::string reason, - Microseconds elapsed); + RemoteCommandResponse(HostAndPort hp, Status s); - RemoteCommandResponse(boost::optional hp, Status s); - - RemoteCommandResponse(boost::optional hp, Status s, Microseconds elapsed); - - RemoteCommandResponse(HostAndPort hp, BSONObj dataObj, Microseconds elapsed); + RemoteCommandResponse(HostAndPort hp, Status s, Microseconds elapsed); RemoteCommandResponse(HostAndPort hp, - const rpc::ReplyInterface& rpcReply, - Microseconds elapsed); + BSONObj dataObj, + Microseconds elapsed, + bool moreToCome = false); std::string toString() const; bool operator==(const RemoteCommandResponse& rhs) const; bool operator!=(const RemoteCommandResponse& rhs) const; - boost::optional target; + bool isOK() const; + + static RemoteCommandResponse make_forTest(Status s); + static RemoteCommandResponse make_forTest(Status s, Microseconds elapsed); + static RemoteCommandResponse make_forTest(BSONObj dataObj, + Microseconds elapsed, + bool moreToCome = false); + + BSONObj data; // Always owned. May point into message. + boost::optional elapsed; + Status status = Status::OK(); + bool moreToCome = false; // Whether or not the moreToCome bit is set on an exhaust message. + HostAndPort target; friend std::ostream& operator<<(std::ostream& os, const RemoteCommandResponse& request); -}; +private: + RemoteCommandResponse(Status s); + RemoteCommandResponse(Status s, Microseconds elapsed); + RemoteCommandResponse(BSONObj dataObj, Microseconds elapsed, bool moreToCome); +}; } // namespace executor } // namespace mongo diff --git a/src/mongo/executor/task_executor_cursor.cpp b/src/mongo/executor/task_executor_cursor.cpp index 31010a7650a82..b4136df5b71d8 100644 --- a/src/mongo/executor/task_executor_cursor.cpp +++ b/src/mongo/executor/task_executor_cursor.cpp @@ -185,7 +185,7 @@ TaskExecutorCursor::~TaskExecutorCursor() { // inline. if (!swCallback.isOK()) { TaskExecutor::RemoteCommandCallbackArgs args( - _executor.get(), {}, {}, swCallback.getStatus()); + _executor.get(), {}, {}, {_rcr.target, swCallback.getStatus()}); callbackToRun(args); } } catch (const DBException& ex) { diff --git a/src/mongo/executor/task_executor_test_common.cpp b/src/mongo/executor/task_executor_test_common.cpp index 4a596d373a05a..21748ef5748c2 100644 --- a/src/mongo/executor/task_executor_test_common.cpp +++ b/src/mongo/executor/task_executor_test_common.cpp @@ -607,7 +607,10 @@ COMMON_EXECUTOR_TEST(ScheduleRemoteCommand) { net->enterNetwork(); ASSERT(net->hasReadyRequests()); NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); - net->scheduleResponse(noi, net->now(), {ErrorCodes::NoSuchKey, "I'm missing"}); + net->scheduleResponse( + noi, + net->now(), + RemoteCommandResponse::make_forTest(Status(ErrorCodes::NoSuchKey, "I'm missing"))); net->runReadyNetworkOperations(); ASSERT(!net->hasReadyRequests()); net->exitNetwork(); @@ -812,9 +815,10 @@ COMMON_EXECUTOR_TEST(ScheduleExhaustRemoteCommandIsResolvedWhenMoreToComeFlagIsF NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const Date_t startTime = net->now(); std::list responses = { - std::make_pair(startTime, RemoteCommandResponse(BSONObj{}, Microseconds(), true)), + std::make_pair(startTime, + RemoteCommandResponse::make_forTest(BSONObj{}, Microseconds(), true)), std::make_pair(startTime + Milliseconds(2), - RemoteCommandResponse(BSONObj{}, Microseconds(), false))}; + RemoteCommandResponse::make_forTest(BSONObj{}, Microseconds(), false))}; for (auto& [when, response] : responses) { net->scheduleResponse(noi, when, response); } @@ -853,9 +857,10 @@ COMMON_EXECUTOR_TEST(ScheduleExhaustRemoteCommandIsResolvedWhenCanceled) { NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const Date_t startTime = net->now(); std::list responses = { - std::make_pair(startTime, RemoteCommandResponse(BSONObj{}, Microseconds(), true)), + std::make_pair(startTime, + RemoteCommandResponse::make_forTest(BSONObj{}, Microseconds(), true)), std::make_pair(startTime + Milliseconds(2), - RemoteCommandResponse(BSONObj{}, Microseconds(), false))}; + RemoteCommandResponse::make_forTest(BSONObj{}, Microseconds(), false))}; for (auto& [when, response] : responses) { net->scheduleResponse(noi, when, response); } @@ -906,11 +911,13 @@ COMMON_EXECUTOR_TEST(ScheduleExhaustRemoteCommandSwallowsErrorsWhenMoreToComeFla ASSERT(net->hasReadyRequests()); NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const Date_t startTime = net->now(); - RemoteCommandResponse error_response{ErrorCodes::NoSuchKey, "I'm missing"}; + RemoteCommandResponse error_response = + RemoteCommandResponse::make_forTest(Status(ErrorCodes::NoSuchKey, "I'm missing")); error_response.moreToCome = true; - std::list responses = {std::make_pair(startTime, error_response), - std::make_pair(startTime + Milliseconds(2), - RemoteCommandResponse(BSONObj{}, Microseconds(), false))}; + std::list responses = { + std::make_pair(startTime, error_response), + std::make_pair(startTime + Milliseconds(2), + RemoteCommandResponse::make_forTest(BSONObj{}, Microseconds(), false))}; for (auto& [when, response] : responses) { net->scheduleResponse(noi, when, response); } @@ -948,7 +955,8 @@ COMMON_EXECUTOR_TEST( ASSERT(net->hasReadyRequests()); NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const Date_t startTime = net->now(); - net->scheduleResponse(noi, startTime, RemoteCommandResponse(BSONObj{}, Microseconds(), false)); + net->scheduleResponse( + noi, startTime, RemoteCommandResponse::make_forTest(BSONObj{}, Microseconds(), false)); net->runUntil(startTime + Milliseconds(1)); ASSERT_EQUALS(numTimesCallbackCalled, 1); @@ -988,9 +996,10 @@ COMMON_EXECUTOR_TEST(ScheduleExhaustRemoteCommandFutureIsResolvedWhenMoreToComeF NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const Date_t startTime = net->now(); std::list responses = { - std::make_pair(startTime, RemoteCommandResponse(BSONObj{}, Microseconds(), true)), + std::make_pair(startTime, + RemoteCommandResponse::make_forTest(BSONObj{}, Microseconds(), true)), std::make_pair(startTime + Milliseconds(2), - RemoteCommandResponse(BSONObj{}, Microseconds(), false))}; + RemoteCommandResponse::make_forTest(BSONObj{}, Microseconds(), false))}; for (auto& [when, response] : responses) { net->scheduleResponse(noi, when, response); } @@ -1033,7 +1042,10 @@ COMMON_EXECUTOR_TEST(ScheduleExhaustRemoteCommandFutureIsResolvedWhenErrorRespon // Respond to the request. ASSERT(net->hasReadyRequests()); NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); - net->scheduleResponse(noi, net->now(), {ErrorCodes::NoSuchKey, "I'm missing"}); + net->scheduleResponse( + noi, + net->now(), + RemoteCommandResponse::make_forTest(Status(ErrorCodes::NoSuchKey, "I'm missing"))); net->runReadyNetworkOperations(); ASSERT_EQUALS(numTimesCallbackCalled, 1); @@ -1073,11 +1085,13 @@ COMMON_EXECUTOR_TEST(ScheduleExhaustRemoteCommandFutureSwallowsErrorsWhenMoreToC // Respond to the request. ASSERT(net->hasReadyRequests()); NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); - RemoteCommandResponse error_response{ErrorCodes::NoSuchKey, "I'm missing"}; + RemoteCommandResponse error_response = + RemoteCommandResponse::make_forTest(Status(ErrorCodes::NoSuchKey, "I'm missing")); error_response.moreToCome = true; - auto responses = {std::make_pair(startTime, error_response), - std::make_pair(startTime + Milliseconds(2), - RemoteCommandResponse(BSONObj{}, Microseconds(), false))}; + auto responses = { + std::make_pair(startTime, error_response), + std::make_pair(startTime + Milliseconds(2), + RemoteCommandResponse::make_forTest(BSONObj{}, Microseconds(), false))}; for (auto& [when, response] : responses) { net->scheduleResponse(noi, when, response); } @@ -1121,9 +1135,10 @@ COMMON_EXECUTOR_TEST(ScheduleExhaustRemoteCommandFutureIsResolvedWithErrorOnCanc NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest(); const Date_t startTime = net->now(); std::list responses = { - std::make_pair(startTime, RemoteCommandResponse(BSONObj{}, Microseconds(), true)), + std::make_pair(startTime, + RemoteCommandResponse::make_forTest(BSONObj{}, Microseconds(), true)), std::make_pair(startTime + Milliseconds(2), - RemoteCommandResponse(BSONObj{}, Microseconds(), false))}; + RemoteCommandResponse::make_forTest(BSONObj{}, Microseconds(), false))}; for (auto& [when, response] : responses) { net->scheduleResponse(noi, when, response); } diff --git a/src/mongo/executor/thread_pool_task_executor.cpp b/src/mongo/executor/thread_pool_task_executor.cpp index f3d0afeb4212a..024abed8ce42e 100644 --- a/src/mongo/executor/thread_pool_task_executor.cpp +++ b/src/mongo/executor/thread_pool_task_executor.cpp @@ -442,7 +442,7 @@ void remoteCommandFailedEarly(const TaskExecutor::CallbackArgs& cbData, const TaskExecutor::RemoteCommandCallbackFn& cb, const RemoteCommandRequest& request) { invariant(!cbData.status.isOK()); - cb({cbData.executor, cbData.myHandle, request, {boost::none, cbData.status}}); + cb({cbData.executor, cbData.myHandle, request, {request.target, cbData.status}}); } } // namespace diff --git a/src/mongo/idl/cluster_server_parameter_common.cpp b/src/mongo/idl/cluster_server_parameter_common.cpp index 174a416b29710..77c0b81e1dde3 100644 --- a/src/mongo/idl/cluster_server_parameter_common.cpp +++ b/src/mongo/idl/cluster_server_parameter_common.cpp @@ -83,8 +83,8 @@ StatusWith>> getTenantsWithConfigDbsOnShard( executor::RemoteCommandRequest request( host, DatabaseName::kAdmin, listDbCommand.toBSON(), opCtx); - executor::RemoteCommandResponse response = - Status(ErrorCodes::InternalError, "Internal error running command"); + executor::RemoteCommandResponse response( + host, Status(ErrorCodes::InternalError, "Internal error running command")); auto swCallbackHandle = executor->scheduleRemoteCommand( request, [&response](const executor::TaskExecutor::RemoteCommandCallbackArgs& args) { diff --git a/src/mongo/s/append_raw_responses_test.cpp b/src/mongo/s/append_raw_responses_test.cpp index 9414e5114b072..72a641f6943db 100644 --- a/src/mongo/s/append_raw_responses_test.cpp +++ b/src/mongo/s/append_raw_responses_test.cpp @@ -93,13 +93,14 @@ const Status kError2Status{ErrorCodes::HostUnreachable, "dummy"}; const Status kWriteConcernError1Status{ErrorCodes::WriteConcernFailed, "dummy"}; const Status kWriteConcernError2Status{ErrorCodes::UnsatisfiableWriteConcern, "dummy"}; -executor::RemoteCommandResponse kOkResponse{BSON("ok" << 1), Milliseconds(0)}; +executor::RemoteCommandResponse kOkResponse = + executor::RemoteCommandResponse::make_forTest(BSON("ok" << 1), Milliseconds(0)); executor::RemoteCommandResponse makeErrorResponse(const Status& errorStatus) { invariant(!errorStatus.isOK()); BSONObjBuilder res; CommandHelpers::appendCommandStatusNoThrow(res, errorStatus); - return {res.obj(), Milliseconds(0)}; + return executor::RemoteCommandResponse::make_forTest(res.obj(), Milliseconds(0)); } executor::RemoteCommandResponse makeWriteConcernErrorResponse( @@ -110,7 +111,7 @@ executor::RemoteCommandResponse makeWriteConcernErrorResponse( wcError.setStatus(writeConcernErrorStatus); res.append("ok", 1); res.append("writeConcernError", wcError.toBSON()); - return {res.obj(), Milliseconds(0)}; + return executor::RemoteCommandResponse::make_forTest(res.obj(), Milliseconds(0)); } HostAndPort makeHostAndPort(const ShardId& shardId) { diff --git a/src/mongo/s/async_requests_sender.cpp b/src/mongo/s/async_requests_sender.cpp index a7e78d425ee12..6e7aea6ba2d84 100644 --- a/src/mongo/s/async_requests_sender.cpp +++ b/src/mongo/s/async_requests_sender.cpp @@ -322,14 +322,14 @@ auto AsyncRequestsSender::RemoteData::scheduleRemoteCommand(std::vector SemiFuture { - if (rcr.response.target) { - _shardHostAndPort = rcr.response.target; - } + _shardHostAndPort = rcr.response.target; auto status = rcr.response.status; + bool isRemote = false; if (status.isOK()) { status = getStatusFromCommandResult(rcr.response.data); + isRemote = true; } if (status.isOK()) { @@ -345,10 +345,10 @@ auto AsyncRequestsSender::RemoteData::handleResponse(RemoteCommandCallbackArgs&& // There was an error with either the response or the command. return getShard() .thenRunOn(*_ars->_subBaton) - .then([this, status = std::move(status), rcr = std::move(rcr)]( + .then([this, status = std::move(status), rcr = std::move(rcr), isRemote]( std::shared_ptr&& shard) { - if (rcr.response.target) { - shard->updateReplSetMonitor(*rcr.response.target, status); + if (!ErrorCodes::isShutdownError(status.code()) || isRemote) { + shard->updateReplSetMonitor(rcr.response.target, status); } bool isStartingTransaction = _cmdObj.getField("startTransaction").booleanSafe(); diff --git a/src/mongo/s/client/shard_remote.cpp b/src/mongo/s/client/shard_remote.cpp index 70c160f35970b..c5562de4e50b8 100644 --- a/src/mongo/s/client/shard_remote.cpp +++ b/src/mongo/s/client/shard_remote.cpp @@ -155,10 +155,7 @@ StatusWith ShardRemote::_runCommand(OperationContext* op const DatabaseName& dbName, Milliseconds maxTimeMSOverride, const BSONObj& cmdObj) { - RemoteCommandResponse response = - Status(ErrorCodes::InternalError, - str::stream() << "Failed to run remote command request cmd: " << cmdObj); - + boost::optional response; auto asyncStatus = _scheduleCommand( opCtx, readPref, @@ -188,17 +185,21 @@ StatusWith ShardRemote::_runCommand(OperationContext* op return e.toStatus(); } + // After wait returns successfully, the callback in _scheduleCommand is guaranteed to have run + // and set the response. + invariant(response); + const auto& host = asyncHandle.hostTargetted; - updateReplSetMonitor(host, response.status); + updateReplSetMonitor(host, response->status); - if (!response.status.isOK()) { - if (ErrorCodes::isExceededTimeLimitError(response.status.code())) { - LOGV2(22739, "Operation timed out", "error"_attr = redact(response.status)); + if (!response->status.isOK()) { + if (ErrorCodes::isExceededTimeLimitError(response->status.code())) { + LOGV2(22739, "Operation timed out", "error"_attr = redact(response->status)); } - return response.status; + return response->status; } - auto result = response.data.getOwned(); + auto result = response->data.getOwned(); auto commandStatus = getStatusFromCommandResult(result); auto writeConcernStatus = getWriteConcernStatusFromCommandResult(result); diff --git a/src/mongo/s/commands/query_cmd/cluster_find_and_modify_cmd.cpp b/src/mongo/s/commands/query_cmd/cluster_find_and_modify_cmd.cpp index f9887bd5e7f88..01dbc91acb8a7 100644 --- a/src/mongo/s/commands/query_cmd/cluster_find_and_modify_cmd.cpp +++ b/src/mongo/s/commands/query_cmd/cluster_find_and_modify_cmd.cpp @@ -698,13 +698,13 @@ Status FindAndModifyCmd::explain(OperationContext* opCtx, const auto millisElapsed = timer.millis(); - executor::RemoteCommandResponse response(bob.obj(), Milliseconds(millisElapsed)); - // We fetch an arbitrary host from the ConnectionString, since // ClusterExplain::buildExplainResult() doesn't use the given HostAndPort. auto shard = uassertStatusOK(Grid::get(opCtx)->shardRegistry()->getShard(opCtx, *shardId)); - AsyncRequestsSender::Response arsResponse{ - *shardId, response, shard->getConnString().getServers().front()}; + auto host = shard->getConnString().getServers().front(); + + executor::RemoteCommandResponse response(host, bob.obj(), Milliseconds(millisElapsed)); + AsyncRequestsSender::Response arsResponse{*shardId, response, host}; return ClusterExplain::buildExplainResult( ExpressionContext::makeBlankExpressionContext(opCtx, nss), diff --git a/src/mongo/s/query/exec/async_results_merger_test.cpp b/src/mongo/s/query/exec/async_results_merger_test.cpp index 7053bcf388c6c..75a218fbd7d8e 100644 --- a/src/mongo/s/query/exec/async_results_merger_test.cpp +++ b/src/mongo/s/query/exec/async_results_merger_test.cpp @@ -762,7 +762,8 @@ TEST_F(AsyncResultsMergerTest, ErrorReceivedFromShard) { responses.emplace_back(kTestNss, CursorId(2), batch2); scheduleNetworkResponses(std::move(responses)); - scheduleErrorResponse({ErrorCodes::BadValue, "bad thing happened"}); + scheduleErrorResponse(executor::RemoteCommandResponse::make_forTest( + Status(ErrorCodes::BadValue, "bad thing happened"))); executor()->waitForEvent(readyEvent); ASSERT_TRUE(arm->ready()); @@ -1222,7 +1223,8 @@ TEST_F(AsyncResultsMergerTest, AllowPartialResults) { ASSERT_FALSE(arm->ready()); // An error occurs with the first host. - scheduleErrorResponse({ErrorCodes::AuthenticationFailed, "authentication failed"}); + scheduleErrorResponse(executor::RemoteCommandResponse::make_forTest( + Status(ErrorCodes::AuthenticationFailed, "authentication failed"))); ASSERT_FALSE(arm->ready()); // Instead of propagating the error, we should be willing to return results from the two @@ -1246,7 +1248,8 @@ TEST_F(AsyncResultsMergerTest, AllowPartialResults) { // Now the second host becomes unreachable. We should still be willing to return results from // the third shard. - scheduleErrorResponse({ErrorCodes::AuthenticationFailed, "authentication failed"}); + scheduleErrorResponse(executor::RemoteCommandResponse::make_forTest( + Status(ErrorCodes::AuthenticationFailed, "authentication failed"))); ASSERT_FALSE(arm->ready()); responses.clear(); @@ -1301,7 +1304,8 @@ TEST_F(AsyncResultsMergerTest, AllowPartialResultsSingleNode) { // The lone host involved in this query returns an error. This should simply cause us to return // EOF. - scheduleErrorResponse({ErrorCodes::AuthenticationFailed, "authentication failed"}); + scheduleErrorResponse(executor::RemoteCommandResponse::make_forTest( + Status(ErrorCodes::AuthenticationFailed, "authentication failed"))); ASSERT_TRUE(arm->ready()); ASSERT_TRUE(unittest::assertGet(arm->nextReady()).isEOF()); } @@ -1326,7 +1330,8 @@ TEST_F(AsyncResultsMergerTest, AllowPartialResultsOnRetriableErrorNoRetries) { scheduleNetworkResponses(std::move(responses)); // From the second host we get a network (retriable) error. - scheduleErrorResponse({ErrorCodes::HostUnreachable, "host unreachable"}); + scheduleErrorResponse(executor::RemoteCommandResponse::make_forTest( + Status(ErrorCodes::HostUnreachable, "host unreachable"))); executor()->waitForEvent(readyEvent); ASSERT_TRUE(arm->ready()); @@ -1360,7 +1365,8 @@ TEST_F(AsyncResultsMergerTest, MaxTimeMSExpiredAllowPartialResultsTrue) { scheduleNetworkResponses(std::move(responses)); // From the second host we get a MaxTimeMSExpired error. - scheduleErrorResponse({ErrorCodes::MaxTimeMSExpired, "MaxTimeMSExpired"}); + scheduleErrorResponse(executor::RemoteCommandResponse::make_forTest( + Status(ErrorCodes::MaxTimeMSExpired, "MaxTimeMSExpired"))); executor()->waitForEvent(readyEvent); @@ -1396,7 +1402,8 @@ TEST_F(AsyncResultsMergerTest, MaxTimeMSExpiredAllowPartialResultsFalse) { scheduleNetworkResponses(std::move(responses)); // From the second host we get a MaxTimeMSExpired error. - scheduleErrorResponse({ErrorCodes::MaxTimeMSExpired, "MaxTimeMSExpired"}); + scheduleErrorResponse(executor::RemoteCommandResponse::make_forTest( + Status(ErrorCodes::MaxTimeMSExpired, "MaxTimeMSExpired"))); executor()->waitForEvent(readyEvent); @@ -1424,7 +1431,8 @@ TEST_F(AsyncResultsMergerTest, AllowPartialResultsOnMaxTimeMSExpiredThenLateData ASSERT_FALSE(arm->ready()); // From the first host we get a MaxTimeMSExpired error. - scheduleErrorResponse({ErrorCodes::MaxTimeMSExpired, "MaxTimeMSExpired"}); + scheduleErrorResponse(executor::RemoteCommandResponse::make_forTest( + Status(ErrorCodes::MaxTimeMSExpired, "MaxTimeMSExpired"))); // Second host returns single result *after* first host times out. std::vector responses; @@ -1455,8 +1463,10 @@ TEST_F(AsyncResultsMergerTest, ReturnsErrorOnRetriableError) { ASSERT_FALSE(arm->ready()); // Both hosts return network (retriable) errors. - scheduleErrorResponse({ErrorCodes::HostUnreachable, "host unreachable"}); - scheduleErrorResponse({ErrorCodes::HostUnreachable, "host unreachable"}); + scheduleErrorResponse(executor::RemoteCommandResponse::make_forTest( + Status(ErrorCodes::HostUnreachable, "host unreachable"))); + scheduleErrorResponse(executor::RemoteCommandResponse::make_forTest( + Status(ErrorCodes::HostUnreachable, "host unreachable"))); executor()->waitForEvent(readyEvent); ASSERT_TRUE(arm->ready()); @@ -2013,7 +2023,8 @@ TEST_F(AsyncResultsMergerTest, ShardCanErrorInBetweenReadyAndNextEvent) { ASSERT_FALSE(arm->ready()); auto readyEvent = unittest::assertGet(arm->nextEvent()); - scheduleErrorResponse({ErrorCodes::BadValue, "bad thing happened"}); + scheduleErrorResponse(executor::RemoteCommandResponse::make_forTest( + Status(ErrorCodes::BadValue, "bad thing happened"))); ASSERT_EQ(ErrorCodes::BadValue, arm->nextEvent().getStatus()); diff --git a/src/mongo/s/query/exec/results_merger_test_fixture.h b/src/mongo/s/query/exec/results_merger_test_fixture.h index a0e5ab661db9c..a22082eb53842 100644 --- a/src/mongo/s/query/exec/results_merger_test_fixture.h +++ b/src/mongo/s/query/exec/results_merger_test_fixture.h @@ -217,7 +217,8 @@ class ResultsMergerTestFixture : public virtual service_context_test::RouterRole for (const auto& obj : objs) { ASSERT_TRUE(net->hasReadyRequests()); Milliseconds millis(0); - executor::RemoteCommandResponse response(obj, millis); + executor::RemoteCommandResponse response = + executor::RemoteCommandResponse::make_forTest(obj, millis); executor::TaskExecutor::ResponseStatus responseStatus(response); net->scheduleResponse(net->getNextReadyRequest(), net->now(), responseStatus); } diff --git a/src/mongo/s/sharding_task_executor.cpp b/src/mongo/s/sharding_task_executor.cpp index 5f01c4cf0894d..115000532503e 100644 --- a/src/mongo/s/sharding_task_executor.cpp +++ b/src/mongo/s/sharding_task_executor.cpp @@ -191,11 +191,7 @@ StatusWith ShardingTaskExecutor::scheduleRemoteCom if (!args.response.isOK()) { HostAndPort target; - if (args.response.target) { - target = *args.response.target; - } else { - target = hosts; - } + target = args.response.target; auto shard = grid->shardRegistry()->getShardForHostNoReload(target); @@ -225,9 +221,7 @@ StatusWith ShardingTaskExecutor::scheduleRemoteCom return; } - invariant(args.response.target); - - auto target = *args.response.target; + auto target = args.response.target; auto shard = grid->shardRegistry()->getShardForHostNoReload(target); diff --git a/src/mongo/s/write_ops/bulk_write_exec_test.cpp b/src/mongo/s/write_ops/bulk_write_exec_test.cpp index ece9bdc0c7573..9c1da8adb2b60 100644 --- a/src/mongo/s/write_ops/bulk_write_exec_test.cpp +++ b/src/mongo/s/write_ops/bulk_write_exec_test.cpp @@ -2116,10 +2116,11 @@ class BulkWriteOpChildBatchErrorTest : public ServiceContextTest { static const inline AsyncRequestsSender::Response kRemoteInterruptedResponse = AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") - .toBSON(), - Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") + .toBSON(), + Microseconds(0))), boost::none}; // We use a custom non-transient error code to confirm that we do not try to determine if an @@ -2129,14 +2130,15 @@ class BulkWriteOpChildBatchErrorTest : public ServiceContextTest { static const inline AsyncRequestsSender::Response kCustomRemoteTransientErrorResponse = AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - [] { - auto error = ErrorReply( - 0, kCustomErrorCode, "CustomError", "simulating custom error for test"); - error.setErrorLabels(std::vector{ErrorLabel::kTransientTransaction}); - return error.toBSON(); - }(), - Microseconds(1))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + [] { + auto error = ErrorReply( + 0, kCustomErrorCode, "CustomError", "simulating custom error for test"); + error.setErrorLabels(std::vector{ErrorLabel::kTransientTransaction}); + return error.toBSON(); + }(), + Microseconds(1))), boost::none}; TargetedBatchMap targetOp(BulkWriteOp& op, bool ordered) const { @@ -2725,7 +2727,7 @@ TEST_F(BulkWriteOpChildBatchErrorTest, WouldChangeOwningShardInTxn) { AsyncRequestsSender::Response wcosResponse = AsyncRequestsSender::Response{ kShardId1, StatusWith( - executor::RemoteCommandResponse(wcosInfo, Microseconds(0))), + executor::RemoteCommandResponse::make_forTest(wcosInfo, Microseconds(0))), boost::none}; // Simulate a WouldChangeOwningShardError. @@ -3580,11 +3582,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatch) { // Simulate ok:1 n:0 response from shard1. op.processChildBatchResponseFromRemote( *targeted[kShardId1].get(), - AsyncRequestsSender::Response{ - kShardId1, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponse, Microseconds(0))), + boost::none}, boost::none); auto& updateOp = op.getWriteOp_forTest(0); @@ -3601,11 +3603,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatch) { // Simulate ok:1 n:0 response from shard2. op.processChildBatchResponseFromRemote( *targeted[kShardId2].get(), - AsyncRequestsSender::Response{ - kShardId2, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId2, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponse, Microseconds(0))), + boost::none}, boost::none); // We are still missing one reply so should still be pending and continuing current round. ASSERT_EQ(updateOp.getWriteState(), WriteOpState_Pending); @@ -3619,11 +3621,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatch) { // Simulate ok:1 n:0 response from shard3. op.processChildBatchResponseFromRemote( *targeted[kShardId3].get(), - AsyncRequestsSender::Response{ - kShardId3, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId3, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponse, Microseconds(0))), + boost::none}, boost::none); // Now that we got replies from all shards the write should be complete. ASSERT_EQ(updateOp.getWriteState(), WriteOpState_Completed); @@ -3653,8 +3655,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatchBatched) { *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -3681,8 +3684,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatchBatched) { *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -3705,8 +3709,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatchBatched) { *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -3741,8 +3746,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatchErrorsOnlyMode) { *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseErrorsOnly, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest(kBulkWriteNoMatchResponseErrorsOnly, + Microseconds(0))), boost::none}, boost::none); @@ -3762,8 +3768,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatchErrorsOnlyMode) { *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseErrorsOnly, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest(kBulkWriteNoMatchResponseErrorsOnly, + Microseconds(0))), boost::none}, boost::none); // We are still missing one reply so should still be pending and continuing current round. @@ -3780,8 +3787,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatchErrorsOnlyMode) { *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseErrorsOnly, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest(kBulkWriteNoMatchResponseErrorsOnly, + Microseconds(0))), boost::none}, boost::none); // Now that we got replies from all shards the write should be complete. @@ -3814,8 +3822,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatchErrorsOnlyModeBatc *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -3841,8 +3850,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatchErrorsOnlyModeBatc *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); // We are still missing one reply so should still be pending and continuing current round. @@ -3864,8 +3874,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoShardFindsMatchErrorsOnlyModeBatc *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -3893,11 +3904,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatch) { // Simulate ok:1 n:0 response from shard1. op.processChildBatchResponseFromRemote( *targeted[kShardId1].get(), - AsyncRequestsSender::Response{ - kShardId1, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponse, Microseconds(0))), + boost::none}, boost::none); auto& updateOp = op.getWriteOp_forTest(0); @@ -3914,11 +3925,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatch) { // Simulate ok:1 n:1 response from shard2. op.processChildBatchResponseFromRemote( *targeted[kShardId2].get(), - AsyncRequestsSender::Response{ - kShardId2, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteUpdateMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId2, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponse, Microseconds(0))), + boost::none}, boost::none); // Because we got a n=1 response we should immediately consider the write to be done and @@ -3954,8 +3965,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchBatched) { *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -3981,8 +3993,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchBatched) { *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4007,8 +4020,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchBatched) { *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteUpdateMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4058,8 +4072,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchErrorsOnlyMode) *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseErrorsOnly, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest(kBulkWriteNoMatchResponseErrorsOnly, + Microseconds(0))), boost::none}, boost::none); @@ -4079,8 +4094,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchErrorsOnlyMode) *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteUpdateMatchResponseErrorsOnly, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponseErrorsOnly, Microseconds(0))), boost::none}, boost::none); @@ -4116,8 +4132,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchErrorsOnlyModeB *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4141,8 +4158,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchErrorsOnlyModeB *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4164,8 +4182,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchErrorsOnlyModeB *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteUpdateMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponseErrorsOnlyMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4212,11 +4231,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchForDelete) { // Simulate ok:1 n:0 response from shard1. op.processChildBatchResponseFromRemote( *targeted[kShardId1].get(), - AsyncRequestsSender::Response{ - kShardId1, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponse, Microseconds(0))), + boost::none}, boost::none); auto& deleteOp = op.getWriteOp_forTest(0); @@ -4233,11 +4252,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchForDelete) { // Simulate ok:1 n:1 response from shard2. op.processChildBatchResponseFromRemote( *targeted[kShardId2].get(), - AsyncRequestsSender::Response{ - kShardId2, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteDeleteMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId2, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteDeleteMatchResponse, Microseconds(0))), + boost::none}, boost::none); // Because we got a n=1 response we should immediately consider the write to be done and @@ -4275,8 +4294,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchForDeleteBatche *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4302,8 +4322,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchForDeleteBatche *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteDeleteMixedMatchResponseMultipleWriteOps1, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteDeleteMixedMatchResponseMultipleWriteOps1, Microseconds(0))), boost::none}, boost::none); @@ -4326,8 +4347,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, SecondShardFindMatchForDeleteBatche *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteDeleteMixedMatchResponseMultipleWriteOps2, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteDeleteMixedMatchResponseMultipleWriteOps2, Microseconds(0))), boost::none}, boost::none); @@ -4370,11 +4392,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, FirstShardFindMatch) { // Simulate ok:1 n:1 response from shard1. op.processChildBatchResponseFromRemote( *targeted[kShardId1].get(), - AsyncRequestsSender::Response{ - kShardId1, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteUpdateMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponse, Microseconds(0))), + boost::none}, boost::none); auto& updateOp = op.getWriteOp_forTest(0); @@ -4403,8 +4425,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, FirstShardFindMatchAndWCError) { *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteUpdateMatchResponseWithWCE, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest(kBulkWriteUpdateMatchResponseWithWCE, + Microseconds(0))), boost::none}, boost::none); @@ -4437,8 +4460,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, FirstShardFindMatchAndWCErrorBatche *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteUpdateMatchResponseWithWCEMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponseWithWCEMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4447,8 +4471,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, FirstShardFindMatchAndWCErrorBatche *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4457,8 +4482,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, FirstShardFindMatchAndWCErrorBatche *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4495,11 +4521,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableError) { // Simulate ok:1 n:0 response from shard1. op.processChildBatchResponseFromRemote( *targeted[kShardId1].get(), - AsyncRequestsSender::Response{ - kShardId1, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponse, Microseconds(0))), + boost::none}, boost::none); auto& updateOp = op.getWriteOp_forTest(0); @@ -4516,11 +4542,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableError) { // Simulate ok:1 n:0 response from shard2. op.processChildBatchResponseFromRemote( *targeted[kShardId2].get(), - AsyncRequestsSender::Response{ - kShardId2, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId2, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponse, Microseconds(0))), + boost::none}, boost::none); // We are still missing one reply so should still be pending and continuing current round. ASSERT_EQ(updateOp.getWriteState(), WriteOpState_Pending); @@ -4534,11 +4560,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableError) { // Simulate StaleConfig response from shard3. op.processChildBatchResponseFromRemote( *targeted[kShardId3].get(), - AsyncRequestsSender::Response{ - kShardId3, - StatusWith( - executor::RemoteCommandResponse(kStaleConfigReplyShard3, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId3, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kStaleConfigReplyShard3, Microseconds(0))), + boost::none}, boost::none); // Due to the retry error, we should have reset the write to ready and cleared the child ops. @@ -4571,8 +4597,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorBatched) { *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4598,8 +4625,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorBatched) { *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4623,8 +4651,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorBatched) { *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - kStaleConfigReplyShard3MultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kStaleConfigReplyShard3MultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4652,11 +4681,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorAndWCError) // Simulate ok:1 n:0 response with WCE from shard1. op.processChildBatchResponseFromRemote( *targeted[kShardId1].get(), - AsyncRequestsSender::Response{ - kShardId1, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponseWithWCE, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseWithWCE, Microseconds(0))), + boost::none}, boost::none); auto& updateOp = op.getWriteOp_forTest(0); @@ -4673,11 +4702,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorAndWCError) // Simulate ok:1 n:0 response with WCE from shard2. op.processChildBatchResponseFromRemote( *targeted[kShardId2].get(), - AsyncRequestsSender::Response{ - kShardId2, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponseWithWCE, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId2, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseWithWCE, Microseconds(0))), + boost::none}, boost::none); // We are still missing one reply so should still be pending and continuing current round. ASSERT_EQ(updateOp.getWriteState(), WriteOpState_Pending); @@ -4691,11 +4720,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorAndWCError) // Simulate StaleConfig response from shard3. op.processChildBatchResponseFromRemote( *targeted[kShardId3].get(), - AsyncRequestsSender::Response{ - kShardId3, - StatusWith( - executor::RemoteCommandResponse(kStaleConfigReplyShard3, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId3, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kStaleConfigReplyShard3, Microseconds(0))), + boost::none}, boost::none); // Due to the retry error, we should have reset the write to ready and cleared the child ops. @@ -4713,11 +4742,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorAndWCError) // Simulate ok:1, n:1 response from shard1. op.processChildBatchResponseFromRemote( *targeted[kShardId1].get(), - AsyncRequestsSender::Response{ - kShardId1, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteUpdateMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponse, Microseconds(0))), + boost::none}, boost::none); // Since we got an n=1 reply we are done. @@ -4752,8 +4781,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorAndWCErrorB *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseWithWCEMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseWithWCEMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4778,8 +4808,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorAndWCErrorB *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseWithWCEMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseWithWCEMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); // We are still missing one reply so should still be pending and continuing current round. @@ -4800,8 +4831,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorAndWCErrorB *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - kStaleConfigReplyShard3MultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kStaleConfigReplyShard3MultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4823,8 +4855,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorAndWCErrorB *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteUpdateMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4832,8 +4865,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorAndWCErrorB *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4841,8 +4875,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndRetryableErrorAndWCErrorB *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4886,8 +4921,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndRetryableErrorBatched) { *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4913,8 +4949,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndRetryableErrorBatched) { *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - kStaleConfigReplyShard3MultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kStaleConfigReplyShard3MultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4942,8 +4979,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndRetryableErrorBatched) { *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteUpdateMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -4969,11 +5007,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndRetryableError) { // Simulate ok:1 n:0 response from shard1. op.processChildBatchResponseFromRemote( *targeted[kShardId1].get(), - AsyncRequestsSender::Response{ - kShardId1, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponse, Microseconds(0))), + boost::none}, boost::none); auto& updateOp = op.getWriteOp_forTest(0); @@ -4990,11 +5028,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndRetryableError) { // Simulate StaleConfig response from shard3. op.processChildBatchResponseFromRemote( *targeted[kShardId3].get(), - AsyncRequestsSender::Response{ - kShardId3, - StatusWith( - executor::RemoteCommandResponse(kStaleConfigReplyShard3, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId3, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kStaleConfigReplyShard3, Microseconds(0))), + boost::none}, boost::none); // Still waiting on a response from shard2, so we are pending. @@ -5012,11 +5050,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndRetryableError) { // Simulate ok:1 n:1 response from shard2. op.processChildBatchResponseFromRemote( *targeted[kShardId2].get(), - AsyncRequestsSender::Response{ - kShardId2, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteUpdateMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId2, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponse, Microseconds(0))), + boost::none}, boost::none); // Despite the retry error, we should consider the write a success since we got an n=1 @@ -5041,11 +5079,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableError) { // Simulate ok:1 n:0 response from shard1. op.processChildBatchResponseFromRemote( *targeted[kShardId1].get(), - AsyncRequestsSender::Response{ - kShardId1, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponse, Microseconds(0))), + boost::none}, boost::none); auto& updateOp = op.getWriteOp_forTest(0); @@ -5062,11 +5100,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableError) { // Simulate ok:1 n:0 response from shard2. op.processChildBatchResponseFromRemote( *targeted[kShardId2].get(), - AsyncRequestsSender::Response{ - kShardId2, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId2, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponse, Microseconds(0))), + boost::none}, boost::none); // We are still missing one reply so should still be pending and continuing current round. ASSERT_EQ(updateOp.getWriteState(), WriteOpState_Pending); @@ -5082,10 +5120,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableError) { *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") - .toBSON(), - Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") + .toBSON(), + Microseconds(0))), boost::none}, boost::none); @@ -5114,8 +5153,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableErrorMatched) *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -5141,8 +5181,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableErrorMatched) *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); // We are still missing one reply so should still be pending and continuing current round. @@ -5164,10 +5205,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableErrorMatched) *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") - .toBSON(), - Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") + .toBSON(), + Microseconds(0))), boost::none}, boost::none); @@ -5195,11 +5237,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableErrorAndWCErr // Simulate ok:1 n:0 response from shard1. op.processChildBatchResponseFromRemote( *targeted[kShardId1].get(), - AsyncRequestsSender::Response{ - kShardId1, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponseWithWCE, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseWithWCE, Microseconds(0))), + boost::none}, boost::none); auto& updateOp = op.getWriteOp_forTest(0); @@ -5216,11 +5258,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableErrorAndWCErr // Simulate ok:1 n:0 response from shard2. op.processChildBatchResponseFromRemote( *targeted[kShardId2].get(), - AsyncRequestsSender::Response{ - kShardId2, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponseWithWCE, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId2, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseWithWCE, Microseconds(0))), + boost::none}, boost::none); // We are still missing one reply so should still be pending and continuing current round. ASSERT_EQ(updateOp.getWriteState(), WriteOpState_Pending); @@ -5236,10 +5278,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableErrorAndWCErr *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") - .toBSON(), - Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") + .toBSON(), + Microseconds(0))), boost::none}, boost::none); @@ -5271,8 +5314,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableErrorAndWCErr *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseWithWCEMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseWithWCEMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -5297,8 +5341,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableErrorAndWCErr *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseWithWCEMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseWithWCEMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); // We are still missing one reply so should still be pending and continuing current round. @@ -5319,10 +5364,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, NoMatchAndNonRetryableErrorAndWCErr *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") - .toBSON(), - Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") + .toBSON(), + Microseconds(0))), boost::none}, boost::none); @@ -5359,8 +5405,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndNonRetryableErrorBatched) { *targeted[kShardId1].get(), AsyncRequestsSender::Response{ kShardId1, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -5386,10 +5433,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndNonRetryableErrorBatched) { *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") - .toBSON(), - Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") + .toBSON(), + Microseconds(0))), boost::none}, boost::none); @@ -5412,8 +5460,9 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndNonRetryableErrorBatched) { *targeted[kShardId2].get(), AsyncRequestsSender::Response{ kShardId2, - StatusWith(executor::RemoteCommandResponse( - kBulkWriteUpdateMatchResponseMultipleWriteOps, Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponseMultipleWriteOps, Microseconds(0))), boost::none}, boost::none); @@ -5441,11 +5490,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndNonRetryableError) { // Simulate ok:1 n:0 response from shard1. op.processChildBatchResponseFromRemote( *targeted[kShardId1].get(), - AsyncRequestsSender::Response{ - kShardId1, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteNoMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteNoMatchResponse, Microseconds(0))), + boost::none}, boost::none); auto& updateOp = op.getWriteOp_forTest(0); @@ -5463,10 +5512,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndNonRetryableError) { *targeted[kShardId3].get(), AsyncRequestsSender::Response{ kShardId3, - StatusWith(executor::RemoteCommandResponse( - ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") - .toBSON(), - Microseconds(0))), + StatusWith( + executor::RemoteCommandResponse::make_forTest( + ErrorReply(0, ErrorCodes::Interrupted, "Interrupted", "simulating interruption") + .toBSON(), + Microseconds(0))), boost::none}, boost::none); @@ -5480,11 +5530,11 @@ TEST_F(BulkWriteOpWithoutShardKeyWithIdTest, MatchAndNonRetryableError) { // Simulate ok:1 n:1 response from shard2. op.processChildBatchResponseFromRemote( *targeted[kShardId2].get(), - AsyncRequestsSender::Response{ - kShardId2, - StatusWith( - executor::RemoteCommandResponse(kBulkWriteUpdateMatchResponse, Microseconds(0))), - boost::none}, + AsyncRequestsSender::Response{kShardId2, + StatusWith( + executor::RemoteCommandResponse::make_forTest( + kBulkWriteUpdateMatchResponse, Microseconds(0))), + boost::none}, boost::none); op.finishExecutingWriteWithoutShardKeyWithId(); @@ -5548,11 +5598,11 @@ TEST_F(BulkWriteOpTest, SummaryFieldsAreMergedAcrossReplies) { 0) .toBSON() .addFields(BSON("ok" << 1)); - auto response1 = - AsyncRequestsSender::Response{shardId1, - StatusWith( - executor::RemoteCommandResponse(reply1, Microseconds(0))), - boost::none}; + auto response1 = AsyncRequestsSender::Response{ + shardId1, + StatusWith( + executor::RemoteCommandResponse::make_forTest(reply1, Microseconds(0))), + boost::none}; op.processChildBatchResponseFromRemote(*targeted[shardId1], response1, boost::none); auto reply2 = BulkWriteCommandReply(BulkWriteCommandResponseCursor( @@ -5567,11 +5617,11 @@ TEST_F(BulkWriteOpTest, SummaryFieldsAreMergedAcrossReplies) { 1) .toBSON() .addFields(BSON("ok" << 1)); - auto response2 = - AsyncRequestsSender::Response{shardId2, - StatusWith( - executor::RemoteCommandResponse(reply2, Microseconds(0))), - boost::none}; + auto response2 = AsyncRequestsSender::Response{ + shardId2, + StatusWith( + executor::RemoteCommandResponse::make_forTest(reply2, Microseconds(0))), + boost::none}; op.processChildBatchResponseFromRemote(*targeted[shardId2], response2, boost::none); ASSERT(op.isFinished()); @@ -5628,11 +5678,11 @@ TEST_F(BulkWriteOpTest, SuccessAndErrorsAreMerged) { 0 /* nDeleted*/) .toBSON() .addFields(BSON("ok" << 1)); - auto response1 = - AsyncRequestsSender::Response{shardIdA, - StatusWith( - executor::RemoteCommandResponse(reply1, Microseconds(0))), - boost::none}; + auto response1 = AsyncRequestsSender::Response{ + shardIdA, + StatusWith( + executor::RemoteCommandResponse::make_forTest(reply1, Microseconds(0))), + boost::none}; op.processChildBatchResponseFromRemote(*targeted[shardIdA], response1, boost::none); // Error response from shard2. @@ -5649,11 +5699,11 @@ TEST_F(BulkWriteOpTest, SuccessAndErrorsAreMerged) { 0 /* nDeleted */) .toBSON() .addFields(BSON("ok" << 1)); - auto response2 = - AsyncRequestsSender::Response{shardIdB, - StatusWith( - executor::RemoteCommandResponse(reply2, Microseconds(0))), - boost::none}; + auto response2 = AsyncRequestsSender::Response{ + shardIdB, + StatusWith( + executor::RemoteCommandResponse::make_forTest(reply2, Microseconds(0))), + boost::none}; op.processChildBatchResponseFromRemote(*targeted[shardIdB], response2, boost::none); ASSERT(op.isFinished());