diff options
author | Leonardo Menti <leonardo.menti@mongodb.com> | 2022-09-08 14:59:24 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-08 18:19:18 +0000 |
commit | 22608cb9c7b2ce3771855dcb7d7fd6f564df4821 (patch) | |
tree | 3cad18f9c127fad3c6eca702d355dd9bb3eb1d2b /src/mongo/db | |
parent | 17dc0a48233b4c7c6e95b43236f0fc8dba2d3b4e (diff) | |
download | mongo-22608cb9c7b2ce3771855dcb7d7fd6f564df4821.tar.gz |
SERVER-67246 Remove size multiple restriction on capped collections
Diffstat (limited to 'src/mongo/db')
4 files changed, 55 insertions, 2 deletions
diff --git a/src/mongo/db/catalog/collection_options.cpp b/src/mongo/db/catalog/collection_options.cpp index fe685c330ed..800e08172cb 100644 --- a/src/mongo/db/catalog/collection_options.cpp +++ b/src/mongo/db/catalog/collection_options.cpp @@ -48,8 +48,12 @@ namespace mongo { namespace { long long adjustCappedSize(long long cappedSize) { - cappedSize += 0xff; - cappedSize &= 0xffffffffffffff00LL; + if (serverGlobalParams.featureCompatibility.isVersionInitialized() && + !feature_flags::gfeatureFlagCappedCollectionsRelaxedSize.isEnabled( + serverGlobalParams.featureCompatibility)) { + cappedSize += 0xff; + cappedSize &= 0xffffffffffffff00LL; + } return cappedSize; } diff --git a/src/mongo/db/catalog/collection_options.idl b/src/mongo/db/catalog/collection_options.idl index 762e664f57d..d8e5e1b30eb 100644 --- a/src/mongo/db/catalog/collection_options.idl +++ b/src/mongo/db/catalog/collection_options.idl @@ -34,6 +34,13 @@ global: imports: - "mongo/db/basic_types.idl" +feature_flags: + featureFlagCappedCollectionsRelaxedSize: + description: Enables capped collections to have a size non multiple of 256 bytes. + cpp_varname: feature_flags::gfeatureFlagCappedCollectionsRelaxedSize + default: true + version: 6.2 + enums: ValidationLevel: description: "Determines how strictly MongoDB applies the validation rules to existing documents during an update." diff --git a/src/mongo/db/catalog/collection_options_test.cpp b/src/mongo/db/catalog/collection_options_test.cpp index da1b1b2874d..f5df8643cf8 100644 --- a/src/mongo/db/catalog/collection_options_test.cpp +++ b/src/mongo/db/catalog/collection_options_test.cpp @@ -99,9 +99,27 @@ TEST(CollectionOptions, ErrorBadMax) { CollectionOptions::parse(BSON("capped" << true << "max" << (1LL << 31))).getStatus()); } +TEST(CollectionOptions, CappedSizeNotRoundUpForAlignment) { + serverGlobalParams.mutableFeatureCompatibility.setVersion( + multiversion::FeatureCompatibilityVersion::kVersion_6_2); + const long long kUnalignedCappedSize = 1000; + const long long kAlignedCappedSize = 1000; + + // Check size rounds up to multiple of alignment. + auto options = assertGet( + CollectionOptions::parse((BSON("capped" << true << "size" << kUnalignedCappedSize)))); + + ASSERT_EQUALS(options.capped, true); + ASSERT_EQUALS(options.cappedSize, kAlignedCappedSize); + ASSERT_EQUALS(options.cappedMaxDocs, 0); +} + TEST(CollectionOptions, CappedSizeRoundsUpForAlignment) { + serverGlobalParams.mutableFeatureCompatibility.setVersion( + multiversion::FeatureCompatibilityVersion::kVersion_6_0); const long long kUnalignedCappedSize = 1000; const long long kAlignedCappedSize = 1024; + // Check size rounds up to multiple of alignment. auto options = assertGet( CollectionOptions::parse((BSON("capped" << true << "size" << kUnalignedCappedSize)))); 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 4a5add8b4b2..24839c2ca59 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -674,6 +674,30 @@ private: }); } } + + if (!feature_flags::gfeatureFlagCappedCollectionsRelaxedSize.isEnabled( + serverGlobalParams.featureCompatibility)) { + for (const auto& dbName : DatabaseHolder::get(opCtx)->getNames()) { + Lock::DBLock dbLock(opCtx, dbName, MODE_IX); + catalog::forEachCollectionFromDb( + opCtx, + dbName, + MODE_S, + [&](const CollectionPtr& collection) { + uasserted( + ErrorCodes::CannotDowngrade, + str::stream() + << "Cannot downgrade the cluster when there are capped " + "collection with a size that is non multiple of 256 bytes. " + "Drop or resize the following collection: '" + << collection->ns() << "'"); + return true; + }, + [&](const CollectionPtr& collection) { + return collection->isCapped() && collection->getCappedMaxSize() % 256 != 0; + }); + } + } } // This helper function is for any internal server downgrade cleanup, such as dropping |