summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/SConscript1
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/s/SConscript3
-rw-r--r--src/mongo/db/s/sharded_connection_info.cpp23
-rw-r--r--src/mongo/db/s/sharding_connection_hook_for_mongod.cpp43
-rw-r--r--src/mongo/db/s/sharding_connection_hook_for_mongod.h44
-rw-r--r--src/mongo/db/s/sharding_egress_metadata_hook_for_mongod.cpp (renamed from src/mongo/s/sharding_egress_metadata_hook_for_mongod.cpp)4
-rw-r--r--src/mongo/db/s/sharding_egress_metadata_hook_for_mongod.h (renamed from src/mongo/s/sharding_egress_metadata_hook_for_mongod.h)6
-rw-r--r--src/mongo/db/s/sharding_initialization_mongod.cpp2
-rw-r--r--src/mongo/db/s/sharding_state.cpp26
-rw-r--r--src/mongo/s/SConscript43
-rw-r--r--src/mongo/s/catalog/sharding_catalog_test_fixture.h1
-rw-r--r--src/mongo/s/client/shard_remote.cpp11
-rw-r--r--src/mongo/s/client/sharding_connection_hook.h7
-rw-r--r--src/mongo/s/client/sharding_connection_hook_for_mongos.cpp42
-rw-r--r--src/mongo/s/client/sharding_connection_hook_for_mongos.h44
-rw-r--r--src/mongo/s/commands/commands_public.cpp1
-rw-r--r--src/mongo/s/config_server_test_fixture.cpp2
-rw-r--r--src/mongo/s/d_state.cpp87
-rw-r--r--src/mongo/s/server.cpp10
-rw-r--r--src/mongo/s/sharding_egress_metadata_hook_for_mongos.cpp1
-rw-r--r--src/mongo/s/sharding_egress_metadata_hook_for_mongos.h2
-rw-r--r--src/mongo/s/sharding_mongod_test_fixture.cpp6
23 files changed, 75 insertions, 335 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index a8aab08791e..1f02fb78741 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -342,7 +342,6 @@ env.Install(
env.Program(
target='mongos',
source=[
- 's/client/sharding_connection_hook_for_mongos.cpp',
's/mongos_options_init.cpp',
's/server.cpp',
's/service_entry_point_mongos.cpp',
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 20aa7fe127e..2f085cdb6aa 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -835,7 +835,6 @@ env.Library(
"$BUILD_DIR/mongo/s/client/sharding_connection_hook",
"$BUILD_DIR/mongo/s/coreshard",
"$BUILD_DIR/mongo/s/shard_id",
- "$BUILD_DIR/mongo/s/serveronly",
"$BUILD_DIR/mongo/scripting/scripting_server",
"$BUILD_DIR/mongo/util/clock_sources",
"$BUILD_DIR/mongo/util/elapsed_tracker",
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index f5c62c47fa6..34cb36d2a65 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -65,7 +65,7 @@ env.Library(
'operation_sharding_state.cpp',
'shard_identity_rollback_notifier.cpp',
'sharded_connection_info.cpp',
- 'sharding_connection_hook_for_mongod.cpp',
+ 'sharding_egress_metadata_hook_for_mongod.cpp',
'sharding_initialization_mongod.cpp',
'sharding_state.cpp',
'sharding_state_recovery.cpp',
@@ -175,7 +175,6 @@ env.Library(
'$BUILD_DIR/mongo/db/index_d',
'$BUILD_DIR/mongo/db/range_deleter_d',
'$BUILD_DIR/mongo/db/repl/repl_coordinator_global',
- '$BUILD_DIR/mongo/s/serveronly',
'balancer',
'metadata',
'sharding',
diff --git a/src/mongo/db/s/sharded_connection_info.cpp b/src/mongo/db/s/sharded_connection_info.cpp
index 2dfaac42fd6..336cb68c1ea 100644
--- a/src/mongo/db/s/sharded_connection_info.cpp
+++ b/src/mongo/db/s/sharded_connection_info.cpp
@@ -38,18 +38,23 @@
#include "mongo/client/global_conn_pool.h"
#include "mongo/db/client.h"
#include "mongo/db/operation_context.h"
-#include "mongo/db/s/sharding_connection_hook_for_mongod.h"
+#include "mongo/db/s/sharding_egress_metadata_hook_for_mongod.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/client/shard_connection.h"
+#include "mongo/s/client/sharding_connection_hook.h"
+#include "mongo/stdx/memory.h"
#include "mongo/util/log.h"
namespace mongo {
-
namespace {
const auto clientSCI = Client::declareDecoration<boost::optional<ShardedConnectionInfo>>();
+stdx::mutex addHookMutex;
+
+AtomicUInt32 alreadyAddedHook{0};
+
} // namespace
ShardedConnectionInfo::ShardedConnectionInfo() {
@@ -86,24 +91,24 @@ void ShardedConnectionInfo::setVersion(const std::string& ns, const ChunkVersion
_versions[ns] = version;
}
-namespace {
-stdx::mutex addHookMutex;
-AtomicUInt32 alreadyAddedHook{0};
-} // namespace
-
void ShardedConnectionInfo::addHook() {
if (alreadyAddedHook.loadRelaxed()) {
return;
}
+
stdx::lock_guard<stdx::mutex> lk{addHookMutex};
if (alreadyAddedHook.load()) {
return;
}
+
log() << "first cluster operation detected, adding sharding hook to enable versioning "
"and authentication to remote servers";
- globalConnPool.addHook(new ShardingConnectionHookForMongod(false));
- shardConnectionPool.addHook(new ShardingConnectionHookForMongod(true));
+ globalConnPool.addHook(new ShardingConnectionHook(
+ false, stdx::make_unique<rpc::ShardingEgressMetadataHookForMongod>()));
+
+ shardConnectionPool.addHook(new ShardingConnectionHook(
+ true, stdx::make_unique<rpc::ShardingEgressMetadataHookForMongod>()));
alreadyAddedHook.store(1);
}
diff --git a/src/mongo/db/s/sharding_connection_hook_for_mongod.cpp b/src/mongo/db/s/sharding_connection_hook_for_mongod.cpp
deleted file mode 100644
index 55abe671115..00000000000
--- a/src/mongo/db/s/sharding_connection_hook_for_mongod.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Copyright (C) 2016 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.
- */
-
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/s/sharding_connection_hook_for_mongod.h"
-
-#include "mongo/s/sharding_egress_metadata_hook_for_mongod.h"
-#include "mongo/stdx/memory.h"
-
-namespace mongo {
-
-ShardingConnectionHookForMongod::ShardingConnectionHookForMongod(bool shardedConnections)
- : ShardingConnectionHook(shardedConnections,
- stdx::make_unique<rpc::ShardingEgressMetadataHookForMongod>()){};
-
-} // namespace mongo
diff --git a/src/mongo/db/s/sharding_connection_hook_for_mongod.h b/src/mongo/db/s/sharding_connection_hook_for_mongod.h
deleted file mode 100644
index 71344aa91bf..00000000000
--- a/src/mongo/db/s/sharding_connection_hook_for_mongod.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Copyright (C) 2016 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/s/client/sharding_connection_hook.h"
-
-namespace mongo {
-
-/**
- * Intercepts creation of sharded connections and transparently performs the internal
- * authentication on them.
- */
-class ShardingConnectionHookForMongod final : public ShardingConnectionHook {
-public:
- explicit ShardingConnectionHookForMongod(bool shardedConnections);
-};
-
-} // namespace mongo
diff --git a/src/mongo/s/sharding_egress_metadata_hook_for_mongod.cpp b/src/mongo/db/s/sharding_egress_metadata_hook_for_mongod.cpp
index 2c8dc215847..99603ce0ed4 100644
--- a/src/mongo/s/sharding_egress_metadata_hook_for_mongod.cpp
+++ b/src/mongo/db/s/sharding_egress_metadata_hook_for_mongod.cpp
@@ -30,16 +30,14 @@
#include "mongo/platform/basic.h"
-#include "mongo/s/sharding_egress_metadata_hook_for_mongod.h"
+#include "mongo/db/s/sharding_egress_metadata_hook_for_mongod.h"
#include "mongo/base/status.h"
#include "mongo/db/repl/replication_coordinator_global.h"
#include "mongo/db/server_options.h"
#include "mongo/s/grid.h"
-#include "mongo/s/sharding_egress_metadata_hook_for_mongos.h"
namespace mongo {
-
namespace rpc {
void ShardingEgressMetadataHookForMongod::_saveGLEStats(const BSONObj& metadata,
diff --git a/src/mongo/s/sharding_egress_metadata_hook_for_mongod.h b/src/mongo/db/s/sharding_egress_metadata_hook_for_mongod.h
index 56272d97cd2..f9032ef6945 100644
--- a/src/mongo/s/sharding_egress_metadata_hook_for_mongod.h
+++ b/src/mongo/db/s/sharding_egress_metadata_hook_for_mongod.h
@@ -31,16 +31,14 @@
#include "mongo/s/sharding_egress_metadata_hook.h"
namespace mongo {
-
namespace rpc {
class ShardingEgressMetadataHookForMongod final : public ShardingEgressMetadataHook {
-public:
- ShardingEgressMetadataHookForMongod() = default;
-
private:
void _saveGLEStats(const BSONObj& metadata, StringData hostString) override;
+
repl::OpTime _getConfigServerOpTime() override;
+
Status _advanceConfigOptimeFromShard(ShardId shardId, const BSONObj& metadataObj) override;
};
diff --git a/src/mongo/db/s/sharding_initialization_mongod.cpp b/src/mongo/db/s/sharding_initialization_mongod.cpp
index d17f26191dd..ba292c269c2 100644
--- a/src/mongo/db/s/sharding_initialization_mongod.cpp
+++ b/src/mongo/db/s/sharding_initialization_mongod.cpp
@@ -36,6 +36,7 @@
#include "mongo/client/connection_string.h"
#include "mongo/client/remote_command_targeter.h"
#include "mongo/client/remote_command_targeter_factory_impl.h"
+#include "mongo/db/s/sharding_egress_metadata_hook_for_mongod.h"
#include "mongo/db/server_options.h"
#include "mongo/executor/task_executor.h"
#include "mongo/rpc/metadata/egress_metadata_hook_list.h"
@@ -43,7 +44,6 @@
#include "mongo/s/client/shard_factory.h"
#include "mongo/s/client/shard_local.h"
#include "mongo/s/client/shard_remote.h"
-#include "mongo/s/sharding_egress_metadata_hook_for_mongod.h"
#include "mongo/s/sharding_initialization.h"
#include "mongo/stdx/memory.h"
diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp
index bc9932a387c..57fda772fb4 100644
--- a/src/mongo/db/s/sharding_state.cpp
+++ b/src/mongo/db/s/sharding_state.cpp
@@ -32,6 +32,7 @@
#include "mongo/db/s/sharding_state.h"
+#include "mongo/base/init.h"
#include "mongo/bson/util/bson_extract.h"
#include "mongo/client/connection_string.h"
#include "mongo/client/replica_set_monitor.h"
@@ -62,6 +63,7 @@
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/client/sharding_network_connection_hook.h"
#include "mongo/s/grid.h"
+#include "mongo/s/local_sharding_info.h"
#include "mongo/s/sharding_initialization.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
@@ -117,6 +119,30 @@ void updateShardIdentityConfigStringCB(const string& setName, const string& newC
}
}
+bool haveLocalShardingInfo(OperationContext* txn, const string& ns) {
+ if (!ShardingState::get(txn)->enabled()) {
+ return false;
+ }
+
+ const auto& oss = OperationShardingState::get(txn);
+ if (oss.hasShardVersion()) {
+ return true;
+ }
+
+ const auto& sci = ShardedConnectionInfo::get(txn->getClient(), false);
+ if (sci && !sci->getVersion(ns).isStrictlyEqualTo(ChunkVersion::UNSHARDED())) {
+ return true;
+ }
+
+ return false;
+}
+
+MONGO_INITIALIZER_WITH_PREREQUISITES(MongoDLocalShardingInfo, ("SetGlobalEnvironment"))
+(InitializerContext* context) {
+ enableLocalShardingInfo(getGlobalServiceContext(), &haveLocalShardingInfo);
+ return Status::OK();
+}
+
} // namespace
ShardingState::ShardingState()
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index ef34405fe0a..ff072e796ea 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -32,7 +32,6 @@ env.Library(
'$BUILD_DIR/mongo/s/catalog/replset_dist_lock_manager',
'client/sharding_connection_hook',
'coreshard',
- 'cluster_last_error_info',
],
)
@@ -102,14 +101,13 @@ env.Library(
'$BUILD_DIR/mongo/executor/network_test_env',
'$BUILD_DIR/mongo/executor/task_executor_pool',
'$BUILD_DIR/mongo/executor/thread_pool_task_executor_test_fixture',
- '$BUILD_DIR/mongo/rpc/metadata',
'$BUILD_DIR/mongo/s/catalog/dist_lock_manager_mock',
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_impl',
'$BUILD_DIR/mongo/s/coreshard',
'$BUILD_DIR/mongo/transport/transport_layer_mock',
'$BUILD_DIR/mongo/util/clock_source_mock',
'$BUILD_DIR/mongo/util/net/message_port_mock',
- 'mongoscore',
+ 'sharding_egress_metadata_hook_for_mongos',
],
)
@@ -153,7 +151,6 @@ env.Library(
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_impl',
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_manager_impl',
'$BUILD_DIR/mongo/s/coreshard',
- '$BUILD_DIR/mongo/s/serveronly',
'$BUILD_DIR/mongo/util/clock_source_mock',
'$BUILD_DIR/mongo/util/net/message_port_mock',
],
@@ -270,10 +267,19 @@ env.Library(
LIBDEPS=[
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/client/connection_string',
+ '$BUILD_DIR/mongo/util/decorable',
+ ]
+)
+
+env.Library(
+ target='sharding_egress_metadata_hook_for_mongos',
+ source=[
+ 'sharding_egress_metadata_hook_for_mongos.cpp'
+ ],
+ LIBDEPS=[
'$BUILD_DIR/mongo/rpc/metadata',
- '$BUILD_DIR/mongo/db/commands/server_status_core',
- '$BUILD_DIR/mongo/db/service_context',
- '$BUILD_DIR/mongo/db/stats/timer_stats',
+ 'cluster_last_error_info',
+ 'coreshard',
]
)
@@ -292,7 +298,6 @@ env.Library(
'mongos_options.cpp',
's_only.cpp',
's_sharding_server_status.cpp',
- 'sharding_egress_metadata_hook_for_mongos.cpp',
'sharding_uptime_reporter.cpp',
'version_mongos.cpp',
],
@@ -302,7 +307,7 @@ env.Library(
'$BUILD_DIR/mongo/db/stats/counters',
'$BUILD_DIR/mongo/s/query/cluster_query',
'$BUILD_DIR/mongo/util/concurrency/task',
- 'cluster_last_error_info',
+ 'sharding_egress_metadata_hook_for_mongos',
'is_mongos',
],
)
@@ -338,23 +343,3 @@ env.Library(
'$BUILD_DIR/mongo/db/service_context',
],
)
-
-env.Library(
- target='serveronly',
- source=[
- 'd_state.cpp',
- 'sharding_egress_metadata_hook_for_mongod.cpp',
- ],
- LIBDEPS=[
- "coreshard",
- "local_sharding_info",
- "$BUILD_DIR/mongo/db/commands/core",
- "$BUILD_DIR/mongo/db/concurrency/lock_manager",
- "$BUILD_DIR/mongo/db/query/query",
- "$BUILD_DIR/mongo/db/range_deleter",
- "$BUILD_DIR/mongo/db/s/metadata",
- "$BUILD_DIR/mongo/db/s/sharding",
- "$BUILD_DIR/mongo/executor/network_interface_factory",
- "$BUILD_DIR/mongo/s/client/shard_local",
- ],
-)
diff --git a/src/mongo/s/catalog/sharding_catalog_test_fixture.h b/src/mongo/s/catalog/sharding_catalog_test_fixture.h
index 4c13a0e8dda..f5736de022a 100644
--- a/src/mongo/s/catalog/sharding_catalog_test_fixture.h
+++ b/src/mongo/s/catalog/sharding_catalog_test_fixture.h
@@ -48,4 +48,5 @@ protected:
void expectFindOnConfigSendBSONObjVector(std::vector<BSONObj> obj);
};
+
} // namespace mongo
diff --git a/src/mongo/s/client/shard_remote.cpp b/src/mongo/s/client/shard_remote.cpp
index 85e0bc7678b..dea32639d84 100644
--- a/src/mongo/s/client/shard_remote.cpp
+++ b/src/mongo/s/client/shard_remote.cpp
@@ -274,22 +274,19 @@ StatusWith<Shard::QueryResponse> ShardRemote::_exhaustiveFindOnConfig(
return;
}
- auto& data = dataStatus.getValue();
+ const auto& data = dataStatus.getValue();
+
if (data.otherFields.metadata.hasField(rpc::kReplSetMetadataFieldName)) {
auto replParseStatus =
rpc::ReplSetMetadata::readFromMetadata(data.otherFields.metadata);
-
if (!replParseStatus.isOK()) {
status = replParseStatus.getStatus();
response.docs.clear();
return;
}
- response.opTime = replParseStatus.getValue().getLastOpCommitted();
-
- // We return the config opTime that was returned for this particular request, but as
- // a safeguard we ensure our global configOpTime is at least as large as it.
- invariant(grid.configOpTime() >= response.opTime);
+ const auto& replSetMetadata = replParseStatus.getValue();
+ response.opTime = replSetMetadata.getLastOpCommitted();
}
for (const BSONObj& doc : data.documents) {
diff --git a/src/mongo/s/client/sharding_connection_hook.h b/src/mongo/s/client/sharding_connection_hook.h
index cde5d86123d..02c300b026b 100644
--- a/src/mongo/s/client/sharding_connection_hook.h
+++ b/src/mongo/s/client/sharding_connection_hook.h
@@ -42,14 +42,13 @@ class DBClientBase;
*/
class ShardingConnectionHook : public DBConnectionHook {
public:
+ ShardingConnectionHook(bool shardedConnections,
+ std::unique_ptr<rpc::ShardingEgressMetadataHook> egressHook);
+
void onCreate(DBClientBase* conn) override;
void onDestroy(DBClientBase* conn) override;
void onRelease(DBClientBase* conn) override;
-protected:
- ShardingConnectionHook(bool shardedConnections,
- std::unique_ptr<rpc::ShardingEgressMetadataHook> egressHook);
-
private:
bool _shardedConnections;
diff --git a/src/mongo/s/client/sharding_connection_hook_for_mongos.cpp b/src/mongo/s/client/sharding_connection_hook_for_mongos.cpp
deleted file mode 100644
index ca39c90ab64..00000000000
--- a/src/mongo/s/client/sharding_connection_hook_for_mongos.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Copyright (C) 2016 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.
- */
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/s/client/sharding_connection_hook_for_mongos.h"
-
-#include "mongo/s/sharding_egress_metadata_hook_for_mongos.h"
-#include "mongo/stdx/memory.h"
-
-namespace mongo {
-
-ShardingConnectionHookForMongos::ShardingConnectionHookForMongos(bool shardedConnections)
- : ShardingConnectionHook(shardedConnections,
- stdx::make_unique<rpc::ShardingEgressMetadataHookForMongos>()){};
-
-} // namespace mongo
diff --git a/src/mongo/s/client/sharding_connection_hook_for_mongos.h b/src/mongo/s/client/sharding_connection_hook_for_mongos.h
deleted file mode 100644
index bfcaef9972f..00000000000
--- a/src/mongo/s/client/sharding_connection_hook_for_mongos.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Copyright (C) 2016 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/s/client/sharding_connection_hook.h"
-
-namespace mongo {
-
-/**
- * Intercepts creation of sharded connections and transparently performs the internal
- * authentication on them.
- */
-class ShardingConnectionHookForMongos final : public ShardingConnectionHook {
-public:
- explicit ShardingConnectionHookForMongos(bool shardedConnections);
-};
-
-} // namespace mongo
diff --git a/src/mongo/s/commands/commands_public.cpp b/src/mongo/s/commands/commands_public.cpp
index d89da63cd0d..ed43e166fa8 100644
--- a/src/mongo/s/commands/commands_public.cpp
+++ b/src/mongo/s/commands/commands_public.cpp
@@ -57,7 +57,6 @@
#include "mongo/s/chunk_manager.h"
#include "mongo/s/client/shard_connection.h"
#include "mongo/s/client/shard_registry.h"
-#include "mongo/s/cluster_last_error_info.h"
#include "mongo/s/commands/cluster_commands_common.h"
#include "mongo/s/commands/cluster_explain.h"
#include "mongo/s/commands/run_on_all_shards_cmd.h"
diff --git a/src/mongo/s/config_server_test_fixture.cpp b/src/mongo/s/config_server_test_fixture.cpp
index 13c45ff9f56..65e8dec3fe8 100644
--- a/src/mongo/s/config_server_test_fixture.cpp
+++ b/src/mongo/s/config_server_test_fixture.cpp
@@ -69,7 +69,6 @@
#include "mongo/s/grid.h"
#include "mongo/s/query/cluster_cursor_manager.h"
#include "mongo/s/set_shard_version_request.h"
-#include "mongo/s/sharding_egress_metadata_hook_for_mongod.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_command_response.h"
#include "mongo/stdx/memory.h"
@@ -82,7 +81,6 @@ using executor::NetworkInterfaceMock;
using executor::NetworkTestEnv;
using executor::RemoteCommandRequest;
using executor::RemoteCommandResponse;
-using rpc::ShardingEgressMetadataHookForMongod;
using unittest::assertGet;
using std::string;
diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp
deleted file mode 100644
index 41960a35ba0..00000000000
--- a/src/mongo/s/d_state.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * Copyright (C) 2008-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/base/init.h"
-#include "mongo/db/auth/action_set.h"
-#include "mongo/db/auth/action_type.h"
-#include "mongo/db/auth/authorization_manager.h"
-#include "mongo/db/auth/authorization_session.h"
-#include "mongo/db/auth/privilege.h"
-#include "mongo/db/commands.h"
-#include "mongo/db/db_raii.h"
-#include "mongo/db/jsobj.h"
-#include "mongo/db/operation_context.h"
-#include "mongo/db/s/collection_metadata.h"
-#include "mongo/db/s/collection_sharding_state.h"
-#include "mongo/db/s/operation_sharding_state.h"
-#include "mongo/db/s/sharded_connection_info.h"
-#include "mongo/db/s/sharding_state.h"
-#include "mongo/db/service_context.h"
-#include "mongo/s/local_sharding_info.h"
-#include "mongo/util/log.h"
-#include "mongo/util/stringutils.h"
-
-namespace mongo {
-
-using std::shared_ptr;
-using std::string;
-using std::stringstream;
-
-namespace {
-
-bool haveLocalShardingInfo(OperationContext* txn, const string& ns) {
- if (!ShardingState::get(txn)->enabled()) {
- return false;
- }
-
- const auto& oss = OperationShardingState::get(txn);
- if (oss.hasShardVersion()) {
- return true;
- }
-
- const auto& sci = ShardedConnectionInfo::get(txn->getClient(), false);
- if (sci && !sci->getVersion(ns).isStrictlyEqualTo(ChunkVersion::UNSHARDED())) {
- return true;
- }
-
- return false;
-}
-
-MONGO_INITIALIZER_WITH_PREREQUISITES(MongoDLocalShardingInfo, ("SetGlobalEnvironment"))
-(InitializerContext* context) {
- enableLocalShardingInfo(getGlobalServiceContext(), &haveLocalShardingInfo);
- return Status::OK();
-}
-
-} // namespace
-
-} // namespace mongo
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index 61784799c0f..60b46736290 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -71,7 +71,7 @@
#include "mongo/s/client/shard_factory.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/client/shard_remote.h"
-#include "mongo/s/client/sharding_connection_hook_for_mongos.h"
+#include "mongo/s/client/sharding_connection_hook.h"
#include "mongo/s/grid.h"
#include "mongo/s/is_mongos.h"
#include "mongo/s/mongos_options.h"
@@ -79,6 +79,7 @@
#include "mongo/s/query/cluster_cursor_manager.h"
#include "mongo/s/service_entry_point_mongos.h"
#include "mongo/s/sharding_egress_metadata_hook_for_mongos.h"
+#include "mongo/s/sharding_egress_metadata_hook_for_mongos.h"
#include "mongo/s/sharding_initialization.h"
#include "mongo/s/sharding_uptime_reporter.h"
#include "mongo/s/version_mongos.h"
@@ -255,8 +256,11 @@ static ExitCode runMongosServer() {
}
// Add sharding hooks to both connection pools - ShardingConnectionHook includes auth hooks
- globalConnPool.addHook(new ShardingConnectionHookForMongos(false));
- shardConnectionPool.addHook(new ShardingConnectionHookForMongos(true));
+ globalConnPool.addHook(new ShardingConnectionHook(
+ false, stdx::make_unique<rpc::ShardingEgressMetadataHookForMongos>()));
+
+ shardConnectionPool.addHook(new ShardingConnectionHook(
+ true, stdx::make_unique<rpc::ShardingEgressMetadataHookForMongos>()));
ReplicaSetMonitor::setAsynchronousConfigChangeHook(
&ShardRegistry::replicaSetChangeConfigServerUpdateHook);
diff --git a/src/mongo/s/sharding_egress_metadata_hook_for_mongos.cpp b/src/mongo/s/sharding_egress_metadata_hook_for_mongos.cpp
index 6fdf800548c..f355054f92b 100644
--- a/src/mongo/s/sharding_egress_metadata_hook_for_mongos.cpp
+++ b/src/mongo/s/sharding_egress_metadata_hook_for_mongos.cpp
@@ -39,7 +39,6 @@
#include "mongo/util/log.h"
namespace mongo {
-
namespace rpc {
void ShardingEgressMetadataHookForMongos::_saveGLEStats(const BSONObj& metadata,
diff --git a/src/mongo/s/sharding_egress_metadata_hook_for_mongos.h b/src/mongo/s/sharding_egress_metadata_hook_for_mongos.h
index 92fd9cf9eef..9cba4226df2 100644
--- a/src/mongo/s/sharding_egress_metadata_hook_for_mongos.h
+++ b/src/mongo/s/sharding_egress_metadata_hook_for_mongos.h
@@ -31,12 +31,12 @@
#include "mongo/s/sharding_egress_metadata_hook.h"
namespace mongo {
-
namespace rpc {
class ShardingEgressMetadataHookForMongos final : public ShardingEgressMetadataHook {
private:
void _saveGLEStats(const BSONObj& metadata, StringData hostString) override;
+
repl::OpTime _getConfigServerOpTime() override;
};
diff --git a/src/mongo/s/sharding_mongod_test_fixture.cpp b/src/mongo/s/sharding_mongod_test_fixture.cpp
index 96694e87e77..53e0fcd62d9 100644
--- a/src/mongo/s/sharding_mongod_test_fixture.cpp
+++ b/src/mongo/s/sharding_mongod_test_fixture.cpp
@@ -70,7 +70,6 @@
#include "mongo/s/grid.h"
#include "mongo/s/query/cluster_cursor_manager.h"
#include "mongo/s/set_shard_version_request.h"
-#include "mongo/s/sharding_egress_metadata_hook_for_mongod.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_command_response.h"
#include "mongo/stdx/memory.h"
@@ -86,7 +85,6 @@ using executor::RemoteCommandResponse;
using repl::ReplicationCoordinator;
using repl::ReplicationCoordinatorMock;
using repl::ReplSettings;
-using rpc::ShardingEgressMetadataHookForMongod;
using unittest::assertGet;
using std::string;
@@ -140,8 +138,6 @@ std::unique_ptr<executor::TaskExecutorPool> ShardingMongodTestFixture::makeTaskE
// threads, tasks in the NetworkInterfaceMock must be carried out synchronously by the (single)
// thread the unit test is running on.
auto netForFixedTaskExecutor = stdx::make_unique<executor::NetworkInterfaceMock>();
- netForFixedTaskExecutor->setEgressMetadataHook(
- stdx::make_unique<ShardingEgressMetadataHookForMongod>());
_mockNetwork = netForFixedTaskExecutor.get();
// Set up a ThreadPoolTaskExecutor. Note, for local tasks this TaskExecutor uses a
@@ -156,8 +152,6 @@ std::unique_ptr<executor::TaskExecutorPool> ShardingMongodTestFixture::makeTaskE
// Set up a NetworkInterfaceMock for the (one) arbitrary TaskExecutor that will go in the set
// of arbitrary TaskExecutors.
auto netForArbitraryExecutor = stdx::make_unique<executor::NetworkInterfaceMock>();
- netForArbitraryExecutor->setEgressMetadataHook(
- stdx::make_unique<ShardingEgressMetadataHookForMongod>());
// Set up (one) TaskExecutor for the set of arbitrary TaskExecutors.
auto arbitraryExecutorForExecutorPool =