summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2021-10-25 18:24:22 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-25 19:20:49 +0000
commit2b7d0c0b5dd84ecd0a3f49f273a5a789ac4b44c4 (patch)
tree04e5bee9174598067efa42b0e92ec019114eb9e9 /src
parent239dc4c61779808daf867a7d19add05f9b3fa97a (diff)
downloadmongo-2b7d0c0b5dd84ecd0a3f49f273a5a789ac4b44c4.tar.gz
SERVER-60576 On downgrade, remove the catalog flag that indicates whether a time-series bucket has mixed-schema data
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/coll_mod.cpp13
-rw-r--r--src/mongo/db/catalog/collection.h2
-rw-r--r--src/mongo/db/catalog/collection_impl.cpp12
-rw-r--r--src/mongo/db/commands/set_feature_compatibility_version_command.cpp60
4 files changed, 62 insertions, 25 deletions
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp
index dc02c016862..8ae88794bb7 100644
--- a/src/mongo/db/catalog/coll_mod.cpp
+++ b/src/mongo/db/catalog/coll_mod.cpp
@@ -639,8 +639,9 @@ Status _collModInternal(OperationContext* opCtx,
opCtx, coll.getWritableCollection(), desc);
}
- // TODO SERVER-60911: When kLatest is 5.3, only check when upgrading from kLastLTS (5.0).
- // TODO SERVER-60912: When kLastLTS is 6.0, remove this FCV-gated upgrade code.
+ // TODO SERVER-60911: When kLatest is 5.3, only check when upgrading from or downgrading to
+ // kLastLTS (5.0).
+ // TODO SERVER-60912: When kLastLTS is 6.0, remove this FCV-gated upgrade/downgrade code.
if (coll->getTimeseriesOptions() && !coll->getTimeseriesBucketsMayHaveMixedSchemaData() &&
serverGlobalParams.featureCompatibility.isFCVUpgradingToOrAlreadyLatest()) {
// While upgrading the FCV to 5.2+, collMod is called as part of the upgrade process to
@@ -649,6 +650,14 @@ Status _collModInternal(OperationContext* opCtx,
// time-series collection existed in earlier server versions and may have mixed-schema
// data.
coll.getWritableCollection()->setTimeseriesBucketsMayHaveMixedSchemaData(opCtx, true);
+ } else if (coll->getTimeseriesBucketsMayHaveMixedSchemaData() &&
+ serverGlobalParams.featureCompatibility
+ .isFCVDowngradingOrAlreadyDowngradedFromLatest()) {
+ // While downgrading the FCV from 5.2, collMod is called as part of the downgrade
+ // process to remove the 'timeseriesBucketsMayHaveMixedSchemaData' catalog entry
+ // flag for time-series collections that have the flag.
+ coll.getWritableCollection()->setTimeseriesBucketsMayHaveMixedSchemaData(opCtx,
+ boost::none);
}
// Only observe non-view collMods, as view operations are observed as operations on the
diff --git a/src/mongo/db/catalog/collection.h b/src/mongo/db/catalog/collection.h
index 051a1c46164..0ba948c2afe 100644
--- a/src/mongo/db/catalog/collection.h
+++ b/src/mongo/db/catalog/collection.h
@@ -536,7 +536,7 @@ public:
* Sets the 'timeseriesBucketsMayHaveMixedSchemaData' catalog entry flag to 'setting' for this
* collection.
*
- * Throws if FCV < 5.2 or if this is not a time-series collection.
+ * Throws if this is not a time-series collection.
*/
virtual void setTimeseriesBucketsMayHaveMixedSchemaData(OperationContext* opCtx,
boost::optional<bool> setting) = 0;
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp
index 3c001c5af53..33426a8804b 100644
--- a/src/mongo/db/catalog/collection_impl.cpp
+++ b/src/mongo/db/catalog/collection_impl.cpp
@@ -1352,12 +1352,12 @@ void CollectionImpl::setTimeseriesBucketsMayHaveMixedSchemaData(OperationContext
boost::optional<bool> setting) {
uassert(6057500, "This is not a time-series collection", _metadata->options.timeseries);
- // TODO SERVER-60911: When kLatest is 5.3, only check when upgrading from kLastLTS (5.0).
- // TODO SERVER-60912: When kLastLTS is 6.0, remove this FCV-gated upgrade code.
- uassert(
- 6057501,
- "Cannot set the 'timeseriesBucketsMayHaveMixedSchemaData' catalog entry flag if FCV < 5.2",
- serverGlobalParams.featureCompatibility.isFCVUpgradingToOrAlreadyLatest());
+ LOGV2_DEBUG(6057601,
+ 1,
+ "Setting 'timeseriesBucketsMayHaveMixedSchemaData' catalog entry flag",
+ logAttrs(ns()),
+ logAttrs(uuid()),
+ "setting"_attr = setting);
_writeMetadata(opCtx, [&](BSONCollectionCatalogEntry::MetaData& md) {
md.timeseriesBucketsMayHaveMixedSchemaData = setting;
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 061faf02f6f..77d9800f8d0 100644
--- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
+++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
@@ -489,16 +489,26 @@ private:
_cancelTenantMigrations(opCtx);
- // 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.
- if (requestedVersion < multiversion::FeatureCompatibilityVersion::kVersion_5_2) {
+ {
+ // Take the global lock in S mode to create a barrier for operations taking the global
+ // IX or X locks. This ensures that either
+ // - The global IX/X locked operation will start after the FCV change, see the
+ // downgrading to the last-lts or last-continuous FCV and act accordingly.
+ // - The global IX/X locked operation began prior to the FCV change, is acting on that
+ // assumption and will finish before downgrade procedures begin right after this.
+ Lock::GlobalLock lk(opCtx, MODE_S);
+ }
+
+ // TODO SERVER-60911: When kLatest is 5.3, only check when downgrading to kLastLTS (5.0).
+ // TODO SERVER-60912: When kLastLTS is 6.0, remove this FCV-gated downgrade code.
+ if (serverGlobalParams.featureCompatibility
+ .isFCVDowngradingOrAlreadyDowngradedFromLatest()) {
for (const auto& dbName : DatabaseHolder::get(opCtx)->getNames()) {
- Lock::DBLock dbLock(opCtx, dbName, MODE_IS);
+ Lock::DBLock dbLock(opCtx, dbName, MODE_IX);
catalog::forEachCollectionFromDb(
opCtx,
dbName,
- MODE_IS,
+ MODE_X,
[&](const CollectionPtr& collection) {
invariant(collection->getTimeseriesOptions());
@@ -508,6 +518,10 @@ private:
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 "
@@ -540,6 +554,30 @@ private:
}
}
+ 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
+ // downgrade process cannot be aborted at this point.
+ return true;
+ }
+
+ BSONObjBuilder unusedBuilder;
+ Status status = collMod(opCtx,
+ collection->ns(),
+ BSON("collMod" << collection->ns().coll()),
+ &unusedBuilder);
+
+ if (!status.isOK()) {
+ LOGV2_FATAL(
+ 6057600,
+ "Failed to remove catalog entry during downgrade",
+ "error"_attr = status,
+ "timeseriesBucketsMayHaveMixedSchemaData"_attr =
+ collection->getTimeseriesBucketsMayHaveMixedSchemaData(),
+ logAttrs(collection->ns()),
+ logAttrs(collection->uuid()));
+ }
+
return true;
},
[&](const CollectionPtr& collection) {
@@ -548,16 +586,6 @@ private:
}
}
- {
- // Take the global lock in S mode to create a barrier for operations taking the global
- // IX or X locks. This ensures that either
- // - The global IX/X locked operation will start after the FCV change, see the
- // downgrading to the last-lts or last-continuous FCV and act accordingly.
- // - The global IX/X locked operation began prior to the FCV change, is acting on that
- // assumption and will finish before downgrade procedures begin right after this.
- Lock::GlobalLock lk(opCtx, MODE_S);
- }
-
uassert(ErrorCodes::Error(549181),
"Failing upgrade due to 'failDowngrading' failpoint set",
!failDowngrading.shouldFail());