diff options
author | Adam Midvidy <amidvidy@gmail.com> | 2015-07-23 14:11:50 -0400 |
---|---|---|
committer | Adam Midvidy <amidvidy@gmail.com> | 2015-07-23 19:02:11 -0400 |
commit | 4e2ef9c48e7df15e5e55afcc985f4b501c69e52d (patch) | |
tree | b77ce62e2c3141703e00295d18a0e11d703af981 | |
parent | 26c5394f79d12ac1c9df7263199e2926ee2e19ff (diff) | |
download | mongo-4e2ef9c48e7df15e5e55afcc985f4b501c69e52d.tar.gz |
SERVER-19420 add ConnectionHook interface to NetworkInterface, and add stubs
-rw-r--r-- | src/mongo/executor/network_interface.h | 66 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_asio.cpp | 4 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_asio.h | 1 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_impl.cpp | 4 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_impl.h | 1 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_mock.cpp | 4 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_mock.h | 1 |
7 files changed, 81 insertions, 0 deletions
diff --git a/src/mongo/executor/network_interface.h b/src/mongo/executor/network_interface.h index 658b0f23d14..6d715db20d0 100644 --- a/src/mongo/executor/network_interface.h +++ b/src/mongo/executor/network_interface.h @@ -28,6 +28,7 @@ #pragma once +#include <boost/optional.hpp> #include <string> #include "mongo/base/disallow_copying.h" @@ -53,6 +54,64 @@ public: virtual ~NetworkInterface(); /** + * An interface for augmenting the NetworkInterface with domain-specific host validation and + * post-connection logic. + */ + class ConnectionHook { + public: + virtual ~ConnectionHook() = default; + + /** + * Runs optional validation logic on an isMaster reply from a remote host. If a non-OK + * Status is returned, it will be propagated up to the completion handler for the command + * that initiated the request that caused this connection to be created. This will + * be called once for each connection that is created, even if a remote host with the + * same HostAndPort has already successfully passed validation on a different connection. + * + * This method must not throw any exceptions or block on network or disk-IO. However, in the + * event that an exception escapes, the NetworkInterface is responsible for calling + * std::terminate. + */ + virtual Status validateHost(const HostAndPort& remoteHost, + const RemoteCommandResponse& isMasterReply) = 0; + + /** + * Generates a command to run on the remote host immediately after connecting to it. + * If a non-OK StatusWith is returned, it will be propagated up to the completion handler + * for the command that initiated the request that caused this connection to be created. + * + * The command will be run after socket setup, SSL handshake, authentication, and wire + * protocol detection, but before any commands submitted to the NetworkInterface via + * startCommand are run. In the case that it isn't neccessary to run a command, makeRequest + * may return boost::none. + * + * This method must not throw any exceptions or block on network or disk-IO. However, in the + * event that an exception escapes, the NetworkInterface is responsible for calling + * std::terminate. + */ + virtual StatusWith<boost::optional<RemoteCommandRequest>> makeRequest( + const HostAndPort& remoteHost) = 0; + + /** + * Handles a remote server's reply to the command generated with makeRequest. If a + * non-OK Status is returned, it will be propagated up to the completion handler for the + * command that initiated the request that caused this connection to be created. + * + * If the corresponding earlier call to makeRequest for this connection returned + * boost::none, the NetworkInterface will not call handleReply. + * + * This method must not throw any exceptions or block on network or disk-IO. However, in the + * event that an exception escapes, the NetworkInterface is responsible for calling + * std::terminate. + */ + virtual Status handleReply(const HostAndPort& remoteHost, + RemoteCommandResponse&& response) = 0; + + protected: + ConnectionHook() = default; + }; + + /** * Returns diagnostic info. */ virtual std::string getDiagnosticString() = 0; @@ -88,6 +147,13 @@ public: virtual void waitForWorkUntil(Date_t when) = 0; /** + * Sets a connection hook for this NetworkInterface. This method can only be + * called once, and must be called before startup() or the result + * is undefined. + */ + virtual void setConnectionHook(std::unique_ptr<ConnectionHook> hook) = 0; + + /** * Signals to the network interface that there is new work (such as a signaled event) for * the executor to process. Wakes the executor from waitForWork() and friends. */ diff --git a/src/mongo/executor/network_interface_asio.cpp b/src/mongo/executor/network_interface_asio.cpp index 9ef278971af..768621e681a 100644 --- a/src/mongo/executor/network_interface_asio.cpp +++ b/src/mongo/executor/network_interface_asio.cpp @@ -109,6 +109,10 @@ void NetworkInterfaceASIO::waitForWorkUntil(Date_t when) { _isExecutorRunnable = false; } +void NetworkInterfaceASIO::setConnectionHook(std::unique_ptr<ConnectionHook> hook) { + MONGO_UNREACHABLE; +} + void NetworkInterfaceASIO::signalWorkAvailable() { stdx::unique_lock<stdx::mutex> lk(_executorMutex); _signalWorkAvailable_inlock(); diff --git a/src/mongo/executor/network_interface_asio.h b/src/mongo/executor/network_interface_asio.h index bc1a4a81e5a..b10120d2d9e 100644 --- a/src/mongo/executor/network_interface_asio.h +++ b/src/mongo/executor/network_interface_asio.h @@ -95,6 +95,7 @@ public: void shutdown() override; void waitForWork() override; void waitForWorkUntil(Date_t when) override; + void setConnectionHook(std::unique_ptr<ConnectionHook> hook) override; void signalWorkAvailable() override; Date_t now() override; void startCommand(const TaskExecutor::CallbackHandle& cbHandle, diff --git a/src/mongo/executor/network_interface_impl.cpp b/src/mongo/executor/network_interface_impl.cpp index c37a371ffe5..7f63d5f25da 100644 --- a/src/mongo/executor/network_interface_impl.cpp +++ b/src/mongo/executor/network_interface_impl.cpp @@ -131,6 +131,10 @@ void NetworkInterfaceImpl::waitForWorkUntil(Date_t when) { _isExecutorRunnable = false; } +void NetworkInterfaceImpl::setConnectionHook(std::unique_ptr<ConnectionHook> hook) { + MONGO_UNREACHABLE; +} + void NetworkInterfaceImpl::_runOneCommand() { stdx::unique_lock<stdx::mutex> lk(_mutex); if (_pending.empty()) { diff --git a/src/mongo/executor/network_interface_impl.h b/src/mongo/executor/network_interface_impl.h index cf9af82cca8..63a71f1150a 100644 --- a/src/mongo/executor/network_interface_impl.h +++ b/src/mongo/executor/network_interface_impl.h @@ -78,6 +78,7 @@ public: void shutdown() override; void waitForWork() override; void waitForWorkUntil(Date_t when) override; + void setConnectionHook(std::unique_ptr<ConnectionHook> hook) override; void signalWorkAvailable() override; Date_t now() override; std::string getHostName() override; diff --git a/src/mongo/executor/network_interface_mock.cpp b/src/mongo/executor/network_interface_mock.cpp index d2f60814016..b4e2b22ddd6 100644 --- a/src/mongo/executor/network_interface_mock.cpp +++ b/src/mongo/executor/network_interface_mock.cpp @@ -290,6 +290,10 @@ void NetworkInterfaceMock::waitForWorkUntil(Date_t when) { _waitForWork_inlock(&lk); } +void NetworkInterfaceMock::setConnectionHook(std::unique_ptr<ConnectionHook> hook) { + MONGO_UNREACHABLE; +} + void NetworkInterfaceMock::signalWorkAvailable() { stdx::lock_guard<stdx::mutex> lk(_mutex); _waitingToRunMask |= kExecutorThread; diff --git a/src/mongo/executor/network_interface_mock.h b/src/mongo/executor/network_interface_mock.h index 92cad82c978..91491b578e0 100644 --- a/src/mongo/executor/network_interface_mock.h +++ b/src/mongo/executor/network_interface_mock.h @@ -82,6 +82,7 @@ public: virtual void shutdown(); virtual void waitForWork(); virtual void waitForWorkUntil(Date_t when); + virtual void setConnectionHook(std::unique_ptr<ConnectionHook> hook); virtual void signalWorkAvailable(); virtual Date_t now(); virtual std::string getHostName(); |