diff options
Diffstat (limited to 'src/mongo/db/repl/storage_interface_impl.cpp')
-rw-r--r-- | src/mongo/db/repl/storage_interface_impl.cpp | 34 |
1 files changed, 32 insertions, 2 deletions
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(); } |