summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2019-10-02 18:27:38 +0000
committerevergreen <evergreen@mongodb.com>2019-10-02 18:27:38 +0000
commitac796463d5f6fbca4e0b7f2dd0f6da2a58a66a9e (patch)
treef2c30f40933bd1f6cd653831d54c421aaef555e9 /src/mongo/db
parent96a7542b2fd6abbdc7a27f12e5cece7310208716 (diff)
downloadmongo-ac796463d5f6fbca4e0b7f2dd0f6da2a58a66a9e.tar.gz
SERVER-43352 RestartCatalog expects listDatabases to include empty databases
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/catalog/collection_catalog.h2
-rw-r--r--src/mongo/db/catalog/database_holder.h7
-rw-r--r--src/mongo/db/catalog/database_holder_impl.cpp9
-rw-r--r--src/mongo/db/catalog/database_holder_impl.h2
-rw-r--r--src/mongo/db/catalog/database_holder_mock.h4
-rw-r--r--src/mongo/db/commands/restart_catalog_command.cpp3
6 files changed, 25 insertions, 2 deletions
diff --git a/src/mongo/db/catalog/collection_catalog.h b/src/mongo/db/catalog/collection_catalog.h
index 912cd629fb9..c27022c26d9 100644
--- a/src/mongo/db/catalog/collection_catalog.h
+++ b/src/mongo/db/catalog/collection_catalog.h
@@ -202,6 +202,8 @@ public:
/**
* This functions gets all the database names. The result is sorted in alphabetical ascending
* order.
+ *
+ * Unlike DatabaseHolder::getNames(), this does not return databases that are empty.
*/
std::vector<std::string> getAllDbNames() const;
diff --git a/src/mongo/db/catalog/database_holder.h b/src/mongo/db/catalog/database_holder.h
index 53413a0e900..890ad037de1 100644
--- a/src/mongo/db/catalog/database_holder.h
+++ b/src/mongo/db/catalog/database_holder.h
@@ -103,6 +103,13 @@ public:
* Returns the set of existing database names that differ only in casing.
*/
virtual std::set<std::string> getNamesWithConflictingCasing(const StringData name) = 0;
+
+ /**
+ * Returns all the database names (including those which are empty).
+ *
+ * Unlike CollectionCatalog::getAllDbNames(), this returns databases that are empty.
+ */
+ virtual std::vector<std::string> getNames() = 0;
};
} // namespace mongo
diff --git a/src/mongo/db/catalog/database_holder_impl.cpp b/src/mongo/db/catalog/database_holder_impl.cpp
index a596a2e4214..c105b6bc07b 100644
--- a/src/mongo/db/catalog/database_holder_impl.cpp
+++ b/src/mongo/db/catalog/database_holder_impl.cpp
@@ -98,6 +98,15 @@ std::set<std::string> DatabaseHolderImpl::getNamesWithConflictingCasing(StringDa
return _getNamesWithConflictingCasing_inlock(name);
}
+std::vector<std::string> DatabaseHolderImpl::getNames() {
+ stdx::lock_guard<SimpleMutex> lk(_m);
+ std::vector<std::string> names;
+ for (const auto& nameAndPointer : _dbs) {
+ names.push_back(nameAndPointer.first);
+ }
+ return names;
+}
+
Database* DatabaseHolderImpl::openDb(OperationContext* opCtx, StringData ns, bool* justCreated) {
const StringData dbname = _todb(ns);
invariant(opCtx->lockState()->isDbLockedForMode(dbname, MODE_X));
diff --git a/src/mongo/db/catalog/database_holder_impl.h b/src/mongo/db/catalog/database_holder_impl.h
index 5a53ad8ff5e..cede54eab55 100644
--- a/src/mongo/db/catalog/database_holder_impl.h
+++ b/src/mongo/db/catalog/database_holder_impl.h
@@ -52,6 +52,8 @@ public:
std::set<std::string> getNamesWithConflictingCasing(StringData name) override;
+ std::vector<std::string> getNames() override;
+
private:
std::set<std::string> _getNamesWithConflictingCasing_inlock(StringData name);
diff --git a/src/mongo/db/catalog/database_holder_mock.h b/src/mongo/db/catalog/database_holder_mock.h
index bccfd4d1f2a..7aaa86f530f 100644
--- a/src/mongo/db/catalog/database_holder_mock.h
+++ b/src/mongo/db/catalog/database_holder_mock.h
@@ -54,6 +54,10 @@ public:
std::set<std::string> getNamesWithConflictingCasing(StringData name) override {
return std::set<std::string>();
}
+
+ std::vector<std::string> getNames() override {
+ return {};
+ }
};
} // namespace mongo
diff --git a/src/mongo/db/commands/restart_catalog_command.cpp b/src/mongo/db/commands/restart_catalog_command.cpp
index 5713cd66a54..99858abf378 100644
--- a/src/mongo/db/commands/restart_catalog_command.cpp
+++ b/src/mongo/db/commands/restart_catalog_command.cpp
@@ -96,8 +96,7 @@ public:
// marked drop-pending. (Otherwise, the Database object will be reconstructed when
// re-opening the catalog, but with the drop pending flag cleared.)
auto databaseHolder = DatabaseHolder::get(opCtx);
- std::vector<std::string> allDbs =
- getGlobalServiceContext()->getStorageEngine()->listDatabases();
+ std::vector<std::string> allDbs = databaseHolder->getNames();
for (auto&& dbName : allDbs) {
const auto db = databaseHolder->getDb(opCtx, dbName);
if (db->isDropPending(opCtx)) {