diff options
author | Jonathan Reams <jbreams@mongodb.com> | 2019-01-16 11:46:03 -0500 |
---|---|---|
committer | Jonathan Reams <jbreams@mongodb.com> | 2019-01-23 17:02:16 -0500 |
commit | c1b72f76bee602cd915bc6ea91bdcef10bd0c707 (patch) | |
tree | 374edbdb9c98344ad9a0543bb1d04633a045e3e7 /src/mongo/executor/connection_pool.h | |
parent | e7b1c689b632610399ab716a98f125605dd8a11c (diff) | |
download | mongo-c1b72f76bee602cd915bc6ea91bdcef10bd0c707.tar.gz |
SERVER-34260 Move bookkeeping functions into ConnectionInterface
Diffstat (limited to 'src/mongo/executor/connection_pool.h')
-rw-r--r-- | src/mongo/executor/connection_pool.h | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/src/mongo/executor/connection_pool.h b/src/mongo/executor/connection_pool.h index e6525319571..ed3dac9c261 100644 --- a/src/mongo/executor/connection_pool.h +++ b/src/mongo/executor/connection_pool.h @@ -208,6 +208,11 @@ public: * It should be safe to cancel a previously canceled, or never set, timer. */ virtual void cancelTimeout() = 0; + + /** + * Returns the current time for the clock used by the timer + */ + virtual Date_t now() = 0; }; /** @@ -223,21 +228,22 @@ class ConnectionPool::ConnectionInterface : public TimerInterface { friend class ConnectionPool; public: - ConnectionInterface() = default; + explicit ConnectionInterface(size_t generation) : _generation(generation) {} + virtual ~ConnectionInterface() = default; /** * Indicates that the user is now done with this connection. Users MUST call either * this method or indicateFailure() before returning the connection to its pool. */ - virtual void indicateSuccess() = 0; + void indicateSuccess(); /** * Indicates that a connection has failed. This will prevent the connection * from re-entering the connection pool. Users MUST call either this method or * indicateSuccess() before returning connections to the pool. */ - virtual void indicateFailure(Status status) = 0; + void indicateFailure(Status status); /** * This method updates a 'liveness' timestamp to avoid unnecessarily refreshing @@ -248,7 +254,7 @@ public: * back in without use, one would expect an indicateSuccess without an indicateUsed. Only if we * checked it out and did work would we call indicateUsed. */ - virtual void indicateUsed() = 0; + void indicateUsed(); /** * The HostAndPort for the connection. This should be the same as the @@ -262,25 +268,33 @@ public: */ virtual bool isHealthy() = 0; -protected: - /** - * Making these protected makes the definitions available to override in - * children. - */ - using SetupCallback = stdx::function<void(ConnectionInterface*, Status)>; - using RefreshCallback = stdx::function<void(ConnectionInterface*, Status)>; - -private: /** * Returns the last used time point for the connection */ - virtual Date_t getLastUsed() const = 0; + Date_t getLastUsed() const; /** * Returns the status associated with the connection. If the status is not * OK, the connection will not be returned to the pool. */ - virtual const Status& getStatus() const = 0; + const Status& getStatus() const; + + /** + * Get the generation of the connection. This is used to track whether to + * continue using a connection after a call to dropConnections() by noting + * if the generation on the specific pool is the same as the generation on + * a connection (if not the connection is from a previous era and should + * not be re-used). + */ + size_t getGeneration() const; + +protected: + /** + * Making these protected makes the definitions available to override in + * children. + */ + using SetupCallback = stdx::function<void(ConnectionInterface*, Status)>; + using RefreshCallback = stdx::function<void(ConnectionInterface*, Status)>; /** * Sets up the connection. This should include connection + auth + any @@ -291,7 +305,7 @@ private: /** * Resets the connection's state to kConnectionStateUnknown for the next user. */ - virtual void resetToUnknown() = 0; + void resetToUnknown(); /** * Refreshes the connection. This should involve a network round trip and @@ -299,14 +313,10 @@ private: */ virtual void refresh(Milliseconds timeout, RefreshCallback cb) = 0; - /** - * Get the generation of the connection. This is used to track whether to - * continue using a connection after a call to dropConnections() by noting - * if the generation on the specific pool is the same as the generation on - * a connection (if not the connection is from a previous era and should - * not be re-used). - */ - virtual size_t getGeneration() const = 0; +private: + size_t _generation; + Date_t _lastUsed; + Status _status = ConnectionPool::kConnectionStateUnknown; }; /** |