diff options
author | Benety Goh <benety@mongodb.com> | 2021-04-29 10:07:19 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-04-29 14:34:13 +0000 |
commit | 93134ab6b29ddf3a9a31ad497b3f298a8928af7e (patch) | |
tree | c12ff1d917515850ec2e3351fed68e4051f7ef80 | |
parent | 9b437dbad5f9b570a579ee3feb92206d79033ecc (diff) | |
download | mongo-93134ab6b29ddf3a9a31ad497b3f298a8928af7e.tar.gz |
SERVER-47123 remove AutoGetOrCreateDb from IndexBuildsManager::_moveRecordToLostAndFound()
This affects repair functionality where we have to save duplicate keys to a local 'lost_and_found'
collection while repairing a unique index.
This commit also includes trivial changes to startup logging and the config.system.indexBuilds helper.
-rw-r--r-- | src/mongo/db/catalog/index_builds_manager.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/index_build_entry_helpers.cpp | 50 | ||||
-rw-r--r-- | src/mongo/db/mongod_main.cpp | 4 |
3 files changed, 35 insertions, 34 deletions
diff --git a/src/mongo/db/catalog/index_builds_manager.cpp b/src/mongo/db/catalog/index_builds_manager.cpp index 479c0afef2c..8d4e3eb973a 100644 --- a/src/mongo/db/catalog/index_builds_manager.cpp +++ b/src/mongo/db/catalog/index_builds_manager.cpp @@ -393,7 +393,9 @@ StatusWith<int> IndexBuildsManager::_moveRecordToLostAndFound( const NamespaceString& nss, const NamespaceString& lostAndFoundNss, RecordId dupRecord) { - invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_IX)); + invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_IX), nss.ns()); + invariant(opCtx->lockState()->isCollectionLockedForMode(lostAndFoundNss, MODE_IX), + lostAndFoundNss.ns()); auto catalog = CollectionCatalog::get(opCtx); auto originalCollection = catalog->lookupCollectionByNamespace(opCtx, nss); @@ -403,12 +405,13 @@ StatusWith<int> IndexBuildsManager::_moveRecordToLostAndFound( if (!localCollection) { Status status = writeConflictRetry(opCtx, "createLostAndFoundCollection", lostAndFoundNss.ns(), [&]() { - WriteUnitOfWork wuow(opCtx); - AutoGetOrCreateDb autoDb(opCtx, NamespaceString::kLocalDb, MODE_X); - Database* db = autoDb.getDb(); + AutoGetCollection autoColl(opCtx, lostAndFoundNss, MODE_IX); // Ensure the database exists. - invariant(db); + auto db = autoColl.ensureDbExists(); + invariant(db, lostAndFoundNss.ns()); + + WriteUnitOfWork wuow(opCtx); // Since we are potentially deleting a document with duplicate _id values, we need // to be able to insert into the lost and found collection without generating any @@ -418,7 +421,7 @@ StatusWith<int> IndexBuildsManager::_moveRecordToLostAndFound( localCollection = db->createCollection(opCtx, lostAndFoundNss, collOptions); // Ensure the collection exists. - invariant(localCollection); + invariant(localCollection, lostAndFoundNss.ns()); wuow.commit(); return Status::OK(); diff --git a/src/mongo/db/index_build_entry_helpers.cpp b/src/mongo/db/index_build_entry_helpers.cpp index efbf58cfccc..6a119e8f625 100644 --- a/src/mongo/db/index_build_entry_helpers.cpp +++ b/src/mongo/db/index_build_entry_helpers.cpp @@ -165,32 +165,30 @@ Status update(OperationContext* opCtx, const BSONObj& filter, const BSONObj& upd namespace indexbuildentryhelpers { void ensureIndexBuildEntriesNamespaceExists(OperationContext* opCtx) { - writeConflictRetry(opCtx, - "createIndexBuildCollection", - NamespaceString::kIndexBuildEntryNamespace.ns(), - [&]() -> void { - AutoGetOrCreateDb autoDb( - opCtx, NamespaceString::kIndexBuildEntryNamespace.db(), MODE_X); - Database* db = autoDb.getDb(); - - // Ensure the database exists. - invariant(db); - - // Create the collection if it doesn't exist. - if (!CollectionCatalog::get(opCtx)->lookupCollectionByNamespace( - opCtx, NamespaceString::kIndexBuildEntryNamespace)) { - WriteUnitOfWork wuow(opCtx); - CollectionOptions defaultCollectionOptions; - CollectionPtr collection = - db->createCollection(opCtx, - NamespaceString::kIndexBuildEntryNamespace, - defaultCollectionOptions); - - // Ensure the collection exists. - invariant(collection); - wuow.commit(); - } - }); + writeConflictRetry( + opCtx, + "createIndexBuildCollection", + NamespaceString::kIndexBuildEntryNamespace.ns(), + [&]() -> void { + AutoGetDb autoDb(opCtx, NamespaceString::kIndexBuildEntryNamespace.db(), MODE_X); + auto db = autoDb.ensureDbExists(); + + // Ensure the database exists. + invariant(db); + + // Create the collection if it doesn't exist. + if (!CollectionCatalog::get(opCtx)->lookupCollectionByNamespace( + opCtx, NamespaceString::kIndexBuildEntryNamespace)) { + WriteUnitOfWork wuow(opCtx); + CollectionOptions defaultCollectionOptions; + CollectionPtr collection = db->createCollection( + opCtx, NamespaceString::kIndexBuildEntryNamespace, defaultCollectionOptions); + + // Ensure the collection exists. + invariant(collection); + wuow.commit(); + } + }); } Status persistCommitReadyMemberInfo(OperationContext* opCtx, diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp index cd4ae044047..ee8b253fd70 100644 --- a/src/mongo/db/mongod_main.cpp +++ b/src/mongo/db/mongod_main.cpp @@ -263,8 +263,8 @@ void logStartup(OperationContext* opCtx) { BSONObj o = toLog.obj(); Lock::GlobalWrite lk(opCtx); - AutoGetOrCreateDb autoDb(opCtx, startupLogCollectionName.db(), mongo::MODE_X); - Database* db = autoDb.getDb(); + AutoGetDb autoDb(opCtx, startupLogCollectionName.db(), mongo::MODE_X); + auto db = autoDb.ensureDbExists(); CollectionPtr collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, startupLogCollectionName); WriteUnitOfWork wunit(opCtx); |