diff options
author | Dianna Hohensee <dianna.hohensee@mongodb.com> | 2021-02-05 14:19:47 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-09 04:17:11 +0000 |
commit | dc96088c84c5411b70caa0c01be000da1a1ae3d1 (patch) | |
tree | fcbe4fbde73597886527de96a66a96c97e1ec541 | |
parent | 871ed94542d7dd45d8af1593ee19ad4c417c779b (diff) | |
download | mongo-dc96088c84c5411b70caa0c01be000da1a1ae3d1.tar.gz |
SERVER-38910 Remove index drop rollback handling on opening the storage engine.
This scenario can no longer occur because we wait for index drops to be majority
committed before dropping the underlying data table.
-rw-r--r-- | src/mongo/db/storage/kv/storage_engine_test.cpp | 25 | ||||
-rw-r--r-- | src/mongo/db/storage/storage_engine_impl.cpp | 31 |
2 files changed, 15 insertions, 41 deletions
diff --git a/src/mongo/db/storage/kv/storage_engine_test.cpp b/src/mongo/db/storage/kv/storage_engine_test.cpp index 9e68420730d..3a19dbd11ef 100644 --- a/src/mongo/db/storage/kv/storage_engine_test.cpp +++ b/src/mongo/db/storage/kv/storage_engine_test.cpp @@ -62,6 +62,7 @@ TEST_F(StorageEngineTest, ReconcileIdentsTest) { // the `ident` name given to the collection. auto swCollInfo = createCollection(opCtx.get(), NamespaceString("db.coll1")); ASSERT_OK(swCollInfo.getStatus()); + // Create a table in the KVEngine not reflected in the DurableCatalog. This should be dropped // when reconciling. ASSERT_OK(createCollTable(opCtx.get(), NamespaceString("db.coll2"))); @@ -72,33 +73,13 @@ TEST_F(StorageEngineTest, ReconcileIdentsTest) { auto identsVec = getAllKVEngineIdents(opCtx.get()); auto idents = std::set<std::string>(identsVec.begin(), identsVec.end()); + // There are two idents. `_mdb_catalog` and the ident for `db.coll1`. ASSERT_EQUALS(static_cast<const unsigned long>(2), idents.size()); ASSERT_TRUE(idents.find(swCollInfo.getValue().ident) != idents.end()); ASSERT_TRUE(idents.find("_mdb_catalog") != idents.end()); - // Create a catalog entry for the `_id` index. Drop the created the table. - { - WriteUnitOfWork wuow(opCtx.get()); - ASSERT_OK(createIndex(opCtx.get(), - NamespaceString("db.coll1"), - "_id", - false /* isBackgroundSecondaryBuild */)); - wuow.commit(); - } - - ASSERT_OK(dropIndexTable(opCtx.get(), NamespaceString("db.coll1"), "_id")); - // The reconcile response should include this index as needing to be rebuilt. - reconcileResult = unittest::assertGet(reconcile(opCtx.get())); - ASSERT_EQUALS(1UL, reconcileResult.indexesToRebuild.size()); - ASSERT_EQUALS(0UL, reconcileResult.indexBuildsToRestart.size()); - ASSERT_EQUALS(0UL, reconcileResult.indexBuildsToResume.size()); - - StorageEngine::IndexIdentifier& toRebuild = reconcileResult.indexesToRebuild[0]; - ASSERT_EQUALS("db.coll1", toRebuild.nss.ns()); - ASSERT_EQUALS("_id", toRebuild.indexName); - - // Now drop the `db.coll1` table, while leaving the DurableCatalog entry. + // Drop the `db.coll1` table, while leaving the DurableCatalog entry. ASSERT_OK(dropIdent(opCtx.get()->recoveryUnit(), swCollInfo.getValue().ident)); ASSERT_EQUALS(static_cast<const unsigned long>(1), getAllKVEngineIdents(opCtx.get()).size()); diff --git a/src/mongo/db/storage/storage_engine_impl.cpp b/src/mongo/db/storage/storage_engine_impl.cpp index 9d0b40c520b..9ba689a9d7f 100644 --- a/src/mongo/db/storage/storage_engine_impl.cpp +++ b/src/mongo/db/storage/storage_engine_impl.cpp @@ -589,21 +589,15 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn "namespace"_attr = coll); } - const bool foundIdent = engineIdents.find(indexIdent) != engineIdents.end(); - // An index drop will immediately remove the ident, but the `indexMetaData` catalog - // entry still exists implying the drop hasn't necessarily been replicated to a - // majority of nodes. The code will rebuild the index, despite potentially - // encountering another `dropIndex` command. - if (indexMetaData.ready && !foundIdent) { - LOGV2(22252, - "Expected index data is missing, rebuilding. Collection: {namespace} Index: " - "{index}", - "Expected index data is missing, rebuilding", - "index"_attr = indexName, - "namespace"_attr = coll); - reconcileResult.indexesToRebuild.push_back({entry.catalogId, coll, indexName}); - continue; - } + // Two-phase index drop ensures that the underlying data table for an index in the + // catalog is not dropped until the index removal from the catalog has been majority + // committed and become part of the latest checkpoint. Therefore, there should never be + // a case where the index catalog entry remains but the index table (identified by + // ident) has been removed. + invariant(engineIdents.find(indexIdent) != engineIdents.end(), + str::stream() << "Failed to find an index data table matching " << indexIdent + << " for durable index catalog entry " << indexMetaData.spec + << " in collection " << coll); // Any index build with a UUID is an unfinished two-phase build and must be restarted. // There are no special cases to handle on primaries or secondaries. An index build may @@ -638,10 +632,9 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn } // If the index was kicked off as a background secondary index build, replication - // recovery will not run into the oplog entry to recreate the index. If the index - // table is not found, or the index build did not successfully complete, this code - // will return the index to be rebuilt. - if (indexMetaData.isBackgroundSecondaryBuild && (!foundIdent || !indexMetaData.ready)) { + // recovery will not run into the oplog entry to recreate the index. If the index build + // did not successfully complete, this code will return the index to be rebuilt. + if (indexMetaData.isBackgroundSecondaryBuild && !indexMetaData.ready) { LOGV2(22255, "Expected background index build did not complete, rebuilding in foreground " "- see SERVER-43097", |