From 5bd87925a006fa591692e097d7929b6764da6d0c Mon Sep 17 00:00:00 2001 From: Kaloian Manassiev Date: Fri, 30 Oct 2020 04:49:28 -0400 Subject: SERVER-50027 Make CollectionType use IDL (Part 3) --- .../set_feature_compatibility_version_command.cpp | 1 - ...rding_catalog_manager_collection_operations.cpp | 2 - .../resharding/resharding_coordinator_service.cpp | 2 - .../s/resharding/resharding_coordinator_test.cpp | 3 +- src/mongo/db/s/resharding_util.h | 2 +- src/mongo/db/s/shardsvr_shard_collection.cpp | 4 +- src/mongo/db/s/type_shard_collection.idl | 5 +- src/mongo/db/s/type_shard_collection_test.cpp | 1 - .../s/catalog/sharding_catalog_client_impl.cpp | 2 - .../s/catalog/sharding_catalog_client_test.cpp | 3 - src/mongo/s/catalog/type_collection.cpp | 86 +-------- src/mongo/s/catalog/type_collection.h | 61 ++---- src/mongo/s/catalog/type_collection.idl | 25 +++ src/mongo/s/catalog/type_collection_test.cpp | 210 ++++++++++----------- src/mongo/s/catalog_cache_test_fixture.h | 1 - src/mongo/s/query/cluster_aggregation_planner.h | 2 +- 16 files changed, 150 insertions(+), 260 deletions(-) (limited to 'src/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 4622a495ae2..54efaed48d1 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -56,7 +56,6 @@ #include "mongo/db/server_options.h" #include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" -#include "mongo/s/catalog/type_collection.h" #include "mongo/s/database_version_helpers.h" #include "mongo/stdx/unordered_set.h" #include "mongo/util/exit.h" diff --git a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp index 31fdcf25466..50470cf2a80 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp @@ -749,8 +749,6 @@ void ShardingCatalogManager::updateShardingCatalogEntryForCollectionInTxn( const bool upsert, const bool startTransaction, TxnNumber txnNumber) { - fassert(51249, coll.validate()); - auto status = getStatusFromCommandResult( writeToConfigDocumentInTxn(opCtx, CollectionType::ConfigNS, diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp index 0988bce67c8..08f23a349e2 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp @@ -402,8 +402,6 @@ CollectionType createTempReshardingCollectionType( emplaceFetchTimestampIfExists(recipient, coordinatorDoc.getFetchTimestamp()); tempEntryReshardingFields.setRecipientFields(recipient); collType.setReshardingFields(std::move(tempEntryReshardingFields)); - - invariant(collType.validate().isOK()); return collType; } diff --git a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp index 691a832603f..4ee4d193ff1 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp @@ -47,6 +47,7 @@ #include "mongo/util/clock_source_mock.h" namespace mongo { +namespace { class ReshardingCoordinatorPersistenceTest : public ConfigServerTestFixture { protected: @@ -109,7 +110,6 @@ protected: } collType.setEpoch(std::move(epoch)); collType.setUpdatedAt(lastUpdated); - collType.setDefaultCollation(BSONObj()); collType.setUnique(false); collType.setDistributionMode(CollectionType::DistributionMode::kSharded); if (reshardingFields) @@ -665,4 +665,5 @@ TEST_F(ReshardingCoordinatorPersistenceTest, ErrorCodes::NamespaceNotFound); } +} // namespace } // namespace mongo diff --git a/src/mongo/db/s/resharding_util.h b/src/mongo/db/s/resharding_util.h index 7b168de9734..33c491a4d23 100644 --- a/src/mongo/db/s/resharding_util.h +++ b/src/mongo/db/s/resharding_util.h @@ -40,7 +40,7 @@ #include "mongo/db/s/resharding/donor_oplog_id_gen.h" #include "mongo/executor/task_executor.h" #include "mongo/s/catalog/type_tags.h" -#include "mongo/s/catalog_cache.h" +#include "mongo/s/chunk_manager.h" #include "mongo/s/resharded_chunk_gen.h" #include "mongo/s/shard_id.h" #include "mongo/s/write_ops/batched_command_request.h" diff --git a/src/mongo/db/s/shardsvr_shard_collection.cpp b/src/mongo/db/s/shardsvr_shard_collection.cpp index dcc9440606c..9508b658d7c 100644 --- a/src/mongo/db/s/shardsvr_shard_collection.cpp +++ b/src/mongo/db/s/shardsvr_shard_collection.cpp @@ -484,7 +484,9 @@ void updateShardingCatalogEntryForCollection( coll.setEpoch(initialChunks.collVersion().epoch()); coll.setUpdatedAt(Date_t::fromMillisSinceEpoch(initialChunks.collVersion().toLong())); coll.setKeyPattern(prerequisites.shardKeyPattern.toBSON()); - coll.setDefaultCollation(defaultCollator ? defaultCollator->getSpec().toBSON() : BSONObj()); + if (defaultCollator) { + coll.setDefaultCollation(defaultCollator->getSpec().toBSON()); + } coll.setUnique(unique); coll.setDistributionMode(CollectionType::DistributionMode::kSharded); diff --git a/src/mongo/db/s/type_shard_collection.idl b/src/mongo/db/s/type_shard_collection.idl index a700a8d49b6..8a58fbe3733 100644 --- a/src/mongo/db/s/type_shard_collection.idl +++ b/src/mongo/db/s/type_shard_collection.idl @@ -101,10 +101,9 @@ structs: optional: false defaultCollation: type: object_owned + description: "Optional collection default collation. If missing or set to the empty + BSON, implies simple collation." default: BSONObj() - description: "Optional collection default collation. If empty, implies simple - collation." - optional: false unique: type: bool description: "Uniqueness of the sharding key." diff --git a/src/mongo/db/s/type_shard_collection_test.cpp b/src/mongo/db/s/type_shard_collection_test.cpp index d5d07bb5ac7..8840aea9851 100644 --- a/src/mongo/db/s/type_shard_collection_test.cpp +++ b/src/mongo/db/s/type_shard_collection_test.cpp @@ -90,7 +90,6 @@ TEST(ShardCollectionType, ToBSONEmptyDefaultCollationNotIncluded) { shardCollType.setKeyPattern(kKeyPattern); shardCollType.setUnique(true); - shardCollType.setDefaultCollation(BSONObj()); BSONObj obj = shardCollType.toBSON(); ASSERT_FALSE(obj.hasField(ShardCollectionType::kDefaultCollationFieldName)); diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp index 03f3cd7bb03..b61d8f13b00 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp +++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp @@ -167,8 +167,6 @@ Status ShardingCatalogClientImpl::updateShardingCatalogEntryForCollection( const NamespaceString& nss, const CollectionType& coll, const bool upsert) { - fassert(28634, coll.validate()); - auto status = _updateConfigDocument(opCtx, CollectionType::ConfigNS, BSON(CollectionType::kNssFieldName << nss.ns()), diff --git a/src/mongo/s/catalog/sharding_catalog_client_test.cpp b/src/mongo/s/catalog/sharding_catalog_client_test.cpp index 0e4ca31239e..3544f433272 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_test.cpp +++ b/src/mongo/s/catalog/sharding_catalog_client_test.cpp @@ -778,7 +778,6 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsNoDb) { coll1.setUnique(false); coll1.setEpoch(OID::gen()); coll1.setKeyPattern(KeyPattern{BSON("_id" << 1)}); - ASSERT_OK(coll1.validate()); CollectionType coll2; coll2.setNss(NamespaceString{"anotherdb.coll1"}); @@ -786,7 +785,6 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsNoDb) { coll2.setUnique(false); coll2.setEpoch(OID::gen()); coll2.setKeyPattern(KeyPattern{BSON("_id" << 1)}); - ASSERT_OK(coll2.validate()); const OpTime newOpTime(Timestamp(7, 6), 5); @@ -901,7 +899,6 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsInvalidCollectionType) { validColl.setUnique(true); validColl.setEpoch(OID::gen()); validColl.setKeyPattern(KeyPattern{BSON("_id" << 1)}); - ASSERT_OK(validColl.validate()); onFindCommand([this, validColl](const RemoteCommandRequest& request) { const NamespaceString nss(request.dbname, request.cmdObj.firstElement().String()); diff --git a/src/mongo/s/catalog/type_collection.cpp b/src/mongo/s/catalog/type_collection.cpp index f81b3eeb418..b1a68ab8095 100644 --- a/src/mongo/s/catalog/type_collection.cpp +++ b/src/mongo/s/catalog/type_collection.cpp @@ -39,19 +39,11 @@ #include "mongo/util/assert_util.h" namespace mongo { -namespace { - -const BSONField kNoBalance("noBalance"); - -} // namespace const NamespaceString CollectionType::ConfigNS("config.collections"); -const BSONField CollectionType::defaultCollation("defaultCollation"); -const BSONField CollectionType::unique("unique"); const BSONField CollectionType::uuid("uuid"); const BSONField CollectionType::distributionMode("distributionMode"); -const BSONField CollectionType::reshardingFields("reshardingFields"); CollectionType::CollectionType(const BSONObj& obj) { CollectionType::parseProtected(IDLParserErrorContext("CollectionType"), obj); @@ -100,34 +92,6 @@ StatusWith CollectionType::fromBSON(const BSONObj& source) { } } - { - BSONElement collDefaultCollation; - Status status = - bsonExtractTypedField(source, defaultCollation.name(), Object, &collDefaultCollation); - if (status.isOK()) { - BSONObj obj = collDefaultCollation.Obj(); - if (obj.isEmpty()) { - return Status(ErrorCodes::BadValue, "empty defaultCollation"); - } - - coll._defaultCollation = obj.getOwned(); - } else if (status != ErrorCodes::NoSuchKey) { - return status; - } - } - - { - bool collUnique; - Status status = bsonExtractBooleanField(source, unique.name(), &collUnique); - if (status.isOK()) { - coll._unique = collUnique; - } else if (status == ErrorCodes::NoSuchKey) { - // Key uniqueness can be missing in which case it is presumed false - } else { - return status; - } - } - { BSONElement uuidElem; Status status = bsonExtractField(source, uuid.name(), &uuidElem); @@ -145,54 +109,17 @@ StatusWith CollectionType::fromBSON(const BSONObj& source) { } } - { - bool collNoBalance; - Status status = bsonExtractBooleanField(source, kNoBalance.name(), &collNoBalance); - if (status.isOK()) { - coll._allowBalance = !collNoBalance; - } else if (status == ErrorCodes::NoSuchKey) { - // No balance can be missing in which case it is presumed as false - } else { - return status; - } - } - - { - const auto reshardingFieldsElem = source.getField(reshardingFields.name()); - if (reshardingFieldsElem) { - coll._reshardingFields = - ReshardingFields::parse(IDLParserErrorContext("TypeCollectionReshardingFields"), - reshardingFieldsElem.Obj()); - } - } - return StatusWith(coll); } -Status CollectionType::validate() const { - return Status::OK(); -} - BSONObj CollectionType::toBSON() const { BSONObjBuilder builder; serialize(&builder); - if (!_defaultCollation.isEmpty()) { - builder.append(defaultCollation.name(), _defaultCollation); - } - - if (_unique.is_initialized()) { - builder.append(unique.name(), _unique.get()); - } - if (_uuid.is_initialized()) { _uuid->appendToBuilder(&builder, uuid.name()); } - if (_allowBalance.is_initialized()) { - builder.append(kNoBalance.name(), !_allowBalance.get()); - } - if (_distributionMode) { if (*_distributionMode == DistributionMode::kUnsharded) { builder.append(distributionMode.name(), "unsharded"); @@ -203,10 +130,6 @@ BSONObj CollectionType::toBSON() const { } } - if (_reshardingFields) { - builder.append(reshardingFields.name(), _reshardingFields->toBSON()); - } - return builder.obj(); } @@ -222,17 +145,18 @@ void CollectionType::setKeyPattern(KeyPattern keyPattern) { setPre50CompatibleKeyPattern(std::move(keyPattern)); } -void CollectionType::setReshardingFields(boost::optional reshardingFields) { - _reshardingFields = std::move(reshardingFields); +void CollectionType::setDefaultCollation(const BSONObj& defaultCollation) { + if (!defaultCollation.isEmpty()) + setPre50CompatibleDefaultCollation(defaultCollation); } bool CollectionType::hasSameOptions(const CollectionType& other) const { return getNss() == other.getNss() && SimpleBSONObjComparator::kInstance.evaluate(getKeyPattern().toBSON() == other.getKeyPattern().toBSON()) && - SimpleBSONObjComparator::kInstance.evaluate(_defaultCollation == + SimpleBSONObjComparator::kInstance.evaluate(getDefaultCollation() == other.getDefaultCollation()) && - *_unique == other.getUnique() && getDistributionMode() == other.getDistributionMode(); + getUnique() == other.getUnique() && getDistributionMode() == other.getDistributionMode(); } } // namespace mongo diff --git a/src/mongo/s/catalog/type_collection.h b/src/mongo/s/catalog/type_collection.h index d0244396deb..b5fddd15fb6 100644 --- a/src/mongo/s/catalog/type_collection.h +++ b/src/mongo/s/catalog/type_collection.h @@ -29,10 +29,7 @@ #pragma once -#include "mongo/db/keypattern.h" -#include "mongo/db/namespace_string.h" #include "mongo/s/catalog/type_collection_gen.h" -#include "mongo/util/uuid.h" namespace mongo { @@ -83,26 +80,31 @@ using ReshardingFields = TypeCollectionReshardingFields; class CollectionType : private CollectionTypeBase { public: // Make field names accessible. - using CollectionTypeBase::kNssFieldName; + static constexpr auto kDefaultCollationFieldName = + CollectionTypeBase::kPre50CompatibleDefaultCollationFieldName; static constexpr auto kEpochFieldName = CollectionTypeBase::kPre22CompatibleEpochFieldName; - using CollectionTypeBase::kUpdatedAtFieldName; static constexpr auto kKeyPatternFieldName = CollectionTypeBase::kPre50CompatibleKeyPatternFieldName; + using CollectionTypeBase::kNssFieldName; + using CollectionTypeBase::kReshardingFieldsFieldName; + using CollectionTypeBase::kUniqueFieldName; + using CollectionTypeBase::kUpdatedAtFieldName; // Make getters and setters accessible. using CollectionTypeBase::getNss; + using CollectionTypeBase::getReshardingFields; + using CollectionTypeBase::getUnique; using CollectionTypeBase::getUpdatedAt; using CollectionTypeBase::setNss; + using CollectionTypeBase::setReshardingFields; + using CollectionTypeBase::setUnique; using CollectionTypeBase::setUpdatedAt; // Name of the collections collection in the config server. static const NamespaceString ConfigNS; - static const BSONField defaultCollation; - static const BSONField unique; static const BSONField uuid; static const BSONField distributionMode; - static const BSONField reshardingFields; CollectionType() = default; @@ -122,12 +124,6 @@ public: kSharded, }; - /** - * Returns OK if all fields have been set. Otherwise returns NoSuchKey and information - * about what is the first field which is missing. - */ - Status validate() const; - /** * Returns the BSON representation of the entry. */ @@ -152,18 +148,14 @@ public: } void setKeyPattern(KeyPattern keyPattern); - const BSONObj& getDefaultCollation() const { - return _defaultCollation; - } - void setDefaultCollation(const BSONObj& collation) { - _defaultCollation = collation.getOwned(); + BSONObj getDefaultCollation() const { + return getPre50CompatibleDefaultCollation() ? *getPre50CompatibleDefaultCollation() + : BSONObj(); } + void setDefaultCollation(const BSONObj& defaultCollation); - bool getUnique() const { - return _unique.get_value_or(false); - } - void setUnique(bool unique) { - _unique = unique; + bool getAllowBalance() const { + return !getNoBalance(); } boost::optional getUUID() const { @@ -173,10 +165,6 @@ public: _uuid = uuid; } - bool getAllowBalance() const { - return _allowBalance.get_value_or(true); - } - DistributionMode getDistributionMode() const { return _distributionMode.get_value_or(DistributionMode::kSharded); } @@ -184,11 +172,6 @@ public: _distributionMode = distributionMode; } - const boost::optional& getReshardingFields() const { - return _reshardingFields; - } - void setReshardingFields(boost::optional reshardingFields); - bool hasSameOptions(const CollectionType& other) const; private: @@ -196,20 +179,8 @@ private: // collection is unsharded or sharded. If missing, implies sharded. boost::optional _distributionMode; - // Optional collection default collation. If empty, implies simple collation. - BSONObj _defaultCollation; - - // Optional uniqueness of the sharding key. If missing, implies false. - boost::optional _unique; - // Optional in 3.6 binaries, because UUID does not exist in featureCompatibilityVersion=3.4. boost::optional _uuid; - - // Optional whether balancing is allowed for this collection. If missing, implies true. - boost::optional _allowBalance; - - // Fields on the collection entry specific to resharding. - boost::optional _reshardingFields; }; } // namespace mongo diff --git a/src/mongo/s/catalog/type_collection.idl b/src/mongo/s/catalog/type_collection.idl index 9bafdfe6be2..a93f633b141 100644 --- a/src/mongo/s/catalog/type_collection.idl +++ b/src/mongo/s/catalog/type_collection.idl @@ -78,3 +78,28 @@ structs: is set to true, because dropped collections' entries were being written as dropped with certain fields missing instead of deleted." optional: true + defaultCollation: + cpp_name: pre50CompatibleDefaultCollation + type: object_owned + description: "Optional collection default collation. If missing or set to the empty + BSON, implies simple collation. + + It is optional for serialisation purposes, because in versions of + MongoDB prior to 5.0, this value must be missing for the default + (empty BSON) collation." + optional: true + unique: + type: bool + description: "Uniqueness of the sharding key." + default: false + noBalance: + type: bool + description: "Consulted by the Balancer only and indicates whether this collection + should be considered for balancing or not." + default: false + reshardingFields: + type: TypeCollectionReshardingFields + description: "Resharding-related fields. Only set when this collection is either the + original collection undergoing a resharding operation or this + collection is the temporary resharding collection." + optional: true diff --git a/src/mongo/s/catalog/type_collection_test.cpp b/src/mongo/s/catalog/type_collection_test.cpp index a6964324d66..57ddd37fe91 100644 --- a/src/mongo/s/catalog/type_collection_test.cpp +++ b/src/mongo/s/catalog/type_collection_test.cpp @@ -50,13 +50,13 @@ TEST(CollectionType, Basic) { << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::defaultCollation(BSON("locale" - << "fr_CA")) - << CollectionType::unique(true))); + << CollectionType::kDefaultCollationFieldName + << BSON("locale" + << "fr_CA") + << CollectionType::kUniqueFieldName << true)); ASSERT_TRUE(status.isOK()); CollectionType coll = status.getValue(); - ASSERT_TRUE(coll.validate().isOK()); ASSERT(coll.getNss() == NamespaceString{"db.coll"}); ASSERT_EQUALS(coll.getEpoch(), oid); ASSERT_EQUALS(coll.getUpdatedAt(), Date_t::fromMillisSinceEpoch(1)); @@ -82,14 +82,14 @@ TEST(CollectionType, AllFieldsPresent) { << "db.coll" << CollectionType::kEpochFieldName << oid << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::defaultCollation(BSON("locale" - << "fr_CA")) - << CollectionType::unique(true) << CollectionType::uuid() << uuid - << CollectionType::reshardingFields() << reshardingFields.toBSON())); + << CollectionType::kDefaultCollationFieldName + << BSON("locale" + << "fr_CA") + << CollectionType::kUniqueFieldName << true << CollectionType::uuid() << uuid + << CollectionType::kReshardingFieldsFieldName << reshardingFields.toBSON())); ASSERT_TRUE(status.isOK()); CollectionType coll = status.getValue(); - ASSERT_TRUE(coll.validate().isOK()); ASSERT(coll.getNss() == NamespaceString{"db.coll"}); ASSERT_EQUALS(coll.getEpoch(), oid); ASSERT_EQUALS(coll.getUpdatedAt(), Date_t::fromMillisSinceEpoch(1)); @@ -106,28 +106,17 @@ TEST(CollectionType, AllFieldsPresent) { ASSERT(coll.getReshardingFields()->getUuid() == reshardingUuid); } -TEST(CollectionType, EmptyDefaultCollationFailsToParse) { - const OID oid = OID::gen(); - StatusWith status = CollectionType::fromBSON( - BSON(CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << oid - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::defaultCollation(BSONObj()) << CollectionType::unique(true))); - ASSERT_FALSE(status.isOK()); -} - TEST(CollectionType, MissingDefaultCollationParses) { const OID oid = OID::gen(); - StatusWith status = CollectionType::fromBSON(BSON( - CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << oid - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) << CollectionType::unique(true))); + StatusWith status = CollectionType::fromBSON( + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName << oid + << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true)); ASSERT_TRUE(status.isOK()); CollectionType coll = status.getValue(); - ASSERT_TRUE(coll.validate().isOK()); ASSERT_BSONOBJ_EQ(coll.getDefaultCollation(), BSONObj()); } @@ -138,46 +127,30 @@ TEST(CollectionType, DefaultCollationSerializesCorrectly) { << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::defaultCollation(BSON("locale" - << "fr_CA")) - << CollectionType::unique(true))); + << CollectionType::kDefaultCollationFieldName + << BSON("locale" + << "fr_CA") + << CollectionType::kUniqueFieldName << true)); ASSERT_TRUE(status.isOK()); CollectionType coll = status.getValue(); - ASSERT_TRUE(coll.validate().isOK()); BSONObj serialized = coll.toBSON(); ASSERT_BSONOBJ_EQ(serialized["defaultCollation"].Obj(), BSON("locale" << "fr_CA")); } -TEST(CollectionType, MissingDefaultCollationIsNotSerialized) { - const OID oid = OID::gen(); - StatusWith status = CollectionType::fromBSON(BSON( - CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << oid - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) << CollectionType::unique(true))); - ASSERT_TRUE(status.isOK()); - - CollectionType coll = status.getValue(); - ASSERT_TRUE(coll.validate().isOK()); - BSONObj serialized = coll.toBSON(); - ASSERT_FALSE(serialized["defaultCollation"]); -} - TEST(CollectionType, MissingDistributionModeImpliesDistributionModeSharded) { const OID oid = OID::gen(); - StatusWith status = CollectionType::fromBSON(BSON( - CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << oid - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) << CollectionType::unique(true))); + StatusWith status = CollectionType::fromBSON( + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName << oid + << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true)); ASSERT_TRUE(status.isOK()); CollectionType coll = status.getValue(); - ASSERT_TRUE(coll.validate().isOK()); - ASSERT(CollectionType::DistributionMode::kSharded == coll.getDistributionMode()); // Since the distributionMode was not explicitly set, it does not get serialized. @@ -188,16 +161,15 @@ TEST(CollectionType, MissingDistributionModeImpliesDistributionModeSharded) { TEST(CollectionType, DistributionModeUnshardedParses) { const OID oid = OID::gen(); StatusWith status = CollectionType::fromBSON( - BSON(CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << oid - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true) << CollectionType::distributionMode("unsharded"))); + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName << oid + << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true + << CollectionType::distributionMode("unsharded"))); ASSERT_TRUE(status.isOK()); CollectionType coll = status.getValue(); - ASSERT_TRUE(coll.validate().isOK()); - ASSERT(CollectionType::DistributionMode::kUnsharded == coll.getDistributionMode()); BSONObj serialized = coll.toBSON(); @@ -207,16 +179,15 @@ TEST(CollectionType, DistributionModeUnshardedParses) { TEST(CollectionType, DistributionModeShardedParses) { const OID oid = OID::gen(); StatusWith status = CollectionType::fromBSON( - BSON(CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << oid - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true) << CollectionType::distributionMode("sharded"))); + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName << oid + << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true + << CollectionType::distributionMode("sharded"))); ASSERT_TRUE(status.isOK()); CollectionType coll = status.getValue(); - ASSERT_TRUE(coll.validate().isOK()); - ASSERT(CollectionType::DistributionMode::kSharded == coll.getDistributionMode()); BSONObj serialized = coll.toBSON(); @@ -226,28 +197,31 @@ TEST(CollectionType, DistributionModeShardedParses) { TEST(CollectionType, UnknownDistributionModeFailsToParse) { const OID oid = OID::gen(); StatusWith status = CollectionType::fromBSON( - BSON(CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << oid - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true) << CollectionType::distributionMode("badvalue"))); + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName << oid + << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true + << CollectionType::distributionMode("badvalue"))); ASSERT_EQUALS(ErrorCodes::FailedToParse, status.getStatus()); } TEST(CollectionType, HasSameOptionsReturnsTrueIfBothDistributionModesExplicitlySetToUnsharded) { const auto collType1 = uassertStatusOK(CollectionType::fromBSON( - BSON(CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << OID::gen() - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true) << CollectionType::distributionMode("unsharded")))); + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName + << OID::gen() << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true + << CollectionType::distributionMode("unsharded")))); const auto collType2 = uassertStatusOK(CollectionType::fromBSON( - BSON(CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << OID::gen() - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true) << CollectionType::distributionMode("unsharded")))); + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName + << OID::gen() << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true + << CollectionType::distributionMode("unsharded")))); ASSERT(collType1.hasSameOptions(collType2)); ASSERT(collType2.hasSameOptions(collType1)); @@ -255,18 +229,20 @@ TEST(CollectionType, HasSameOptionsReturnsTrueIfBothDistributionModesExplicitlyS TEST(CollectionType, HasSameOptionsReturnsTrueIfBothDistributionModesExplicitlySetToSharded) { const auto collType1 = uassertStatusOK(CollectionType::fromBSON( - BSON(CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << OID::gen() - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true) << CollectionType::distributionMode("sharded")))); + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName + << OID::gen() << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true + << CollectionType::distributionMode("sharded")))); const auto collType2 = uassertStatusOK(CollectionType::fromBSON( - BSON(CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << OID::gen() - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true) << CollectionType::distributionMode("sharded")))); + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName + << OID::gen() << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true + << CollectionType::distributionMode("sharded")))); ASSERT(collType1.hasSameOptions(collType2)); ASSERT(collType2.hasSameOptions(collType1)); @@ -276,18 +252,20 @@ TEST( CollectionType, HasSameOptionsReturnsFalseIfOneDistributionModeExplicitlySetToUnshardedAndOtherExplicitlySetToSharded) { const auto collType1 = uassertStatusOK(CollectionType::fromBSON( - BSON(CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << OID::gen() - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true) << CollectionType::distributionMode("unsharded")))); + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName + << OID::gen() << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true + << CollectionType::distributionMode("unsharded")))); const auto collType2 = uassertStatusOK(CollectionType::fromBSON( - BSON(CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << OID::gen() - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true) << CollectionType::distributionMode("sharded")))); + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName + << OID::gen() << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true + << CollectionType::distributionMode("sharded")))); ASSERT(!collType1.hasSameOptions(collType2)); ASSERT(!collType2.hasSameOptions(collType1)); @@ -296,18 +274,19 @@ TEST( TEST(CollectionType, HasSameOptionsReturnsTrueIfOneDistributionModeExplicitlySetToShardedAndOtherIsNotSet) { const auto collType1 = uassertStatusOK(CollectionType::fromBSON( - BSON(CollectionType::kNssFieldName - << "db.coll" << CollectionType::kEpochFieldName << OID::gen() - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true) << CollectionType::distributionMode("sharded")))); + BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName + << OID::gen() << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true + << CollectionType::distributionMode("sharded")))); const auto collType2 = uassertStatusOK(CollectionType::fromBSON( BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName << OID::gen() << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true)))); + << CollectionType::kUniqueFieldName << true))); ASSERT(collType1.hasSameOptions(collType2)); ASSERT(collType2.hasSameOptions(collType1)); @@ -319,14 +298,14 @@ TEST(CollectionType, HasSameOptionsReturnsTrueIfNeitherDistributionModeExplicitl << OID::gen() << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true)))); + << CollectionType::kUniqueFieldName << true))); const auto collType2 = uassertStatusOK(CollectionType::fromBSON( BSON(CollectionType::kNssFieldName << "db.coll" << CollectionType::kEpochFieldName << OID::gen() << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) << CollectionType::kKeyPatternFieldName << BSON("a" << 1) - << CollectionType::unique(true)))); + << CollectionType::kUniqueFieldName << true))); ASSERT(collType1.hasSameOptions(collType2)); ASSERT(collType2.hasSameOptions(collType1)); @@ -350,11 +329,12 @@ TEST(CollectionType, Pre22Format) { TEST(CollectionType, InvalidCollectionNamespace) { const OID oid = OID::gen(); - StatusWith result = CollectionType::fromBSON(BSON( - CollectionType::kNssFieldName - << "foo\\bar.coll" << CollectionType::kEpochFieldName << oid - << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) - << CollectionType::kKeyPatternFieldName << BSON("a" << 1) << CollectionType::unique(true))); + StatusWith result = CollectionType::fromBSON( + BSON(CollectionType::kNssFieldName << "foo\\bar.coll" << CollectionType::kEpochFieldName + << oid << CollectionType::kUpdatedAtFieldName + << Date_t::fromMillisSinceEpoch(1) + << CollectionType::kKeyPatternFieldName << BSON("a" << 1) + << CollectionType::kUniqueFieldName << true)); ASSERT_NOT_OK(result.getStatus()); } @@ -364,7 +344,7 @@ TEST(CollectionType, BadType) { BSON(CollectionType::kNssFieldName << 1 << CollectionType::kEpochFieldName << oid << CollectionType::kUpdatedAtFieldName << Date_t::fromMillisSinceEpoch(1) << CollectionType::kKeyPatternFieldName - << BSON("a" << 1) << CollectionType::unique(true))); + << BSON("a" << 1) << CollectionType::kUniqueFieldName << true)); ASSERT_NOT_OK(result.getStatus()); } diff --git a/src/mongo/s/catalog_cache_test_fixture.h b/src/mongo/s/catalog_cache_test_fixture.h index 8886c1e74bb..fb6c53a6dad 100644 --- a/src/mongo/s/catalog_cache_test_fixture.h +++ b/src/mongo/s/catalog_cache_test_fixture.h @@ -34,7 +34,6 @@ #include "mongo/db/namespace_string.h" #include "mongo/s/catalog/type_shard.h" -#include "mongo/s/catalog_cache.h" #include "mongo/s/sharding_router_test_fixture.h" namespace mongo { diff --git a/src/mongo/s/query/cluster_aggregation_planner.h b/src/mongo/s/query/cluster_aggregation_planner.h index b1257914099..8cc0ccc4cea 100644 --- a/src/mongo/s/query/cluster_aggregation_planner.h +++ b/src/mongo/s/query/cluster_aggregation_planner.h @@ -32,7 +32,7 @@ #include #include "mongo/db/pipeline/pipeline.h" -#include "mongo/s/catalog_cache.h" +#include "mongo/s/chunk_manager.h" #include "mongo/s/query/cluster_aggregate.h" #include "mongo/s/query/cluster_client_cursor_guard.h" #include "mongo/s/query/cluster_client_cursor_impl.h" -- cgit v1.2.1