summaryrefslogtreecommitdiff
path: root/src/mongo/client/remote_command_targeter.h
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2016-09-06 16:57:35 -0400
committerAndy Schwerin <schwerin@mongodb.com>2016-09-07 09:26:50 -0400
commit645a77b3fa5b28d29d245e30cc195fd5a8eda049 (patch)
treed91a9bc7ed7012e753ec8d92859f7f342a994f86 /src/mongo/client/remote_command_targeter.h
parent1f389ce467330cda1171d2a04bd0e0b2890aaf8d (diff)
downloadmongo-645a77b3fa5b28d29d245e30cc195fd5a8eda049.tar.gz
SERVER-24600 Increase interruptibility of RemoteCommandTargeter::findHost.
By making more calls of RemoteCommandTargeter::findHost interruptible, this change speeds up the shutdown of mongos when no config servers are discoverable.
Diffstat (limited to 'src/mongo/client/remote_command_targeter.h')
-rw-r--r--src/mongo/client/remote_command_targeter.h46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/mongo/client/remote_command_targeter.h b/src/mongo/client/remote_command_targeter.h
index 020cc68945c..ca751be0dec 100644
--- a/src/mongo/client/remote_command_targeter.h
+++ b/src/mongo/client/remote_command_targeter.h
@@ -29,6 +29,7 @@
#pragma once
#include "mongo/base/disallow_copying.h"
+#include "mongo/util/net/hostandport.h"
#include "mongo/util/time_support.h"
namespace mongo {
@@ -58,19 +59,38 @@ public:
virtual ConnectionString connectionString() = 0;
/**
- * Obtains a host, which matches the read preferences specified by readPref, blocking for the
+ * Finds a host matching readPref blocking up to 20 seconds or until the given operation is
+ * interrupted or its deadline expires.
+ *
+ * TODO(schwerin): Once operation max-time behavior is more uniformly integrated into sharding,
+ * remove the 20-second ceiling on wait time.
+ */
+ virtual StatusWith<HostAndPort> findHost(OperationContext* txn,
+ const ReadPreferenceSetting& readPref) = 0;
+
+
+ /**
+ * Finds a host that matches the read preference specified by readPref, blocking for up to
* specified maxWait milliseconds, if a match cannot be found immediately.
*
- * Specifying a maxWait of zero means non-blocking. I.e., the call will just check the in-memory
- * cached view of the replica set's host state and won't wait for it to be refreshed if it is
- * found to be stale.
+ * DEPRECATED. Prefer findHost(OperationContext*, const ReadPreferenceSetting&), whenever
+ * an OperationContext is available.
+ */
+ virtual StatusWith<HostAndPort> findHostWithMaxWait(const ReadPreferenceSetting& readPref,
+ Milliseconds maxWait) = 0;
+
+ /**
+ * Finds a host matching the given read preference, giving up if a match is not found promptly.
+ *
+ * This method may still engage in blocking networking calls, but will attempt contact every
+ * member of the replica set at most one time.
*
- * Returns OK and a host and port to use for the specified read preference or an ErrorCode.
- * Known error codes are:
- * All error codes which can be returned by ReplicaSetMonitor::getHostOrRefresh.
+ * TODO(schwerin): Change this implementation to not perform any networking, once existing
+ * callers have been shown to be safe with this behavior or changed to call findHost.
*/
- virtual StatusWith<HostAndPort> findHost(const ReadPreferenceSetting& readPref,
- Milliseconds maxWait = Milliseconds(0)) = 0;
+ StatusWith<HostAndPort> findHostNoWait(const ReadPreferenceSetting& readPref) {
+ return findHostWithMaxWait(readPref, Milliseconds::zero());
+ }
/**
* Reports to the targeter that a NotMaster response was received when communicating with
@@ -86,14 +106,6 @@ public:
*/
virtual void markHostUnreachable(const HostAndPort& host) = 0;
- /**
- * Based on the remaining time of the operation and the default max wait time for findHost,
- * selects an appropriate value to pass to the maxWait argument of the findHost method, so it
- * has high likelyhood in returning on time and also leaving time for the rest of the call to
- * complete.
- */
- static Milliseconds selectFindHostMaxWaitTime(OperationContext* txn);
-
protected:
RemoteCommandTargeter() = default;
};