summaryrefslogtreecommitdiff
path: root/src/mongo/s/catalog
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2020-10-30 11:48:09 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-11-03 16:39:42 +0000
commitab6d6baf541e762b272738da8d9c5b257caa3be4 (patch)
tree0f9a824c741fc4a5ced8fb792b82893bfc228f0e /src/mongo/s/catalog
parentcd587a2171ea96b86ac82508eef065a601e4f3df (diff)
downloadmongo-ab6d6baf541e762b272738da8d9c5b257caa3be4.tar.gz
SERVER-50027 Convert the CollectionType's UUID field to IDL
... and make it required
Diffstat (limited to 'src/mongo/s/catalog')
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_test.cpp45
-rw-r--r--src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp7
-rw-r--r--src/mongo/s/catalog/type_collection.cpp32
-rw-r--r--src/mongo/s/catalog/type_collection.h19
-rw-r--r--src/mongo/s/catalog/type_collection.idl11
-rw-r--r--src/mongo/s/catalog/type_collection_test.cpp5
6 files changed, 49 insertions, 70 deletions
diff --git a/src/mongo/s/catalog/sharding_catalog_client_test.cpp b/src/mongo/s/catalog/sharding_catalog_client_test.cpp
index 3544f433272..d2e397abc35 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_test.cpp
@@ -90,11 +90,9 @@ BSONObj getReplSecondaryOkMetadata() {
TEST_F(ShardingCatalogClientTest, GetCollectionExisting) {
configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1"));
- CollectionType expectedColl;
- expectedColl.setNss(NamespaceString("TestDB.TestNS"));
+ CollectionType expectedColl(
+ NamespaceString("TestDB.TestNS"), OID::gen(), Date_t::now(), UUID::gen());
expectedColl.setKeyPattern(BSON("KeyName" << 1));
- expectedColl.setUpdatedAt(Date_t());
- expectedColl.setEpoch(OID::gen());
const OpTime newOpTime(Timestamp(7, 6), 5);
@@ -772,19 +770,16 @@ TEST_F(ShardingCatalogClientTest, RunUserManagementWriteCommandNotWritablePrimar
TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsNoDb) {
configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1"));
- CollectionType coll1;
- coll1.setNss(NamespaceString{"test.coll1"});
- coll1.setUpdatedAt(network()->now());
- coll1.setUnique(false);
- coll1.setEpoch(OID::gen());
+ CollectionType coll1(NamespaceString{"test.coll1"}, OID::gen(), network()->now(), UUID::gen());
coll1.setKeyPattern(KeyPattern{BSON("_id" << 1)});
+ coll1.setUnique(false);
- CollectionType coll2;
- coll2.setNss(NamespaceString{"anotherdb.coll1"});
- coll2.setUpdatedAt(network()->now());
- coll2.setUnique(false);
- coll2.setEpoch(OID::gen());
+
+ CollectionType coll2(
+ NamespaceString{"anotherdb.coll1"}, OID::gen(), network()->now(), UUID::gen());
coll2.setKeyPattern(KeyPattern{BSON("_id" << 1)});
+ coll2.setUnique(false);
+
const OpTime newOpTime(Timestamp(7, 6), 5);
@@ -836,19 +831,13 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsNoDb) {
TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsWithDb) {
configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1"));
- CollectionType coll1;
- coll1.setNss(NamespaceString{"test.coll1"});
- coll1.setUpdatedAt(network()->now());
- coll1.setUnique(true);
- coll1.setEpoch(OID::gen());
+ CollectionType coll1(NamespaceString{"test.coll1"}, OID::gen(), network()->now(), UUID::gen());
coll1.setKeyPattern(KeyPattern{BSON("_id" << 1)});
+ coll1.setUnique(true);
- CollectionType coll2;
- coll2.setNss(NamespaceString{"test.coll2"});
- coll2.setUpdatedAt(network()->now());
- coll2.setUnique(false);
- coll2.setEpoch(OID::gen());
+ CollectionType coll2(NamespaceString{"test.coll2"}, OID::gen(), network()->now(), UUID::gen());
coll2.setKeyPattern(KeyPattern{BSON("_id" << 1)});
+ coll2.setUnique(false);
auto future = launchAsync([this] {
const std::string dbName = "test";
@@ -893,12 +882,10 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsInvalidCollectionType) {
ASSERT_EQ(ErrorCodes::FailedToParse, swCollections.getStatus());
});
- CollectionType validColl;
- validColl.setNss(NamespaceString{"test.coll1"});
- validColl.setUpdatedAt(network()->now());
- validColl.setUnique(true);
- validColl.setEpoch(OID::gen());
+ CollectionType validColl(
+ NamespaceString{"test.coll1"}, OID::gen(), network()->now(), UUID::gen());
validColl.setKeyPattern(KeyPattern{BSON("_id" << 1)});
+ validColl.setUnique(true);
onFindCommand([this, validColl](const RemoteCommandRequest& request) {
const NamespaceString nss(request.dbname, request.cmdObj.firstElement().String());
diff --git a/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp b/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp
index d60c8d77c32..5cc2d0707db 100644
--- a/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp
@@ -408,11 +408,8 @@ TEST_F(UpdateRetryTest, NotWritablePrimaryOnceSuccessAfterRetry) {
HostAndPort host2("TestHost2");
configTargeter()->setFindHostReturnValue(host1);
- CollectionType collection;
- collection.setNss(NamespaceString("db.coll"));
- collection.setUpdatedAt(network()->now());
- collection.setUnique(true);
- collection.setEpoch(OID::gen());
+ CollectionType collection(
+ NamespaceString("db.coll"), OID::gen(), network()->now(), UUID::gen());
collection.setKeyPattern(KeyPattern(BSON("_id" << 1)));
BSONObj objToUpdate = BSON("_id" << 1 << "Value"
diff --git a/src/mongo/s/catalog/type_collection.cpp b/src/mongo/s/catalog/type_collection.cpp
index b1a68ab8095..6b42f7aadcb 100644
--- a/src/mongo/s/catalog/type_collection.cpp
+++ b/src/mongo/s/catalog/type_collection.cpp
@@ -42,9 +42,14 @@ namespace mongo {
const NamespaceString CollectionType::ConfigNS("config.collections");
-const BSONField<UUID> CollectionType::uuid("uuid");
const BSONField<std::string> CollectionType::distributionMode("distributionMode");
+CollectionType::CollectionType(NamespaceString nss, OID epoch, Date_t updatedAt, UUID uuid)
+ : CollectionTypeBase(std::move(nss), std::move(updatedAt)) {
+ setEpoch(std::move(epoch));
+ setUuid(std::move(uuid));
+}
+
CollectionType::CollectionType(const BSONObj& obj) {
CollectionType::parseProtected(IDLParserErrorContext("CollectionType"), obj);
uassert(ErrorCodes::BadValue,
@@ -92,23 +97,6 @@ StatusWith<CollectionType> CollectionType::fromBSON(const BSONObj& source) {
}
}
- {
- BSONElement uuidElem;
- Status status = bsonExtractField(source, uuid.name(), &uuidElem);
- if (status.isOK()) {
- auto swUUID = UUID::parse(uuidElem);
- if (!swUUID.isOK()) {
- return swUUID.getStatus();
- }
- coll._uuid = swUUID.getValue();
- } else if (status == ErrorCodes::NoSuchKey) {
- // UUID can be missing in 3.6, because featureCompatibilityVersion can be 3.4, in which
- // case it remains boost::none.
- } else {
- return status;
- }
- }
-
return StatusWith<CollectionType>(coll);
}
@@ -116,10 +104,6 @@ BSONObj CollectionType::toBSON() const {
BSONObjBuilder builder;
serialize(&builder);
- if (_uuid.is_initialized()) {
- _uuid->appendToBuilder(&builder, uuid.name());
- }
-
if (_distributionMode) {
if (*_distributionMode == DistributionMode::kUnsharded) {
builder.append(distributionMode.name(), "unsharded");
@@ -141,6 +125,10 @@ void CollectionType::setEpoch(OID epoch) {
setPre22CompatibleEpoch(std::move(epoch));
}
+void CollectionType::setUuid(UUID uuid) {
+ setPre50CompatibleUuid(std::move(uuid));
+}
+
void CollectionType::setKeyPattern(KeyPattern keyPattern) {
setPre50CompatibleKeyPattern(std::move(keyPattern));
}
diff --git a/src/mongo/s/catalog/type_collection.h b/src/mongo/s/catalog/type_collection.h
index b5fddd15fb6..b0f1e81ff6a 100644
--- a/src/mongo/s/catalog/type_collection.h
+++ b/src/mongo/s/catalog/type_collection.h
@@ -85,6 +85,7 @@ public:
static constexpr auto kEpochFieldName = CollectionTypeBase::kPre22CompatibleEpochFieldName;
static constexpr auto kKeyPatternFieldName =
CollectionTypeBase::kPre50CompatibleKeyPatternFieldName;
+ static constexpr auto kUuidFieldName = CollectionTypeBase::kPre50CompatibleUuidFieldName;
using CollectionTypeBase::kNssFieldName;
using CollectionTypeBase::kReshardingFieldsFieldName;
using CollectionTypeBase::kUniqueFieldName;
@@ -103,11 +104,12 @@ public:
// Name of the collections collection in the config server.
static const NamespaceString ConfigNS;
- static const BSONField<UUID> uuid;
static const BSONField<std::string> distributionMode;
CollectionType() = default;
+ CollectionType(NamespaceString nss, OID epoch, Date_t updatedAt, UUID uuid);
+
explicit CollectionType(const BSONObj& obj);
/**
@@ -139,6 +141,11 @@ public:
}
void setEpoch(OID epoch);
+ const UUID& getUuid() const {
+ return *getPre50CompatibleUuid();
+ }
+ void setUuid(UUID uuid);
+
bool getDropped() const {
return getPre50CompatibleDropped() ? *getPre50CompatibleDropped() : false;
}
@@ -158,13 +165,6 @@ public:
return !getNoBalance();
}
- boost::optional<UUID> getUUID() const {
- return _uuid;
- }
- void setUUID(UUID uuid) {
- _uuid = uuid;
- }
-
DistributionMode getDistributionMode() const {
return _distributionMode.get_value_or(DistributionMode::kSharded);
}
@@ -178,9 +178,6 @@ private:
// New field in v4.4; optional in v4.4 for backwards compatibility with v4.2. Whether the
// collection is unsharded or sharded. If missing, implies sharded.
boost::optional<DistributionMode> _distributionMode;
-
- // Optional in 3.6 binaries, because UUID does not exist in featureCompatibilityVersion=3.4.
- boost::optional<UUID> _uuid;
};
} // namespace mongo
diff --git a/src/mongo/s/catalog/type_collection.idl b/src/mongo/s/catalog/type_collection.idl
index a93f633b141..643627f0863 100644
--- a/src/mongo/s/catalog/type_collection.idl
+++ b/src/mongo/s/catalog/type_collection.idl
@@ -62,6 +62,17 @@ structs:
description: "Contains the time of when the collection was either created, or if
dropped = true, when it was dropped."
optional: false
+ uuid:
+ cpp_name: pre50CompatibleUuid
+ type: uuid
+ description: "The UUID that will be used to create the local collection on each of
+ the shards which have chunks.
+
+ It is optional for parsing purposes, because in versions of MongoDB
+ prior to 5.0, this value would be missing for entries where 'dropped'
+ is set to true, because dropped collections' entries were being
+ written as dropped with certain fields missing instead of deleted."
+ optional: true
dropped: # TODO (SERVER-51881): Remove this field after 5.0 is released
cpp_name: pre50CompatibleDropped
type: bool
diff --git a/src/mongo/s/catalog/type_collection_test.cpp b/src/mongo/s/catalog/type_collection_test.cpp
index 57ddd37fe91..89155459611 100644
--- a/src/mongo/s/catalog/type_collection_test.cpp
+++ b/src/mongo/s/catalog/type_collection_test.cpp
@@ -85,7 +85,7 @@ TEST(CollectionType, AllFieldsPresent) {
<< CollectionType::kDefaultCollationFieldName
<< BSON("locale"
<< "fr_CA")
- << CollectionType::kUniqueFieldName << true << CollectionType::uuid() << uuid
+ << CollectionType::kUniqueFieldName << true << CollectionType::kUuidFieldName << uuid
<< CollectionType::kReshardingFieldsFieldName << reshardingFields.toBSON()));
ASSERT_TRUE(status.isOK());
@@ -100,8 +100,7 @@ TEST(CollectionType, AllFieldsPresent) {
ASSERT_EQUALS(coll.getUnique(), true);
ASSERT_EQUALS(coll.getAllowBalance(), true);
ASSERT_EQUALS(coll.getDropped(), false);
- ASSERT_TRUE(coll.getUUID());
- ASSERT_EQUALS(*coll.getUUID(), uuid);
+ ASSERT_EQUALS(coll.getUuid(), uuid);
ASSERT(coll.getReshardingFields()->getState() == CoordinatorStateEnum::kUnused);
ASSERT(coll.getReshardingFields()->getUuid() == reshardingUuid);
}