diff options
author | Damian Wasilewicz <damian.wasilewicz@mongodb.com> | 2022-06-16 21:24:25 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-06-16 22:40:14 +0000 |
commit | b5917554358bc6abf85fac8fd11ba16dfdf1722a (patch) | |
tree | 9ee6373decb37e78712e5054a8a832f57f77e82e /src/mongo | |
parent | 11feb08b20e51a5c2be42132f1f3be64b0298b1e (diff) | |
download | mongo-b5917554358bc6abf85fac8fd11ba16dfdf1722a.tar.gz |
SERVER-65634 Added "clustered" to field name strings in index descriptor
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/catalog/index_catalog_impl.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_key_validate.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/commands/create_indexes.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/index/index_descriptor.h | 1 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/s/migration_destination_manager.cpp | 2 |
6 files changed, 14 insertions, 11 deletions
diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index 74049b34427..a7b8643561b 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -118,8 +118,8 @@ Status isSpecOKClusteredIndexCheck(const BSONObj& indexSpec, auto key = indexSpec.getObjectField("key"); bool keysMatch = clustered_util::matchesClusterKey(key, collInfo); - bool clusteredOptionPresent = - indexSpec.hasField("clustered") && indexSpec["clustered"].trueValue(); + bool clusteredOptionPresent = indexSpec.hasField(IndexDescriptor::kClusteredFieldName) && + indexSpec[IndexDescriptor::kClusteredFieldName].trueValue(); if (clusteredOptionPresent && !keysMatch) { // The 'clustered' option implies the indexSpec must match the clustered index. diff --git a/src/mongo/db/catalog/index_key_validate.cpp b/src/mongo/db/catalog/index_key_validate.cpp index 1abc7b14e03..1107d7a7fa8 100644 --- a/src/mongo/db/catalog/index_key_validate.cpp +++ b/src/mongo/db/catalog/index_key_validate.cpp @@ -85,7 +85,7 @@ static const std::set<StringData> allowedClusteredIndexFieldNames = { ClusteredIndexSpec::kVFieldName, ClusteredIndexSpec::kKeyFieldName, // This is for indexSpec creation only. - "clustered", + IndexDescriptor::kClusteredFieldName, }; /** @@ -268,7 +268,8 @@ BSONObj repairIndexSpec(const NamespaceString& ns, IndexDescriptor::kUniqueFieldName == fieldName || IndexDescriptor::kSparseFieldName == fieldName || IndexDescriptor::kDropDuplicatesFieldName == fieldName || - IndexDescriptor::kPrepareUniqueFieldName == fieldName || "clustered" == fieldName) && + IndexDescriptor::kPrepareUniqueFieldName == fieldName || + IndexDescriptor::kClusteredFieldName == fieldName) && !indexSpecElem.isNumber() && !indexSpecElem.isBoolean() && indexSpecElem.trueValue()) { LOGV2_WARNING(6444400, "Fixing boolean field from index spec", @@ -293,7 +294,7 @@ StatusWith<BSONObj> validateIndexSpec(OperationContext* opCtx, const BSONObj& in bool hasOriginalSpecField = false; bool unique = false; bool prepareUnique = false; - auto clusteredField = indexSpec["clustered"]; + auto clusteredField = indexSpec[IndexDescriptor::kClusteredFieldName]; bool apiStrict = opCtx && APIParameters::get(opCtx).getAPIStrict().value_or(false); auto fieldNamesValidStatus = validateIndexSpecFieldNames(indexSpec); @@ -504,7 +505,7 @@ StatusWith<BSONObj> validateIndexSpec(OperationContext* opCtx, const BSONObj& in IndexDescriptor::k2dsphereFinestIndexedLevel == indexSpecElemFieldName || IndexDescriptor::kDropDuplicatesFieldName == indexSpecElemFieldName || IndexDescriptor::kPrepareUniqueFieldName == indexSpecElemFieldName || - "clustered" == indexSpecElemFieldName)) { + IndexDescriptor::kClusteredFieldName == indexSpecElemFieldName)) { if (!indexSpecElem.isNumber() && !indexSpecElem.isBoolean()) { return {ErrorCodes::TypeMismatch, str::stream() @@ -629,7 +630,7 @@ StatusWith<BSONObj> validateIndexSpec(OperationContext* opCtx, const BSONObj& in } Status validateIdIndexSpec(const BSONObj& indexSpec) { - bool isClusteredIndexSpec = indexSpec.hasField("clustered"); + bool isClusteredIndexSpec = indexSpec.hasField(IndexDescriptor::kClusteredFieldName); if (!isClusteredIndexSpec) { // Field names for a 'clustered' index spec have already been validated through @@ -691,7 +692,7 @@ Status validateIndexSpecFieldNames(const BSONObj& indexSpec) { return Status::OK(); } - if (indexSpec.hasField("clustered")) { + if (indexSpec.hasField(IndexDescriptor::kClusteredFieldName)) { return validateClusteredSpecFieldNames(indexSpec); } diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 94027121c10..9b848683cd3 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -375,7 +375,7 @@ CreateIndexesReply runCreateIndexesOnNewCollection( for (const auto& spec : specs) { uassert(6100900, "Cannot implicitly create a new collection with createIndex 'clustered' option", - !spec["clustered"]); + !spec[IndexDescriptor::kClusteredFieldName]); } // We need to create the collection. diff --git a/src/mongo/db/index/index_descriptor.h b/src/mongo/db/index/index_descriptor.h index f4f48cb35b9..115fc8b1d17 100644 --- a/src/mongo/db/index/index_descriptor.h +++ b/src/mongo/db/index/index_descriptor.h @@ -89,6 +89,7 @@ public: static constexpr StringData kWeightsFieldName = "weights"_sd; static constexpr StringData kOriginalSpecFieldName = "originalSpec"_sd; static constexpr StringData kPrepareUniqueFieldName = "prepareUnique"_sd; + static constexpr StringData kClusteredFieldName = "clustered"_sd; /** * infoObj is a copy of the index-describing BSONObj contained in the catalog. diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index 180e6f2d8bc..196019d0d92 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -1812,7 +1812,8 @@ void IndexBuildsCoordinator::createIndexesOnEmptyCollection(OperationContext* op // Always run single phase index build for empty collection. And, will be coordinated using // createIndexes oplog entry. for (const auto& spec : specs) { - if (spec.hasField("clustered") && spec.getBoolField("clustered")) { + if (spec.hasField(IndexDescriptor::kClusteredFieldName) && + spec.getBoolField(IndexDescriptor::kClusteredFieldName)) { // The index is already built implicitly. continue; } diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp index 09a39686779..c532b48ed2a 100644 --- a/src/mongo/db/s/migration_destination_manager.cpp +++ b/src/mongo/db/s/migration_destination_manager.cpp @@ -819,7 +819,7 @@ MigrationDestinationManager::IndexesAndIdIndex MigrationDestinationManager::getC Milliseconds(-1))); for (auto&& spec : indexes.docs) { - if (spec["clustered"]) { + if (spec[IndexDescriptor::kClusteredFieldName]) { // The 'clustered' index is implicitly created upon clustered collection creation. } else { donorIndexSpecs.push_back(spec); |