summaryrefslogtreecommitdiff
path: root/src/mongo/s/client/shard_remote.cpp
diff options
context:
space:
mode:
authorMisha Tyulenev <misha@mongodb.com>2016-08-09 16:01:02 -0400
committerMisha Tyulenev <misha@mongodb.com>2016-08-09 18:48:57 -0400
commit4c6009e67d3e503f796b5afcbcbeaa95eba80b44 (patch)
treeadb17522b67867f32da6a0dd9aa666a90ae6783e /src/mongo/s/client/shard_remote.cpp
parentf82f0122a5db98ac1ac8a893e42b5c267aa24a02 (diff)
downloadmongo-4c6009e67d3e503f796b5afcbcbeaa95eba80b44.tar.gz
SERVER-22620 prefer config servers with recent opTime
Diffstat (limited to 'src/mongo/s/client/shard_remote.cpp')
-rw-r--r--src/mongo/s/client/shard_remote.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/mongo/s/client/shard_remote.cpp b/src/mongo/s/client/shard_remote.cpp
index ad9e697bb55..006647b748c 100644
--- a/src/mongo/s/client/shard_remote.cpp
+++ b/src/mongo/s/client/shard_remote.cpp
@@ -174,8 +174,12 @@ Shard::HostWithResponse ShardRemote::_runCommand(OperationContext* txn,
Milliseconds maxTimeMSOverride,
const BSONObj& cmdObj) {
- const auto host =
- _targeter->findHost(readPref, RemoteCommandTargeter::selectFindHostMaxWaitTime(txn));
+ ReadPreferenceSetting readPrefWithMinOpTime(readPref);
+ if (getId() == "config") {
+ readPrefWithMinOpTime.minOpTime = grid.configOpTime();
+ }
+ const auto host = _targeter->findHost(readPrefWithMinOpTime,
+ RemoteCommandTargeter::selectFindHostMaxWaitTime(txn));
if (!host.isOK()) {
return Shard::HostWithResponse(boost::none, host.getStatus());
}
@@ -187,7 +191,7 @@ Shard::HostWithResponse ShardRemote::_runCommand(OperationContext* txn,
host.getValue(),
dbName,
appendMaxTimeToCmdObj(maxTimeMSOverride, cmdObj),
- _getMetadataForCommand(readPref),
+ _getMetadataForCommand(readPrefWithMinOpTime),
txn,
requestTimeout < Milliseconds::max() ? requestTimeout : RemoteCommandRequest::kNoTimeout);
@@ -238,8 +242,12 @@ StatusWith<Shard::QueryResponse> ShardRemote::_exhaustiveFindOnConfig(
const BSONObj& query,
const BSONObj& sort,
boost::optional<long long> limit) {
- const auto host =
- _targeter->findHost(readPref, RemoteCommandTargeter::selectFindHostMaxWaitTime(txn));
+ invariant(getId() == "config");
+ ReadPreferenceSetting readPrefWithMinOpTime(readPref);
+ readPrefWithMinOpTime.minOpTime = grid.configOpTime();
+
+ const auto host = _targeter->findHost(readPrefWithMinOpTime,
+ RemoteCommandTargeter::selectFindHostMaxWaitTime(txn));
if (!host.isOK()) {
return host.getStatus();
}
@@ -326,7 +334,7 @@ StatusWith<Shard::QueryResponse> ShardRemote::_exhaustiveFindOnConfig(
nss.db().toString(),
findCmdBuilder.done(),
fetcherCallback,
- _getMetadataForCommand(readPref),
+ _getMetadataForCommand(readPrefWithMinOpTime),
maxTimeMS);
Status scheduleStatus = fetcher.schedule();
if (!scheduleStatus.isOK()) {