summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-12-14 11:57:35 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-12-28 11:47:14 -0500
commitedc1557cee4763ed45fe5140bc8c61db28e95dfe (patch)
tree8b211cfc55bbaeb3b655d284d225f2a40ecf5fc8
parent9483f715e824c9fcd4caae3a5c7d9d7fc598bc7e (diff)
downloadmongo-edc1557cee4763ed45fe5140bc8c61db28e95dfe.tar.gz
SERVER-29909 Remove circular dependency between db_raii and sharding libraries
(cherry picked from commit 8467708af7fa83f8827362b80f56dab4aad30a41) (cherry picked from commit 4312da76ee19623dd60811a22a53fa8e9beb484c)
-rw-r--r--jstests/sharding/movePrimary1.js64
-rw-r--r--src/mongo/SConscript1
-rw-r--r--src/mongo/db/SConscript9
-rw-r--r--src/mongo/db/catalog/SConscript17
-rw-r--r--src/mongo/db/catalog/capped_utils.cpp5
-rw-r--r--src/mongo/db/catalog/catalog_raii.cpp121
-rw-r--r--src/mongo/db/catalog/catalog_raii.h217
-rw-r--r--src/mongo/db/catalog/coll_mod.cpp2
-rw-r--r--src/mongo/db/catalog/drop_collection.cpp2
-rw-r--r--src/mongo/db/catalog/drop_database.cpp5
-rw-r--r--src/mongo/db/catalog/drop_indexes.cpp4
-rw-r--r--src/mongo/db/catalog/rename_collection.cpp2
-rw-r--r--src/mongo/db/commands/SConscript8
-rw-r--r--src/mongo/db/commands/list_databases.cpp12
-rw-r--r--src/mongo/db/concurrency/SConscript24
-rw-r--r--src/mongo/db/db_raii.cpp84
-rw-r--r--src/mongo/db/db_raii.h192
-rw-r--r--src/mongo/db/s/SConscript34
-rw-r--r--src/mongo/db/s/active_migrations_registry.cpp2
-rw-r--r--src/mongo/db/s/check_sharding_index_command.cpp2
-rw-r--r--src/mongo/db/s/cleanup_orphaned_cmd.cpp5
-rw-r--r--src/mongo/db/s/collection_range_deleter.cpp5
-rw-r--r--src/mongo/db/s/collection_range_deleter_test.cpp8
-rw-r--r--src/mongo/db/s/collection_sharding_state.cpp6
-rw-r--r--src/mongo/db/s/collection_sharding_state_test.cpp101
-rw-r--r--src/mongo/db/s/flush_routing_table_cache_updates_command.cpp2
-rw-r--r--src/mongo/db/s/get_shard_version_command.cpp3
-rw-r--r--src/mongo/db/s/merge_chunks_command.cpp4
-rw-r--r--src/mongo/db/s/metadata_manager.cpp2
-rw-r--r--src/mongo/db/s/metadata_manager_test.cpp4
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp3
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy_commands.cpp2
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp3
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp11
-rw-r--r--src/mongo/db/s/migration_source_manager.cpp2
-rw-r--r--src/mongo/db/s/move_chunk_command.cpp15
-rw-r--r--src/mongo/db/s/session_catalog_migration_source.cpp3
-rw-r--r--src/mongo/db/s/set_shard_version_command.cpp6
-rw-r--r--src/mongo/db/s/sharding_state.cpp12
-rw-r--r--src/mongo/db/s/sharding_state_recovery.cpp3
-rw-r--r--src/mongo/db/s/split_chunk.cpp2
-rw-r--r--src/mongo/db/s/split_vector.cpp2
-rw-r--r--src/mongo/s/catalog/SConscript2
-rw-r--r--src/mongo/s/catalog/sharding_catalog_config_initialization_test.cpp3
-rw-r--r--src/mongo/s/catalog/sharding_catalog_manager_chunk_operations.cpp2
-rw-r--r--src/mongo/s/catalog/sharding_catalog_manager_shard_operations.cpp2
-rw-r--r--src/mongo/s/client/shard_local_test.cpp3
-rw-r--r--src/mongo/s/config_server_test_fixture.cpp2
-rw-r--r--src/mongo/s/sharding_mongod_test_fixture.cpp2
49 files changed, 530 insertions, 497 deletions
diff --git a/jstests/sharding/movePrimary1.js b/jstests/sharding/movePrimary1.js
index 4db1a09c41a..80928677984 100644
--- a/jstests/sharding/movePrimary1.js
+++ b/jstests/sharding/movePrimary1.js
@@ -1,60 +1,56 @@
(function() {
+ 'use strict';
- var s = new ShardingTest({name: "movePrimary1", shards: 2});
+ var s = new ShardingTest({shards: 2});
- initDB = function(name) {
- var db = s.getDB(name);
- var c = db.foo;
- c.save({a: 1});
- c.save({a: 2});
- c.save({a: 3});
- assert.eq(3, c.count());
+ var db = s.getDB('test1');
+ var c = db.foo;
+ c.save({a: 1});
+ c.save({a: 2});
+ c.save({a: 3});
+ assert.eq(3, c.count());
- assert.commandWorked(
- db.runCommand({create: "view", viewOn: "foo", pipeline: [{$match: {a: 3}}]}));
+ assert.commandWorked(
+ db.runCommand({create: "view", viewOn: "foo", pipeline: [{$match: {a: 3}}]}));
- return s.getPrimaryShard(name);
- };
+ var fromShard = s.getPrimaryShard('test1');
+ var toShard = s.getOther(fromShard);
- from = initDB("test1");
- to = s.getOther(from);
-
- assert.eq(3, from.getDB("test1").foo.count(), "from doesn't have data before move");
- assert.eq(0, to.getDB("test1").foo.count(), "to has data before move");
+ assert.eq(3, fromShard.getDB("test1").foo.count(), "from doesn't have data before move");
+ assert.eq(0, toShard.getDB("test1").foo.count(), "to has data before move");
assert.eq(1, s.s.getDB("test1").view.count(), "count on view incorrect before move");
+ s.printShardingStatus();
assert.eq(s.normalize(s.config.databases.findOne({_id: "test1"}).primary),
- s.normalize(from.name),
+ s.normalize(fromShard.name),
"not in db correctly to start");
- s.printShardingStatus();
- oldShardName = s.config.databases.findOne({_id: "test1"}).primary;
- s.admin.runCommand({moveprimary: "test1", to: to.name});
+
+ var oldShardName = s.config.databases.findOne({_id: "test1"}).primary;
+
+ assert.commandWorked(s.s0.adminCommand({movePrimary: "test1", to: toShard.name}));
s.printShardingStatus();
assert.eq(s.normalize(s.config.databases.findOne({_id: "test1"}).primary),
- s.normalize(to.name),
+ s.normalize(toShard.name),
"to in config db didn't change after first move");
- assert.eq(0, from.getDB("test1").foo.count(), "from still has data after move");
- assert.eq(3, to.getDB("test1").foo.count(), "to doesn't have data after move");
+ assert.eq(0, fromShard.getDB("test1").foo.count(), "from still has data after move");
+ assert.eq(3, toShard.getDB("test1").foo.count(), "to doesn't have data after move");
assert.eq(1, s.s.getDB("test1").view.count(), "count on view incorrect after move");
- // move back, now using shard name instead of server address
- s.admin.runCommand({moveprimary: "test1", to: oldShardName});
+ // Move back, now using shard name instead of server address
+ assert.commandWorked(s.s0.adminCommand({movePrimary: "test1", to: oldShardName}));
s.printShardingStatus();
assert.eq(s.normalize(s.config.databases.findOne({_id: "test1"}).primary),
oldShardName,
"to in config db didn't change after second move");
- assert.eq(3, from.getDB("test1").foo.count(), "from doesn't have data after move back");
- assert.eq(0, to.getDB("test1").foo.count(), "to has data after move back");
+ assert.eq(3, fromShard.getDB("test1").foo.count(), "from doesn't have data after move back");
+ assert.eq(0, toShard.getDB("test1").foo.count(), "to has data after move back");
assert.eq(1, s.s.getDB("test1").view.count(), "count on view incorrect after move back");
- // attempting to move primary DB to non-existent shard should error out with appropriate code
- var res = s.admin.runCommand({movePrimary: 'test1', to: 'dontexist'});
- assert.commandFailed(res, 'attempting to use non-existent shard as primary should error out');
- // ErrorCodes::ShardNotFound === 70
- assert.eq(res.code, 70, 'ShardNotFound code not used');
+ assert.commandFailedWithCode(s.s0.adminCommand({movePrimary: 'test1', to: 'dontexist'}),
+ ErrorCodes.ShardNotFound,
+ 'attempting to use non-existent shard as primary should fail');
s.stop();
-
})();
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index 9cde72809d9..ac0f86004ed 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -281,7 +281,6 @@ env.Library(
"db/mongod_options_init.cpp",
],
LIBDEPS=[
- 'db/catalog/catalog',
'db/clientcursor',
'db/commands/core',
'db/conn_pool_options',
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 45b2c134b87..55de905b531 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -533,13 +533,10 @@ env.Library(
'db_raii.cpp',
],
LIBDEPS=[
+ 'catalog/catalog_raii',
'curop',
+ 's/sharding',
'stats/top',
- 'views/views',
- '$BUILD_DIR/mongo/db/concurrency/lock_manager',
- '$BUILD_DIR/mongo/db/s/sharding',
- '$BUILD_DIR/mongo/db/catalog/database',
- '$BUILD_DIR/mongo/db/catalog/database_holder',
],
)
@@ -793,7 +790,7 @@ env.Library(
"auth/authmongod",
"authz_manager_external_state_factory_d",
"background",
- "catalog/catalog",
+ "catalog/catalog_impl",
"catalog/collection_options",
"catalog/document_validation",
"catalog/index_key_validate",
diff --git a/src/mongo/db/catalog/SConscript b/src/mongo/db/catalog/SConscript
index 8a92c492aa6..8ea1877cf19 100644
--- a/src/mongo/db/catalog/SConscript
+++ b/src/mongo/db/catalog/SConscript
@@ -119,6 +119,21 @@ env.Library(
],
)
+env.Library(
+ target='catalog_raii',
+ source=[
+ 'catalog_raii.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/db/catalog/database_holder',
+ '$BUILD_DIR/mongo/db/concurrency/lock_manager',
+ '$BUILD_DIR/mongo/db/views/views',
+ 'collection',
+ 'database',
+ 'uuid_catalog',
+ ],
+)
+
env.CppUnitTest(
target='database_test',
source=[
@@ -205,7 +220,7 @@ env.CppUnitTest(
)
env.Library(
- target='catalog',
+ target='catalog_impl',
source=[
"collection_compact.cpp",
"collection_impl.cpp",
diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp
index cc5c82ac2fc..d84b7bbc7ac 100644
--- a/src/mongo/db/catalog/capped_utils.cpp
+++ b/src/mongo/db/catalog/capped_utils.cpp
@@ -34,10 +34,9 @@
#include "mongo/base/error_codes.h"
#include "mongo/db/background.h"
-#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/catalog/collection_catalog_entry.h"
#include "mongo/db/catalog/create_collection.h"
-#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/document_validation.h"
#include "mongo/db/catalog/drop_collection.h"
#include "mongo/db/catalog/index_catalog.h"
@@ -45,13 +44,11 @@
#include "mongo/db/client.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/index_builder.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/query/plan_yield_policy.h"
#include "mongo/db/repl/replication_coordinator_global.h"
#include "mongo/db/service_context.h"
-#include "mongo/db/views/view.h"
#include "mongo/util/scopeguard.h"
mongo::Status mongo::emptyCapped(OperationContext* opCtx, const NamespaceString& collectionName) {
diff --git a/src/mongo/db/catalog/catalog_raii.cpp b/src/mongo/db/catalog/catalog_raii.cpp
new file mode 100644
index 00000000000..ef61f3db568
--- /dev/null
+++ b/src/mongo/db/catalog/catalog_raii.cpp
@@ -0,0 +1,121 @@
+/**
+ * Copyright (C) 2017 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/catalog/catalog_raii.h"
+
+#include "mongo/db/catalog/database_holder.h"
+#include "mongo/db/catalog/uuid_catalog.h"
+#include "mongo/util/fail_point_service.h"
+
+namespace mongo {
+namespace {
+
+MONGO_FP_DECLARE(setAutoGetCollectionWait);
+
+} // namespace
+
+AutoGetDb::AutoGetDb(OperationContext* opCtx, StringData ns, LockMode mode)
+ : _dbLock(opCtx, ns, mode), _db(dbHolder().get(opCtx, ns)) {}
+
+AutoGetDb::AutoGetDb(OperationContext* opCtx, StringData ns, Lock::DBLock lock)
+ : _dbLock(std::move(lock)), _db(dbHolder().get(opCtx, ns)) {}
+
+AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
+ const NamespaceString& nss,
+ const UUID& uuid,
+ LockMode modeAll)
+ : _viewMode(ViewMode::kViewsForbidden),
+ _autoDb(opCtx, nss.db(), Lock::DBLock(opCtx, nss.db(), modeAll)),
+ _collLock(opCtx->lockState(), nss.ns(), modeAll),
+ _coll(UUIDCatalog::get(opCtx).lookupCollectionByUUID(uuid)) {
+ // Wait for a configured amount of time after acquiring locks if the failpoint is enabled
+ MONGO_FAIL_POINT_BLOCK(setAutoGetCollectionWait, customWait) {
+ const BSONObj& data = customWait.getData();
+ sleepFor(Milliseconds(data["waitForMillis"].numberInt()));
+ }
+}
+
+AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
+ const NamespaceString& nss,
+ LockMode modeColl,
+ ViewMode viewMode,
+ Lock::DBLock lock)
+ : _viewMode(viewMode),
+ _autoDb(opCtx, nss.db(), std::move(lock)),
+ _collLock(opCtx->lockState(), nss.ns(), modeColl),
+ _coll(_autoDb.getDb() ? _autoDb.getDb()->getCollection(opCtx, nss) : nullptr) {
+ Database* const db = _autoDb.getDb();
+
+ // If the database exists, but not the collection, check for views
+ if (_viewMode == ViewMode::kViewsForbidden && db && !_coll &&
+ db->getViewCatalog()->lookup(opCtx, nss.ns())) {
+ uasserted(ErrorCodes::CommandNotSupportedOnView,
+ str::stream() << "Namespace " << nss.ns() << " is a view, not a collection");
+ }
+
+ // Wait for a configured amount of time after acquiring locks if the failpoint is enabled
+ MONGO_FAIL_POINT_BLOCK(setAutoGetCollectionWait, customWait) {
+ const BSONObj& data = customWait.getData();
+ sleepFor(Milliseconds(data["waitForMillis"].numberInt()));
+ }
+}
+
+AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
+ const NamespaceString& nss,
+ LockMode modeDB,
+ LockMode modeColl,
+ ViewMode viewMode)
+ : AutoGetCollection(opCtx, nss, modeColl, viewMode, Lock::DBLock(opCtx, nss.db(), modeDB)) {}
+
+AutoGetCollectionOrView::AutoGetCollectionOrView(OperationContext* opCtx,
+ const NamespaceString& nss,
+ LockMode modeAll)
+ : _autoColl(opCtx, nss, modeAll, modeAll, AutoGetCollection::ViewMode::kViewsPermitted),
+ _view(_autoColl.getDb() && !_autoColl.getCollection()
+ ? _autoColl.getDb()->getViewCatalog()->lookup(opCtx, nss.ns())
+ : nullptr) {}
+
+AutoGetOrCreateDb::AutoGetOrCreateDb(OperationContext* opCtx, StringData ns, LockMode mode)
+ : _dbLock(opCtx, ns, mode), _db(dbHolder().get(opCtx, ns)) {
+ invariant(mode == MODE_IX || mode == MODE_X);
+ _justCreated = false;
+
+ // If the database didn't exist, relock in MODE_X
+ if (_db == NULL) {
+ if (mode != MODE_X) {
+ _dbLock.relockWithMode(MODE_X);
+ }
+
+ _db = dbHolder().openDb(opCtx, ns);
+ _justCreated = true;
+ }
+}
+
+} // namespace mongo
diff --git a/src/mongo/db/catalog/catalog_raii.h b/src/mongo/db/catalog/catalog_raii.h
new file mode 100644
index 00000000000..8ff5401dc18
--- /dev/null
+++ b/src/mongo/db/catalog/catalog_raii.h
@@ -0,0 +1,217 @@
+/**
+ * Copyright (C) 2017 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/base/string_data.h"
+#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/database.h"
+#include "mongo/db/concurrency/d_concurrency.h"
+#include "mongo/db/namespace_string.h"
+#include "mongo/db/operation_context.h"
+#include "mongo/db/views/view.h"
+
+namespace mongo {
+
+/**
+ * RAII-style class, which acquires a lock on the specified database in the requested mode and
+ * obtains a reference to the database. Used as a shortcut for calls to dbHolder().get().
+ *
+ * Use this when you want to do a database-level operation, like read a list of all collections, or
+ * drop a collection.
+ *
+ * It is guaranteed that the lock will be released when this object goes out of scope, therefore
+ * the database reference returned by this class should not be retained.
+ */
+class AutoGetDb {
+ MONGO_DISALLOW_COPYING(AutoGetDb);
+
+public:
+ AutoGetDb(OperationContext* opCtx, StringData ns, LockMode mode);
+ AutoGetDb(OperationContext* opCtx, StringData ns, Lock::DBLock lock);
+
+ Database* getDb() const {
+ return _db;
+ }
+
+private:
+ const Lock::DBLock _dbLock;
+ Database* const _db;
+};
+
+/**
+ * RAII-style class, which acquires a locks on the specified database and collection in the
+ * requested mode and obtains references to both.
+ *
+ * Use this when you want to access something at the collection level, but do not want to do any of
+ * the tasks associated with the 'ForRead' variants below. For example, you can use this to access a
+ * Collection's CursorManager, or to remove a document.
+ *
+ * It is guaranteed that locks will be released when this object goes out of scope, therefore
+ * the database and the collection references returned by this class should not be retained.
+ */
+class AutoGetCollection {
+ MONGO_DISALLOW_COPYING(AutoGetCollection);
+
+public:
+ enum class ViewMode { kViewsPermitted, kViewsForbidden };
+
+ AutoGetCollection(OperationContext* opCtx, const NamespaceString& nss, LockMode modeAll)
+ : AutoGetCollection(opCtx, nss, modeAll, modeAll, ViewMode::kViewsForbidden) {}
+
+ AutoGetCollection(OperationContext* opCtx,
+ const NamespaceString& nss,
+ LockMode modeDB,
+ LockMode modeColl)
+ : AutoGetCollection(opCtx, nss, modeDB, modeColl, ViewMode::kViewsForbidden) {}
+
+ AutoGetCollection(OperationContext* opCtx,
+ const NamespaceString& nss,
+ const UUID& uuid,
+ LockMode modeAll);
+
+ AutoGetCollection(OperationContext* opCtx,
+ const NamespaceString& nss,
+ LockMode modeColl,
+ ViewMode viewMode,
+ Lock::DBLock lock);
+
+ /**
+ * This constructor is intended for internal use and should not be used outside this file.
+ * AutoGetCollectionForReadCommand and AutoGetCollectionOrViewForReadCommand use 'viewMode' to
+ * determine whether or not it is permissible to obtain a handle on a view namespace. Use
+ * another constructor or another 'AutoGet' class instead.
+ */
+ AutoGetCollection(OperationContext* opCtx,
+ const NamespaceString& nss,
+ LockMode modeDB,
+ LockMode modeColl,
+ ViewMode viewMode);
+
+ /**
+ * Returns nullptr if the database didn't exist.
+ */
+ Database* getDb() const {
+ return _autoDb.getDb();
+ }
+
+ /**
+ * Returns nullptr if the collection didn't exist.
+ */
+ Collection* getCollection() const {
+ return _coll;
+ }
+
+private:
+ const ViewMode _viewMode;
+ const AutoGetDb _autoDb;
+ const Lock::CollectionLock _collLock;
+
+ Collection* const _coll;
+};
+
+/**
+ * RAII-style class which acquires the appropriate hierarchy of locks for a collection or
+ * view. The pointer to a view definition is nullptr if it does not exist.
+ *
+ * Use this when you have not yet determined if the namespace is a view or a collection.
+ * For example, you can use this to access a namespace's CursorManager.
+ *
+ * It is guaranteed that locks will be released when this object goes out of scope, therefore
+ * the view returned by this class should not be retained.
+ */
+class AutoGetCollectionOrView {
+ MONGO_DISALLOW_COPYING(AutoGetCollectionOrView);
+
+public:
+ AutoGetCollectionOrView(OperationContext* opCtx, const NamespaceString& nss, LockMode modeAll);
+
+ /**
+ * Returns nullptr if the database didn't exist.
+ */
+ Database* getDb() const {
+ return _autoColl.getDb();
+ }
+
+ /**
+ * Returns nullptr if the collection didn't exist.
+ */
+ Collection* getCollection() const {
+ return _autoColl.getCollection();
+ }
+
+ /**
+ * Returns nullptr if the view didn't exist.
+ */
+ ViewDefinition* getView() const {
+ return _view.get();
+ }
+
+private:
+ const AutoGetCollection _autoColl;
+ std::shared_ptr<ViewDefinition> _view;
+};
+
+/**
+ * RAII-style class, which acquires a lock on the specified database in the requested mode and
+ * obtains a reference to the database, creating it was non-existing. Used as a shortcut for
+ * calls to dbHolder().openDb(), taking care of locking details. The requested mode must be
+ * MODE_IX or MODE_X. If the database needs to be created, the lock will automatically be
+ * reacquired as MODE_X.
+ *
+ * Use this when you are about to perform a write, and want to create the database if it doesn't
+ * already exist.
+ *
+ * It is guaranteed that locks will be released when this object goes out of scope, therefore
+ * the database reference returned by this class should not be retained.
+ */
+class AutoGetOrCreateDb {
+ MONGO_DISALLOW_COPYING(AutoGetOrCreateDb);
+
+public:
+ AutoGetOrCreateDb(OperationContext* opCtx, StringData ns, LockMode mode);
+
+ Database* getDb() const {
+ return _db;
+ }
+
+ bool justCreated() const {
+ return _justCreated;
+ }
+
+ Lock::DBLock& lock() {
+ return _dbLock;
+ }
+
+private:
+ Lock::DBLock _dbLock; // not const, as we may need to relock for implicit create
+ Database* _db;
+ bool _justCreated;
+};
+
+} // namespace mongo
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp
index baf7e98ed49..cd1022f9f93 100644
--- a/src/mongo/db/catalog/coll_mod.cpp
+++ b/src/mongo/db/catalog/coll_mod.cpp
@@ -37,10 +37,8 @@
#include "mongo/bson/simple_bsonelement_comparator.h"
#include "mongo/db/background.h"
-#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/collection_catalog_entry.h"
#include "mongo/db/catalog/collection_options.h"
-#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/client.h"
#include "mongo/db/commands/feature_compatibility_version_command_parser.h"
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp
index 46cd73e0766..cd9e6ad4106 100644
--- a/src/mongo/db/catalog/drop_collection.cpp
+++ b/src/mongo/db/catalog/drop_collection.cpp
@@ -33,8 +33,6 @@
#include "mongo/db/catalog/drop_collection.h"
#include "mongo/db/background.h"
-#include "mongo/db/catalog/collection.h"
-#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/client.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
diff --git a/src/mongo/db/catalog/drop_database.cpp b/src/mongo/db/catalog/drop_database.cpp
index 9fe58b7230f..59a919ad7ef 100644
--- a/src/mongo/db/catalog/drop_database.cpp
+++ b/src/mongo/db/catalog/drop_database.cpp
@@ -35,12 +35,10 @@
#include <algorithm>
#include "mongo/db/background.h"
-#include "mongo/db/catalog/database.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/client.h"
-#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/op_observer.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/service_context.h"
@@ -49,7 +47,6 @@
#include "mongo/util/scopeguard.h"
namespace mongo {
-
namespace {
// This is used to wait for the collection drops to replicate to a majority of the replica set.
diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp
index 12aae53b281..29b9ec80cd5 100644
--- a/src/mongo/db/catalog/drop_indexes.cpp
+++ b/src/mongo/db/catalog/drop_indexes.cpp
@@ -33,8 +33,6 @@
#include "mongo/db/catalog/drop_indexes.h"
#include "mongo/db/background.h"
-#include "mongo/db/catalog/collection.h"
-#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/client.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
@@ -48,6 +46,7 @@
namespace mongo {
namespace {
+
Status wrappedRun(OperationContext* opCtx,
Collection* collection,
const BSONObj& jsobj,
@@ -142,6 +141,7 @@ Status wrappedRun(OperationContext* opCtx,
return Status(ErrorCodes::IndexNotFound, "invalid index name spec");
}
+
} // namespace
Status dropIndexes(OperationContext* opCtx,
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp
index 8b32346d169..21553d58e55 100644
--- a/src/mongo/db/catalog/rename_collection.cpp
+++ b/src/mongo/db/catalog/rename_collection.cpp
@@ -33,9 +33,7 @@
#include "mongo/db/catalog/rename_collection.h"
#include "mongo/db/background.h"
-#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/collection_catalog_entry.h"
-#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/document_validation.h"
#include "mongo/db/catalog/drop_collection.h"
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index 3984f00b2d7..94b79efa17f 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -205,29 +205,29 @@ env.Library(
'$BUILD_DIR/mongo/client/clientdriver',
'$BUILD_DIR/mongo/db/auth/authmongod',
'$BUILD_DIR/mongo/db/background',
- '$BUILD_DIR/mongo/db/catalog/catalog',
+ '$BUILD_DIR/mongo/db/catalog/catalog_helpers',
'$BUILD_DIR/mongo/db/catalog/collection',
'$BUILD_DIR/mongo/db/catalog/index_key_validate',
- '$BUILD_DIR/mongo/db/catalog/catalog_helpers',
'$BUILD_DIR/mongo/db/clientcursor',
'$BUILD_DIR/mongo/db/cloner',
'$BUILD_DIR/mongo/db/commands',
'$BUILD_DIR/mongo/db/index/index_access_methods',
'$BUILD_DIR/mongo/db/index_d',
'$BUILD_DIR/mongo/db/lasterror',
- '$BUILD_DIR/mongo/db/write_ops',
'$BUILD_DIR/mongo/db/ops/write_ops_parsers',
'$BUILD_DIR/mongo/db/pipeline/serveronly',
'$BUILD_DIR/mongo/db/repair_database',
'$BUILD_DIR/mongo/db/repl/dbcheck',
- '$BUILD_DIR/mongo/db/repl/oplog',
'$BUILD_DIR/mongo/db/repl/isself',
+ '$BUILD_DIR/mongo/db/repl/oplog',
'$BUILD_DIR/mongo/db/repl/repl_coordinator_impl',
'$BUILD_DIR/mongo/db/rw_concern_d',
'$BUILD_DIR/mongo/db/server_options_core',
'$BUILD_DIR/mongo/db/stats/serveronly',
'$BUILD_DIR/mongo/db/storage/mmap_v1/storage_mmapv1',
'$BUILD_DIR/mongo/db/views/views_mongod',
+ '$BUILD_DIR/mongo/db/write_ops',
+ '$BUILD_DIR/mongo/s/catalog/sharding_catalog_manager',
'$BUILD_DIR/mongo/s/client/parallel',
'core',
'current_op_common',
diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp
index fb719e1bda6..74c7a50d2dd 100644
--- a/src/mongo/db/commands/list_databases.cpp
+++ b/src/mongo/db/commands/list_databases.cpp
@@ -28,12 +28,13 @@
* it in the license file.
*/
-#include "mongo/db/catalog/database.h"
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/auth/authorization_session.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/catalog/database_catalog_entry.h"
-#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
-#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
@@ -134,9 +135,8 @@ public:
if (filterNameOnly && !filter->matchesBSON(b.asTempObj()))
continue;
- Lock::DBLock dbLock(opCtx, dbname, MODE_IS);
-
- Database* db = dbHolder().get(opCtx, dbname);
+ AutoGetDb autoDb(opCtx, dbname, MODE_IS);
+ Database* const db = autoDb.getDb();
if (!db)
continue;
diff --git a/src/mongo/db/concurrency/SConscript b/src/mongo/db/concurrency/SConscript
index 8f8a703b388..ba2a08dae90 100644
--- a/src/mongo/db/concurrency/SConscript
+++ b/src/mongo/db/concurrency/SConscript
@@ -24,40 +24,31 @@ env.Library(
target='write_conflict_exception',
source=[
'write_conflict_exception.cpp'
- ],
+ ],
LIBDEPS=[
'$BUILD_DIR/mongo/db/server_parameters'
- ]
-)
-
-env.Library(
- target='global_lock_acquisition_tracker',
- source=[
- 'global_lock_acquisition_tracker.cpp'
- ],
- LIBDEPS=[
- '$BUILD_DIR/mongo/util/decorable',
- ]
+ ],
)
-
env.Library(
target='lock_manager',
source=[
'd_concurrency.cpp',
+ 'global_lock_acquisition_tracker.cpp',
'lock_manager.cpp',
'lock_state.cpp',
'lock_stats.cpp',
],
LIBDEPS=[
- 'global_lock_acquisition_tracker',
- '$BUILD_DIR/mongo/util/background_job',
'$BUILD_DIR/mongo/base',
+ '$BUILD_DIR/mongo/util/background_job',
+ '$BUILD_DIR/mongo/util/decorable',
+
# Temporary crutch since the ssl cleanup is hard coded in background.cpp
- '$BUILD_DIR/mongo/util/net/network',
'$BUILD_DIR/mongo/db/server_parameters',
'$BUILD_DIR/mongo/db/service_context',
'$BUILD_DIR/mongo/util/concurrency/spin_lock',
+ '$BUILD_DIR/mongo/util/net/network',
'$BUILD_DIR/third_party/shim_boost',
],
)
@@ -75,7 +66,6 @@ env.CppUnitTest(
'$BUILD_DIR/mongo/db/curop',
'$BUILD_DIR/mongo/util/progress_meter',
'$BUILD_DIR/mongo/db/service_context_noop_init',
- 'global_lock_acquisition_tracker',
'lock_manager',
'write_conflict_exception',
]
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp
index 3ca2b1e5752..ee955eee546 100644
--- a/src/mongo/db/db_raii.cpp
+++ b/src/mongo/db/db_raii.cpp
@@ -30,96 +30,15 @@
#include "mongo/db/db_raii.h"
-#include "mongo/db/catalog/collection.h"
-#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/uuid_catalog.h"
-#include "mongo/db/client.h"
#include "mongo/db/curop.h"
-#include "mongo/db/repl/replication_coordinator_global.h"
+#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/stats/top.h"
-#include "mongo/util/fail_point_service.h"
namespace mongo {
-namespace {
-MONGO_FP_DECLARE(setAutoGetCollectionWait);
-} // namespace
-
-AutoGetDb::AutoGetDb(OperationContext* opCtx, StringData ns, LockMode mode)
- : _dbLock(opCtx, ns, mode), _db(dbHolder().get(opCtx, ns)) {}
-
-AutoGetDb::AutoGetDb(OperationContext* opCtx, StringData ns, Lock::DBLock lock)
- : _dbLock(std::move(lock)), _db(dbHolder().get(opCtx, ns)) {}
-
-AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
- LockMode modeAll)
- : _viewMode(ViewMode::kViewsForbidden),
- _autoDb(opCtx, nss.db(), Lock::DBLock(opCtx, nss.db(), modeAll)),
- _collLock(opCtx->lockState(), nss.ns(), modeAll),
- _coll(UUIDCatalog::get(opCtx).lookupCollectionByUUID(uuid)) {
- // Wait for a configured amount of time after acquiring locks if the failpoint is enabled.
- MONGO_FAIL_POINT_BLOCK(setAutoGetCollectionWait, customWait) {
- const BSONObj& data = customWait.getData();
- sleepFor(Milliseconds(data["waitForMillis"].numberInt()));
- }
-}
-
-AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
- const NamespaceString& nss,
- LockMode modeDB,
- LockMode modeColl,
- ViewMode viewMode)
- : AutoGetCollection(opCtx, nss, modeColl, viewMode, Lock::DBLock(opCtx, nss.db(), modeDB)) {}
-
-AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
- const NamespaceString& nss,
- LockMode modeColl,
- ViewMode viewMode,
- Lock::DBLock lock)
- : _viewMode(viewMode),
- _autoDb(opCtx, nss.db(), std::move(lock)),
- _collLock(opCtx->lockState(), nss.ns(), modeColl),
- _coll(_autoDb.getDb() ? _autoDb.getDb()->getCollection(opCtx, nss) : nullptr) {
- Database* db = _autoDb.getDb();
- // If the database exists, but not the collection, check for views.
- if (_viewMode == ViewMode::kViewsForbidden && db && !_coll &&
- db->getViewCatalog()->lookup(opCtx, nss.ns()))
- uasserted(ErrorCodes::CommandNotSupportedOnView,
- str::stream() << "Namespace " << nss.ns() << " is a view, not a collection");
-
- // Wait for a configured amount of time after acquiring locks if the failpoint is enabled.
- MONGO_FAIL_POINT_BLOCK(setAutoGetCollectionWait, customWait) {
- const BSONObj& data = customWait.getData();
- sleepFor(Milliseconds(data["waitForMillis"].numberInt()));
- }
-}
-
-AutoGetCollectionOrView::AutoGetCollectionOrView(OperationContext* opCtx,
- const NamespaceString& nss,
- LockMode modeAll)
- : _autoColl(opCtx, nss, modeAll, modeAll, AutoGetCollection::ViewMode::kViewsPermitted),
- _view(_autoColl.getDb() && !_autoColl.getCollection()
- ? _autoColl.getDb()->getViewCatalog()->lookup(opCtx, nss.ns())
- : nullptr) {}
-
-AutoGetOrCreateDb::AutoGetOrCreateDb(OperationContext* opCtx, StringData ns, LockMode mode)
- : _dbLock(opCtx, ns, mode), _db(dbHolder().get(opCtx, ns)) {
- invariant(mode == MODE_IX || mode == MODE_X);
- _justCreated = false;
- // If the database didn't exist, relock in MODE_X
- if (_db == NULL) {
- if (mode != MODE_X) {
- _dbLock.relockWithMode(MODE_X);
- }
- _db = dbHolder().openDb(opCtx, ns);
- _justCreated = true;
- }
-}
-
AutoStatsTracker::AutoStatsTracker(OperationContext* opCtx,
const NamespaceString& nss,
Top::LockType lockType,
@@ -133,6 +52,7 @@ AutoStatsTracker::AutoStatsTracker(OperationContext* opCtx,
dbProfilingLevel = autoDb.getDb()->getProfilingLevel();
}
}
+
stdx::lock_guard<Client> clientLock(*_opCtx->getClient());
CurOp::get(_opCtx)->enter_inlock(nss.ns().c_str(), dbProfilingLevel);
}
diff --git a/src/mongo/db/db_raii.h b/src/mongo/db/db_raii.h
index f764d671d31..ec270c2f237 100644
--- a/src/mongo/db/db_raii.h
+++ b/src/mongo/db/db_raii.h
@@ -30,197 +30,12 @@
#include <string>
-#include "mongo/base/string_data.h"
-#include "mongo/db/catalog/database.h"
-#include "mongo/db/concurrency/d_concurrency.h"
-#include "mongo/db/namespace_string.h"
-#include "mongo/db/operation_context.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/stats/top.h"
-#include "mongo/db/views/view.h"
#include "mongo/util/timer.h"
namespace mongo {
-class Collection;
-
-/**
- * RAII-style class, which acquires a lock on the specified database in the requested mode and
- * obtains a reference to the database. Used as a shortcut for calls to dbHolder().get().
- *
- * Use this when you want to do a database-level operation, like read a list of all collections, or
- * drop a collection.
- *
- * It is guaranteed that the lock will be released when this object goes out of scope, therefore
- * the database reference returned by this class should not be retained.
- */
-class AutoGetDb {
- MONGO_DISALLOW_COPYING(AutoGetDb);
-
-public:
- AutoGetDb(OperationContext* opCtx, StringData ns, LockMode mode);
- AutoGetDb(OperationContext* opCtx, StringData ns, Lock::DBLock lock);
-
- Database* getDb() const {
- return _db;
- }
-
-private:
- const Lock::DBLock _dbLock;
- Database* const _db;
-};
-
-/**
- * RAII-style class, which acquires a locks on the specified database and collection in the
- * requested mode and obtains references to both.
- *
- * Use this when you want to access something at the collection level, but do not want to do any of
- * the tasks associated with the 'ForRead' variants below. For example, you can use this to access a
- * Collection's CursorManager, or to remove a document.
- *
- * It is guaranteed that locks will be released when this object goes out of scope, therefore
- * the database and the collection references returned by this class should not be retained.
- */
-class AutoGetCollection {
- MONGO_DISALLOW_COPYING(AutoGetCollection);
-
- enum class ViewMode;
-
-public:
- AutoGetCollection(OperationContext*, const NamespaceString&, const UUID&, LockMode modeAll);
-
- AutoGetCollection(OperationContext* opCtx, const NamespaceString& nss, LockMode modeAll)
- : AutoGetCollection(opCtx, nss, modeAll, modeAll, ViewMode::kViewsForbidden) {}
-
- AutoGetCollection(OperationContext* opCtx,
- const NamespaceString& nss,
- LockMode modeDB,
- LockMode modeColl)
- : AutoGetCollection(opCtx, nss, modeDB, modeColl, ViewMode::kViewsForbidden) {}
-
- AutoGetCollection(OperationContext* opCtx,
- const NamespaceString& nss,
- LockMode modeColl,
- ViewMode viewMode,
- Lock::DBLock lock);
- /**
- * This constructor is intended for internal use and should not be used outside this file.
- * AutoGetCollectionForReadCommand and AutoGetCollectionOrViewForReadCommand use 'viewMode' to
- * determine whether or not it is permissible to obtain a handle on a view namespace. Use
- * another constructor or another 'AutoGet' class instead.
- */
- AutoGetCollection(OperationContext* opCtx,
- const NamespaceString& nss,
- LockMode modeDB,
- LockMode modeColl,
- ViewMode viewMode);
-
- /**
- * Returns nullptr if the database didn't exist.
- */
- Database* getDb() const {
- return _autoDb.getDb();
- }
-
- /**
- * Returns nullptr if the collection didn't exist.
- */
- Collection* getCollection() const {
- return _coll;
- }
-
-private:
- enum class ViewMode { kViewsPermitted, kViewsForbidden };
-
- const ViewMode _viewMode;
- const AutoGetDb _autoDb;
- const Lock::CollectionLock _collLock;
- Collection* const _coll;
-
- friend class AutoGetCollectionOrView;
- friend class AutoGetCollectionForRead;
- friend class AutoGetCollectionForReadCommand;
- friend class AutoGetCollectionOrViewForReadCommand;
-};
-
-/**
- * RAII-style class which acquires the appropriate hierarchy of locks for a collection or
- * view. The pointer to a view definition is nullptr if it does not exist.
- *
- * Use this when you have not yet determined if the namespace is a view or a collection.
- * For example, you can use this to access a namespace's CursorManager.
- *
- * It is guaranteed that locks will be released when this object goes out of scope, therefore
- * the view returned by this class should not be retained.
- */
-class AutoGetCollectionOrView {
- MONGO_DISALLOW_COPYING(AutoGetCollectionOrView);
-
-public:
- AutoGetCollectionOrView(OperationContext* opCtx, const NamespaceString& nss, LockMode modeAll);
-
- /**
- * Returns nullptr if the database didn't exist.
- */
- Database* getDb() const {
- return _autoColl.getDb();
- }
-
- /**
- * Returns nullptr if the collection didn't exist.
- */
- Collection* getCollection() const {
- return _autoColl.getCollection();
- }
-
- /**
- * Returns nullptr if the view didn't exist.
- */
- ViewDefinition* getView() const {
- return _view.get();
- }
-
-private:
- const AutoGetCollection _autoColl;
- std::shared_ptr<ViewDefinition> _view;
-};
-
-/**
- * RAII-style class, which acquires a lock on the specified database in the requested mode and
- * obtains a reference to the database, creating it was non-existing. Used as a shortcut for
- * calls to dbHolder().openDb(), taking care of locking details. The requested mode must be
- * MODE_IX or MODE_X. If the database needs to be created, the lock will automatically be
- * reacquired as MODE_X.
- *
- * Use this when you are about to perform a write, and want to create the database if it doesn't
- * already exist.
- *
- * It is guaranteed that locks will be released when this object goes out of scope, therefore
- * the database reference returned by this class should not be retained.
- */
-class AutoGetOrCreateDb {
- MONGO_DISALLOW_COPYING(AutoGetOrCreateDb);
-
-public:
- AutoGetOrCreateDb(OperationContext* opCtx, StringData ns, LockMode mode);
-
- Database* getDb() const {
- return _db;
- }
-
- bool justCreated() const {
- return _justCreated;
- }
-
- Lock::DBLock& lock() {
- return _dbLock;
- }
-
-private:
- Lock::DBLock _dbLock; // not const, as we may need to relock for implicit create
- Database* _db;
- bool _justCreated;
-};
-
/**
* RAII-style class which automatically tracks the operation namespace in CurrentOp and records the
* operation via Top upon destruction.
@@ -270,10 +85,6 @@ public:
AutoGetCollectionForRead(OperationContext* opCtx, const NamespaceString& nss)
: AutoGetCollectionForRead(opCtx, nss, AutoGetCollection::ViewMode::kViewsForbidden) {}
- AutoGetCollectionForRead(OperationContext* opCtx, const NamespaceString& nss, Lock::DBLock lock)
- : AutoGetCollectionForRead(
- opCtx, nss, AutoGetCollection::ViewMode::kViewsForbidden, std::move(lock)) {}
-
AutoGetCollectionForRead(OperationContext* opCtx, const StringData dbName, const UUID& uuid);
/**
@@ -448,7 +259,6 @@ private:
Timer _timer;
};
-
class OldClientWriteContext {
MONGO_DISALLOW_COPYING(OldClientWriteContext);
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index 6ae29f02a03..c74aa9b9a6b 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -90,12 +90,10 @@ env.Library(
LIBDEPS=[
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/bson/util/bson_extract',
- '$BUILD_DIR/mongo/db/catalog/collection',
- '$BUILD_DIR/mongo/db/catalog/database',
+ '$BUILD_DIR/mongo/db/catalog/catalog_raii',
'$BUILD_DIR/mongo/db/catalog/index_catalog',
'$BUILD_DIR/mongo/db/catalog/index_create',
'$BUILD_DIR/mongo/db/common',
- '$BUILD_DIR/mongo/db/concurrency/lock_manager',
'$BUILD_DIR/mongo/db/query/internal_plans',
'$BUILD_DIR/mongo/s/client/shard_local',
'$BUILD_DIR/mongo/s/coreshard',
@@ -106,8 +104,6 @@ env.Library(
'migration_types',
'sharding_task_executor',
'type_shard_identity',
- #'$BUILD_DIR/mongo/db/catalog/catalog', # CYCLE
- #'$BUILD_DIR/mongo/db/db_raii', # CYCLE
#'$BUILD_DIR/mongo/db/dbhelpers', # CYCLE
#'$BUILD_DIR/mongo/db/write_ops', # CYCLE
#'$BUILD_DIR/mongo/db/query/query', # CYCLE
@@ -285,37 +281,37 @@ env.Library(
'split_chunk.cpp',
],
LIBDEPS=[
- 'sharding',
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/bson/util/bson_extract',
+ '$BUILD_DIR/mongo/db/catalog/catalog_raii',
'$BUILD_DIR/mongo/db/clientcursor',
- '$BUILD_DIR/mongo/db/db_raii',
'$BUILD_DIR/mongo/db/dbhelpers',
'$BUILD_DIR/mongo/db/exec/exec',
'$BUILD_DIR/mongo/db/pipeline/serveronly',
'$BUILD_DIR/mongo/db/query/query',
'$BUILD_DIR/mongo/db/rw_concern_d',
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_manager',
+ 'sharding',
]
)
env.Library(
target='split_vector',
source=[
- 'split_vector.cpp',
+ 'split_vector.cpp',
],
LIBDEPS=[
- '$BUILD_DIR/mongo/db/bson/dotted_path_support',
- '$BUILD_DIR/mongo/db/commands/dcommands_fcv',
- '$BUILD_DIR/mongo/db/commands/server_status',
- '$BUILD_DIR/mongo/db/db_raii',
- '$BUILD_DIR/mongo/db/dbhelpers',
- '$BUILD_DIR/mongo/db/index_d',
- '$BUILD_DIR/mongo/db/repl/repl_coordinator_global',
- '$BUILD_DIR/mongo/s/sharding_request_types',
- 'balancer',
- 'collection_metadata',
- 'sharding',
+ '$BUILD_DIR/mongo/db/bson/dotted_path_support',
+ '$BUILD_DIR/mongo/db/catalog/catalog_raii',
+ '$BUILD_DIR/mongo/db/commands/dcommands_fcv',
+ '$BUILD_DIR/mongo/db/commands/server_status',
+ '$BUILD_DIR/mongo/db/dbhelpers',
+ '$BUILD_DIR/mongo/db/index_d',
+ '$BUILD_DIR/mongo/db/repl/repl_coordinator_global',
+ '$BUILD_DIR/mongo/s/sharding_request_types',
+ 'balancer',
+ 'collection_metadata',
+ 'sharding',
]
)
diff --git a/src/mongo/db/s/active_migrations_registry.cpp b/src/mongo/db/s/active_migrations_registry.cpp
index 91aa5dd7bf4..9aadaeb1937 100644
--- a/src/mongo/db/s/active_migrations_registry.cpp
+++ b/src/mongo/db/s/active_migrations_registry.cpp
@@ -31,7 +31,7 @@
#include "mongo/db/s/active_migrations_registry.h"
#include "mongo/base/status_with.h"
-#include "mongo/db/db_raii.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/migration_session_id.h"
#include "mongo/db/s/migration_source_manager.h"
diff --git a/src/mongo/db/s/check_sharding_index_command.cpp b/src/mongo/db/s/check_sharding_index_command.cpp
index 7fc5eb0c6ab..6955d93db83 100644
--- a/src/mongo/db/s/check_sharding_index_command.cpp
+++ b/src/mongo/db/s/check_sharding_index_command.cpp
@@ -35,9 +35,9 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/privilege.h"
#include "mongo/db/bson/dotted_path_support.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/commands.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/exec/working_set_common.h"
#include "mongo/db/index/index_descriptor.h"
diff --git a/src/mongo/db/s/cleanup_orphaned_cmd.cpp b/src/mongo/db/s/cleanup_orphaned_cmd.cpp
index 69e7b311b79..99a8ee8fc10 100644
--- a/src/mongo/db/s/cleanup_orphaned_cmd.cpp
+++ b/src/mongo/db/s/cleanup_orphaned_cmd.cpp
@@ -32,21 +32,18 @@
#include <boost/optional.hpp>
#include <string>
-#include <vector>
#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/catalog/catalog_raii.h"
#include "mongo/db/commands.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/field_parser.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/range_arithmetic.h"
-#include "mongo/db/repl/replication_coordinator_global.h"
#include "mongo/db/s/chunk_move_write_concern_options.h"
-#include "mongo/db/s/collection_metadata.h"
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/service_context.h"
diff --git a/src/mongo/db/s/collection_range_deleter.cpp b/src/mongo/db/s/collection_range_deleter.cpp
index 7bf41703968..050013c6c65 100644
--- a/src/mongo/db/s/collection_range_deleter.cpp
+++ b/src/mongo/db/s/collection_range_deleter.cpp
@@ -35,11 +35,10 @@
#include <algorithm>
#include <utility>
-#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/client.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/exec/working_set_common.h"
#include "mongo/db/index/index_descriptor.h"
@@ -49,9 +48,7 @@
#include "mongo/db/query/query_knobs.h"
#include "mongo/db/query/query_planner.h"
#include "mongo/db/repl/repl_client_info.h"
-#include "mongo/db/repl/replication_coordinator_global.h"
#include "mongo/db/s/collection_sharding_state.h"
-#include "mongo/db/s/metadata_manager.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/service_context.h"
#include "mongo/db/write_concern.h"
diff --git a/src/mongo/db/s/collection_range_deleter_test.cpp b/src/mongo/db/s/collection_range_deleter_test.cpp
index 8939860c9be..1b6bb61928f 100644
--- a/src/mongo/db/s/collection_range_deleter_test.cpp
+++ b/src/mongo/db/s/collection_range_deleter_test.cpp
@@ -32,17 +32,14 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/client/query.h"
#include "mongo/client/remote_command_targeter_mock.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/client.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/keypattern.h"
-#include "mongo/db/repl/replication_coordinator_global.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
-#include "mongo/db/s/collection_range_deleter.h"
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/sharding_state.h"
-#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/s/balancer_configuration.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/client/shard_registry.h"
@@ -70,8 +67,7 @@ protected:
serverGlobalParams.clusterRole = ClusterRole::ShardServer;
ShardingMongodTestFixture::setUp();
replicationCoordinator()->alwaysAllowWrites(true);
- initializeGlobalShardingStateForMongodForTest(ConnectionString(dummyHost))
- .transitional_ignore();
+ ASSERT_OK(initializeGlobalShardingStateForMongodForTest(ConnectionString(dummyHost)));
// RemoteCommandTargeterMock::get(shardRegistry()->getConfigShard()->getTargeter())
// ->setConnectionStringReturnValue(kConfigConnStr);
diff --git a/src/mongo/db/s/collection_sharding_state.cpp b/src/mongo/db/s/collection_sharding_state.cpp
index 872f8fbc11a..2458d9861c5 100644
--- a/src/mongo/db/s/collection_sharding_state.cpp
+++ b/src/mongo/db/s/collection_sharding_state.cpp
@@ -33,12 +33,10 @@
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/bson/util/bson_extract.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/client.h"
-#include "mongo/db/concurrency/lock_state.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/operation_context.h"
-#include "mongo/db/repl/replication_coordinator_global.h"
-#include "mongo/db/s/collection_metadata.h"
+#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/s/migration_chunk_cloner_source.h"
#include "mongo/db/s/migration_source_manager.h"
#include "mongo/db/s/operation_sharding_state.h"
diff --git a/src/mongo/db/s/collection_sharding_state_test.cpp b/src/mongo/db/s/collection_sharding_state_test.cpp
index f9fcbc69420..3f64a1be7d2 100644
--- a/src/mongo/db/s/collection_sharding_state_test.cpp
+++ b/src/mongo/db/s/collection_sharding_state_test.cpp
@@ -27,12 +27,9 @@
#include "mongo/platform/basic.h"
-#include "mongo/db/s/collection_sharding_state.h"
-
-#include "mongo/db/concurrency/d_concurrency.h"
-#include "mongo/db/db_raii.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/namespace_string.h"
-#include "mongo/db/s/collection_metadata.h"
+#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/s/type_shard_identity.h"
#include "mongo/s/shard_server_test_fixture.h"
@@ -40,6 +37,8 @@
namespace mongo {
namespace {
+const NamespaceString kTestNss("TestDB", "TestColl");
+
class CollShardingStateTest : public ShardServerTestFixture {
public:
void setUp() override {
@@ -165,10 +164,6 @@ TEST_F(CollShardingStateTest, GlobalInitDoesntGetsCalledIfShardIdentityDocWasNot
ASSERT_EQ(0, getInitCallCount());
}
-namespace {
-
-NamespaceString testNss("testDB", "TestColl");
-
/**
* Constructs a CollectionMetadata suitable for refreshing a CollectionShardingState. The only
* salient detail is the argument `keyPattern` which, defining the shard key, selects the fields
@@ -178,78 +173,108 @@ NamespaceString testNss("testDB", "TestColl");
auto makeAMetadata(BSONObj const& keyPattern) -> std::unique_ptr<CollectionMetadata> {
const OID epoch = OID::gen();
auto range = ChunkRange(BSON("key" << MINKEY), BSON("key" << MAXKEY));
- auto chunk = ChunkType(testNss, std::move(range), ChunkVersion(1, 0, epoch), ShardId("other"));
+ auto chunk = ChunkType(kTestNss, std::move(range), ChunkVersion(1, 0, epoch), ShardId("other"));
auto cm = ChunkManager::makeNew(
- testNss, UUID::gen(), KeyPattern(keyPattern), nullptr, false, epoch, {std::move(chunk)});
+ kTestNss, UUID::gen(), KeyPattern(keyPattern), nullptr, false, epoch, {std::move(chunk)});
return stdx::make_unique<CollectionMetadata>(std::move(cm), ShardId("this"));
}
-} // namespace
-
-// clang-format off
-
TEST_F(CollShardingStateTest, MakeDeleteStateUnsharded) {
- AutoGetCollection autoColl(operationContext(), testNss, MODE_IX);
- auto* css = CollectionShardingState::get(operationContext(), testNss);
-
- auto doc = BSON("key3" << "abc" << "key" << 3 << "_id" << "hello" << "key2" << true);
+ AutoGetCollection autoColl(operationContext(), kTestNss, MODE_IX);
+ auto* css = CollectionShardingState::get(operationContext(), kTestNss);
+
+ auto doc = BSON("key3"
+ << "abc"
+ << "key"
+ << 3
+ << "_id"
+ << "hello"
+ << "key2"
+ << true);
// First, check that an order for deletion from an unsharded collection (where css has not been
// "refreshed" with chunk metadata) extracts just the "_id" field:
auto deleteState = css->makeDeleteState(doc);
- ASSERT_BSONOBJ_EQ(deleteState.documentKey, BSON("_id" << "hello"));
+ ASSERT_BSONOBJ_EQ(deleteState.documentKey,
+ BSON("_id"
+ << "hello"));
ASSERT_FALSE(deleteState.isMigrating);
}
TEST_F(CollShardingStateTest, MakeDeleteStateShardedWithoutIdInShardKey) {
- AutoGetCollection autoColl(operationContext(), testNss, MODE_IX);
- auto* css = CollectionShardingState::get(operationContext(), testNss);
+ AutoGetCollection autoColl(operationContext(), kTestNss, MODE_IX);
+ auto* css = CollectionShardingState::get(operationContext(), kTestNss);
// Push a CollectionMetadata with a shard key not including "_id"...
css->refreshMetadata(operationContext(), makeAMetadata(BSON("key" << 1 << "key3" << 1)));
// The order of fields in `doc` deliberately does not match the shard key
- auto doc = BSON("key3" << "abc" << "key" << 100 << "_id" << "hello" << "key2" << true);
+ auto doc = BSON("key3"
+ << "abc"
+ << "key"
+ << 100
+ << "_id"
+ << "hello"
+ << "key2"
+ << true);
// Verify the shard key is extracted, in correct order, followed by the "_id" field.
auto deleteState = css->makeDeleteState(doc);
- ASSERT_BSONOBJ_EQ(
- deleteState.documentKey, BSON("key" << 100 << "key3" << "abc" << "_id" << "hello"));
+ ASSERT_BSONOBJ_EQ(deleteState.documentKey,
+ BSON("key" << 100 << "key3"
+ << "abc"
+ << "_id"
+ << "hello"));
ASSERT_FALSE(deleteState.isMigrating);
}
TEST_F(CollShardingStateTest, MakeDeleteStateShardedWithIdInShardKey) {
- AutoGetCollection autoColl(operationContext(), testNss, MODE_IX);
- auto* css = CollectionShardingState::get(operationContext(), testNss);
+ AutoGetCollection autoColl(operationContext(), kTestNss, MODE_IX);
+ auto* css = CollectionShardingState::get(operationContext(), kTestNss);
// Push a CollectionMetadata with a shard key that does have "_id" in the middle...
- css->refreshMetadata(
- operationContext(), makeAMetadata(BSON("key" << 1 << "_id" << 1 << "key2" << 1)));
+ css->refreshMetadata(operationContext(),
+ makeAMetadata(BSON("key" << 1 << "_id" << 1 << "key2" << 1)));
// The order of fields in `doc` deliberately does not match the shard key
- auto doc = BSON("key2" << true << "key3" << "abc" << "_id" << "hello" << "key" << 100);
+ auto doc = BSON("key2" << true << "key3"
+ << "abc"
+ << "_id"
+ << "hello"
+ << "key"
+ << 100);
// Verify the shard key is extracted with "_id" in the right place.
auto deleteState = css->makeDeleteState(doc);
- ASSERT_BSONOBJ_EQ(
- deleteState.documentKey, BSON("key" << 100 << "_id" << "hello" << "key2" << true));
+ ASSERT_BSONOBJ_EQ(deleteState.documentKey,
+ BSON("key" << 100 << "_id"
+ << "hello"
+ << "key2"
+ << true));
ASSERT_FALSE(deleteState.isMigrating);
}
TEST_F(CollShardingStateTest, MakeDeleteStateShardedWithIdHashInShardKey) {
- AutoGetCollection autoColl(operationContext(), testNss, MODE_IX);
- auto* css = CollectionShardingState::get(operationContext(), testNss);
+ AutoGetCollection autoColl(operationContext(), kTestNss, MODE_IX);
+ auto* css = CollectionShardingState::get(operationContext(), kTestNss);
// Push a CollectionMetadata with a shard key "_id", hashed.
- auto aMetadata = makeAMetadata(BSON("_id" << "hashed"));
+ auto aMetadata = makeAMetadata(BSON("_id"
+ << "hashed"));
css->refreshMetadata(operationContext(), std::move(aMetadata));
- auto doc = BSON("key2" << true << "_id" << "hello" << "key" << 100);
+ auto doc = BSON("key2" << true << "_id"
+ << "hello"
+ << "key"
+ << 100);
// Verify the shard key is extracted with "_id" in the right place, not hashed.
auto deleteState = css->makeDeleteState(doc);
- ASSERT_BSONOBJ_EQ(deleteState.documentKey, BSON("_id" << "hello"));
+ ASSERT_BSONOBJ_EQ(deleteState.documentKey,
+ BSON("_id"
+ << "hello"));
ASSERT_FALSE(deleteState.isMigrating);
}
-} // unnamed namespace
+
+} // namespace
} // namespace mongo
diff --git a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp
index 70a7ac8c4e8..3bdf4d5556f 100644
--- a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp
+++ b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp
@@ -35,9 +35,9 @@
#include "mongo/db/auth/authorization_manager.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/privilege.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/s/migration_source_manager.h"
diff --git a/src/mongo/db/s/get_shard_version_command.cpp b/src/mongo/db/s/get_shard_version_command.cpp
index 91c7707eae6..7853b107279 100644
--- a/src/mongo/db/s/get_shard_version_command.cpp
+++ b/src/mongo/db/s/get_shard_version_command.cpp
@@ -35,9 +35,8 @@
#include "mongo/db/auth/authorization_manager.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/privilege.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/commands.h"
-#include "mongo/db/db_raii.h"
-#include "mongo/db/s/collection_metadata.h"
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/sharded_connection_info.h"
#include "mongo/db/s/sharding_state.h"
diff --git a/src/mongo/db/s/merge_chunks_command.cpp b/src/mongo/db/s/merge_chunks_command.cpp
index f4ec0529dee..a589e580864 100644
--- a/src/mongo/db/s/merge_chunks_command.cpp
+++ b/src/mongo/db/s/merge_chunks_command.cpp
@@ -33,13 +33,11 @@
#include "mongo/db/auth/action_type.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/privilege.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/commands.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/field_parser.h"
#include "mongo/db/namespace_string.h"
-#include "mongo/db/s/collection_metadata.h"
#include "mongo/db/s/collection_sharding_state.h"
-#include "mongo/db/s/metadata_manager.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/client/shard_registry.h"
diff --git a/src/mongo/db/s/metadata_manager.cpp b/src/mongo/db/s/metadata_manager.cpp
index 3c60b433f0e..60b8edca338 100644
--- a/src/mongo/db/s/metadata_manager.cpp
+++ b/src/mongo/db/s/metadata_manager.cpp
@@ -36,10 +36,8 @@
#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/bson/util/builder.h"
#include "mongo/db/bson/dotted_path_support.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/range_arithmetic.h"
-#include "mongo/db/s/collection_range_deleter.h"
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/stdx/memory.h"
diff --git a/src/mongo/db/s/metadata_manager_test.cpp b/src/mongo/db/s/metadata_manager_test.cpp
index eb0999b6b00..2c09b55c69d 100644
--- a/src/mongo/db/s/metadata_manager_test.cpp
+++ b/src/mongo/db/s/metadata_manager_test.cpp
@@ -32,14 +32,12 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/client/remote_command_targeter_mock.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/client.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
-#include "mongo/db/s/collection_metadata.h"
-#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/metadata_manager.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/s/type_shard_identity.h"
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
index 7c1beb1dcce..42bb184d83a 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
@@ -34,9 +34,8 @@
#include "mongo/base/status.h"
#include "mongo/client/read_preference.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/catalog/index_catalog.h"
-#include "mongo/db/concurrency/locker.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/exec/plan_stage.h"
#include "mongo/db/exec/working_set_common.h"
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy_commands.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy_commands.cpp
index 41bf7d385cd..2b36c3efa30 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy_commands.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy_commands.cpp
@@ -35,9 +35,9 @@
#include "mongo/db/auth/authorization_manager.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/privilege.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/commands.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/migration_chunk_cloner_source_legacy.h"
#include "mongo/db/s/migration_source_manager.h"
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp
index a15f6487a33..4025dbca918 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp
@@ -29,8 +29,7 @@
#include "mongo/platform/basic.h"
#include "mongo/client/remote_command_targeter_mock.h"
-#include "mongo/db/catalog/collection.h"
-#include "mongo/db/db_raii.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index 95d6db11dc4..7c06445204e 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -38,9 +38,7 @@
#include "mongo/client/connpool.h"
#include "mongo/db/auth/authorization_manager_global.h"
#include "mongo/db/auth/authorization_session.h"
-#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/collection_catalog_entry.h"
-#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/document_validation.h"
#include "mongo/db/catalog/index_create.h"
#include "mongo/db/db_raii.h"
@@ -50,8 +48,6 @@
#include "mongo/db/ops/delete.h"
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/repl/replication_coordinator_global.h"
-#include "mongo/db/s/collection_metadata.h"
-#include "mongo/db/s/collection_range_deleter.h"
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/migration_util.h"
#include "mongo/db/s/move_timing_helper.h"
@@ -434,7 +430,8 @@ void MigrationDestinationManager::_migrateThread(BSONObj min,
OID epoch,
WriteConcernOptions writeConcern) {
Client::initThread("migrateThread");
- auto opCtx = getGlobalServiceContext()->makeOperationContext(&cc());
+ auto opCtx = Client::getCurrent()->makeOperationContext();
+
if (getGlobalAuthorizationManager()->isAuthEnabled()) {
AuthorizationSession::get(opCtx->getClient())->grantInternalAuthorization();
@@ -472,6 +469,8 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* opCtx,
invariant(!min.isEmpty());
invariant(!max.isEmpty());
+ auto const serviceContext = opCtx->getServiceContext();
+
log() << "Starting receiving end of migration of chunk " << redact(min) << " -> " << redact(max)
<< " for collection " << _nss.ns() << " from " << fromShardConnString << " at epoch "
<< epoch.toString() << " with session id " << *_sessionId;
@@ -655,7 +654,7 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* opCtx,
for (auto&& infoObj : indexInfoObjs.getValue()) {
// make sure to create index on secondaries as well
- getGlobalServiceContext()->getOpObserver()->onCreateIndex(
+ serviceContext->getOpObserver()->onCreateIndex(
opCtx, collection->ns(), collection->uuid(), infoObj, true /* fromMigrate */);
}
diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp
index 592872bdf7d..934570a2946 100644
--- a/src/mongo/db/s/migration_source_manager.cpp
+++ b/src/mongo/db/s/migration_source_manager.cpp
@@ -33,8 +33,8 @@
#include "mongo/db/s/migration_source_manager.h"
#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/s/migration_chunk_cloner_source_legacy.h"
#include "mongo/db/s/migration_util.h"
diff --git a/src/mongo/db/s/move_chunk_command.cpp b/src/mongo/db/s/move_chunk_command.cpp
index a4c894b8a1c..235e053a3f8 100644
--- a/src/mongo/db/s/move_chunk_command.cpp
+++ b/src/mongo/db/s/move_chunk_command.cpp
@@ -36,15 +36,11 @@
#include "mongo/db/auth/authorization_manager.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/s/chunk_move_write_concern_options.h"
-#include "mongo/db/s/collection_metadata.h"
-#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/migration_source_manager.h"
#include "mongo/db/s/move_timing_helper.h"
#include "mongo/db/s/sharding_state.h"
-#include "mongo/s/catalog_cache_loader.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/s/migration_secondary_throttle_options.h"
@@ -54,9 +50,6 @@
#include "mongo/util/log.h"
namespace mongo {
-
-using std::string;
-
namespace {
/**
@@ -100,7 +93,7 @@ public:
}
Status checkAuthForCommand(Client* client,
- const string& dbname,
+ const std::string& dbname,
const BSONObj& cmdObj) override {
if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forClusterResource(), ActionType::internal)) {
@@ -109,12 +102,12 @@ public:
return Status::OK();
}
- string parseNs(const string& dbname, const BSONObj& cmdObj) const override {
+ std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const override {
return parseNsFullyQualified(dbname, cmdObj);
}
bool run(OperationContext* opCtx,
- const string& dbname,
+ const std::string& dbname,
const BSONObj& cmdObj,
BSONObjBuilder& result) override {
auto shardingState = ShardingState::get(opCtx);
@@ -196,7 +189,7 @@ private:
ReadPreferenceSetting{ReadPreference::PrimaryOnly});
}());
- string unusedErrMsg;
+ std::string unusedErrMsg;
MoveTimingHelper moveTimingHelper(opCtx,
"from",
moveChunkRequest.getNss().ns(),
diff --git a/src/mongo/db/s/session_catalog_migration_source.cpp b/src/mongo/db/s/session_catalog_migration_source.cpp
index 9ca38970dc7..e99913c1eeb 100644
--- a/src/mongo/db/s/session_catalog_migration_source.cpp
+++ b/src/mongo/db/s/session_catalog_migration_source.cpp
@@ -30,8 +30,8 @@
#include "mongo/db/s/session_catalog_migration_source.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/repl/repl_client_info.h"
@@ -46,7 +46,6 @@
#include "mongo/util/mongoutils/str.h"
namespace mongo {
-
namespace {
PseudoRandom hashGenerator(std::unique_ptr<SecureRandom>(SecureRandom::create())->nextInt64());
diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp
index 4049a4cae69..61ab7ece2b1 100644
--- a/src/mongo/db/s/set_shard_version_command.cpp
+++ b/src/mongo/db/s/set_shard_version_command.cpp
@@ -35,18 +35,16 @@
#include "mongo/db/auth/authorization_manager.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/privilege.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/lasterror.h"
#include "mongo/db/operation_context.h"
-#include "mongo/db/repl/replication_coordinator_global.h"
-#include "mongo/db/s/collection_metadata.h"
+#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/migration_source_manager.h"
#include "mongo/db/s/sharded_connection_info.h"
#include "mongo/db/s/sharding_state.h"
-#include "mongo/db/wire_version.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp
index 16a0627e48b..d4025ea9e11 100644
--- a/src/mongo/db/s/sharding_state.cpp
+++ b/src/mongo/db/s/sharding_state.cpp
@@ -37,15 +37,14 @@
#include "mongo/client/connection_string.h"
#include "mongo/client/replica_set_monitor.h"
#include "mongo/db/auth/authorization_session.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/client.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/ops/update.h"
#include "mongo/db/ops/update_lifecycle_impl.h"
#include "mongo/db/repl/optime.h"
-#include "mongo/db/repl/replication_coordinator_global.h"
-#include "mongo/db/s/collection_metadata.h"
+#include "mongo/db/repl/replication_coordinator.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"
@@ -67,11 +66,6 @@
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
-#include <chrono>
-#include <ctime>
-#include <iomanip>
-#include <iostream>
-
namespace mongo {
using std::shared_ptr;
@@ -100,7 +94,7 @@ void updateShardIdentityConfigStringCB(const string& setName, const string& newC
}
Client::initThread("updateShardIdentityConfigConnString");
- auto uniqOpCtx = getGlobalServiceContext()->makeOperationContext(&cc());
+ auto uniqOpCtx = Client::getCurrent()->makeOperationContext();
auto status = ShardingState::get(uniqOpCtx.get())
->updateShardIdentityConfigString(uniqOpCtx.get(), newConnectionString);
diff --git a/src/mongo/db/s/sharding_state_recovery.cpp b/src/mongo/db/s/sharding_state_recovery.cpp
index 090b1ba30ed..51e71a1c4cf 100644
--- a/src/mongo/db/s/sharding_state_recovery.cpp
+++ b/src/mongo/db/s/sharding_state_recovery.cpp
@@ -35,8 +35,7 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/bson/util/bson_extract.h"
-#include "mongo/client/connection_string.h"
-#include "mongo/db/db_raii.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/operation_context.h"
diff --git a/src/mongo/db/s/split_chunk.cpp b/src/mongo/db/s/split_chunk.cpp
index 348e8d1c52b..f37c825dbfd 100644
--- a/src/mongo/db/s/split_chunk.cpp
+++ b/src/mongo/db/s/split_chunk.cpp
@@ -34,9 +34,9 @@
#include "mongo/base/status_with.h"
#include "mongo/bson/util/bson_extract.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/commands.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/keypattern.h"
diff --git a/src/mongo/db/s/split_vector.cpp b/src/mongo/db/s/split_vector.cpp
index 9aad6ad17b2..3e917524aaf 100644
--- a/src/mongo/db/s/split_vector.cpp
+++ b/src/mongo/db/s/split_vector.cpp
@@ -34,8 +34,8 @@
#include "mongo/base/status_with.h"
#include "mongo/db/bson/dotted_path_support.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/catalog/index_catalog.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/exec/working_set_common.h"
#include "mongo/db/index/index_descriptor.h"
diff --git a/src/mongo/s/catalog/SConscript b/src/mongo/s/catalog/SConscript
index 7b76bf58d1b..aed7e63ab86 100644
--- a/src/mongo/s/catalog/SConscript
+++ b/src/mongo/s/catalog/SConscript
@@ -147,8 +147,8 @@ env.Library(
'sharding_catalog_manager_zone_operations.cpp',
],
LIBDEPS=[
+ '$BUILD_DIR/mongo/db/catalog/catalog_raii',
'$BUILD_DIR/mongo/db/commands/dcommands_fcv',
- '$BUILD_DIR/mongo/db/db_raii',
'$BUILD_DIR/mongo/db/repl/read_concern_args',
'$BUILD_DIR/mongo/db/s/balancer',
'$BUILD_DIR/mongo/executor/network_interface',
diff --git a/src/mongo/s/catalog/sharding_catalog_config_initialization_test.cpp b/src/mongo/s/catalog/sharding_catalog_config_initialization_test.cpp
index 40d0c0861e3..71705b712eb 100644
--- a/src/mongo/s/catalog/sharding_catalog_config_initialization_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_config_initialization_test.cpp
@@ -32,10 +32,9 @@
#include <vector>
#include "mongo/bson/json.h"
-#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
diff --git a/src/mongo/s/catalog/sharding_catalog_manager_chunk_operations.cpp b/src/mongo/s/catalog/sharding_catalog_manager_chunk_operations.cpp
index 3b5464fa63b..e60a6e951d8 100644
--- a/src/mongo/s/catalog/sharding_catalog_manager_chunk_operations.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_manager_chunk_operations.cpp
@@ -37,7 +37,7 @@
#include "mongo/bson/util/bson_extract.h"
#include "mongo/client/connection_string.h"
#include "mongo/client/read_preference.h"
-#include "mongo/db/db_raii.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/operation_context.h"
diff --git a/src/mongo/s/catalog/sharding_catalog_manager_shard_operations.cpp b/src/mongo/s/catalog/sharding_catalog_manager_shard_operations.cpp
index 97a28b4a3b1..bb208c19063 100644
--- a/src/mongo/s/catalog/sharding_catalog_manager_shard_operations.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_manager_shard_operations.cpp
@@ -43,9 +43,9 @@
#include "mongo/client/remote_command_targeter.h"
#include "mongo/client/replica_set_monitor.h"
#include "mongo/db/audit.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/client.h"
#include "mongo/db/commands/feature_compatibility_version.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/repl_client_info.h"
diff --git a/src/mongo/s/client/shard_local_test.cpp b/src/mongo/s/client/shard_local_test.cpp
index cb969394ccc..a4760feff40 100644
--- a/src/mongo/s/client/shard_local_test.cpp
+++ b/src/mongo/s/client/shard_local_test.cpp
@@ -31,9 +31,8 @@
#include "mongo/s/client/shard_local.h"
#include "mongo/client/read_preference.h"
-#include "mongo/db/catalog/database_holder.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/client.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/query/cursor_response.h"
#include "mongo/db/query/find_and_modify_request.h"
#include "mongo/db/repl/replication_coordinator_global.h"
diff --git a/src/mongo/s/config_server_test_fixture.cpp b/src/mongo/s/config_server_test_fixture.cpp
index 2715c61d852..e6b47f65a9a 100644
--- a/src/mongo/s/config_server_test_fixture.cpp
+++ b/src/mongo/s/config_server_test_fixture.cpp
@@ -36,9 +36,9 @@
#include "mongo/base/status_with.h"
#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/client/remote_command_targeter_mock.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/op_observer.h"
#include "mongo/db/ops/write_ops.h"
diff --git a/src/mongo/s/sharding_mongod_test_fixture.cpp b/src/mongo/s/sharding_mongod_test_fixture.cpp
index 453951a1735..a211fa3e4f9 100644
--- a/src/mongo/s/sharding_mongod_test_fixture.cpp
+++ b/src/mongo/s/sharding_mongod_test_fixture.cpp
@@ -36,9 +36,9 @@
#include "mongo/base/status_with.h"
#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/client/remote_command_targeter_mock.h"
+#include "mongo/db/catalog/catalog_raii.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
-#include "mongo/db/db_raii.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/op_observer_impl.h"
#include "mongo/db/query/cursor_response.h"