diff options
Diffstat (limited to 'src/mongo/s/client/shard_connection.h')
-rw-r--r-- | src/mongo/s/client/shard_connection.h | 228 |
1 files changed, 115 insertions, 113 deletions
diff --git a/src/mongo/s/client/shard_connection.h b/src/mongo/s/client/shard_connection.h index 4fc7f0f01a8..42040a3ab79 100644 --- a/src/mongo/s/client/shard_connection.h +++ b/src/mongo/s/client/shard_connection.h @@ -35,124 +35,126 @@ namespace mongo { - class ChunkManager; - typedef std::shared_ptr<ChunkManager> ChunkManagerPtr; - - - class ShardConnection : public AScopedConnection { - public: - ShardConnection(const ConnectionString& connectionString, - const std::string& ns, - std::shared_ptr<ChunkManager> manager = nullptr); - - ~ShardConnection(); - - void done(); - void kill(); - - DBClientBase& conn() { - _finishInit(); - verify( _conn ); - return *_conn; - } - - DBClientBase* operator->() { - _finishInit(); - verify( _conn ); - return _conn; - } - - DBClientBase* get() { - _finishInit(); - verify( _conn ); - return _conn; - } - - /** - * @return the connection object underneath without setting the shard version. - * @throws AssertionException if _conn is uninitialized. - */ - DBClientBase* getRawConn() const { - verify( _conn ); - return _conn; - } - - std::string getHost() const { - return _cs.toString(); - } - - std::string getNS() const { - return _ns; - } - - std::shared_ptr<ChunkManager> getManager() const { - return _manager; - } - - bool setVersion() { - _finishInit(); - return _setVersion; - } - - static void sync(); - - void donotCheckVersion() { - _setVersion = false; - _finishedInit = true; - } - - bool ok() const { return _conn != NULL; } - - /** checks all of my thread local connections for the version of this ns */ - static void checkMyConnectionVersions( const std::string & ns ); - - /** - * Returns all the current sharded connections to the pool. - * Note: This is *dangerous* if we have GLE state. - */ - static void releaseMyConnections(); - - /** - * Clears all connections in the sharded pool, including connections in the - * thread local storage pool of the current thread. - */ - static void clearPool(); - - /** - * Forgets a namespace to prevent future versioning. - */ - static void forgetNS( const std::string& ns ); - - private: - void _init(); - void _finishInit(); - - const ConnectionString _cs; - const std::string _ns; - - std::shared_ptr<ChunkManager> _manager; - - bool _finishedInit; - - DBClientBase* _conn; - bool _setVersion; - }; +class ChunkManager; +typedef std::shared_ptr<ChunkManager> ChunkManagerPtr; +class ShardConnection : public AScopedConnection { +public: + ShardConnection(const ConnectionString& connectionString, + const std::string& ns, + std::shared_ptr<ChunkManager> manager = nullptr); + + ~ShardConnection(); + + void done(); + void kill(); + + DBClientBase& conn() { + _finishInit(); + verify(_conn); + return *_conn; + } + + DBClientBase* operator->() { + _finishInit(); + verify(_conn); + return _conn; + } + + DBClientBase* get() { + _finishInit(); + verify(_conn); + return _conn; + } + + /** + * @return the connection object underneath without setting the shard version. + * @throws AssertionException if _conn is uninitialized. + */ + DBClientBase* getRawConn() const { + verify(_conn); + return _conn; + } + + std::string getHost() const { + return _cs.toString(); + } + + std::string getNS() const { + return _ns; + } + + std::shared_ptr<ChunkManager> getManager() const { + return _manager; + } + + bool setVersion() { + _finishInit(); + return _setVersion; + } + + static void sync(); + + void donotCheckVersion() { + _setVersion = false; + _finishedInit = true; + } + + bool ok() const { + return _conn != NULL; + } + + /** checks all of my thread local connections for the version of this ns */ + static void checkMyConnectionVersions(const std::string& ns); + + /** + * Returns all the current sharded connections to the pool. + * Note: This is *dangerous* if we have GLE state. + */ + static void releaseMyConnections(); + /** - * Sends the setShardVersion command on the specified connection. + * Clears all connections in the sharded pool, including connections in the + * thread local storage pool of the current thread. */ - bool setShardVersion(DBClientBase & conn, - const std::string& ns, - const std::string& configServerPrimary, - ChunkVersion version, - ChunkManager* manager, - bool authoritative, - BSONObj& result); + static void clearPool(); + + /** + * Forgets a namespace to prevent future versioning. + */ + static void forgetNS(const std::string& ns); + +private: + void _init(); + void _finishInit(); + + const ConnectionString _cs; + const std::string _ns; + + std::shared_ptr<ChunkManager> _manager; + + bool _finishedInit; + + DBClientBase* _conn; + bool _setVersion; +}; + + +/** + * Sends the setShardVersion command on the specified connection. + */ +bool setShardVersion(DBClientBase& conn, + const std::string& ns, + const std::string& configServerPrimary, + ChunkVersion version, + ChunkManager* manager, + bool authoritative, + BSONObj& result); - typedef std::shared_ptr<ShardConnection> ShardConnectionPtr; +typedef std::shared_ptr<ShardConnection> ShardConnectionPtr; - extern DBConnectionPool shardConnectionPool; +extern DBConnectionPool shardConnectionPool; -} // namespace mongo +} // namespace mongo |