summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaMont Nelson <lamont.nelson@mongodb.com>2020-07-25 02:06:01 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-05 16:56:01 +0000
commitb2c1fa4f121fdb6cdffa924b802271d68c3367a3 (patch)
tree6310ec0c55f64cd1b9c340c92e863390d4ea87fc
parent14ef67e5d039a491ef897edd49bd7d075a18029c (diff)
downloadmongo-b2c1fa4f121fdb6cdffa924b802271d68c3367a3.tar.gz
SERVER-49694: fix latency measurement in RSM; change latency measurement for command responses to Microseconds
-rw-r--r--src/mongo/client/async_client.cpp16
-rw-r--r--src/mongo/client/fetcher.cpp2
-rw-r--r--src/mongo/client/fetcher.h2
-rw-r--r--src/mongo/client/fetcher_test.cpp2
-rw-r--r--src/mongo/client/replica_set_monitor_manager.cpp3
-rw-r--r--src/mongo/client/sdam/sdam_datatypes.h2
-rw-r--r--src/mongo/client/sdam/server_description.cpp6
-rw-r--r--src/mongo/client/sdam/server_description_test.cpp26
-rw-r--r--src/mongo/client/sdam/topology_listener.cpp15
-rw-r--r--src/mongo/client/sdam/topology_listener.h16
-rw-r--r--src/mongo/client/server_ping_monitor.cpp2
-rw-r--r--src/mongo/client/server_ping_monitor_test.cpp7
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp9
-rw-r--r--src/mongo/executor/network_interface_integration_test.cpp35
-rw-r--r--src/mongo/executor/remote_command_response.cpp45
-rw-r--r--src/mongo/executor/remote_command_response.h18
-rw-r--r--src/mongo/s/commands/cluster_multicast_cmd.cpp6
-rw-r--r--src/mongo/s/query/results_merger_test_fixture.h2
18 files changed, 121 insertions, 93 deletions
diff --git a/src/mongo/client/async_client.cpp b/src/mongo/client/async_client.cpp
index d3df41d9705..692f38191f5 100644
--- a/src/mongo/client/async_client.cpp
+++ b/src/mongo/client/async_client.cpp
@@ -226,18 +226,14 @@ Future<void> AsyncDBClient::initWireVersion(const std::string& appName,
// have to communicate with servers that do not support other protocols.
auto requestMsg =
rpc::legacyRequestFromOpMsgRequest(OpMsgRequest::fromDBAndBody("admin", requestObj));
- auto clkSource = _svcCtx->getFastClockSource();
- auto start = clkSource->now();
-
auto msgId = nextMessageId();
return _call(requestMsg, msgId)
.then([msgId, this]() { return _waitForResponse(msgId); })
- .then([this, requestObj, hook, clkSource, start](Message response) {
+ .then([this, requestObj, hook, timer = Timer{}](Message response) {
auto cmdReply = rpc::makeReply(&response);
_parseIsMasterResponse(requestObj, cmdReply);
if (hook) {
- auto millis = duration_cast<Milliseconds>(clkSource->now() - start);
- executor::RemoteCommandResponse cmdResp(*cmdReply, millis);
+ executor::RemoteCommandResponse cmdResp(*cmdReply, timer.elapsed());
uassertStatusOK(hook->validateHost(_peer, requestObj, std::move(cmdResp)));
}
});
@@ -310,16 +306,14 @@ Future<rpc::UniqueReply> AsyncDBClient::runCommand(OpMsgRequest request,
Future<executor::RemoteCommandResponse> AsyncDBClient::runCommandRequest(
executor::RemoteCommandRequest request, const BatonHandle& baton) {
- auto clkSource = _svcCtx->getPreciseClockSource();
- auto start = clkSource->now();
+ auto startTimer = Timer();
auto opMsgRequest = OpMsgRequest::fromDBAndBody(
std::move(request.dbname), std::move(request.cmdObj), std::move(request.metadata));
auto fireAndForget =
request.fireAndForgetMode == executor::RemoteCommandRequest::FireAndForgetMode::kOn;
return runCommand(std::move(opMsgRequest), baton, fireAndForget)
- .then([start, clkSource, this](rpc::UniqueReply response) {
- auto duration = duration_cast<Milliseconds>(clkSource->now() - start);
- return executor::RemoteCommandResponse(*response, duration);
+ .then([this, startTimer = std::move(startTimer)](rpc::UniqueReply response) {
+ return executor::RemoteCommandResponse(*response, startTimer.elapsed());
});
}
diff --git a/src/mongo/client/fetcher.cpp b/src/mongo/client/fetcher.cpp
index ae04a7c4c5c..d8c78fd25c0 100644
--- a/src/mongo/client/fetcher.cpp
+++ b/src/mongo/client/fetcher.cpp
@@ -345,7 +345,7 @@ void Fetcher::_callback(const RemoteCommandCallbackArgs& rcbd, const char* batch
}
batchData.otherFields.metadata = std::move(rcbd.response.data);
- batchData.elapsedMillis = rcbd.response.elapsedMillis.value_or(Milliseconds{0});
+ batchData.elapsed = rcbd.response.elapsed.value_or(Microseconds{0});
{
stdx::lock_guard<Latch> lk(_mutex);
batchData.first = _first;
diff --git a/src/mongo/client/fetcher.h b/src/mongo/client/fetcher.h
index bd4556d0ee4..3d0d10abec8 100644
--- a/src/mongo/client/fetcher.h
+++ b/src/mongo/client/fetcher.h
@@ -70,7 +70,7 @@ public:
struct OtherFields {
BSONObj metadata;
} otherFields;
- Milliseconds elapsedMillis = Milliseconds(0);
+ Microseconds elapsed = Microseconds(0);
bool first = false;
};
diff --git a/src/mongo/client/fetcher_test.cpp b/src/mongo/client/fetcher_test.cpp
index e8283d1a4a6..c958d860e9c 100644
--- a/src/mongo/client/fetcher_test.cpp
+++ b/src/mongo/client/fetcher_test.cpp
@@ -175,7 +175,7 @@ void FetcherTest::_callback(const StatusWith<Fetcher::QueryResponse>& result,
cursorId = batchData.cursorId;
nss = batchData.nss;
documents = batchData.documents;
- elapsedMillis = batchData.elapsedMillis;
+ elapsedMillis = duration_cast<Milliseconds>(batchData.elapsed);
first = batchData.first;
}
diff --git a/src/mongo/client/replica_set_monitor_manager.cpp b/src/mongo/client/replica_set_monitor_manager.cpp
index 56ac55234c2..3f8bffe62dd 100644
--- a/src/mongo/client/replica_set_monitor_manager.cpp
+++ b/src/mongo/client/replica_set_monitor_manager.cpp
@@ -51,6 +51,7 @@
#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/rpc/metadata/egress_metadata_hook_list.h"
+#include "mongo/util/duration.h"
namespace mongo {
@@ -89,7 +90,7 @@ Status ReplicaSetMonitorManagerNetworkConnectionHook::validateHost(
try {
if (isMasterReply.status.isOK()) {
publisher->onServerHandshakeCompleteEvent(
- isMasterReply.elapsedMillis.get(), remoteHost, isMasterReply.data);
+ *isMasterReply.elapsed, remoteHost, isMasterReply.data);
} else {
publisher->onServerHandshakeFailedEvent(
remoteHost, isMasterReply.status, isMasterReply.data);
diff --git a/src/mongo/client/sdam/sdam_datatypes.h b/src/mongo/client/sdam/sdam_datatypes.h
index 4e59dd5a6b7..87a107db7ad 100644
--- a/src/mongo/client/sdam/sdam_datatypes.h
+++ b/src/mongo/client/sdam/sdam_datatypes.h
@@ -73,7 +73,7 @@ std::string toString(const ServerType serverType);
StatusWith<ServerType> parseServerType(StringData strServerType);
std::ostream& operator<<(std::ostream& os, const ServerType serverType);
-using IsMasterRTT = mongo::Nanoseconds;
+using IsMasterRTT = mongo::Microseconds;
// The result of an attempt to call the "ismaster" command on a server.
class IsMasterOutcome {
diff --git a/src/mongo/client/sdam/server_description.cpp b/src/mongo/client/sdam/server_description.cpp
index 08500bbe2db..93138d222a6 100644
--- a/src/mongo/client/sdam/server_description.cpp
+++ b/src/mongo/client/sdam/server_description.cpp
@@ -171,8 +171,10 @@ void ServerDescription::calculateRtt(const boost::optional<IsMasterRTT> currentR
_rtt = currentRtt;
} else {
// new_rtt = alpha * x + (1 - alpha) * old_rtt
- _rtt = IsMasterRTT(static_cast<IsMasterRTT::rep>(kRttAlpha * currentRtt.get().count() +
- (1 - kRttAlpha) * lastRtt.get().count()));
+ auto currentMicros = durationCount<Microseconds>(*currentRtt);
+ auto lastMicros = durationCount<Microseconds>(*lastRtt);
+ _rtt = Microseconds(static_cast<Microseconds::rep>(kRttAlpha * currentMicros +
+ (1 - kRttAlpha) * lastMicros));
}
}
diff --git a/src/mongo/client/sdam/server_description_test.cpp b/src/mongo/client/sdam/server_description_test.cpp
index 9949ddec9ee..3c335201281 100644
--- a/src/mongo/client/sdam/server_description_test.cpp
+++ b/src/mongo/client/sdam/server_description_test.cpp
@@ -37,6 +37,8 @@
#include "mongo/client/sdam/server_description_builder.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/repl/optime.h"
+#include "mongo/platform/random.h"
+#include "mongo/unittest/unittest.h"
#include "mongo/util/system_clock_source.h"
namespace mongo::sdam {
@@ -231,6 +233,8 @@ protected:
return std::move(BSONObjBuilder().append("ok", 1));
}
+ static inline auto rand = PseudoRandom(SecureRandom().nextInt64());
+
static inline const auto clockSource = SystemClockSource::get();
static inline const auto kBsonOk = okBuilder().obj();
@@ -383,6 +387,28 @@ TEST_F(ServerDescriptionTestFixture,
ASSERT_EQUALS(20, durationCount<mongo::Milliseconds>(*description2.getRtt()));
}
+TEST_F(ServerDescriptionTestFixture, ShouldPreserveRTTPrecisionForMicroseconds) {
+ const int numIterations = 100;
+ const int minRttMicros = 100;
+
+ const auto randMicroseconds = [](int m) { return Microseconds(rand.nextInt64(m) + m); };
+ auto lastServerDescription = ServerDescriptionBuilder()
+ .withType(ServerType::kRSPrimary)
+ .withRtt(randMicroseconds(minRttMicros))
+ .instance();
+
+ for (int i = 0; i < numIterations; ++i) {
+ auto lastRtt = *lastServerDescription->getRtt();
+ auto response = IsMasterOutcome(
+ HostAndPort("foo:1234"), kBsonRsPrimary, randMicroseconds(minRttMicros));
+ lastServerDescription = std::make_shared<ServerDescription>(clockSource, response, lastRtt);
+ }
+
+ // assert the value does not decay to zero
+ ASSERT_GT(durationCount<Microseconds>(*lastServerDescription->getRtt()), minRttMicros);
+ ASSERT_LT(durationCount<Microseconds>(*lastServerDescription->getRtt()), 2 * minRttMicros);
+}
+
TEST_F(ServerDescriptionTestFixture, ShouldStoreLastWriteDate) {
auto response = IsMasterOutcome(HostAndPort("foo:1234"),
kBsonLastWrite,
diff --git a/src/mongo/client/sdam/topology_listener.cpp b/src/mongo/client/sdam/topology_listener.cpp
index b4d6be361e8..d91f444c033 100644
--- a/src/mongo/client/sdam/topology_listener.cpp
+++ b/src/mongo/client/sdam/topology_listener.cpp
@@ -59,14 +59,14 @@ void TopologyEventsPublisher::onTopologyDescriptionChangedEvent(
_scheduleNextDelivery();
}
-void TopologyEventsPublisher::onServerHandshakeCompleteEvent(IsMasterRTT durationMs,
+void TopologyEventsPublisher::onServerHandshakeCompleteEvent(IsMasterRTT duration,
const HostAndPort& address,
const BSONObj reply) {
{
stdx::lock_guard<Mutex> lock(_eventQueueMutex);
EventPtr event = std::make_unique<Event>();
event->type = EventType::HANDSHAKE_COMPLETE;
- event->duration = duration_cast<IsMasterRTT>(durationMs);
+ event->duration = duration;
event->hostAndPort = address;
event->reply = reply;
_eventQueue.push_back(std::move(event));
@@ -136,13 +136,13 @@ void TopologyEventsPublisher::onServerPingFailedEvent(const HostAndPort& hostAnd
_scheduleNextDelivery();
}
-void TopologyEventsPublisher::onServerPingSucceededEvent(IsMasterRTT durationMS,
+void TopologyEventsPublisher::onServerPingSucceededEvent(IsMasterRTT duration,
const HostAndPort& hostAndPort) {
{
stdx::lock_guard lock(_eventQueueMutex);
EventPtr event = std::make_unique<Event>();
event->type = EventType::PING_SUCCESS;
- event->duration = duration_cast<IsMasterRTT>(durationMS);
+ event->duration = duration;
event->hostAndPort = hostAndPort;
_eventQueue.push_back(std::move(event));
}
@@ -193,13 +193,10 @@ void TopologyEventsPublisher::_sendEvent(TopologyListenerPtr listener, const Eve
break;
case EventType::HANDSHAKE_COMPLETE:
listener->onServerHandshakeCompleteEvent(
- sdam::IsMasterRTT(duration_cast<Milliseconds>(event.duration)),
- event.hostAndPort,
- event.reply);
+ event.duration, event.hostAndPort, event.reply);
break;
case EventType::PING_SUCCESS:
- listener->onServerPingSucceededEvent(duration_cast<IsMasterRTT>(event.duration),
- event.hostAndPort);
+ listener->onServerPingSucceededEvent(event.duration, event.hostAndPort);
break;
case EventType::PING_FAILURE:
listener->onServerPingFailedEvent(event.hostAndPort, event.status);
diff --git a/src/mongo/client/sdam/topology_listener.h b/src/mongo/client/sdam/topology_listener.h
index a503193ff5c..c7824912b92 100644
--- a/src/mongo/client/sdam/topology_listener.h
+++ b/src/mongo/client/sdam/topology_listener.h
@@ -55,9 +55,9 @@ public:
const BSONObj reply){};
/**
* Called when a ServerHandshakeCompleteEvent is published - The initial handshake to the server
- * at hostAndPort was successful. durationMS is the measured RTT (Round Trip Time).
+ * at hostAndPort was successful. duration is the measured RTT (Round Trip Time).
*/
- virtual void onServerHandshakeCompleteEvent(IsMasterRTT durationMs,
+ virtual void onServerHandshakeCompleteEvent(IsMasterRTT duration,
const HostAndPort& address,
const BSONObj reply = BSONObj()){};
@@ -67,7 +67,7 @@ public:
/**
* Called when a ServerHeartBeatSucceededEvent is published - A heartbeat sent to the server at
- * hostAndPort succeeded. durationMS is the execution time of the event, including the time it
+ * hostAndPort succeeded. duration is the execution time of the event, including the time it
* took to send the message and recieve the reply from the server.
*/
virtual void onServerHeartbeatSucceededEvent(const HostAndPort& hostAndPort,
@@ -81,10 +81,9 @@ public:
/**
* Called when a ServerPingSucceededEvent is published - A monitoring ping to the server at
- * hostAndPort was successful. durationMS is the measured RTT (Round Trip Time).
+ * hostAndPort was successful. duration is the measured RTT (Round Trip Time).
*/
- virtual void onServerPingSucceededEvent(IsMasterRTT durationMS,
- const HostAndPort& hostAndPort){};
+ virtual void onServerPingSucceededEvent(IsMasterRTT duration, const HostAndPort& hostAndPort){};
};
/**
@@ -104,7 +103,7 @@ public:
void onTopologyDescriptionChangedEvent(TopologyDescriptionPtr previousDescription,
TopologyDescriptionPtr newDescription) override;
- virtual void onServerHandshakeCompleteEvent(IsMasterRTT durationMs,
+ virtual void onServerHandshakeCompleteEvent(IsMasterRTT duration,
const HostAndPort& address,
const BSONObj reply = BSONObj()) override;
@@ -118,8 +117,7 @@ public:
const HostAndPort& hostAndPort,
const BSONObj reply) override;
void onServerPingFailedEvent(const HostAndPort& hostAndPort, const Status& status) override;
- void onServerPingSucceededEvent(IsMasterRTT durationMS,
- const HostAndPort& hostAndPort) override;
+ void onServerPingSucceededEvent(IsMasterRTT duration, const HostAndPort& hostAndPort) override;
private:
enum class EventType {
diff --git a/src/mongo/client/server_ping_monitor.cpp b/src/mongo/client/server_ping_monitor.cpp
index 478dd037670..30ad5806e0d 100644
--- a/src/mongo/client/server_ping_monitor.cpp
+++ b/src/mongo/client/server_ping_monitor.cpp
@@ -167,7 +167,7 @@ void SingleServerPingMonitor::_doServerPing() {
anchor->_rttListener->onServerPingFailedEvent(anchor->_hostAndPort,
result.response.status);
} else {
- auto rtt = sdam::IsMasterRTT(timer.micros());
+ auto rtt = Microseconds(timer.micros());
anchor->_rttListener->onServerPingSucceededEvent(rtt, anchor->_hostAndPort);
}
}
diff --git a/src/mongo/client/server_ping_monitor_test.cpp b/src/mongo/client/server_ping_monitor_test.cpp
index 6851f672cc9..2a86b31615e 100644
--- a/src/mongo/client/server_ping_monitor_test.cpp
+++ b/src/mongo/client/server_ping_monitor_test.cpp
@@ -153,11 +153,11 @@ protected:
const HostAndPort& hostAndPort,
MockReplicaSet* replSet) {
processPingRequest(hostAndPort, replSet);
-
auto deadline = elapsed() + pingFrequency;
while (elapsed() < deadline && !_topologyListener->hasPingResponse(hostAndPort)) {
advanceTime(Milliseconds(100));
}
+
ASSERT_TRUE(_topologyListener->hasPingResponse(hostAndPort));
ASSERT_LT(elapsed(), deadline);
auto pingResponse = _topologyListener->getPingResponse(hostAndPort);
@@ -165,6 +165,11 @@ protected:
// There should only be one isMaster response queued up.
ASSERT_EQ(pingResponse.size(), 1);
ASSERT(pingResponse[0].isOK());
+
+ // The latency is from the ping monitor's local timer; not from the mocked clock.
+ // Just assert that we receive a signal.
+ ASSERT_GTE(durationCount<Microseconds>(pingResponse[0].getValue()), 1);
+
checkNoActivityBefore(deadline, hostAndPort);
}
diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
index b0c79aaffb4..41054ca6aa4 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
@@ -240,11 +240,11 @@ void ReplicationCoordinatorImpl::_handleHeartbeatResponse(
}
}
const Date_t now = _replExecutor->now();
- Milliseconds networkTime(0);
+ Microseconds networkTime(0);
StatusWith<ReplSetHeartbeatResponse> hbStatusResponse(hbResponse);
if (responseStatus.isOK()) {
- networkTime = cbData.response.elapsedMillis.value_or(Milliseconds{0});
+ networkTime = cbData.response.elapsed.value_or(Microseconds{0});
// TODO(sz) Because the term is duplicated in ReplSetMetaData, we can get rid of this
// and update tests.
const auto& hbResponse = hbStatusResponse.getValue();
@@ -269,8 +269,9 @@ void ReplicationCoordinatorImpl::_handleHeartbeatResponse(
hbStatusResponse = StatusWith<ReplSetHeartbeatResponse>(responseStatus);
}
- HeartbeatResponseAction action =
- _topCoord->processHeartbeatResponse(now, networkTime, target, hbStatusResponse);
+ // Leaving networkTime units as ms since the average ping calulation may be affected.
+ HeartbeatResponseAction action = _topCoord->processHeartbeatResponse(
+ now, duration_cast<Milliseconds>(networkTime), target, hbStatusResponse);
if (action.getAction() == HeartbeatResponseAction::NoAction && hbStatusResponse.isOK() &&
hbStatusResponse.getValue().hasState() &&
diff --git a/src/mongo/executor/network_interface_integration_test.cpp b/src/mongo/executor/network_interface_integration_test.cpp
index 366b92ff22e..b84fcb844d8 100644
--- a/src/mongo/executor/network_interface_integration_test.cpp
+++ b/src/mongo/executor/network_interface_integration_test.cpp
@@ -343,7 +343,7 @@ TEST_F(NetworkInterfaceTest, CancelLocally) {
// Wait for op to complete, assert that it was canceled.
auto result = deferred.get();
ASSERT_EQ(ErrorCodes::CallbackCanceled, result.status);
- ASSERT(result.elapsedMillis);
+ ASSERT(result.elapsed);
assertNumOps(1u, 0u, 0u, 0u);
}
@@ -394,7 +394,7 @@ TEST_F(NetworkInterfaceTest, CancelRemotely) {
// Wait for the command to return, assert that it was canceled.
auto result = deferred.get();
ASSERT_EQ(ErrorCodes::CallbackCanceled, result.status);
- ASSERT(result.elapsedMillis);
+ ASSERT(result.elapsed);
// Wait for the operation to be killed on the remote host.
numCurrentOpRan += waitForCommandToStop("echo", kMaxWait);
@@ -460,7 +460,7 @@ TEST_F(NetworkInterfaceTest, CancelRemotelyTimedOut) {
// Wait for the command to return, assert that it was canceled.
auto result = deferred.get();
ASSERT_EQ(ErrorCodes::CallbackCanceled, result.status);
- ASSERT(result.elapsedMillis);
+ ASSERT(result.elapsed);
// We have one canceled operation (echo), one timedout operation (_killOperations),
// and one succeeded operation on top of the currentOp operations (configureFailPoint).
@@ -488,7 +488,7 @@ TEST_F(NetworkInterfaceTest, ImmediateCancel) {
// Wait for op to complete, assert that it was canceled.
auto result = deferred.get();
ASSERT_EQ(ErrorCodes::CallbackCanceled, result.status);
- ASSERT(result.elapsedMillis);
+ ASSERT(result.elapsed);
assertNumOps(1u, 0u, 0u, 0u);
}
@@ -502,7 +502,7 @@ TEST_F(NetworkInterfaceTest, LateCancel) {
net().cancelCommand(cbh);
ASSERT_OK(result.status);
- ASSERT(result.elapsedMillis);
+ ASSERT(result.elapsed);
assertNumOps(0u, 0u, 0u, 1u);
}
@@ -520,7 +520,7 @@ TEST_F(NetworkInterfaceTest, AsyncOpTimeout) {
// check that we've timed out.
if (!pingCommandMissing(result)) {
ASSERT_EQ(ErrorCodes::NetworkInterfaceExceededTimeLimit, result.status);
- ASSERT(result.elapsedMillis);
+ ASSERT(result.elapsed);
assertNumOps(0u, 1u, 0u, 0u);
}
}
@@ -552,11 +552,11 @@ TEST_F(NetworkInterfaceTest, AsyncOpTimeoutWithOpCtxDeadlineSooner) {
}
ASSERT_EQ(ErrorCodes::NetworkInterfaceExceededTimeLimit, result.status);
- ASSERT(result.elapsedMillis);
+ ASSERT(result.elapsed);
// check that the request timeout uses the smaller of the operation context deadline and
// the timeout specified in the request constructor.
- ASSERT_GTE(result.elapsedMillis.value(), opCtxDeadline);
- ASSERT_LT(result.elapsedMillis.value(), requestTimeout);
+ ASSERT_GTE(result.elapsed.value(), opCtxDeadline);
+ ASSERT_LT(result.elapsed.value(), requestTimeout);
assertNumOps(0u, 1u, 0u, 0u);
}
@@ -586,11 +586,12 @@ TEST_F(NetworkInterfaceTest, AsyncOpTimeoutWithOpCtxDeadlineLater) {
}
ASSERT_EQ(ErrorCodes::NetworkInterfaceExceededTimeLimit, result.status);
- ASSERT(result.elapsedMillis);
+ ASSERT(result.elapsed);
// check that the request timeout uses the smaller of the operation context deadline and
// the timeout specified in the request constructor.
- ASSERT_GTE(result.elapsedMillis.value(), requestTimeout);
- ASSERT_LT(result.elapsedMillis.value(), opCtxDeadline);
+ ASSERT_GTE(duration_cast<Milliseconds>(result.elapsed.value()), requestTimeout);
+ ASSERT_LT(duration_cast<Milliseconds>(result.elapsed.value()), opCtxDeadline);
+
assertNumOps(0u, 1u, 0u, 0u);
}
@@ -602,7 +603,7 @@ TEST_F(NetworkInterfaceTest, StartCommand) {
auto res = deferred.get();
- ASSERT(res.elapsedMillis);
+ ASSERT(res.elapsed);
uassertStatusOK(res.status);
// This opmsg request expect the following reply, which is generated below
@@ -650,7 +651,7 @@ TEST_F(NetworkInterfaceTest, FireAndForget) {
for (auto& future : futures) {
auto result = future.get();
- ASSERT(result.elapsedMillis);
+ ASSERT(result.elapsed);
uassertStatusOK(result.status);
ASSERT_EQ(1, result.data.getIntField("ok"));
}
@@ -658,7 +659,7 @@ TEST_F(NetworkInterfaceTest, FireAndForget) {
// Run a non-fireAndForget command and verify that we get a CommandFailed response.
auto nonFireAndForgetRequest = makeTestCommand(kNoTimeout, makeEchoCmdObj());
auto result = runCommandSync(nonFireAndForgetRequest);
- ASSERT(result.elapsedMillis);
+ ASSERT(result.elapsed);
uassertStatusOK(result.status);
ASSERT_EQ(0, result.data.getIntField("ok"));
ASSERT_EQ(ErrorCodes::CommandFailed, result.data.getIntField("code"));
@@ -750,7 +751,7 @@ TEST_F(NetworkInterfaceInternalClientTest,
// Verify that the ping op is counted as a success.
auto res = deferred.get();
- ASSERT(res.elapsedMillis);
+ ASSERT(res.elapsed);
assertNumOps(0u, 0u, 0u, 1u);
}
@@ -764,7 +765,7 @@ TEST_F(NetworkInterfaceTest, IsMasterRequestMissingInternalClientInfoWhenNotInte
ASSERT_FALSE(isMasterHandshake.request["internalClient"]);
// Verify that the ping op is counted as a success.
auto res = deferred.get();
- ASSERT(res.elapsedMillis);
+ ASSERT(res.elapsed);
assertNumOps(0u, 0u, 0u, 1u);
}
diff --git a/src/mongo/executor/remote_command_response.cpp b/src/mongo/executor/remote_command_response.cpp
index d069c0832dc..64e26295c87 100644
--- a/src/mongo/executor/remote_command_response.cpp
+++ b/src/mongo/executor/remote_command_response.cpp
@@ -35,6 +35,7 @@
#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/rpc/reply_interface.h"
+#include "mongo/util/duration.h"
#include "mongo/util/str.h"
namespace mongo {
@@ -45,22 +46,22 @@ RemoteCommandResponseBase::RemoteCommandResponseBase(ErrorCodes::Error code, std
RemoteCommandResponseBase::RemoteCommandResponseBase(ErrorCodes::Error code,
std::string reason,
- Milliseconds millis)
- : elapsedMillis(millis), status(code, reason) {}
+ Microseconds elapsed)
+ : elapsed(elapsed), status(code, reason) {}
RemoteCommandResponseBase::RemoteCommandResponseBase(Status s) : status(std::move(s)) {
invariant(!isOK());
};
-RemoteCommandResponseBase::RemoteCommandResponseBase(Status s, Milliseconds millis)
- : elapsedMillis(millis), status(std::move(s)) {
+RemoteCommandResponseBase::RemoteCommandResponseBase(Status s, Microseconds elapsed)
+ : elapsed(elapsed), status(std::move(s)) {
invariant(!isOK());
};
RemoteCommandResponseBase::RemoteCommandResponseBase(BSONObj dataObj,
- Milliseconds millis,
+ Microseconds elapsed,
bool moreToCome)
- : data(std::move(dataObj)), elapsedMillis(millis), moreToCome(moreToCome) {
+ : data(std::move(dataObj)), elapsed(elapsed), moreToCome(moreToCome) {
// The buffer backing the default empty BSONObj has static duration so it is effectively
// owned.
invariant(data.isOwned() || data.objdata() == BSONObj().objdata());
@@ -69,9 +70,9 @@ RemoteCommandResponseBase::RemoteCommandResponseBase(BSONObj dataObj,
// 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,
- Milliseconds millis,
+ Microseconds elapsed,
bool moreToCome)
- : RemoteCommandResponseBase(rpcReply.getCommandReply(), std::move(millis), moreToCome) {}
+ : RemoteCommandResponseBase(rpcReply.getCommandReply(), std::move(elapsed), moreToCome) {}
bool RemoteCommandResponseBase::isOK() const {
return status.isOK();
@@ -81,11 +82,11 @@ std::string RemoteCommandResponse::toString() const {
return format(FMT_STRING("RemoteResponse --"
" cmd: {}"
" status: {}"
- " elapsedMillis: {}"
+ " elapsed: {}"
" moreToCome: {}"),
data.toString(),
status.toString(),
- elapsedMillis ? StringData(elapsedMillis->toString()) : "n/a"_sd,
+ elapsed ? StringData(elapsed->toString()) : "n/a"_sd,
moreToCome);
}
@@ -94,7 +95,7 @@ bool RemoteCommandResponse::operator==(const RemoteCommandResponse& rhs) const {
return true;
}
SimpleBSONObjComparator bsonComparator;
- return bsonComparator.evaluate(data == rhs.data) && elapsedMillis == rhs.elapsedMillis;
+ return bsonComparator.evaluate(data == rhs.data) && elapsed == rhs.elapsed;
}
bool RemoteCommandResponse::operator!=(const RemoteCommandResponse& rhs) const {
@@ -116,26 +117,26 @@ RemoteCommandOnAnyResponse::RemoteCommandOnAnyResponse(boost::optional<HostAndPo
RemoteCommandOnAnyResponse::RemoteCommandOnAnyResponse(boost::optional<HostAndPort> hp,
ErrorCodes::Error code,
std::string reason,
- Milliseconds millis)
- : RemoteCommandResponseBase(code, std::move(reason), millis), target(std::move(hp)) {}
+ Microseconds elapsed)
+ : RemoteCommandResponseBase(code, std::move(reason), elapsed), target(std::move(hp)) {}
RemoteCommandOnAnyResponse::RemoteCommandOnAnyResponse(boost::optional<HostAndPort> hp, Status s)
: RemoteCommandResponseBase(std::move(s)), target(std::move(hp)) {}
RemoteCommandOnAnyResponse::RemoteCommandOnAnyResponse(boost::optional<HostAndPort> hp,
Status s,
- Milliseconds millis)
- : RemoteCommandResponseBase(std::move(s), millis), target(std::move(hp)) {}
+ Microseconds elapsed)
+ : RemoteCommandResponseBase(std::move(s), elapsed), target(std::move(hp)) {}
RemoteCommandOnAnyResponse::RemoteCommandOnAnyResponse(HostAndPort hp,
BSONObj dataObj,
- Milliseconds millis)
- : RemoteCommandResponseBase(std::move(dataObj), millis), target(std::move(hp)) {}
+ Microseconds elapsed)
+ : RemoteCommandResponseBase(std::move(dataObj), elapsed), target(std::move(hp)) {}
RemoteCommandOnAnyResponse::RemoteCommandOnAnyResponse(HostAndPort hp,
const rpc::ReplyInterface& rpcReply,
- Milliseconds millis)
- : RemoteCommandResponseBase(rpcReply, millis), target(std::move(hp)) {}
+ Microseconds elapsed)
+ : RemoteCommandResponseBase(rpcReply, elapsed), target(std::move(hp)) {}
RemoteCommandOnAnyResponse::RemoteCommandOnAnyResponse(boost::optional<HostAndPort> hp,
const RemoteCommandResponse& other)
@@ -146,7 +147,7 @@ bool RemoteCommandOnAnyResponse::operator==(const RemoteCommandOnAnyResponse& rh
return true;
}
SimpleBSONObjComparator bsonComparator;
- return bsonComparator.evaluate(data == rhs.data) && elapsedMillis == rhs.elapsedMillis &&
+ return bsonComparator.evaluate(data == rhs.data) && elapsed == rhs.elapsed &&
target == rhs.target;
}
@@ -159,12 +160,12 @@ std::string RemoteCommandOnAnyResponse::toString() const {
" cmd: {}"
" target: {}"
" status: {}"
- " elapsedMillis: {}"
+ " elapsedMicros: {}"
" moreToCome: {}"),
data.toString(),
target ? StringData(target->toString()) : "[none]"_sd,
status.toString(),
- elapsedMillis ? StringData(elapsedMillis.get().toString()) : "n/a"_sd,
+ elapsed ? StringData(elapsed.get().toString()) : "n/a"_sd,
moreToCome);
}
diff --git a/src/mongo/executor/remote_command_response.h b/src/mongo/executor/remote_command_response.h
index 7842ebdfe14..53c785ab874 100644
--- a/src/mongo/executor/remote_command_response.h
+++ b/src/mongo/executor/remote_command_response.h
@@ -57,22 +57,22 @@ struct RemoteCommandResponseBase {
RemoteCommandResponseBase(ErrorCodes::Error code, std::string reason);
- RemoteCommandResponseBase(ErrorCodes::Error code, std::string reason, Milliseconds millis);
+ RemoteCommandResponseBase(ErrorCodes::Error code, std::string reason, Microseconds elapsed);
RemoteCommandResponseBase(Status s);
- RemoteCommandResponseBase(Status s, Milliseconds millis);
+ RemoteCommandResponseBase(Status s, Microseconds elapsed);
- RemoteCommandResponseBase(BSONObj dataObj, Milliseconds millis, bool moreToCome = false);
+ RemoteCommandResponseBase(BSONObj dataObj, Microseconds elapsed, bool moreToCome = false);
RemoteCommandResponseBase(const rpc::ReplyInterface& rpcReply,
- Milliseconds millis,
+ Microseconds elapsed,
bool moreToCome = false);
bool isOK() const;
BSONObj data; // Always owned. May point into message.
- boost::optional<Milliseconds> elapsedMillis;
+ boost::optional<Microseconds> elapsed;
Status status = Status::OK();
bool moreToCome = false; // Whether or not the moreToCome bit is set on an exhaust message.
@@ -111,17 +111,17 @@ struct RemoteCommandOnAnyResponse : RemoteCommandResponseBase {
RemoteCommandOnAnyResponse(boost::optional<HostAndPort> hp,
ErrorCodes::Error code,
std::string reason,
- Milliseconds millis);
+ Microseconds elapsed);
RemoteCommandOnAnyResponse(boost::optional<HostAndPort> hp, Status s);
- RemoteCommandOnAnyResponse(boost::optional<HostAndPort> hp, Status s, Milliseconds millis);
+ RemoteCommandOnAnyResponse(boost::optional<HostAndPort> hp, Status s, Microseconds elapsed);
- RemoteCommandOnAnyResponse(HostAndPort hp, BSONObj dataObj, Milliseconds millis);
+ RemoteCommandOnAnyResponse(HostAndPort hp, BSONObj dataObj, Microseconds elapsed);
RemoteCommandOnAnyResponse(HostAndPort hp,
const rpc::ReplyInterface& rpcReply,
- Milliseconds millis);
+ Microseconds elapsed);
RemoteCommandOnAnyResponse(boost::optional<HostAndPort> hp, const RemoteCommandResponse& other);
diff --git a/src/mongo/s/commands/cluster_multicast_cmd.cpp b/src/mongo/s/commands/cluster_multicast_cmd.cpp
index 974da4fc557..d4d283e4b13 100644
--- a/src/mongo/s/commands/cluster_multicast_cmd.cpp
+++ b/src/mongo/s/commands/cluster_multicast_cmd.cpp
@@ -39,6 +39,7 @@
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/commands/cluster_commands_gen.h"
#include "mongo/s/grid.h"
+#include "mongo/util/duration.h"
namespace mongo {
namespace {
@@ -132,8 +133,9 @@ public:
if (CommandHelpers::appendCommandStatusNoThrow(subbob, response.status)) {
subbob.append("data", response.data);
- if (response.elapsedMillis) {
- subbob.append("elapsedMillis", response.elapsedMillis->count());
+ if (response.elapsed) {
+ subbob.append("elapsedMillis",
+ durationCount<Milliseconds>(*response.elapsed));
}
}
}
diff --git a/src/mongo/s/query/results_merger_test_fixture.h b/src/mongo/s/query/results_merger_test_fixture.h
index 911ab99a1e1..8fc20eb2903 100644
--- a/src/mongo/s/query/results_merger_test_fixture.h
+++ b/src/mongo/s/query/results_merger_test_fixture.h
@@ -196,7 +196,7 @@ protected:
void scheduleErrorResponse(executor::TaskExecutor::ResponseStatus rs) {
invariant(!rs.isOK());
- rs.elapsedMillis = Milliseconds(0);
+ rs.elapsed = Milliseconds(0);
executor::NetworkInterfaceMock* net = network();
net->enterNetwork();
ASSERT_TRUE(net->hasReadyRequests());