summaryrefslogtreecommitdiff
path: root/src/mongo/db/repair_database_and_check_version.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2018-11-26 14:27:10 -0500
committerBenety Goh <benety@mongodb.com>2018-11-26 14:27:10 -0500
commit820fd6a3a741844949103b200ed5558799faaad9 (patch)
treea586cf3e6b24b7994203619da094924627d58ca8 /src/mongo/db/repair_database_and_check_version.cpp
parent08a3ced33927cc4de0f9ff09384abbcd9c2212f4 (diff)
downloadmongo-820fd6a3a741844949103b200ed5558799faaad9.tar.gz
SERVER-38216 convert free function checkForIdIndexesAndDropPendingCollections() to a method on Database
Diffstat (limited to 'src/mongo/db/repair_database_and_check_version.cpp')
-rw-r--r--src/mongo/db/repair_database_and_check_version.cpp54
1 files changed, 1 insertions, 53 deletions
diff --git a/src/mongo/db/repair_database_and_check_version.cpp b/src/mongo/db/repair_database_and_check_version.cpp
index 43b3d1f7537..8ca17635703 100644
--- a/src/mongo/db/repair_database_and_check_version.cpp
+++ b/src/mongo/db/repair_database_and_check_version.cpp
@@ -38,18 +38,13 @@
#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/database_catalog_entry.h"
#include "mongo/db/catalog/database_holder.h"
-#include "mongo/db/catalog/drop_collection.h"
-#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/commands/feature_compatibility_version.h"
#include "mongo/db/commands/feature_compatibility_version_documentation.h"
#include "mongo/db/commands/feature_compatibility_version_parser.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
-#include "mongo/db/dbdirectclient.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/operation_context.h"
-#include "mongo/db/query/internal_plans.h"
#include "mongo/db/repair_database.h"
-#include "mongo/db/repl/drop_pending_collection_reaper.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/server_options.h"
#include "mongo/db/storage/storage_repair_observer.h"
@@ -57,7 +52,6 @@
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
#include "mongo/util/quick_exit.h"
-#include "mongo/util/version.h"
#if !defined(_WIN32)
#include <sys/file.h>
@@ -65,9 +59,6 @@
namespace mongo {
-using logger::LogComponent;
-using std::endl;
-
// Exit after repair has started, but before data is repaired.
MONGO_FAIL_POINT_DEFINE(exitBeforeDataRepair);
// Exit after repairing data, but before the replica set configuration is invalidated.
@@ -460,7 +451,7 @@ StatusWith<bool> repairDatabasesAndCheckVersion(OperationContext* opCtx) {
if (replSettings.usingReplSets()) {
// We only care about _id indexes and drop-pending collections if we are in a replset.
- checkForIdIndexesAndDropPendingCollections(opCtx, db);
+ db->checkForIdIndexesAndDropPendingCollections(opCtx);
// Ensure oplog is capped (mongodb does not guarantee order of inserts on noncapped
// collections)
if (db->name() == "local") {
@@ -487,47 +478,4 @@ StatusWith<bool> repairDatabasesAndCheckVersion(OperationContext* opCtx) {
return nonLocalDatabases;
}
-/**
- * If we are in a replset, every replicated collection must have an _id index.
- * As we scan each database, we also gather a list of drop-pending collection namespaces for
- * the DropPendingCollectionReaper to clean up eventually.
- */
-void checkForIdIndexesAndDropPendingCollections(OperationContext* opCtx, Database* db) {
- if (db->name() == "local") {
- // Collections in the local database are not replicated, so we do not need an _id index on
- // any collection. For the same reason, it is not possible for the local database to contain
- // any drop-pending collections (drops are effective immediately).
- return;
- }
-
- std::list<std::string> collectionNames;
- db->getDatabaseCatalogEntry()->getCollectionNamespaces(&collectionNames);
-
- for (const auto& collectionName : collectionNames) {
- const NamespaceString ns(collectionName);
-
- if (ns.isDropPendingNamespace()) {
- auto dropOpTime = fassert(40459, ns.getDropPendingNamespaceOpTime());
- log() << "Found drop-pending namespace " << ns << " with drop optime " << dropOpTime;
- repl::DropPendingCollectionReaper::get(opCtx)->addDropPendingNamespace(dropOpTime, ns);
- }
-
- if (ns.isSystem())
- continue;
-
- Collection* coll = db->getCollection(opCtx, collectionName);
- if (!coll)
- continue;
-
- if (coll->getIndexCatalog()->findIdIndex(opCtx))
- continue;
-
- log() << "WARNING: the collection '" << collectionName << "' lacks a unique index on _id."
- << " This index is needed for replication to function properly" << startupWarningsLog;
- log() << "\t To fix this, you need to create a unique index on _id."
- << " See http://dochub.mongodb.org/core/build-replica-set-indexes"
- << startupWarningsLog;
- }
-}
-
} // namespace mongo