summaryrefslogtreecommitdiff
path: root/src/mongo/s/catalog_cache_test_fixture.cpp
diff options
context:
space:
mode:
authorJordi Serra Torrens <jordi.serra-torrens@mongodb.com>2021-02-24 08:53:55 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-03-08 17:21:27 +0000
commitdc009c5a8d484f6a0db2f357274e14e30ea9f476 (patch)
treed36f970ae4e8604f25809d6133058fd823005a75 /src/mongo/s/catalog_cache_test_fixture.cpp
parent931b53d712eaeaec29653799722127983687c284 (diff)
downloadmongo-dc009c5a8d484f6a0db2f357274e14e30ea9f476.tar.gz
SERVER-54874: Ensure reading consistent config.collections and config.chunks when refreshing the CatalogCache
Diffstat (limited to 'src/mongo/s/catalog_cache_test_fixture.cpp')
-rw-r--r--src/mongo/s/catalog_cache_test_fixture.cpp45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/mongo/s/catalog_cache_test_fixture.cpp b/src/mongo/s/catalog_cache_test_fixture.cpp
index 0bb9c38ce9c..5154f98d3ed 100644
--- a/src/mongo/s/catalog_cache_test_fixture.cpp
+++ b/src/mongo/s/catalog_cache_test_fixture.cpp
@@ -180,8 +180,16 @@ ChunkManager CatalogCacheTestFixture::makeChunkManager(
auto future = scheduleRoutingInfoUnforcedRefresh(nss);
expectFindSendBSONObjVector(kConfigHostAndPort, {databaseBSON});
- expectFindSendBSONObjVector(kConfigHostAndPort, {collectionBSON});
- expectFindSendBSONObjVector(kConfigHostAndPort, initialChunks);
+ expectFindSendBSONObjVector(kConfigHostAndPort, [&]() {
+ std::vector<BSONObj> aggResult;
+ std::transform(initialChunks.begin(),
+ initialChunks.end(),
+ std::back_inserter(aggResult),
+ [&collectionBSON](const auto& chunk) {
+ return collectionBSON.addFields(BSON("chunks" << chunk));
+ });
+ return aggResult;
+ }());
return *future.default_timed_get();
}
@@ -205,6 +213,29 @@ void CatalogCacheTestFixture::expectGetCollection(NamespaceString nss,
}());
}
+void CatalogCacheTestFixture::expectCollectionAndChunksAggregation(
+ NamespaceString nss,
+ OID epoch,
+ UUID uuid,
+ const ShardKeyPattern& shardKeyPattern,
+ const std::vector<ChunkType>& chunks) {
+ expectFindSendBSONObjVector(kConfigHostAndPort, [&]() {
+ CollectionType collType(nss, epoch, Date_t::now(), uuid);
+ collType.setKeyPattern(shardKeyPattern.toBSON());
+ collType.setUnique(false);
+ const auto collObj = collType.toBSON();
+
+ std::vector<BSONObj> aggResult;
+ std::transform(chunks.begin(),
+ chunks.end(),
+ std::back_inserter(aggResult),
+ [&collObj](const auto& chunk) {
+ return collObj.addFields(BSON("chunks" << chunk.toConfigBSON()));
+ });
+ return aggResult;
+ }());
+}
+
ChunkManager CatalogCacheTestFixture::loadRoutingTableWithTwoChunksAndTwoShards(
NamespaceString nss) {
@@ -237,8 +268,11 @@ ChunkManager CatalogCacheTestFixture::loadRoutingTableWithTwoChunksAndTwoShardsI
expectGetDatabase(nss);
}
}
- expectGetCollection(nss, epoch, uuid, shardKeyPattern);
expectFindSendBSONObjVector(kConfigHostAndPort, [&]() {
+ CollectionType collType(nss, epoch, Date_t::now(), uuid);
+ collType.setKeyPattern(shardKeyPattern.toBSON());
+ collType.setUnique(false);
+
ChunkVersion version(1, 0, epoch, boost::none /* timestamp */);
ChunkType chunk1(
@@ -251,7 +285,10 @@ ChunkManager CatalogCacheTestFixture::loadRoutingTableWithTwoChunksAndTwoShardsI
chunk2.setName(OID::gen());
version.incMinor();
- return std::vector<BSONObj>{chunk1.toConfigBSON(), chunk2.toConfigBSON()};
+ const auto collObj = collType.toBSON();
+ const auto chunk1Obj = collObj.addFields(BSON("chunks" << chunk1.toConfigBSON()));
+ const auto chunk2Obj = collObj.addFields(BSON("chunks" << chunk2.toConfigBSON()));
+ return std::vector<BSONObj>{chunk1Obj, chunk2Obj};
}());
return *future.default_timed_get();