diff options
Diffstat (limited to 'src/mongo/db/commands/set_feature_compatibility_version_command.cpp')
| -rw-r--r-- | src/mongo/db/commands/set_feature_compatibility_version_command.cpp | 82 |
1 files changed, 48 insertions, 34 deletions
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 73933d1abe2..2c74781c36e 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -84,6 +84,7 @@ #include "mongo/db/session_catalog.h" #include "mongo/db/session_catalog_mongod.h" #include "mongo/db/session_txn_record_gen.h" +#include "mongo/db/storage/storage_parameters_gen.h" #include "mongo/db/timeseries/timeseries_index_schema_conversion_functions.h" #include "mongo/db/vector_clock.h" #include "mongo/idl/cluster_server_parameter_gen.h" @@ -465,7 +466,7 @@ public: if (actualVersion > requestedVersion && !feature_flags::gOrphanTracking.isEnabledOnVersion(requestedVersion)) { BalancerStatsRegistry::get(opCtx)->terminate(); - ScopedRangeDeleterLock rangeDeleterLock(opCtx); + ScopedRangeDeleterLock rangeDeleterLock(opCtx, LockMode::MODE_X); clearOrphanCountersFromRangeDeletionTasks(opCtx); } @@ -750,37 +751,19 @@ private: const auto& dbName = tenantDbName.dbName(); Lock::DBLock dbLock(opCtx, dbName, MODE_IX); catalog::forEachCollectionFromDb( - opCtx, - tenantDbName, - MODE_X, - [&](const CollectionPtr& collection) { - invariant(collection->getTimeseriesOptions()); - + opCtx, tenantDbName, MODE_X, [&](const CollectionPtr& collection) { + const auto collNs = collection->getTimeseriesOptions() + ? collection->ns().getTimeseriesViewNamespace() + : collection->ns(); auto indexCatalog = collection->getIndexCatalog(); - auto indexIt = indexCatalog->getIndexIterator( - opCtx, /*includeUnfinishedIndexes=*/true); + auto indexIt = indexCatalog->getIndexIterator( + opCtx, + IndexCatalog::InclusionPolicy::kReady | + IndexCatalog::InclusionPolicy::kUnfinished | + IndexCatalog::InclusionPolicy::kFrozen); while (indexIt->more()) { auto indexEntry = indexIt->next(); - // Secondary indexes on time-series measurements are only supported - // in 5.2 and up. If the user tries to downgrade the cluster to an - // earlier version, they must first remove all incompatible secondary - // indexes on time-series measurements. - uassert( - ErrorCodes::CannotDowngrade, - str::stream() - << "Cannot downgrade the cluster when there are secondary " - "indexes on time-series measurements present, or when there " - "are partial indexes on a time-series collection. Drop all " - "secondary indexes on time-series measurements, and all " - "partial indexes on time-series collections, before " - "downgrading. First detected incompatible index name: '" - << indexEntry->descriptor()->indexName() << "' on collection: '" - << collection->ns().getTimeseriesViewNamespace() << "'", - timeseries::isBucketsIndexSpecCompatibleForDowngrade( - *collection->getTimeseriesOptions(), - indexEntry->descriptor()->infoObj())); - if (auto filter = indexEntry->getFilterExpression()) { auto status = IndexCatalogImpl::checkValidFilterExpressions( filter, @@ -794,12 +777,43 @@ private: "partial filter elements before downgrading. First " "detected incompatible index name: '" << indexEntry->descriptor()->indexName() - << "' on collection: '" - << collection->ns().getTimeseriesViewNamespace() << "'", + << "' on collection: '" << collNs << "'", status.isOK()); } } + if (!collection->getTimeseriesOptions()) { + return true; + } + + indexIt = indexCatalog->getIndexIterator( + opCtx, + IndexCatalog::InclusionPolicy::kReady | + IndexCatalog::InclusionPolicy::kUnfinished | + IndexCatalog::InclusionPolicy::kFrozen); + while (indexIt->more()) { + auto indexEntry = indexIt->next(); + // Secondary indexes on time-series measurements are only supported + // in 5.2 and up. If the user tries to downgrade the cluster to an + // earlier version, they must first remove all incompatible secondary + // indexes on time-series measurements. + uassert( + ErrorCodes::CannotDowngrade, + str::stream() + << "Cannot downgrade the cluster when there are secondary " + "indexes on time-series measurements present, or when " + "there are partial indexes on a time-series collection. " + "Drop " + "all secondary indexes on time-series measurements, and all " + "partial indexes on time-series collections, before " + "downgrading. First detected incompatible index name: '" + << indexEntry->descriptor()->indexName() << "' on collection: '" + << collNs << "'", + timeseries::isBucketsIndexSpecCompatibleForDowngrade( + *collection->getTimeseriesOptions(), + indexEntry->descriptor()->infoObj())); + } + if (!collection->getTimeseriesBucketsMayHaveMixedSchemaData()) { // The catalog entry flag has already been removed. This can happen if // the downgrade process was interrupted and is being run again. The @@ -824,9 +838,6 @@ private: } return true; - }, - [&](const CollectionPtr& collection) { - return collection->getTimeseriesOptions() != boost::none; }); } } @@ -868,7 +879,10 @@ private: opCtx, tenantDbName, MODE_X, [&](const CollectionPtr& collection) { auto indexCatalog = collection->getIndexCatalog(); auto indexIt = indexCatalog->getIndexIterator( - opCtx, true /* includeUnfinishedIndexes */); + opCtx, + IndexCatalog::InclusionPolicy::kReady | + IndexCatalog::InclusionPolicy::kUnfinished | + IndexCatalog::InclusionPolicy::kFrozen); while (indexIt->more()) { auto indexEntry = indexIt->next(); uassert( |
