diff options
author | Sergi Mateo Bellido <sergi.mateo-bellido@mongodb.com> | 2021-06-01 06:48:00 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-14 17:18:34 +0000 |
commit | e7f91b95941b2e636ba4715c2cea5baf5bc3e2d2 (patch) | |
tree | 6d823474977fe3bb42b0b451b8b922fef5946b10 /src/mongo/s/catalog/type_chunk_test.cpp | |
parent | 389ecf35aa15a97a3bf855518c19a4ad05075acb (diff) | |
download | mongo-e7f91b95941b2e636ba4715c2cea5baf5bc3e2d2.tar.gz |
SERVER-57313 Pass the collection epoch and timestamp when building a ChunkType from a config.chunks BSON
- Pass the epoch and the timestamp to the functions that build
ChunkTypes from config.chunks BSON
- Fixing our tests
(cherry picked from commit 7b30ab1943ecbb48e8bdbc50bf928eab09f619b5)
Diffstat (limited to 'src/mongo/s/catalog/type_chunk_test.cpp')
-rw-r--r-- | src/mongo/s/catalog/type_chunk_test.cpp | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/src/mongo/s/catalog/type_chunk_test.cpp b/src/mongo/s/catalog/type_chunk_test.cpp index 38de85bba2c..0e2fe0d0eda 100644 --- a/src/mongo/s/catalog/type_chunk_test.cpp +++ b/src/mongo/s/catalog/type_chunk_test.cpp @@ -47,21 +47,24 @@ const BSONObj kMax = BSON("a" << 20); const ShardId kShard("shard0000"); TEST(ChunkType, MissingConfigRequiredFields) { - ChunkVersion chunkVersion(1, 2, OID::gen(), boost::none /* timestamp */); + const auto collEpoch = OID::gen(); + const auto collTimestamp = boost::none; + + ChunkVersion chunkVersion(1, 2, collEpoch, collTimestamp); BSONObj objModNS = BSON(ChunkType::name(OID::gen()) << ChunkType::min(BSON("a" << 10 << "b" << 10)) << ChunkType::max(BSON("a" << 20)) << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001")); - StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(objModNS); + StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(objModNS, collEpoch, collTimestamp); ASSERT_FALSE(chunkRes.isOK()); BSONObj objModKeys = BSON(ChunkType::name(OID::gen()) << ChunkType::ns("test.mycol") << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001")); - chunkRes = ChunkType::fromConfigBSON(objModKeys); + chunkRes = ChunkType::fromConfigBSON(objModKeys, collEpoch, collTimestamp); ASSERT_FALSE(chunkRes.isOK()); BSONObj objModShard = @@ -69,14 +72,14 @@ TEST(ChunkType, MissingConfigRequiredFields) { << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 10 << "b" << 10)) << ChunkType::max(BSON("a" << 20)) << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch" << chunkVersion.epoch()); - chunkRes = ChunkType::fromConfigBSON(objModShard); + chunkRes = ChunkType::fromConfigBSON(objModShard, collEpoch, collTimestamp); ASSERT_FALSE(chunkRes.isOK()); BSONObj objModVersion = BSON(ChunkType::name(OID::gen()) << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 10 << "b" << 10)) << ChunkType::max(BSON("a" << 20)) << ChunkType::shard("shard0001")); - chunkRes = ChunkType::fromConfigBSON(objModVersion); + chunkRes = ChunkType::fromConfigBSON(objModVersion, collEpoch, collTimestamp); ASSERT_FALSE(chunkRes.isOK()); } @@ -130,49 +133,61 @@ TEST(ChunkType, ToFromShardBSON) { } TEST(ChunkType, MinAndMaxShardKeysDifferInNumberOfKeys) { - ChunkVersion chunkVersion(1, 2, OID::gen(), boost::none /* timestamp */); + const auto collEpoch = OID::gen(); + const auto collTimestamp = boost::none; + + ChunkVersion chunkVersion(1, 2, collEpoch, collTimestamp); BSONObj obj = BSON(ChunkType::name(OID::gen()) << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 10 << "b" << 10)) << ChunkType::max(BSON("a" << 20)) << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001")); - StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj); + StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj, collEpoch, collTimestamp); ASSERT_OK(chunkRes.getStatus()); ASSERT_FALSE(chunkRes.getValue().validate().isOK()); } TEST(ChunkType, MinAndMaxShardKeysDifferInKeyNames) { - ChunkVersion chunkVersion(1, 2, OID::gen(), boost::none /* timestamp */); + const auto collEpoch = OID::gen(); + const auto collTimestamp = boost::none; + + ChunkVersion chunkVersion(1, 2, collEpoch, collTimestamp); BSONObj obj = BSON(ChunkType::name(OID::gen()) << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 10)) << ChunkType::max(BSON("b" << 20)) << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001")); - StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj); + StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj, collEpoch, collTimestamp); ASSERT_OK(chunkRes.getStatus()); ASSERT_FALSE(chunkRes.getValue().validate().isOK()); } TEST(ChunkType, MinToMaxNotAscending) { - ChunkVersion chunkVersion(1, 2, OID::gen(), boost::none /* timestamp */); + const auto collEpoch = OID::gen(); + const auto collTimestamp = boost::none; + + ChunkVersion chunkVersion(1, 2, collEpoch, collTimestamp); BSONObj obj = BSON(ChunkType::name(OID::gen()) << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 20)) << ChunkType::max(BSON("a" << 10)) << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001")); - StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj); + StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj, collEpoch, collTimestamp); ASSERT_EQ(ErrorCodes::FailedToParse, chunkRes.getStatus()); } TEST(ChunkType, ToFromConfigBSON) { + const auto collEpoch = OID::gen(); + const auto collTimestamp = boost::none; + const auto chunkID = OID::gen(); - ChunkVersion chunkVersion(1, 2, OID::gen(), boost::none /* timestamp */); + ChunkVersion chunkVersion(1, 2, collEpoch, collTimestamp); BSONObj obj = BSON(ChunkType::name(chunkID) << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 10)) << ChunkType::max(BSON("a" << 20)) << ChunkType::shard("shard0001") << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch" << chunkVersion.epoch()); - StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj); + StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj, collEpoch, collTimestamp); ASSERT_OK(chunkRes.getStatus()); ChunkType chunk = chunkRes.getValue(); @@ -189,13 +204,19 @@ TEST(ChunkType, ToFromConfigBSON) { } TEST(ChunkType, BadType) { + const auto collEpoch = OID::gen(); + const auto collTimestamp = boost::none; + BSONObj obj = BSON(ChunkType::name() << 0); - StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj); + StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj, collEpoch, collTimestamp); ASSERT_FALSE(chunkRes.isOK()); } TEST(ChunkType, BothNsAndUUID) { - ChunkVersion chunkVersion(1, 2, OID::gen(), boost::none /* timestamp */); + const auto collEpoch = OID::gen(); + const auto collTimestamp = boost::none; + + ChunkVersion chunkVersion(1, 2, collEpoch, collTimestamp); BSONObj objModNS = BSON(ChunkType::name(OID::gen()) @@ -203,12 +224,15 @@ TEST(ChunkType, BothNsAndUUID) { << ChunkType::min(BSON("a" << 10 << "b" << 10)) << ChunkType::max(BSON("a" << 20)) << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001")); - StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(objModNS); + StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(objModNS, collEpoch, collTimestamp); ASSERT_TRUE(chunkRes.isOK()); } TEST(ChunkType, UUIDPresentAndNsMissing) { - ChunkVersion chunkVersion(1, 2, OID::gen(), boost::none /* timestamp */); + const auto collEpoch = OID::gen(); + const auto collTimestamp = boost::none; + + ChunkVersion chunkVersion(1, 2, collEpoch, collTimestamp); BSONObj objModNS = BSON(ChunkType::name(OID::gen()) @@ -216,7 +240,7 @@ TEST(ChunkType, UUIDPresentAndNsMissing) { << ChunkType::min(BSON("a" << 10 << "b" << 10)) << ChunkType::max(BSON("a" << 20)) << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001")); - StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(objModNS); + StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(objModNS, collEpoch, collTimestamp); ASSERT_TRUE(chunkRes.isOK()); } |