summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-04-15 18:09:26 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-04-16 10:10:49 -0400
commit30a061c7f72f7b47029142bc641534eb8f0feed8 (patch)
tree8053156d7c68cbbdb50dd6f9ede2b3a49ee0e714 /src/mongo
parentb83a9baed05507e5c29983186b0f704a9a606dae (diff)
downloadmongo-30a061c7f72f7b47029142bc641534eb8f0feed8.tar.gz
SERVER-18072 Pull ShardingConnectionHook into its own library
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/SConscript2
-rw-r--r--src/mongo/db/audit.h4
-rw-r--r--src/mongo/s/SConscript15
-rw-r--r--src/mongo/s/client/SConscript14
-rw-r--r--src/mongo/s/client/multi_host_query.cpp (renamed from src/mongo/s/multi_host_query.cpp)4
-rw-r--r--src/mongo/s/client/multi_host_query.h (renamed from src/mongo/s/multi_host_query.h)1
-rw-r--r--src/mongo/s/client/multi_host_query_test.cpp (renamed from src/mongo/s/multi_host_query_test.cpp)3
-rw-r--r--src/mongo/s/client/scc_fast_query_handler.cpp (renamed from src/mongo/s/scc_fast_query_handler.cpp)4
-rw-r--r--src/mongo/s/client/scc_fast_query_handler.h (renamed from src/mongo/s/scc_fast_query_handler.h)2
-rw-r--r--src/mongo/s/client/shard.cpp94
-rw-r--r--src/mongo/s/client/shard_connection.h16
-rw-r--r--src/mongo/s/client/sharding_connection_hook.cpp137
-rw-r--r--src/mongo/s/client/sharding_connection_hook.h53
-rw-r--r--src/mongo/s/d_state.cpp2
-rw-r--r--src/mongo/s/server.cpp1
-rw-r--r--src/mongo/s/strategy.cpp2
-rw-r--r--src/mongo/s/write_ops/batch_downconvert.h3
17 files changed, 218 insertions, 139 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index e9a1640bcc7..64ee90cf6e6 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -931,6 +931,7 @@ env.Library('mongoscore',
'db/fts/ftsmongos',
'db/query/explain_common',
'db/query/lite_parsed_query',
+ 's/client/sharding_connection_hook',
's/cluster_ops',
's/cluster_write_op_conversion',
's/commands/cluster_commands',
@@ -1078,6 +1079,7 @@ serveronlyLibdeps = ["coreshard",
"update_index_data",
's/metadata',
's/batch_write_types',
+ 's/client/sharding_connection_hook',
"db/catalog/collection_options",
"db/exec/working_set",
"db/exec/exec",
diff --git a/src/mongo/db/audit.h b/src/mongo/db/audit.h
index e784ffe4929..74fff7581cc 100644
--- a/src/mongo/db/audit.h
+++ b/src/mongo/db/audit.h
@@ -48,10 +48,6 @@ namespace mongo {
class StringData;
class UserName;
-namespace mutablebson {
- class Document;
-} // namespace mutablebson
-
namespace audit {
/**
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index b9a0e045149..43cc7f41696 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -149,7 +149,6 @@ env.Library(
'write_ops/write_op.cpp',
'write_ops/batch_write_op.cpp',
'write_ops/batch_write_exec.cpp',
- 'multi_host_query.cpp'
],
LIBDEPS=[
'$BUILD_DIR/mongo/bson',
@@ -173,19 +172,6 @@ env.CppUnitTest(
]
)
-env.CppUnitTest(
- target='multi_host_query_test',
- source=[
- 'multi_host_query_test.cpp',
- ],
- LIBDEPS=[
- 'base',
- 'cluster_ops',
- '$BUILD_DIR/mongo/db/common',
- '$BUILD_DIR/mongo/clientdriver',
- ],
-)
-
# Upconvert/Downconvert write functionality for mongos
env.Library(
target='cluster_write_op_conversion',
@@ -228,7 +214,6 @@ env.Library(
'cluster_explain.cpp',
'cluster_write.cpp',
'dbclient_shard_resolver.cpp',
- 'scc_fast_query_handler.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/bson',
diff --git a/src/mongo/s/client/SConscript b/src/mongo/s/client/SConscript
index c22a4be4635..edd1c282ef9 100644
--- a/src/mongo/s/client/SConscript
+++ b/src/mongo/s/client/SConscript
@@ -14,9 +14,23 @@ env.Library(
]
)
+env.Library(
+ target='sharding_connection_hook',
+ source=[
+ 'multi_host_query.cpp',
+ 'scc_fast_query_handler.cpp',
+ 'sharding_connection_hook.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/clientdriver',
+ ]
+)
+
+
env.CppUnitTest(
target='sharding_client_test',
source=[
+ 'multi_host_query_test.cpp',
'shard_connection_test.cpp'
],
LIBDEPS=[
diff --git a/src/mongo/s/multi_host_query.cpp b/src/mongo/s/client/multi_host_query.cpp
index 451b764cde4..b3b5727ee6c 100644
--- a/src/mongo/s/multi_host_query.cpp
+++ b/src/mongo/s/client/multi_host_query.cpp
@@ -28,9 +28,7 @@
#include "mongo/platform/basic.h"
-#include "mongo/s/multi_host_query.h"
-
-#include <boost/shared_ptr.hpp>
+#include "mongo/s/client/multi_host_query.h"
#include "mongo/bson/util/builder.h"
diff --git a/src/mongo/s/multi_host_query.h b/src/mongo/s/client/multi_host_query.h
index bfdf5d8c766..2fb7086b81d 100644
--- a/src/mongo/s/multi_host_query.h
+++ b/src/mongo/s/client/multi_host_query.h
@@ -35,7 +35,6 @@
#include <vector>
#include "mongo/base/disallow_copying.h"
-#include "mongo/base/owned_pointer_vector.h"
#include "mongo/client/dbclientinterface.h"
#include "mongo/stdx/functional.h"
diff --git a/src/mongo/s/multi_host_query_test.cpp b/src/mongo/s/client/multi_host_query_test.cpp
index 1c6757c882b..384d08f815e 100644
--- a/src/mongo/s/multi_host_query_test.cpp
+++ b/src/mongo/s/client/multi_host_query_test.cpp
@@ -26,11 +26,10 @@
* it in the license file.
*/
-#include "mongo/s/multi_host_query.h"
-
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
+#include "mongo/s/client/multi_host_query.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/concurrency/synchronization.h"
diff --git a/src/mongo/s/scc_fast_query_handler.cpp b/src/mongo/s/client/scc_fast_query_handler.cpp
index 0db1a4e4ad4..70894893f18 100644
--- a/src/mongo/s/scc_fast_query_handler.cpp
+++ b/src/mongo/s/client/scc_fast_query_handler.cpp
@@ -28,7 +28,9 @@
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding
-#include "mongo/s/scc_fast_query_handler.h"
+#include "mongo/platform/basic.h"
+
+#include "mongo/s/client/scc_fast_query_handler.h"
#include <vector>
diff --git a/src/mongo/s/scc_fast_query_handler.h b/src/mongo/s/client/scc_fast_query_handler.h
index 22875f6b9db..3cf1af119d1 100644
--- a/src/mongo/s/scc_fast_query_handler.h
+++ b/src/mongo/s/client/scc_fast_query_handler.h
@@ -29,7 +29,7 @@
#pragma once
#include "mongo/client/syncclusterconnection.h"
-#include "mongo/s/multi_host_query.h"
+#include "mongo/s/client/multi_host_query.h"
namespace mongo {
diff --git a/src/mongo/s/client/shard.cpp b/src/mongo/s/client/shard.cpp
index 0ed061636c2..9f461ff187d 100644
--- a/src/mongo/s/client/shard.cpp
+++ b/src/mongo/s/client/shard.cpp
@@ -37,29 +37,21 @@
#include <string>
#include <vector>
+#include "mongo/client/connpool.h"
#include "mongo/client/dbclientcursor.h"
#include "mongo/client/replica_set_monitor.h"
-#include "mongo/db/audit.h"
#include "mongo/db/auth/action_set.h"
#include "mongo/db/auth/action_type.h"
-#include "mongo/db/auth/authorization_manager_global.h"
-#include "mongo/db/auth/internal_user_auth.h"
#include "mongo/db/auth/privilege.h"
#include "mongo/db/commands.h"
#include "mongo/db/jsobj.h"
#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/s/catalog/type_shard.h"
-#include "mongo/s/client/shard_connection.h"
-#include "mongo/s/cluster_last_error_info.h"
#include "mongo/s/grid.h"
-#include "mongo/s/scc_fast_query_handler.h"
-#include "mongo/s/version_manager.h"
#include "mongo/util/log.h"
namespace mongo {
- using std::auto_ptr;
- using std::endl;
using std::list;
using std::map;
using std::ostream;
@@ -67,22 +59,6 @@ namespace mongo {
using std::stringstream;
using std::vector;
- static 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;
- }
class StaticShardInfo {
public:
@@ -394,7 +370,7 @@ namespace mongo {
if (!rs) {
// Possibly still yet to be initialized. See SERVER-8194.
- warning() << "Monitor not found for a known shard: " << _cs.getSetName() << endl;
+ warning() << "Monitor not found for a known shard: " << _cs.getSetName();
return false;
}
@@ -518,7 +494,7 @@ namespace mongo {
best = t;
}
- LOG(1) << "best shard for new allocation is " << best << endl;
+ LOG(1) << "best shard for new allocation is " << best;
return best.shard();
}
@@ -530,66 +506,4 @@ namespace mongo {
_shard(shard), _dataSizeBytes(dataSizeBytes), _mongoVersion(version) {
}
- 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() << endl;
-
- bool result = authenticateInternalUser(conn);
-
- 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 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->setPostRunCommandHook(stdx::bind(&saveGLEStats, stdx::placeholders::_1, stdx::placeholders::_2));
- }
-
- // 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->setRunCommandHook(stdx::bind(&audit::appendImpersonatedUsers, stdx::placeholders::_1));
-
- // 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::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
diff --git a/src/mongo/s/client/shard_connection.h b/src/mongo/s/client/shard_connection.h
index 1eeed9fd87e..ff280ddd774 100644
--- a/src/mongo/s/client/shard_connection.h
+++ b/src/mongo/s/client/shard_connection.h
@@ -140,22 +140,6 @@ namespace mongo {
};
- class ShardingConnectionHook : public DBConnectionHook {
- public:
-
- ShardingConnectionHook( bool shardedConnections )
- : _shardedConnections( shardedConnections ) {
-
- }
-
- virtual void onCreate( DBClientBase * conn );
- virtual void onDestroy( DBClientBase * conn );
- virtual void onRelease(DBClientBase* conn);
-
- bool _shardedConnections;
- };
-
-
/**
* Sends the setShardVersion command on the specified connection.
*/
diff --git a/src/mongo/s/client/sharding_connection_hook.cpp b/src/mongo/s/client/sharding_connection_hook.cpp
new file mode 100644
index 00000000000..b6c334419a2
--- /dev/null
+++ b/src/mongo/s/client/sharding_connection_hook.cpp
@@ -0,0 +1,137 @@
+/**
+ * Copyright (C) 2015 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/s/client/sharding_connection_hook.h"
+
+#include <string>
+
+#include "mongo/db/audit.h"
+#include "mongo/db/auth/authorization_manager_global.h"
+#include "mongo/db/auth/internal_user_auth.h"
+#include "mongo/s/client/scc_fast_query_handler.h"
+#include "mongo/s/cluster_last_error_info.h"
+#include "mongo/s/version_manager.h"
+#include "mongo/util/log.h"
+
+namespace mongo {
+
+ 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;
+ }
+
+} // namespace
+
+
+ ShardingConnectionHook::ShardingConnectionHook(bool shardedConnections)
+ : _shardedConnections(shardedConnections) {
+
+ }
+
+ 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);
+
+ 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 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->setPostRunCommandHook(stdx::bind(&saveGLEStats, stdx::placeholders::_1, stdx::placeholders::_2));
+ }
+
+ // 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->setRunCommandHook(stdx::bind(&audit::appendImpersonatedUsers, stdx::placeholders::_1));
+
+ // 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::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
diff --git a/src/mongo/s/client/sharding_connection_hook.h b/src/mongo/s/client/sharding_connection_hook.h
new file mode 100644
index 00000000000..661bb42f34c
--- /dev/null
+++ b/src/mongo/s/client/sharding_connection_hook.h
@@ -0,0 +1,53 @@
+/**
+ * Copyright (C) 2015 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+#include "mongo/client/connpool.h"
+
+namespace mongo {
+
+ class DBClientBase;
+
+ /**
+ * Intercepts creation of sharded connections and transparently performs the internal
+ * authentication on them.
+ */
+ class ShardingConnectionHook : public DBConnectionHook {
+ public:
+ ShardingConnectionHook(bool shardedConnections);
+
+ virtual void onCreate(DBClientBase* conn);
+ virtual void onDestroy(DBClientBase* conn);
+ virtual void onRelease(DBClientBase* conn);
+
+ private:
+ bool _shardedConnections;
+ };
+
+} // namespace mongo
diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp
index e3d6ab35cf6..14f1ad76c9a 100644
--- a/src/mongo/s/d_state.cpp
+++ b/src/mongo/s/d_state.cpp
@@ -59,6 +59,7 @@
#include "mongo/db/wire_version.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/client/shard_connection.h"
+#include "mongo/s/client/sharding_connection_hook.h"
#include "mongo/s/config.h"
#include "mongo/s/grid.h"
#include "mongo/s/metadata_loader.h"
@@ -66,7 +67,6 @@
#include "mongo/util/concurrency/mutex.h"
#include "mongo/util/concurrency/ticketholder.h"
#include "mongo/util/log.h"
-#include "mongo/util/queue.h"
#include "mongo/util/stringutils.h"
namespace mongo {
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index 8d9633f3944..b69ac75720e 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -61,6 +61,7 @@
#include "mongo/platform/process_id.h"
#include "mongo/s/balance.h"
#include "mongo/s/catalog/legacy/config_upgrade.h"
+#include "mongo/s/client/sharding_connection_hook.h"
#include "mongo/s/chunk_manager.h"
#include "mongo/s/client_info.h"
#include "mongo/s/config.h"
diff --git a/src/mongo/s/strategy.cpp b/src/mongo/s/strategy.cpp
index d34c0256616..769be5ceeca 100644
--- a/src/mongo/s/strategy.cpp
+++ b/src/mongo/s/strategy.cpp
@@ -68,8 +68,6 @@
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/timer.h"
-// error codes 8010-8040
-
namespace mongo {
using boost::scoped_ptr;
diff --git a/src/mongo/s/write_ops/batch_downconvert.h b/src/mongo/s/write_ops/batch_downconvert.h
index 7cd8e95169d..1c48b4e0ef1 100644
--- a/src/mongo/s/write_ops/batch_downconvert.h
+++ b/src/mongo/s/write_ops/batch_downconvert.h
@@ -35,13 +35,10 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/timestamp.h"
#include "mongo/s/write_ops/batch_write_exec.h"
-#include "mongo/s/write_ops/batch_write_op.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_command_response.h"
#include "mongo/s/write_ops/write_error_detail.h"
-// TODO: Remove post-2.6
-
namespace mongo {
class MultiCommandDispatch;