summaryrefslogtreecommitdiff
path: root/src/mongo/s/client/sharding_connection_hook.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/client/sharding_connection_hook.cpp')
-rw-r--r--src/mongo/s/client/sharding_connection_hook.cpp142
1 files changed, 69 insertions, 73 deletions
diff --git a/src/mongo/s/client/sharding_connection_hook.cpp b/src/mongo/s/client/sharding_connection_hook.cpp
index b1567441d83..80e924e1121 100644
--- a/src/mongo/s/client/sharding_connection_hook.cpp
+++ b/src/mongo/s/client/sharding_connection_hook.cpp
@@ -47,101 +47,97 @@
namespace mongo {
- using std::string;
+using std::string;
namespace {
- bool initWireVersion(DBClientBase* conn, std::string* errMsg) {
- BSONObj response;
- if (!conn->runCommand("admin", BSON("isMaster" << 1), response)) {
- *errMsg = str::stream() << "Failed to determine wire version "
- << "for internal connection: " << response;
- return false;
- }
-
- if (response.hasField("minWireVersion") && response.hasField("maxWireVersion")) {
- int minWireVersion = response["minWireVersion"].numberInt();
- int maxWireVersion = response["maxWireVersion"].numberInt();
- conn->setWireVersions(minWireVersion, maxWireVersion);
- }
-
- return true;
+bool initWireVersion(DBClientBase* conn, std::string* errMsg) {
+ BSONObj response;
+ if (!conn->runCommand("admin", BSON("isMaster" << 1), response)) {
+ *errMsg = str::stream() << "Failed to determine wire version "
+ << "for internal connection: " << response;
+ return false;
}
-} // namespace
+ if (response.hasField("minWireVersion") && response.hasField("maxWireVersion")) {
+ int minWireVersion = response["minWireVersion"].numberInt();
+ int maxWireVersion = response["maxWireVersion"].numberInt();
+ conn->setWireVersions(minWireVersion, maxWireVersion);
+ }
+ return true;
+}
- ShardingConnectionHook::ShardingConnectionHook(bool shardedConnections)
- : _shardedConnections(shardedConnections) {
+} // namespace
- }
- void ShardingConnectionHook::onCreate(DBClientBase * conn) {
+ShardingConnectionHook::ShardingConnectionHook(bool shardedConnections)
+ : _shardedConnections(shardedConnections) {}
- // Authenticate as the first thing we do
- // NOTE: Replica set authentication allows authentication against *any* online host
- if (getGlobalAuthorizationManager()->isAuthEnabled()) {
- LOG(2) << "calling onCreate auth for " << conn->toString();
+void ShardingConnectionHook::onCreate(DBClientBase* conn) {
+ // Authenticate as the first thing we do
+ // NOTE: Replica set authentication allows authentication against *any* online host
+ if (getGlobalAuthorizationManager()->isAuthEnabled()) {
+ LOG(2) << "calling onCreate auth for " << conn->toString();
- bool result = authenticateInternalUser(conn);
+ bool result = authenticateInternalUser(conn);
- uassert(15847, str::stream() << "can't authenticate to server "
- << conn->getServerAddress(),
+ uassert(15847,
+ str::stream() << "can't authenticate to server " << conn->getServerAddress(),
result);
- }
-
- // Initialize the wire version of single connections
- if (conn->type() == ConnectionString::MASTER) {
+ }
- LOG(2) << "checking wire version of new connection " << conn->toString();
+ // Initialize the wire version of single connections
+ if (conn->type() == ConnectionString::MASTER) {
+ LOG(2) << "checking wire version of new connection " << conn->toString();
- // Initialize the wire protocol version of the connection to find out if we
- // can send write commands to this connection.
- string errMsg;
- if (!initWireVersion(conn, &errMsg)) {
- uasserted(17363, errMsg);
- }
+ // Initialize the wire protocol version of the connection to find out if we
+ // can send write commands to this connection.
+ string errMsg;
+ if (!initWireVersion(conn, &errMsg)) {
+ uasserted(17363, errMsg);
}
+ }
- if (_shardedConnections) {
- // For every DBClient created by mongos, add a hook that will capture the response from
- // commands we pass along from the client, so that we can target the correct node when
- // subsequent getLastError calls are made by mongos.
- conn->setReplyMetadataReader([](const BSONObj& metadataObj, StringData hostString)
+ if (_shardedConnections) {
+ // For every DBClient created by mongos, add a hook that will capture the response from
+ // commands we pass along from the client, so that we can target the correct node when
+ // subsequent getLastError calls are made by mongos.
+ conn->setReplyMetadataReader([](const BSONObj& metadataObj, StringData hostString)
-> Status {
- saveGLEStats(metadataObj, hostString);
- return Status::OK();
- });
- }
-
- // For every DBClient created by mongos, add a hook that will append impersonated users
- // to the end of every runCommand. mongod uses this information to produce auditing
- // records attributed to the proper authenticated user(s).
- conn->setRequestMetadataWriter([](BSONObjBuilder* metadataBob) -> Status {
- audit::writeImpersonatedUsersToMetadata(metadataBob);
- return Status::OK();
- });
-
- // For every SCC created, add a hook that will allow fastest-config-first config reads if
- // the appropriate server options are set.
- if (conn->type() == ConnectionString::SYNC) {
- SyncClusterConnection* scc = dynamic_cast<SyncClusterConnection*>(conn);
- if (scc) {
- scc->attachQueryHandler(new SCCFastQueryHandler);
- }
- }
+ saveGLEStats(metadataObj, hostString);
+ return Status::OK();
+ });
}
- void ShardingConnectionHook::onDestroy(DBClientBase * conn) {
- if (_shardedConnections && versionManager.isVersionableCB(conn)){
- versionManager.resetShardVersionCB(conn);
+ // For every DBClient created by mongos, add a hook that will append impersonated users
+ // to the end of every runCommand. mongod uses this information to produce auditing
+ // records attributed to the proper authenticated user(s).
+ conn->setRequestMetadataWriter([](BSONObjBuilder* metadataBob) -> Status {
+ audit::writeImpersonatedUsersToMetadata(metadataBob);
+ return Status::OK();
+ });
+
+ // For every SCC created, add a hook that will allow fastest-config-first config reads if
+ // the appropriate server options are set.
+ if (conn->type() == ConnectionString::SYNC) {
+ SyncClusterConnection* scc = dynamic_cast<SyncClusterConnection*>(conn);
+ if (scc) {
+ scc->attachQueryHandler(new SCCFastQueryHandler);
}
}
+}
- void ShardingConnectionHook::onRelease(DBClientBase* conn) {
- // This is currently for making the replica set connections release
- // secondary connections to the pool.
- conn->reset();
+void ShardingConnectionHook::onDestroy(DBClientBase* conn) {
+ if (_shardedConnections && versionManager.isVersionableCB(conn)) {
+ versionManager.resetShardVersionCB(conn);
}
+}
+
+void ShardingConnectionHook::onRelease(DBClientBase* conn) {
+ // This is currently for making the replica set connections release
+ // secondary connections to the pool.
+ conn->reset();
+}
-} // namespace mongo
+} // namespace mongo