summaryrefslogtreecommitdiff
path: root/src/mongo/s/catalog
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2020-03-23 17:05:48 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-27 15:16:30 +0000
commit272a73ec66783ffbf7f954c12fed41825caa96e4 (patch)
treebfd85467cd384ec2422e9ef7c016d781b49c4364 /src/mongo/s/catalog
parent6694a0434f37db0d6671d05e37a54e78eb1f156b (diff)
downloadmongo-272a73ec66783ffbf7f954c12fed41825caa96e4.tar.gz
SERVER-44034 Remove refineCollectionShardKey and config.chunks/tags upgrade/downgrade code
Diffstat (limited to 'src/mongo/s/catalog')
-rw-r--r--src/mongo/s/catalog/type_chunk.cpp51
-rw-r--r--src/mongo/s/catalog/type_chunk.h24
-rw-r--r--src/mongo/s/catalog/type_chunk_test.cpp64
-rw-r--r--src/mongo/s/catalog/type_tags.cpp7
-rw-r--r--src/mongo/s/catalog/type_tags.h8
-rw-r--r--src/mongo/s/catalog/type_tags_test.cpp14
6 files changed, 1 insertions, 167 deletions
diff --git a/src/mongo/s/catalog/type_chunk.cpp b/src/mongo/s/catalog/type_chunk.cpp
index b9736e478b4..9e78e767649 100644
--- a/src/mongo/s/catalog/type_chunk.cpp
+++ b/src/mongo/s/catalog/type_chunk.cpp
@@ -47,7 +47,6 @@ const NamespaceString ChunkType::ConfigNS("config.chunks");
const std::string ChunkType::ShardNSPrefix = "config.cache.chunks.";
const BSONField<OID> ChunkType::name("_id");
-const BSONField<std::string> ChunkType::legacyName("_id");
const BSONField<BSONObj> ChunkType::minShardID("_id");
const BSONField<std::string> ChunkType::ns("ns");
const BSONField<BSONObj> ChunkType::min("min");
@@ -216,14 +215,9 @@ StatusWith<ChunkType> ChunkType::parseFromConfigBSONCommand(const BSONObj& sourc
Status status = bsonExtractOIDField(source, name.name(), &chunkID);
if (status.isOK()) {
chunk._id = chunkID;
- } else if (status == ErrorCodes::NoSuchKey || status == ErrorCodes::TypeMismatch) {
+ } else if (status == ErrorCodes::NoSuchKey) {
// Ignore NoSuchKey because when chunks are sent in commands they are not required to
// include it.
- //
- // Ignore TypeMismatch for compatibility with binaries 4.2 and earlier, since the _id
- // type was changed from string to OID.
- //
- // TODO SERVER-44034: Stop ignoring TypeMismatch.
} else {
return status;
}
@@ -308,11 +302,6 @@ StatusWith<ChunkType> ChunkType::fromConfigBSON(const BSONObj& source) {
Status status = bsonExtractOIDField(source, name.name(), &chunkID);
if (status.isOK()) {
chunk._id = chunkID;
- } else if (status == ErrorCodes::TypeMismatch) {
- // The format of _id changed between 4.2 and 4.4 so for compatibility with chunks
- // created in earlier versions we ignore TypeMismatch.
- //
- // TODO SERVER-44034: Stop ignoring TypeMismatch.
} else {
return status;
}
@@ -342,26 +331,6 @@ BSONObj ChunkType::toConfigBSON() const {
return builder.obj();
}
-BSONObj ChunkType::toConfigBSONLegacyID() const {
- BSONObjBuilder builder;
- if (_nss && _min)
- builder.append(name.name(), genLegacyID(*_nss, *_min));
- if (_nss)
- builder.append(ns.name(), getNS().ns());
- if (_min)
- builder.append(min.name(), getMin());
- if (_max)
- builder.append(max.name(), getMax());
- if (_shard)
- builder.append(shard.name(), getShard().toString());
- if (_version)
- _version->appendLegacyWithField(&builder, ChunkType::lastmod());
- if (_jumbo)
- builder.append(jumbo.name(), getJumbo());
- addHistoryToBSON(builder);
- return builder.obj();
-}
-
StatusWith<ChunkType> ChunkType::fromShardBSON(const BSONObj& source, const OID& epoch) {
ChunkType chunk;
@@ -547,22 +516,4 @@ std::string ChunkType::toString() const {
return toConfigBSON().toString();
}
-std::string ChunkType::genLegacyID(const NamespaceString& nss, const BSONObj& o) {
- StringBuilder buf;
- buf << nss.ns() << "-";
-
- BSONObjIterator i(o);
- while (i.more()) {
- BSONElement e = i.next();
- buf << e.fieldName() << "_" << e.toString(false, true);
- }
-
- return buf.str();
-}
-
-std::string ChunkType::getLegacyName() const {
- invariant(_nss && _min);
- return genLegacyID(*_nss, *_min);
-}
-
} // namespace mongo
diff --git a/src/mongo/s/catalog/type_chunk.h b/src/mongo/s/catalog/type_chunk.h
index 2e64e86d3dc..3e602cb191c 100644
--- a/src/mongo/s/catalog/type_chunk.h
+++ b/src/mongo/s/catalog/type_chunk.h
@@ -194,7 +194,6 @@ public:
// Field names and types in the chunks collections.
static const BSONField<OID> name;
- static const BSONField<std::string> legacyName; // TODO SERVER-44034: Remove legacyName.
static const BSONField<BSONObj> minShardID;
static const BSONField<std::string> ns;
static const BSONField<BSONObj> min;
@@ -225,14 +224,6 @@ public:
BSONObj toConfigBSON() const;
/**
- * Returns the BSON representation of the entry for the config server's config.chunks
- * collection using the _id format expected by binaries in 4.2 and earlier.
- *
- * TODO SERVER-44034: Remove when 4.4 becomes last-stable.
- */
- BSONObj toConfigBSONLegacyID() const;
-
- /**
* Constructs a new ChunkType object from BSON that has a shard server's config.chunks.<epoch>
* collection format.
*
@@ -241,26 +232,11 @@ public:
static StatusWith<ChunkType> fromShardBSON(const BSONObj& source, const OID& epoch);
/**
- * Generates the chunk id that would be expected in binaries 4.2 and earlier based on the
- * namespace and lower chunk bound.
- *
- * TODO SERVER-44034: Remove when 4.4 becomes last-stable.
- */
- static std::string genLegacyID(const NamespaceString& nss, const BSONObj& o);
-
- /**
* Returns the BSON representation of the entry for a shard server's config.chunks.<epoch>
* collection.
*/
BSONObj toShardBSON() const;
- /**
- * Returns the _id that would be used for this chunk in binaries 4.2 and earlier.
- *
- * TODO SERVER-44034: Remove when 4.4 becomes last-stable.
- */
- std::string getLegacyName() const;
-
const OID& getName() const;
void setName(const OID& id);
diff --git a/src/mongo/s/catalog/type_chunk_test.cpp b/src/mongo/s/catalog/type_chunk_test.cpp
index aeabb3749c5..42f7b43264d 100644
--- a/src/mongo/s/catalog/type_chunk_test.cpp
+++ b/src/mongo/s/catalog/type_chunk_test.cpp
@@ -267,69 +267,5 @@ TEST(ChunkRange, MinGreaterThanMaxShouldError) {
ASSERT_EQ(ErrorCodes::FailedToParse, parseStatus.getStatus());
}
-// TODO SERVER-44034: Delete this test.
-TEST(ChunkType, FromConfigBSONParsesIgnores42_idFormat) {
- NamespaceString nss("test.mycol");
- auto minBound = BSON("a" << 10);
- ChunkVersion chunkVersion(1, 2, OID::gen());
-
- BSONObj obj = BSON("_id" << ChunkType::genLegacyID(nss, minBound) << ChunkType::ns(nss.ns())
- << ChunkType::min(minBound) << ChunkType::max(BSON("a" << 20))
- << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch"
- << chunkVersion.epoch() << ChunkType::shard("shard0001"));
-
- // Parsing will succeed despite the string _id.
- auto chunk = uassertStatusOK(ChunkType::fromConfigBSON(obj));
-
- // Attempting to get the 4.4 _id will throw since it hasn't been set.
- ASSERT_THROWS_CODE(chunk.getName(), AssertionException, 51264);
-}
-
-// TODO SERVER-44034: Delete this test.
-TEST(ChunkType, LegacyNameBSONFieldIs_id) {
- auto obj = BSON(ChunkType::legacyName("dummyId"));
- ASSERT_BSONOBJ_EQ(obj,
- BSON("_id"
- << "dummyId"));
-}
-
-// TODO SERVER-44034: Delete this test.
-TEST(ChunkType, GetLegacyNameAndGenLegacyIDReturn42_idFormat) {
- NamespaceString nss("test.mycol");
- auto minBound = BSON("a" << 10);
- ChunkVersion chunkVersion(1, 2, OID::gen());
-
- BSONObj obj =
- BSON(ChunkType::name(OID::gen())
- << ChunkType::ns(nss.ns()) << ChunkType::min(minBound)
- << ChunkType::max(BSON("a" << 20)) << "lastmod" << Timestamp(chunkVersion.toLong())
- << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001"));
- auto chunk = uassertStatusOK(ChunkType::fromConfigBSON(obj));
-
- ASSERT_EQ("test.mycol-a_10", ChunkType::genLegacyID(nss, minBound));
- ASSERT_EQ(ChunkType::genLegacyID(nss, minBound), chunk.getLegacyName());
-}
-
-// TODO SERVER-44034: Delete this test.
-TEST(ChunkType, ToConfigBSONLegacyIDUses42_idFormat) {
- NamespaceString nss("test.mycol");
- auto minBound = BSON("a" << 10);
- ChunkVersion chunkVersion(1, 2, OID::gen());
-
- BSONObj obj =
- BSON(ChunkType::name(OID::gen())
- << ChunkType::ns(nss.ns()) << ChunkType::min(minBound)
- << ChunkType::max(BSON("a" << 20)) << "lastmod" << Timestamp(chunkVersion.toLong())
- << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001"));
- auto chunk = uassertStatusOK(ChunkType::fromConfigBSON(obj));
-
- ASSERT_BSONOBJ_EQ(chunk.toConfigBSONLegacyID(),
- BSON("_id" << ChunkType::genLegacyID(nss, minBound)
- << ChunkType::ns("test.mycol") << ChunkType::min(minBound)
- << ChunkType::max(BSON("a" << 20)) << ChunkType::shard("shard0001")
- << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch"
- << chunkVersion.epoch()));
-}
-
} // namespace
} // namespace mongo
diff --git a/src/mongo/s/catalog/type_tags.cpp b/src/mongo/s/catalog/type_tags.cpp
index 9f21a2a5dfa..4f949c5b754 100644
--- a/src/mongo/s/catalog/type_tags.cpp
+++ b/src/mongo/s/catalog/type_tags.cpp
@@ -147,13 +147,6 @@ BSONObj TagsType::toBSON() const {
return builder.obj();
}
-BSONObj TagsType::toBSONLegacyID() const {
- // Note that toBSON() doesn't append an _id.
- BSONObjBuilder bob(toBSON());
- bob.append("_id", BSON(TagsType::ns(_ns->ns()) << TagsType::min(*_minKey)));
- return bob.obj();
-}
-
std::string TagsType::toString() const {
return toBSON().toString();
}
diff --git a/src/mongo/s/catalog/type_tags.h b/src/mongo/s/catalog/type_tags.h
index 6e1f3e33dc1..d69d9eeb057 100644
--- a/src/mongo/s/catalog/type_tags.h
+++ b/src/mongo/s/catalog/type_tags.h
@@ -81,14 +81,6 @@ public:
BSONObj toBSON() const;
/**
- * Returns the BSON representation of the tag with an _id in the format expected by binaries 4.2
- * and below.
- *
- * TODO SERVER-44034: Remove this method.
- */
- BSONObj toBSONLegacyID() const;
-
- /**
* Returns a std::string representation of the current internal state.
*/
std::string toString() const;
diff --git a/src/mongo/s/catalog/type_tags_test.cpp b/src/mongo/s/catalog/type_tags_test.cpp
index e78f6eedeea..1cd8ed6d276 100644
--- a/src/mongo/s/catalog/type_tags_test.cpp
+++ b/src/mongo/s/catalog/type_tags_test.cpp
@@ -129,18 +129,4 @@ TEST(TagsType, BadType) {
ASSERT_EQUALS(ErrorCodes::NoSuchKey, status.getStatus());
}
-TEST(TagsType, ToBSONLegacyID) {
- BSONObj obj =
- BSON(TagsType::ns("test.mycol") << TagsType::tag("tag") << TagsType::min(BSON("a" << 10))
- << TagsType::max(BSON("a" << 20)));
-
- auto tag = uassertStatusOK(TagsType::fromBSON(obj));
-
- ASSERT_BSONOBJ_EQ(tag.toBSONLegacyID(),
- BSON(TagsType::ns("test.mycol")
- << TagsType::tag("tag") << TagsType::min(BSON("a" << 10))
- << TagsType::max(BSON("a" << 20)) << "_id"
- << BSON(TagsType::ns("test.mycol") << TagsType::min(BSON("a" << 10)))));
-}
-
} // namespace