diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/catalog/database.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/catalog/database.h | 9 | ||||
-rw-r--r-- | src/mongo/db/catalog/database_impl.cpp | 29 | ||||
-rw-r--r-- | src/mongo/db/catalog/database_impl.h | 24 | ||||
-rw-r--r-- | src/mongo/db/repl/storage_interface_impl.cpp | 34 |
5 files changed, 37 insertions, 64 deletions
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp index 43696613a64..ca6e2714af0 100644 --- a/src/mongo/db/catalog/database.cpp +++ b/src/mongo/db/catalog/database.cpp @@ -28,14 +28,12 @@ * it in the license file. */ -#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kStorage - #include "mongo/platform/basic.h" #include "mongo/db/catalog/database.h" - namespace mongo { + Database::Impl::~Impl() = default; MONGO_DEFINE_SHIM(Database::makeImpl); @@ -44,5 +42,4 @@ void Database::TUHook::hook() noexcept {} MONGO_DEFINE_SHIM(Database::userCreateNS); -MONGO_DEFINE_SHIM(Database::dropAllDatabasesExceptLocal); } // namespace mongo diff --git a/src/mongo/db/catalog/database.h b/src/mongo/db/catalog/database.h index 34f35bad0f2..f37fac1ffce 100644 --- a/src/mongo/db/catalog/database.h +++ b/src/mongo/db/catalog/database.h @@ -41,15 +41,14 @@ #include "mongo/db/catalog/collection_options.h" #include "mongo/db/namespace_string.h" #include "mongo/db/repl/optime.h" -#include "mongo/db/storage/storage_options.h" -#include "mongo/db/views/view.h" #include "mongo/db/views/view_catalog.h" -#include "mongo/stdx/functional.h" -#include "mongo/util/mongoutils/str.h" #include "mongo/util/string_map.h" namespace mongo { +class DatabaseCatalogEntry; +class OperationContext; + /** * Represents a logical database containing Collections. * @@ -131,8 +130,6 @@ public: }; public: - static MONGO_DECLARE_SHIM((OperationContext * opCtx)->void) dropAllDatabasesExceptLocal; - /** * Creates the namespace 'ns' in the database 'db' according to 'options'. If * 'createDefaultIndexes' is true, creates the _id index for the collection (and the system diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index 1eaa1b2934c..11817a1783f 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -1123,33 +1123,4 @@ MONGO_REGISTER_SHIM(Database::userCreateNS) return Status::OK(); } -MONGO_REGISTER_SHIM(Database::dropAllDatabasesExceptLocal)(OperationContext* opCtx)->void { - Lock::GlobalWrite lk(opCtx); - - vector<string> n; - StorageEngine* storageEngine = opCtx->getServiceContext()->getStorageEngine(); - storageEngine->listDatabases(&n); - - if (n.size() == 0) - return; - log() << "dropAllDatabasesExceptLocal " << n.size(); - - repl::ReplicationCoordinator::get(opCtx)->dropAllSnapshots(); - - for (const auto& dbName : n) { - if (dbName != "local") { - writeConflictRetry(opCtx, "dropAllDatabasesExceptLocal", dbName, [&opCtx, &dbName] { - Database* db = DatabaseHolder::getDatabaseHolder().get(opCtx, dbName); - - // This is needed since dropDatabase can't be rolled back. - // This is safe be replaced by "invariant(db);dropDatabase(opCtx, db);" once fixed - if (db == nullptr) { - log() << "database disappeared after listDatabases but before drop: " << dbName; - } else { - DatabaseHolder::getDatabaseHolder().dropDb(opCtx, db); - } - }); - } - } -} } // namespace mongo diff --git a/src/mongo/db/catalog/database_impl.h b/src/mongo/db/catalog/database_impl.h index 6df1f03a58d..6a0cbd57e53 100644 --- a/src/mongo/db/catalog/database_impl.h +++ b/src/mongo/db/catalog/database_impl.h @@ -32,27 +32,10 @@ #include "mongo/db/catalog/database.h" -#include <memory> -#include <string> - -#include "mongo/base/string_data.h" -#include "mongo/bson/bsonobj.h" -#include "mongo/db/catalog/collection_options.h" -#include "mongo/db/namespace_string.h" -#include "mongo/db/storage/storage_options.h" -#include "mongo/db/views/view.h" -#include "mongo/db/views/view_catalog.h" -#include "mongo/util/mongoutils/str.h" -#include "mongo/util/string_map.h" +#include "mongo/platform/random.h" namespace mongo { -class Collection; -class DatabaseCatalogEntry; -class IndexCatalog; -class OperationContext; -class PseudoRandom; - /** * Represents a logical database containing Collections. * @@ -312,11 +295,6 @@ private: DurableViewCatalogImpl _durableViews; // interface for system.views operations ViewCatalog _views; // in-memory representation of _durableViews Database* _this; // Pointer to wrapper, for external caller compatibility. - - friend class Collection; - friend class IndexCatalog; }; -void dropAllDatabasesExceptLocalImpl(OperationContext* opCtx); - } // namespace mongo diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp index 8d96d926e95..cffc5e835f3 100644 --- a/src/mongo/db/repl/storage_interface_impl.cpp +++ b/src/mongo/db/repl/storage_interface_impl.cpp @@ -48,7 +48,7 @@ #include "mongo/db/catalog/coll_mod.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/index_catalog.h" #include "mongo/db/catalog/uuid_catalog.h" @@ -372,7 +372,37 @@ Status StorageInterfaceImpl::insertDocuments(OperationContext* opCtx, } Status StorageInterfaceImpl::dropReplicatedDatabases(OperationContext* opCtx) { - Database::dropAllDatabasesExceptLocal(opCtx); + Lock::GlobalWrite globalWriteLock(opCtx); + + std::vector<std::string> dbNames; + opCtx->getServiceContext()->getStorageEngine()->listDatabases(&dbNames); + invariant(!dbNames.empty()); + log() << "dropReplicatedDatabases - dropping " << dbNames.size() << " databases"; + + ReplicationCoordinator::get(opCtx)->dropAllSnapshots(); + + auto dbHolder = &DatabaseHolder::getDatabaseHolder(); + auto hasLocalDatabase = false; + for (const auto& dbName : dbNames) { + if (dbName == "local") { + hasLocalDatabase = true; + continue; + } + writeConflictRetry(opCtx, "dropReplicatedDatabases", dbName, [&] { + if (auto db = dbHolder->get(opCtx, dbName)) { + dbHolder->dropDb(opCtx, db); + } else { + // This is needed since dropDatabase can't be rolled back. + // This is safe be replaced by "invariant(db);dropDatabase(opCtx, db);" once fixed. + log() << "dropReplicatedDatabases - database disappeared after retrieving list of " + "database names but before drop: " + << dbName; + } + }); + } + invariant(hasLocalDatabase, "local database missing"); + log() << "dropReplicatedDatabases - dropped " << dbNames.size() << " databases"; + return Status::OK(); } |