From 8e4f280e492fe2bfb7842733ff640030d559cd0a Mon Sep 17 00:00:00 2001 From: Xiangyu Yao Date: Mon, 8 Jul 2019 11:29:36 -0400 Subject: SERVER-39471 Remove unique index FCV upgrade codepath --- src/mongo/db/catalog/coll_mod.cpp | 188 +-------------------- src/mongo/db/catalog/coll_mod.h | 18 -- .../set_feature_compatibility_version_command.cpp | 2 - src/mongo/db/repl/initial_syncer.cpp | 14 -- src/mongo/db/repl/initial_syncer_test.cpp | 68 +------- src/mongo/db/repl/oplog.cpp | 5 +- ...replication_coordinator_external_state_impl.cpp | 23 --- src/mongo/db/repl/storage_interface.h | 6 - src/mongo/db/repl/storage_interface_impl.cpp | 4 - src/mongo/db/repl/storage_interface_impl.h | 2 - src/mongo/db/repl/storage_interface_mock.h | 9 - src/mongo/db/storage/durable_catalog.h | 7 - src/mongo/db/storage/durable_catalog_impl.cpp | 22 --- src/mongo/db/storage/durable_catalog_impl.h | 7 - src/mongo/db/storage/kv/kv_engine.h | 5 - .../db/storage/wiredtiger/wiredtiger_index.cpp | 25 ++- .../db/storage/wiredtiger/wiredtiger_kv_engine.cpp | 14 -- .../db/storage/wiredtiger/wiredtiger_kv_engine.h | 4 - 18 files changed, 28 insertions(+), 395 deletions(-) (limited to 'src/mongo') diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 569dbb1bd0a..9aac38954e8 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -246,8 +246,7 @@ StatusWith parseCollModRequest(OperationContext* opCtx, Status _collModInternal(OperationContext* opCtx, const NamespaceString& nss, const BSONObj& cmdObj, - BSONObjBuilder* result, - bool upgradeUniqueIndexes) { + BSONObjBuilder* result) { StringData dbName = nss.db(); AutoGetDb autoDb(opCtx, dbName, MODE_X); Database* const db = autoDb.getDb(); @@ -372,32 +371,6 @@ Status _collModInternal(OperationContext* opCtx, if (!cmr.collValidationLevel.empty()) invariant(coll->setValidationLevel(opCtx, cmr.collValidationLevel)); - // Upgrade unique indexes - if (upgradeUniqueIndexes) { - // A cmdObj with an empty collMod, i.e. nFields = 1, implies that it is a Unique Index - // upgrade collMod. - invariant(cmdObj.nFields() == 1); - std::vector indexNames; - DurableCatalog::get(opCtx)->getAllUniqueIndexes(opCtx, nss, &indexNames); - - for (size_t i = 0; i < indexNames.size(); i++) { - const IndexDescriptor* desc = - coll->getIndexCatalog()->findIndexByName(opCtx, indexNames[i]); - invariant(desc); - - // Update index metadata in storage engine. - DurableCatalog::get(opCtx)->updateIndexMetadata(opCtx, nss, desc); - - // Refresh the in-memory instance of the index. - desc = coll->getIndexCatalog()->refreshEntry(opCtx, desc); - - if (MONGO_FAIL_POINT(assertAfterIndexUpdate)) { - log() << "collMod - assertAfterIndexUpdate fail point enabled."; - uasserted(50971, "trigger rollback for unique index update"); - } - } - } - // Only observe non-view collMods, as view operations are observed as operations on the // system.views collection. getGlobalServiceContext()->getOpObserver()->onCollMod( @@ -414,164 +387,7 @@ Status collMod(OperationContext* opCtx, const NamespaceString& nss, const BSONObj& cmdObj, BSONObjBuilder* result) { - return _collModInternal(opCtx, - nss, - cmdObj, - result, - /*upgradeUniqueIndexes*/ false); -} - -Status collModWithUpgrade(OperationContext* opCtx, - const NamespaceString& nss, - const BSONObj& cmdObj) { - // An empty collMod is used to upgrade unique index during FCV upgrade. If an application - // executes the empty collMod when the secondary is upgrading FCV it is fine to upgrade the - // unique index becuase the secondary will eventually get the real empty collMod. If the - // application issues an empty collMod when FCV is not upgrading or upgraded to 4.2 then the - // unique index should not be upgraded due to this collMod on the secondary. - bool upgradeUniqueIndex = - (cmdObj.nFields() == 1 && serverGlobalParams.featureCompatibility.isVersionInitialized() && - serverGlobalParams.featureCompatibility.isVersionUpgradingOrUpgraded()); - - // Update all non-replicated unique indexes on upgrade i.e. setFCV=4.2. - if (upgradeUniqueIndex && nss == NamespaceString::kServerConfigurationNamespace) { - auto schemaStatus = updateNonReplicatedUniqueIndexes(opCtx); - if (!schemaStatus.isOK()) { - return schemaStatus; - } - } - - BSONObjBuilder resultWeDontCareAbout; - return _collModInternal(opCtx, nss, cmdObj, &resultWeDontCareAbout, upgradeUniqueIndex); -} - -Status _updateNonReplicatedIndexPerCollection(OperationContext* opCtx, Collection* coll) { - BSONObjBuilder collModObjBuilder; - collModObjBuilder.append("collMod", coll->ns().coll()); - BSONObj collModObj = collModObjBuilder.done(); - - BSONObjBuilder resultWeDontCareAbout; - auto collModStatus = _collModInternal(opCtx, - coll->ns(), - collModObj, - &resultWeDontCareAbout, - /*upgradeUniqueIndexes*/ true); - return collModStatus; -} - -Status _updateNonReplicatedUniqueIndexesPerDatabase(OperationContext* opCtx, - const std::string& dbName) { - AutoGetDb autoDb(opCtx, dbName, MODE_X); - Database* const db = autoDb.getDb(); - - // Iterate through all collections if we're in the "local" database. - if (dbName == "local") { - for (auto collectionIt = db->begin(opCtx); collectionIt != db->end(opCtx); ++collectionIt) { - Collection* coll = *collectionIt; - if (!coll) { - break; - } - - auto collModStatus = _updateNonReplicatedIndexPerCollection(opCtx, coll); - if (!collModStatus.isOK()) - return collModStatus; - } - } else { - // If we're not in the "local" database, the only non-replicated collection - // could be system.profile. - Collection* coll = - db ? db->getCollection(opCtx, NamespaceString(dbName, "system.profile")) : nullptr; - if (!coll) - return Status::OK(); - - auto collModStatus = _updateNonReplicatedIndexPerCollection(opCtx, coll); - if (!collModStatus.isOK()) - return collModStatus; - } - return Status::OK(); -} - -void _updateUniqueIndexesForDatabase(OperationContext* opCtx, const std::string& dbname) { - // Iterate through all replicated collections of the database, for unique index update. - // Non-replicated unique indexes are updated via the upgrade of admin.system.version - // collection. - { - AutoGetDb autoDb(opCtx, dbname, MODE_X); - Database* const db = autoDb.getDb(); - // If the database no longer exists, nothing more to do. - if (!db) - return; - - for (auto collectionIt = db->begin(opCtx); collectionIt != db->end(opCtx); ++collectionIt) { - Collection* coll = *collectionIt; - if (!coll) { - break; - } - - NamespaceString collNSS = coll->ns(); - - // Skip non-replicated collection. - if (collNSS.coll() == "system.profile") - continue; - - BSONObjBuilder collModObjBuilder; - collModObjBuilder.append("collMod", collNSS.coll()); - BSONObj collModObj = collModObjBuilder.done(); - - uassertStatusOK(collModWithUpgrade(opCtx, collNSS, collModObj)); - } - } -} - -void updateUniqueIndexesOnUpgrade(OperationContext* opCtx) { - // Update all unique indexes except the _id index. - std::vector dbNames; - { - Lock::GlobalLock lk(opCtx, MODE_IS); - dbNames = CollectionCatalog::get(opCtx).getAllDbNames(); - } - - for (auto it = dbNames.begin(); it != dbNames.end(); ++it) { - auto dbName = *it; - - // Non-replicated unique indexes are updated via the upgrade of admin.system.version - // collection. - if (dbName != "local") - _updateUniqueIndexesForDatabase(opCtx, dbName); - } - - const auto& clientInfo = repl::ReplClientInfo::forClient(opCtx->getClient()); - auto awaitOpTime = clientInfo.getLastOp(); - - log() << "Finished updating version of unique indexes for upgrade, waiting for all" - << " index updates to be committed at optime " << awaitOpTime; - - auto timeout = opCtx->getWriteConcern().usedDefault ? WriteConcernOptions::kNoTimeout - : opCtx->getWriteConcern().wTimeout; - const WriteConcernOptions writeConcern( - WriteConcernOptions::kMajority, WriteConcernOptions::SyncMode::UNSET, timeout); - - uassertStatusOK(repl::ReplicationCoordinator::get(opCtx) - ->awaitReplication(opCtx, awaitOpTime, writeConcern) - .status); -} - -Status updateNonReplicatedUniqueIndexes(OperationContext* opCtx) { - // Update all unique indexes belonging to all non-replicated collections. - // (_id indexes are not updated). - std::vector dbNames; - { - Lock::GlobalLock lk(opCtx, MODE_IS); - dbNames = CollectionCatalog::get(opCtx).getAllDbNames(); - } - for (auto it = dbNames.begin(); it != dbNames.end(); ++it) { - auto dbName = *it; - auto schemaStatus = _updateNonReplicatedUniqueIndexesPerDatabase(opCtx, dbName); - if (!schemaStatus.isOK()) { - return schemaStatus; - } - } - return Status::OK(); + return _collModInternal(opCtx, nss, cmdObj, result); } } // namespace mongo diff --git a/src/mongo/db/catalog/coll_mod.h b/src/mongo/db/catalog/coll_mod.h index 5629926b4b7..e92205e5888 100644 --- a/src/mongo/db/catalog/coll_mod.h +++ b/src/mongo/db/catalog/coll_mod.h @@ -52,22 +52,4 @@ Status collMod(OperationContext* opCtx, const BSONObj& cmdObj, BSONObjBuilder* result); -/** - * Applies the collMod operation and optionally updates formatVersion of unique indexes belonging - * to collection "nss". - */ -Status collModWithUpgrade(OperationContext* opCtx, - const NamespaceString& nss, - const BSONObj& cmdObj); - -/* - * Updates the unique indexes to timestamp safe unique index format on setFCV=4.2. It also updates - * non-replicated unique indexes indirectly by calling updateNonReplicatedUniqueIndexes(). - */ -void updateUniqueIndexesOnUpgrade(OperationContext* opCtx); - -/* - * Updates non-replicated unique indexes to timestamp safe unique index format. - */ -Status updateNonReplicatedUniqueIndexes(OperationContext* opCtx); } // namespace mongo diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index bd9b65ddaa0..e71f4b0682e 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -328,8 +328,6 @@ public: Lock::GlobalLock lk(opCtx, MODE_S); } - updateUniqueIndexesOnUpgrade(opCtx); - upgradeTransactionTable(opCtx); // Upgrade shards before config finishes its upgrade. diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp index 4a8a488999e..d235d56795b 100644 --- a/src/mongo/db/repl/initial_syncer.cpp +++ b/src/mongo/db/repl/initial_syncer.cpp @@ -1372,20 +1372,6 @@ void InitialSyncer::_rollbackCheckerCheckForRollbackCallback( return; } - // Update all unique indexes belonging to non-replicated collections on secondaries. See comment - // in ReplicationCoordinatorExternalStateImpl::initializeReplSetStorage() for the explanation of - // why we do this. - if (serverGlobalParams.featureCompatibility.isVersionInitialized() && - serverGlobalParams.featureCompatibility.getVersion() == - ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42) { - auto opCtx = makeOpCtx(); - auto updateStatus = _storage->upgradeNonReplicatedUniqueIndexes(opCtx.get()); - if (!updateStatus.isOK()) { - onCompletionGuard->setResultAndCancelRemainingWork_inlock(lock, updateStatus); - return; - } - } - // Success! onCompletionGuard->setResultAndCancelRemainingWork_inlock(lock, _lastApplied); } diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp index f3bd8cbc8d2..ff548abbe55 100644 --- a/src/mongo/db/repl/initial_syncer_test.cpp +++ b/src/mongo/db/repl/initial_syncer_test.cpp @@ -242,8 +242,6 @@ protected: bool droppedUserDBs = false; std::vector droppedCollections; int documentsInsertedCount = 0; - bool uniqueIndexUpdated = false; - bool upgradeNonReplicatedUniqueIndexesShouldFail = false; }; stdx::mutex _storageInterfaceWorkDoneMutex; // protects _storageInterfaceWorkDone. @@ -256,8 +254,6 @@ protected: const NamespaceString& nss) { LockGuard lock(_storageInterfaceWorkDoneMutex); _storageInterfaceWorkDone.createOplogCalled = true; - _storageInterfaceWorkDone.uniqueIndexUpdated = false; - _storageInterfaceWorkDone.upgradeNonReplicatedUniqueIndexesShouldFail = false; return Status::OK(); }; _storageInterface->truncateCollFn = [this](OperationContext* opCtx, @@ -312,19 +308,6 @@ protected: return std::move(localLoader); }; - _storageInterface->upgradeNonReplicatedUniqueIndexesFn = [this](OperationContext* opCtx) { - LockGuard lock(_storageInterfaceWorkDoneMutex); - if (_storageInterfaceWorkDone.upgradeNonReplicatedUniqueIndexesShouldFail) { - // One of the status codes a failed upgradeNonReplicatedUniqueIndexes call - // can return is NamespaceNotFound. - return Status(ErrorCodes::NamespaceNotFound, - "upgradeNonReplicatedUniqueIndexes failed because the desired " - "ns was not found."); - } else { - _storageInterfaceWorkDone.uniqueIndexUpdated = true; - return Status::OK(); - } - }; _dbWorkThreadPool = std::make_unique(ThreadPool::Options()); _dbWorkThreadPool->startup(); @@ -457,8 +440,8 @@ protected: void runInitialSyncWithBadFCVResponse(std::vector docs, ErrorCodes::Error expectedError); - void doSuccessfulInitialSyncWithOneBatch(bool shouldSetFCV); - OplogEntry doInitialSyncWithOneBatch(bool shouldSetFCV); + void doSuccessfulInitialSyncWithOneBatch(); + OplogEntry doInitialSyncWithOneBatch(); std::unique_ptr _executorProxy; @@ -3775,7 +3758,7 @@ TEST_F(InitialSyncerTest, InitialSyncerCancelsGetNextApplierBatchCallbackOnOplog ASSERT_EQUALS(ErrorCodes::OperationFailed, _lastApplied); } -OplogEntry InitialSyncerTest::doInitialSyncWithOneBatch(bool shouldSetFCV) { +OplogEntry InitialSyncerTest::doInitialSyncWithOneBatch() { auto initialSyncer = &getInitialSyncer(); auto opCtx = makeOpCtx(); @@ -3828,12 +3811,6 @@ OplogEntry InitialSyncerTest::doInitialSyncWithOneBatch(bool shouldSetFCV) { assertRemoteCommandNameEquals("getMore", request); net->blackHole(noi); - // Last rollback ID check. Before this check, set fCV to 4.2 if required by the test. - if (shouldSetFCV) { - serverGlobalParams.featureCompatibility.setVersion( - ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); - } - request = net->scheduleSuccessfulResponse(makeRollbackCheckerResponse(baseRollbackId)); assertRemoteCommandNameEquals("replSetGetRBID", request); net->runReadyNetworkOperations(); @@ -3849,8 +3826,8 @@ OplogEntry InitialSyncerTest::doInitialSyncWithOneBatch(bool shouldSetFCV) { return lastOp; } -void InitialSyncerTest::doSuccessfulInitialSyncWithOneBatch(bool shouldSetFCV) { - auto lastOp = doInitialSyncWithOneBatch(shouldSetFCV); +void InitialSyncerTest::doSuccessfulInitialSyncWithOneBatch() { + auto lastOp = doInitialSyncWithOneBatch(); serverGlobalParams.featureCompatibility.reset(); ASSERT_OK(_lastApplied.getStatus()); ASSERT_EQUALS(lastOp.getOpTime(), _lastApplied.getValue().opTime); @@ -3866,14 +3843,7 @@ TEST_F(InitialSyncerTest, // when reconstructPreparedTransactions uses DBDirectClient to call into ServiceEntryPoint. FailPointEnableBlock skipReconstructPreparedTransactions("skipReconstructPreparedTransactions"); - // Tell test to setFCV=4.2 before the last rollback ID check. - // _rollbackCheckerCheckForRollbackCallback() calls upgradeNonReplicatedUniqueIndexes - // only if fCV is 4.2. - doSuccessfulInitialSyncWithOneBatch(true); - - // Ensure that upgradeNonReplicatedUniqueIndexes is called. - LockGuard lock(_storageInterfaceWorkDoneMutex); - ASSERT_TRUE(_storageInterfaceWorkDone.uniqueIndexUpdated); + doSuccessfulInitialSyncWithOneBatch(); } TEST_F(InitialSyncerTest, @@ -4535,30 +4505,4 @@ TEST_F(InitialSyncerTest, GetInitialSyncProgressOmitsClonerStatsIfClonerStatsExc initialSyncer->join(); } -TEST_F(InitialSyncerTest, InitialSyncerDoesNotCallUpgradeNonReplicatedUniqueIndexesOnFCV40) { - // Skip reconstructing prepared transactions at the end of initial sync because - // InitialSyncerTest does not construct ServiceEntryPoint and this causes a segmentation fault - // when reconstructPreparedTransactions uses DBDirectClient to call into ServiceEntryPoint. - FailPointEnableBlock skipReconstructPreparedTransactions("skipReconstructPreparedTransactions"); - - // In MongoDB 4.2, upgradeNonReplicatedUniqueIndexes will only be called if fCV is 4.2. - doSuccessfulInitialSyncWithOneBatch(false); - - LockGuard lock(_storageInterfaceWorkDoneMutex); - ASSERT_FALSE(_storageInterfaceWorkDone.uniqueIndexUpdated); -} - -TEST_F(InitialSyncerTest, InitialSyncerUpgradeNonReplicatedUniqueIndexesError) { - // Ensure upgradeNonReplicatedUniqueIndexes returns a bad status. This should be passed to the - // initial syncer. - { - LockGuard lock(_storageInterfaceWorkDoneMutex); - _storageInterfaceWorkDone.upgradeNonReplicatedUniqueIndexesShouldFail = true; - } - doInitialSyncWithOneBatch(true); - - // Ensure the upgradeNonReplicatedUniqueIndexes status was captured. - ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, _lastApplied); -} - } // namespace diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 490a2a6acf0..68df63b3cff 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -954,10 +954,9 @@ const StringMap kOpsMap = { OplogApplication::Mode mode, boost::optional stableTimestampForRecovery) -> Status { NamespaceString nss; + BSONObjBuilder resultWeDontCareAbout; std::tie(std::ignore, nss) = parseCollModUUIDAndNss(opCtx, ui, ns, cmd); - // The collMod for apply ops could be either a user driven collMod or a collMod triggered - // by an upgrade. - return collModWithUpgrade(opCtx, nss, cmd); + return collMod(opCtx, nss, cmd, &resultWeDontCareAbout); }, {ErrorCodes::IndexNotFound, ErrorCodes::NamespaceNotFound}}}, {"dbCheck", {dbCheckOplogCommand, {}}}, diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp index 02b23bce8b4..c2744e2bb5a 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -414,29 +414,6 @@ Status ReplicationCoordinatorExternalStateImpl::initializeReplSetStorage(Operati _storageInterface->waitForAllEarlierOplogWritesToBeVisible(opCtx); }); - // Update unique index format version for all non-replicated collections. It is possible - // for MongoDB to have a "clean startup", i.e., no non-local databases, but still have - // unique indexes on collections in the local database. On clean startup, - // setFeatureCompatibilityVersion (which updates the unique index format version of - // collections) is not called, so any pre-existing collections are upgraded here. We exclude - // ShardServers when updating indexes belonging to non-replicated collections on the primary - // because ShardServers are started up by default with featureCompatibilityVersion 4.0, so - // we don't want to update those indexes until the cluster's featureCompatibilityVersion is - // explicitly set to 4.2 by config server. The below unique index update for non-replicated - // collections only occurs on the primary; updates for unique indexes belonging to - // non-replicated collections are done on secondaries during InitialSync. When the config - // server sets the featureCompatibilityVersion to 4.2, the shard primary will update unique - // indexes belonging to all the collections. One special case here is if a shard is already - // in featureCompatibilityVersion 4.2 and a new node is started up with --shardsvr and added - // to that shard, the new node will still start up with featureCompatibilityVersion 4.0 and - // may need to have unique index version updated. Such indexes would be updated during - // InitialSync because the new node is a secondary. - if (serverGlobalParams.clusterRole != ClusterRole::ShardServer && - FeatureCompatibilityVersion::isCleanStartUp()) { - auto updateStatus = updateNonReplicatedUniqueIndexes(opCtx); - if (!updateStatus.isOK()) - return updateStatus; - } FeatureCompatibilityVersion::setIfCleanStartup(opCtx, _storageInterface); } catch (const DBException& ex) { return ex.toStatus(); diff --git a/src/mongo/db/repl/storage_interface.h b/src/mongo/db/repl/storage_interface.h index e0c4ef9a29f..0dab0f4588f 100644 --- a/src/mongo/db/repl/storage_interface.h +++ b/src/mongo/db/repl/storage_interface.h @@ -341,12 +341,6 @@ public: virtual StatusWith getCollectionUUID(OperationContext* opCtx, const NamespaceString& nss) = 0; - /** - * Updates unique indexes belonging to all non-replicated collections. To be called at the - * end of initial sync. - */ - virtual Status upgradeNonReplicatedUniqueIndexes(OperationContext* opCtx) = 0; - /** * Sets the highest timestamp at which the storage engine is allowed to take a checkpoint. * This timestamp can never decrease, and thus should be a timestamp that can never roll back. diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp index 9e4b67fb2e3..f1e80568f7a 100644 --- a/src/mongo/db/repl/storage_interface_impl.cpp +++ b/src/mongo/db/repl/storage_interface_impl.cpp @@ -1070,10 +1070,6 @@ StatusWith StorageInterfaceImpl::getCollectionUUID( return collection->uuid(); } -Status StorageInterfaceImpl::upgradeNonReplicatedUniqueIndexes(OperationContext* opCtx) { - return updateNonReplicatedUniqueIndexes(opCtx); -} - void StorageInterfaceImpl::setStableTimestamp(ServiceContext* serviceCtx, Timestamp snapshotName) { serviceCtx->getStorageEngine()->setStableTimestamp(snapshotName); } diff --git a/src/mongo/db/repl/storage_interface_impl.h b/src/mongo/db/repl/storage_interface_impl.h index bce44c30cab..51ed102028f 100644 --- a/src/mongo/db/repl/storage_interface_impl.h +++ b/src/mongo/db/repl/storage_interface_impl.h @@ -156,8 +156,6 @@ public: StatusWith getCollectionUUID(OperationContext* opCtx, const NamespaceString& nss) override; - Status upgradeNonReplicatedUniqueIndexes(OperationContext* opCtx) override; - void setStableTimestamp(ServiceContext* serviceCtx, Timestamp snapshotName) override; void setInitialDataTimestamp(ServiceContext* serviceCtx, Timestamp snapshotName) override; diff --git a/src/mongo/db/repl/storage_interface_mock.h b/src/mongo/db/repl/storage_interface_mock.h index 2e259255ee8..71508cd41fe 100644 --- a/src/mongo/db/repl/storage_interface_mock.h +++ b/src/mongo/db/repl/storage_interface_mock.h @@ -126,7 +126,6 @@ public: using IsAdminDbValidFn = std::function; using GetCollectionUUIDFn = std::function( OperationContext*, const NamespaceString&)>; - using UpgradeNonReplicatedUniqueIndexesFn = std::function; StorageInterfaceMock() = default; @@ -285,9 +284,6 @@ public: return getCollectionUUIDFn(opCtx, nss); } - Status upgradeNonReplicatedUniqueIndexes(OperationContext* opCtx) override { - return upgradeNonReplicatedUniqueIndexesFn(opCtx); - } void setStableTimestamp(ServiceContext* serviceCtx, Timestamp snapshotName) override; void setInitialDataTimestamp(ServiceContext* serviceCtx, Timestamp snapshotName) override; @@ -403,11 +399,6 @@ public: OperationContext* opCtx, const NamespaceString& nss) -> StatusWith { return Status{ErrorCodes::IllegalOperation, "GetCollectionUUIDFn not implemented."}; }; - UpgradeNonReplicatedUniqueIndexesFn upgradeNonReplicatedUniqueIndexesFn = - [](OperationContext* opCtx) -> Status { - return Status{ErrorCodes::IllegalOperation, - "upgradeNonReplicatedUniqueIndexesFn not implemented."}; - }; bool supportsDocLockingBool = false; Timestamp allCommittedTimestamp = Timestamp::min(); diff --git a/src/mongo/db/storage/durable_catalog.h b/src/mongo/db/storage/durable_catalog.h index a38adb1501d..7212e139206 100644 --- a/src/mongo/db/storage/durable_catalog.h +++ b/src/mongo/db/storage/durable_catalog.h @@ -159,10 +159,6 @@ public: StringData validationLevel, StringData validationAction) = 0; - virtual void updateIndexMetadata(OperationContext* opCtx, - NamespaceString ns, - const IndexDescriptor* desc) = 0; - virtual Status removeIndex(OperationContext* opCtx, NamespaceString ns, StringData indexName) = 0; @@ -281,9 +277,6 @@ public: virtual void getReadyIndexes(OperationContext* opCtx, NamespaceString ns, std::vector* names) const = 0; - virtual void getAllUniqueIndexes(OperationContext* opCtx, - NamespaceString ns, - std::vector* names) const = 0; virtual bool isIndexPresent(OperationContext* opCtx, NamespaceString ns, diff --git a/src/mongo/db/storage/durable_catalog_impl.cpp b/src/mongo/db/storage/durable_catalog_impl.cpp index a9849baab70..208566a2385 100644 --- a/src/mongo/db/storage/durable_catalog_impl.cpp +++ b/src/mongo/db/storage/durable_catalog_impl.cpp @@ -942,15 +942,6 @@ void DurableCatalogImpl::updateValidator(OperationContext* opCtx, putMetaData(opCtx, ns, md); } -void DurableCatalogImpl::updateIndexMetadata(OperationContext* opCtx, - NamespaceString ns, - const IndexDescriptor* desc) { - // Update any metadata Ident has for this index - const string ident = getIndexIdent(opCtx, ns, desc->indexName()); - auto kvEngine = _engine->getEngine(); - kvEngine->alterIdentMetadata(opCtx, ident, desc); -} - Status DurableCatalogImpl::removeIndex(OperationContext* opCtx, NamespaceString ns, StringData indexName) { @@ -1244,19 +1235,6 @@ void DurableCatalogImpl::getReadyIndexes(OperationContext* opCtx, } } -void DurableCatalogImpl::getAllUniqueIndexes(OperationContext* opCtx, - NamespaceString ns, - std::vector* names) const { - BSONCollectionCatalogEntry::MetaData md = getMetaData(opCtx, ns); - - for (unsigned i = 0; i < md.indexes.size(); i++) { - if (md.indexes[i].spec["unique"]) { - std::string indexName = md.indexes[i].spec["name"].String(); - names->push_back(indexName); - } - } -} - bool DurableCatalogImpl::isIndexPresent(OperationContext* opCtx, NamespaceString ns, StringData indexName) const { diff --git a/src/mongo/db/storage/durable_catalog_impl.h b/src/mongo/db/storage/durable_catalog_impl.h index 8d2b8bf45b6..b7683e9da68 100644 --- a/src/mongo/db/storage/durable_catalog_impl.h +++ b/src/mongo/db/storage/durable_catalog_impl.h @@ -138,10 +138,6 @@ public: StringData validationLevel, StringData validationAction); - void updateIndexMetadata(OperationContext* opCtx, - NamespaceString ns, - const IndexDescriptor* desc); - Status removeIndex(OperationContext* opCtx, NamespaceString ns, StringData indexName); Status prepareForIndexBuild(OperationContext* opCtx, @@ -206,9 +202,6 @@ public: void getReadyIndexes(OperationContext* opCtx, NamespaceString ns, std::vector* names) const; - void getAllUniqueIndexes(OperationContext* opCtx, - NamespaceString ns, - std::vector* names) const; bool isIndexPresent(OperationContext* opCtx, NamespaceString ns, StringData indexName) const; diff --git a/src/mongo/db/storage/kv/kv_engine.h b/src/mongo/db/storage/kv/kv_engine.h index 97b95e728c6..3344908b525 100644 --- a/src/mongo/db/storage/kv/kv_engine.h +++ b/src/mongo/db/storage/kv/kv_engine.h @@ -195,11 +195,6 @@ public: return status; } - - virtual void alterIdentMetadata(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc){}; - // optional virtual int flushAllFiles(OperationContext* opCtx, bool sync) { return 0; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp index eb3cbec3d0d..fcc6b76838c 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp @@ -158,10 +158,7 @@ std::string WiredTigerIndex::generateAppMetadataString(const IndexDescriptor& de int keyStringVersion; - // The FCV controls the creation between timestamp safe and timestamp unsafe unique indexes. - if (serverGlobalParams.featureCompatibility.isVersionInitialized() && - serverGlobalParams.featureCompatibility.isVersionUpgradingOrUpgraded() && desc.unique() && - !desc.isIdIndex()) { + if (desc.unique() && !desc.isIdIndex()) { keyStringVersion = desc.version() >= IndexDescriptor::IndexVersion::kV2 ? kDataFormatV4KeyStringV1UniqueIndexVersionV2 : kDataFormatV3KeyStringV0UniqueIndexVersionV1; @@ -276,13 +273,27 @@ WiredTigerIndex::WiredTigerIndex(OperationContext* ctx, str::stream() << versionStatus.reason() << " Index: {name: " << desc->indexName() << ", ns: " << desc->parentNS() - << "} - version too new for this mongod." - << " See http://dochub.mongodb.org/core/4.2-downgrade-index for detailed" - << " instructions on how to handle this error."); + << "} - version either too old or too new for this mongod."); fassertFailedWithStatusNoTrace(28579, indexVersionStatus); } _dataFormatVersion = version.getValue(); + if (!_isIdIndex && desc->unique()) { + Status versionStatus = _dataFormatVersion == kDataFormatV3KeyStringV0UniqueIndexVersionV1 || + _dataFormatVersion == kDataFormatV4KeyStringV1UniqueIndexVersionV2 + ? Status::OK() + : Status(ErrorCodes::UnsupportedFormat, + str::stream() << "Index: {name: " << desc->indexName() << ", ns: " + << desc->parentNS() + << "} has incompatible format version: " + << _dataFormatVersion + << ". MongoDB 4.2 onwards, WT secondary unique indexes use " + "either format version 11 or 12. See " + "https://dochub.mongodb.org/core/upgrade-4.2-procedures for " + "detailed instructions on upgrading the index format."); + fassertNoTrace(31179, versionStatus); + } + // Index data format 6 and 11 correspond to KeyString version V0 and data format 8 and 12 // correspond to KeyString version V1 _keyStringVersion = (_dataFormatVersion == kDataFormatV2KeyStringV1IndexVersionV2 || diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index 6002d277602..72aa1d4dfcf 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -1335,20 +1335,6 @@ std::unique_ptr WiredTigerKVEngine::makeTemporaryRecordStore(Operat return std::move(rs); } -void WiredTigerKVEngine::alterIdentMetadata(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc) { - WiredTigerSession session(_conn); - std::string uri = _uri(ident); - - // Make the alter call to update metadata without taking exclusive lock to avoid conflicts with - // concurrent operations. - std::string alterString = - WiredTigerIndex::generateAppMetadataString(*desc) + "exclusive_refreshed=false,"; - invariantWTOK( - session.getSession()->alter(session.getSession(), uri.c_str(), alterString.c_str())); -} - Status WiredTigerKVEngine::dropIdent(OperationContext* opCtx, StringData ident) { string uri = _uri(ident); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h index 4589602da4d..ba86106efec 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h @@ -155,10 +155,6 @@ public: Status dropIdent(OperationContext* opCtx, StringData ident) override; - void alterIdentMetadata(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc) override; - Status okToRename(OperationContext* opCtx, StringData fromNS, StringData toNS, -- cgit v1.2.1