diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2020-10-30 04:49:28 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-11-02 14:34:43 +0000 |
commit | 5bd87925a006fa591692e097d7929b6764da6d0c (patch) | |
tree | d262cecab92e276753a4e23b786796cad10eeeb0 /src/mongo/s/catalog | |
parent | 7d8e64df2d2d56a821f638ef88aa619403d03d31 (diff) | |
download | mongo-5bd87925a006fa591692e097d7929b6764da6d0c.tar.gz |
SERVER-50027 Make CollectionType use IDL (Part 3)
Diffstat (limited to 'src/mongo/s/catalog')
-rw-r--r-- | src/mongo/s/catalog/sharding_catalog_client_impl.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/catalog/sharding_catalog_client_test.cpp | 3 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_collection.cpp | 86 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_collection.h | 61 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_collection.idl | 25 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_collection_test.cpp | 210 |
6 files changed, 141 insertions, 246 deletions
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<bool> kNoBalance("noBalance"); - -} // namespace const NamespaceString CollectionType::ConfigNS("config.collections"); -const BSONField<BSONObj> CollectionType::defaultCollation("defaultCollation"); -const BSONField<bool> CollectionType::unique("unique"); const BSONField<UUID> CollectionType::uuid("uuid"); const BSONField<std::string> CollectionType::distributionMode("distributionMode"); -const BSONField<ReshardingFields> CollectionType::reshardingFields("reshardingFields"); CollectionType::CollectionType(const BSONObj& obj) { CollectionType::parseProtected(IDLParserErrorContext("CollectionType"), obj); @@ -101,34 +93,6 @@ StatusWith<CollectionType> 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); if (status.isOK()) { @@ -145,54 +109,17 @@ StatusWith<CollectionType> 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<CollectionType>(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) { - _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<BSONObj> defaultCollation; - static const BSONField<bool> unique; static const BSONField<UUID> uuid; static const BSONField<std::string> distributionMode; - static const BSONField<ReshardingFields> reshardingFields; CollectionType() = default; @@ -123,12 +125,6 @@ public: }; /** - * 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. */ BSONObj toBSON() const; @@ -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<UUID> 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<ReshardingFields>& getReshardingFields() const { - return _reshardingFields; - } - void setReshardingFields(boost::optional<ReshardingFields> 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> _distributionMode; - // Optional collection default collation. If empty, implies simple collation. - BSONObj _defaultCollation; - - // Optional uniqueness of the sharding key. If missing, implies false. - boost::optional<bool> _unique; - // Optional in 3.6 binaries, because UUID does not exist in featureCompatibilityVersion=3.4. boost::optional<UUID> _uuid; - - // Optional whether balancing is allowed for this collection. If missing, implies true. - boost::optional<bool> _allowBalance; - - // Fields on the collection entry specific to resharding. - boost::optional<ReshardingFields> _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<CollectionType> 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<CollectionType> 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<CollectionType> 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<CollectionType> 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<CollectionType> 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<CollectionType> 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<CollectionType> 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<CollectionType> 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<CollectionType> 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<CollectionType> 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<CollectionType> 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()); } |