1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
/**
* Copyright (C) 2018-present MongoDB, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*
* As a special exception, the copyright holders give permission to link the
* code of portions of this program with the OpenSSL library under certain
* conditions as described in each individual source file and distribute
* linked combinations including the program with the OpenSSL library. You
* must comply with the Server Side Public License in all respects for
* all of the code used other than as permitted herein. If you modify file(s)
* with this exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do so,
* delete this exception statement from your version. If you delete this
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
#include "mongo/platform/basic.h"
#include <boost/optional/optional_io.hpp>
#include "mongo/db/s/shard_server_catalog_cache_loader.h"
#include "mongo/db/s/shard_server_test_fixture.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/catalog_cache_loader_mock.h"
#include "mongo/s/type_collection_common_types_gen.h"
namespace mongo {
namespace {
using executor::RemoteCommandRequest;
using executor::RemoteCommandResponse;
using std::vector;
using unittest::assertGet;
using CollectionAndChangedChunks = CatalogCacheLoader::CollectionAndChangedChunks;
const NamespaceString kNss = NamespaceString("foo.bar");
const std::string kPattern = "_id";
const ShardId kShardId = ShardId("shard0");
class ShardServerCatalogCacheLoaderTest : public ShardServerTestFixture {
public:
/**
* Returns five chunks using collVersion as a starting version.
*/
vector<ChunkType> makeFiveChunks(const ChunkVersion& collectionVersion);
/**
* Returns a chunk update diff GTE 'collVersion' for the chunks created by makeFiveChunks above.
*/
vector<ChunkType> makeThreeUpdatedChunksDiff(const ChunkVersion& collectionVersion);
/**
* Returns a routing table applying 'threeUpdatedChunks' (the result of
* makeThreeUpdatedChunksDiff) to 'originalFiveChunks' (the result of makeFiveChunks).
*/
vector<ChunkType> makeCombinedOriginalFiveChunksAndThreeNewChunksDiff(
const vector<ChunkType>& originalFiveChunks, const vector<ChunkType>& threeUpdatedChunks);
/**
* This helper makes a CollectionType with the current _maxCollVersion.
*/
CollectionType makeCollectionType(const ChunkVersion& collVersion);
/**
* Sets up the _shardLoader with the results of makeFiveChunks().
*/
std::pair<CollectionType, vector<ChunkType>> setUpChunkLoaderWithFiveChunks();
void refreshCollectionEpochOnRemoteLoader();
const KeyPattern kKeyPattern = KeyPattern(BSON(kPattern << 1));
CatalogCacheLoaderMock* _remoteLoaderMock;
std::unique_ptr<ShardServerCatalogCacheLoader> _shardLoader;
private:
void setUp() override;
void tearDown() override;
};
void ShardServerCatalogCacheLoaderTest::setUp() {
ShardServerTestFixture::setUp();
// Create mock remote and real shard loader, retaining a pointer to the mock remote loader so
// that unit tests can manipulate it to return certain responses.
auto mockLoader = std::make_unique<CatalogCacheLoaderMock>();
_remoteLoaderMock = mockLoader.get();
_shardLoader = std::make_unique<ShardServerCatalogCacheLoader>(std::move(mockLoader));
// Set the shard loader to primary mode, and set it for testing.
_shardLoader->initializeReplicaSetRole(true);
}
void ShardServerCatalogCacheLoaderTest::tearDown() {
_shardLoader->shutDown();
_shardLoader.reset();
ShardServerTestFixture::tearDown();
}
vector<ChunkType> ShardServerCatalogCacheLoaderTest::makeFiveChunks(
const ChunkVersion& collectionVersion) {
ChunkVersion collVersion(collectionVersion);
vector<ChunkType> chunks;
const UUID uuid = UUID::gen();
BSONObj mins[] = {
BSON("a" << MINKEY), BSON("a" << 10), BSON("a" << 50), BSON("a" << 100), BSON("a" << 200)};
BSONObj maxs[] = {
BSON("a" << 10), BSON("a" << 50), BSON("a" << 100), BSON("a" << 200), BSON("a" << MAXKEY)};
for (int i = 0; i < 5; ++i) {
collVersion.incMajor();
ChunkType chunk;
chunk.setCollectionUUID(uuid);
chunk.setMin(mins[i]);
chunk.setMax(maxs[i]);
chunk.setShard(kShardId);
chunk.setVersion(collVersion);
chunks.push_back(chunk);
}
return chunks;
}
vector<ChunkType> ShardServerCatalogCacheLoaderTest::makeThreeUpdatedChunksDiff(
const ChunkVersion& collectionVersion) {
ChunkVersion collVersion(collectionVersion);
vector<ChunkType> chunks;
const UUID uuid = UUID::gen();
// The diff query is for GTE a known version, so prepend the previous newest chunk, which is
// unmodified by this change and so should be found. Note: it is important for testing that the
// previous highest versioned chunk is unmodified. Otherwise the shard loader's results are
// dependent on a race between persistence and retrieving data because it combines enqueued and
// persisted results without applying modifications.
ChunkType oldChunk;
oldChunk.setCollectionUUID(uuid);
oldChunk.setMin(BSON("a" << 200));
oldChunk.setMax(BSON("a" << MAXKEY));
oldChunk.setShard(kShardId);
oldChunk.setVersion(collVersion);
chunks.push_back(oldChunk);
// Make chunk updates
BSONObj mins[] = {BSON("a" << MINKEY), BSON("a" << 5), BSON("a" << 10)};
BSONObj maxs[] = {BSON("a" << 5), BSON("a" << 10), BSON("a" << 100)};
for (int i = 0; i < 3; ++i) {
collVersion.incMinor();
ChunkType chunk;
chunk.setCollectionUUID(uuid);
chunk.setMin(mins[i]);
chunk.setMax(maxs[i]);
chunk.setShard(kShardId);
chunk.setVersion(collVersion);
chunks.push_back(chunk);
}
return chunks;
}
vector<ChunkType>
ShardServerCatalogCacheLoaderTest::makeCombinedOriginalFiveChunksAndThreeNewChunksDiff(
const vector<ChunkType>& originalFiveChunks, const vector<ChunkType>& threeUpdatedChunksDiff) {
vector<ChunkType> chunks;
// Sorted by ascending chunk version, not range! Note, threeUpdatedChunksDiff already includes
// the last originalFiveChunks chunk because the diff query is GTE.
chunks.push_back(originalFiveChunks[3]);
chunks.insert(chunks.end(), threeUpdatedChunksDiff.begin(), threeUpdatedChunksDiff.end());
return chunks;
}
CollectionType ShardServerCatalogCacheLoaderTest::makeCollectionType(
const ChunkVersion& collVersion) {
CollectionType coll(
kNss, collVersion.epoch(), collVersion.getTimestamp(), Date_t::now(), UUID::gen());
coll.setKeyPattern(kKeyPattern);
coll.setUnique(false);
return coll;
}
std::pair<CollectionType, vector<ChunkType>>
ShardServerCatalogCacheLoaderTest::setUpChunkLoaderWithFiveChunks() {
ChunkVersion collectionVersion(1, 0, OID::gen(), Timestamp(1, 1));
CollectionType collectionType = makeCollectionType(collectionVersion);
vector<ChunkType> chunks = makeFiveChunks(collectionVersion);
_remoteLoaderMock->setCollectionRefreshReturnValue(collectionType);
_remoteLoaderMock->setChunkRefreshReturnValue(chunks);
auto collAndChunksRes = _shardLoader->getChunksSince(kNss, ChunkVersion::UNSHARDED()).get();
ASSERT_EQUALS(collAndChunksRes.epoch, collectionType.getEpoch());
ASSERT_EQUALS(collAndChunksRes.changedChunks.size(), 5UL);
ASSERT(!collAndChunksRes.timeseriesFields.is_initialized());
for (unsigned int i = 0; i < collAndChunksRes.changedChunks.size(); ++i) {
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks[i].toShardBSON(), chunks[i].toShardBSON());
}
return std::pair{collectionType, std::move(chunks)};
}
TEST_F(ShardServerCatalogCacheLoaderTest, PrimaryLoadFromUnshardedToUnsharded) {
// Return a NamespaceNotFound error that means the collection doesn't exist.
Status errorStatus = Status(ErrorCodes::NamespaceNotFound, "collection not found");
_remoteLoaderMock->setCollectionRefreshReturnValue(errorStatus);
ASSERT_THROWS_CODE_AND_WHAT(_shardLoader->getChunksSince(kNss, ChunkVersion::UNSHARDED()).get(),
DBException,
errorStatus.code(),
errorStatus.reason());
}
TEST_F(ShardServerCatalogCacheLoaderTest, PrimaryLoadFromShardedToUnsharded) {
// First set up the shard chunk loader as sharded.
auto collAndChunks = setUpChunkLoaderWithFiveChunks();
auto& chunks = collAndChunks.second;
// Then return a NamespaceNotFound error, which means the collection must have been dropped,
// clearing the chunk metadata.
Status errorStatus = Status(ErrorCodes::NamespaceNotFound, "collection not found");
_remoteLoaderMock->setCollectionRefreshReturnValue(errorStatus);
ASSERT_THROWS_CODE_AND_WHAT(
_shardLoader->getChunksSince(kNss, chunks.back().getVersion()).get(),
DBException,
errorStatus.code(),
errorStatus.reason());
}
TEST_F(ShardServerCatalogCacheLoaderTest, PrimaryLoadFromShardedAndFindNoDiff) {
// First set up the shard chunk loader as sharded.
auto collAndChunks = setUpChunkLoaderWithFiveChunks();
auto& chunks = collAndChunks.second;
// Then set up the remote loader to return a single document we've already seen -- indicates
// there's nothing new.
vector<ChunkType> lastChunk;
lastChunk.push_back(chunks.back());
_remoteLoaderMock->setChunkRefreshReturnValue(lastChunk);
auto collAndChunksRes = _shardLoader->getChunksSince(kNss, chunks.back().getVersion()).get();
// Check that refreshing from the latest version returned a single document matching that
// version.
ASSERT_EQUALS(collAndChunksRes.epoch, chunks.back().getVersion().epoch());
ASSERT_EQUALS(collAndChunksRes.changedChunks.size(), 1UL);
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks.back().toShardBSON(),
chunks.back().toShardBSON());
}
// Same as the above unit test, PrimaryLoadFromShardedAndFindNoDiff, but caller requests complete
// routing table, rather than diff from a known version.
TEST_F(ShardServerCatalogCacheLoaderTest, PrimaryLoadFromShardedAndFindNoDiffRequestAll) {
// First set up the shard chunk loader as sharded.
auto collAndChunks = setUpChunkLoaderWithFiveChunks();
auto& chunks = collAndChunks.second;
// Then set up the remote loader to return a single document we've already seen -- indicates
// there's nothing new.
vector<ChunkType> lastChunk;
lastChunk.push_back(chunks.back());
_remoteLoaderMock->setChunkRefreshReturnValue(lastChunk);
auto collAndChunksRes = _shardLoader->getChunksSince(kNss, ChunkVersion::UNSHARDED()).get();
ASSERT_EQUALS(collAndChunksRes.epoch, chunks.back().getVersion().epoch());
ASSERT_EQUALS(collAndChunksRes.changedChunks.size(), 5UL);
for (unsigned int i = 0; i < collAndChunksRes.changedChunks.size(); ++i) {
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks[i].getMin(), chunks[i].getMin());
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks[i].getMax(), chunks[i].getMax());
ASSERT_EQUALS(collAndChunksRes.changedChunks[i].getVersion(), chunks[i].getVersion());
}
}
TEST_F(ShardServerCatalogCacheLoaderTest, PrimaryLoadFromShardedAndFindDiff) {
// First set up the shard chunk loader as sharded.
auto collAndChunks = setUpChunkLoaderWithFiveChunks();
auto& chunks = collAndChunks.second;
// Then refresh again and find updated chunks.
ChunkVersion collVersion = chunks.back().getVersion();
vector<ChunkType> updatedChunksDiff = makeThreeUpdatedChunksDiff(collVersion);
_remoteLoaderMock->setChunkRefreshReturnValue(updatedChunksDiff);
auto collAndChunksRes = _shardLoader->getChunksSince(kNss, chunks.back().getVersion()).get();
// Check that the diff was returned successfull.
ASSERT_EQUALS(collAndChunksRes.epoch, updatedChunksDiff.front().getVersion().epoch());
ASSERT_EQUALS(collAndChunksRes.changedChunks.size(), 4UL);
for (unsigned int i = 0; i < collAndChunksRes.changedChunks.size(); ++i) {
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks[i].getMin(),
updatedChunksDiff[i].getMin());
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks[i].getMax(),
updatedChunksDiff[i].getMax());
ASSERT_EQUALS(collAndChunksRes.changedChunks[i].getVersion(),
updatedChunksDiff[i].getVersion());
}
}
TEST_F(ShardServerCatalogCacheLoaderTest, PrimaryLoadFromShardedAndFindDiffRequestAll) {
// First set up the shard chunk loader as sharded.
auto collAndChunks = setUpChunkLoaderWithFiveChunks();
auto& chunks = collAndChunks.second;
// First cause a remote refresh to find the updated chunks. Then wait for persistence, so that
// we ensure that nothing is enqueued and the next getChunksSince call will return a predictable
// number of chunk documents: the result of applying the enqueued update diff.
vector<ChunkType> updatedChunksDiff = makeThreeUpdatedChunksDiff(chunks.back().getVersion());
_remoteLoaderMock->setChunkRefreshReturnValue(updatedChunksDiff);
_shardLoader->getChunksSince(kNss, chunks.back().getVersion()).get();
// Wait for persistence of update
_shardLoader->waitForCollectionFlush(operationContext(), kNss);
// Set up the remote loader to return a single document we've already seen, indicating no change
// occurred.
vector<ChunkType> lastChunk;
lastChunk.push_back(updatedChunksDiff.back());
_remoteLoaderMock->setChunkRefreshReturnValue(lastChunk);
vector<ChunkType> completeRoutingTableWithDiffApplied =
makeCombinedOriginalFiveChunksAndThreeNewChunksDiff(chunks, updatedChunksDiff);
auto collAndChunksRes = _shardLoader->getChunksSince(kNss, ChunkVersion::UNSHARDED()).get();
ASSERT_EQUALS(collAndChunksRes.epoch,
completeRoutingTableWithDiffApplied.front().getVersion().epoch());
ASSERT_EQUALS(collAndChunksRes.changedChunks.size(), 5UL);
for (unsigned int i = 0; i < collAndChunksRes.changedChunks.size(); ++i) {
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks[i].getMin(),
completeRoutingTableWithDiffApplied[i].getMin());
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks[i].getMax(),
completeRoutingTableWithDiffApplied[i].getMax());
ASSERT_EQUALS(collAndChunksRes.changedChunks[i].getVersion(),
completeRoutingTableWithDiffApplied[i].getVersion());
}
}
TEST_F(ShardServerCatalogCacheLoaderTest, PrimaryLoadFromShardedAndFindNewEpoch) {
// First set up the shard chunk loader as sharded.
auto collAndChunks = setUpChunkLoaderWithFiveChunks();
auto& chunks = collAndChunks.second;
// Then refresh again and find that the collection has been dropped and recreated.
ChunkVersion collVersionWithNewEpoch(1, 0, OID::gen(), Timestamp(2, 0));
CollectionType collectionTypeWithNewEpoch = makeCollectionType(collVersionWithNewEpoch);
vector<ChunkType> chunksWithNewEpoch = makeFiveChunks(collVersionWithNewEpoch);
_remoteLoaderMock->setCollectionRefreshReturnValue(collectionTypeWithNewEpoch);
_remoteLoaderMock->setChunkRefreshReturnValue(chunksWithNewEpoch);
auto collAndChunksRes = _shardLoader->getChunksSince(kNss, chunks.back().getVersion()).get();
ASSERT_EQUALS(collAndChunksRes.epoch, collectionTypeWithNewEpoch.getEpoch());
ASSERT_EQUALS(collAndChunksRes.changedChunks.size(), 5UL);
for (unsigned int i = 0; i < collAndChunksRes.changedChunks.size(); ++i) {
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks[i].getMin(),
chunksWithNewEpoch[i].getMin());
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks[i].getMax(),
chunksWithNewEpoch[i].getMax());
ASSERT_EQUALS(collAndChunksRes.changedChunks[i].getVersion(),
chunksWithNewEpoch[i].getVersion());
}
}
TEST_F(ShardServerCatalogCacheLoaderTest, PrimaryLoadFromShardedAndFindMixedChunkVersions) {
// First set up the shard chunk loader as sharded.
auto collAndChunks = setUpChunkLoaderWithFiveChunks();
auto& chunks = collAndChunks.second;
// Then refresh again and retrieve chunks from the config server that have mixed epoches, like
// as if the chunks read yielded around a drop and recreate of the collection.
ChunkVersion collVersionWithNewEpoch(1, 0, OID::gen(), Timestamp(2, 0));
CollectionType collectionTypeWithNewEpoch = makeCollectionType(collVersionWithNewEpoch);
vector<ChunkType> chunksWithNewEpoch = makeFiveChunks(collVersionWithNewEpoch);
vector<ChunkType> mixedChunks;
mixedChunks.push_back(chunks.back());
mixedChunks.insert(mixedChunks.end(), chunksWithNewEpoch.begin(), chunksWithNewEpoch.end());
_remoteLoaderMock->setChunkRefreshReturnValue(mixedChunks);
ASSERT_THROWS_CODE(_shardLoader->getChunksSince(kNss, chunks.back().getVersion()).get(),
DBException,
ErrorCodes::ConflictingOperationInProgress);
// Now make sure the newly recreated collection is cleanly loaded. We cannot ensure a
// non-variable response until the loader has remotely retrieved the new metadata and applied
// them to the persisted store. So first do a reload and ignore the results. Then call again,
// this time checking the results.
_remoteLoaderMock->setCollectionRefreshReturnValue(collectionTypeWithNewEpoch);
_remoteLoaderMock->setChunkRefreshReturnValue(chunksWithNewEpoch);
_shardLoader->getChunksSince(kNss, chunks.back().getVersion()).get();
// Wait for persistence of update.
_shardLoader->waitForCollectionFlush(operationContext(), kNss);
vector<ChunkType> lastChunkWithNewEpoch;
lastChunkWithNewEpoch.push_back(chunksWithNewEpoch.back());
_remoteLoaderMock->setChunkRefreshReturnValue(lastChunkWithNewEpoch);
auto collAndChunksRes = _shardLoader->getChunksSince(kNss, ChunkVersion::UNSHARDED()).get();
ASSERT_EQUALS(collAndChunksRes.epoch, collectionTypeWithNewEpoch.getEpoch());
ASSERT_EQUALS(collAndChunksRes.changedChunks.size(), 5UL);
for (unsigned int i = 0; i < collAndChunksRes.changedChunks.size(); ++i) {
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks[i].getMin(),
chunksWithNewEpoch[i].getMin());
ASSERT_BSONOBJ_EQ(collAndChunksRes.changedChunks[i].getMax(),
chunksWithNewEpoch[i].getMax());
ASSERT_EQUALS(collAndChunksRes.changedChunks[i].getVersion(),
chunksWithNewEpoch[i].getVersion());
}
}
TEST_F(ShardServerCatalogCacheLoaderTest, TimeseriesFieldsAreProperlyPropagatedOnSSCCL) {
ChunkVersion collectionVersion(1, 0, OID::gen(), Timestamp(1, 1));
CollectionType collectionType = makeCollectionType(collectionVersion);
vector<ChunkType> chunks = makeFiveChunks(collectionVersion);
auto timeseriesOptions = TimeseriesOptions("fieldName");
{
TypeCollectionTimeseriesFields tsFields;
tsFields.setTimeseriesOptions(timeseriesOptions);
collectionType.setTimeseriesFields(tsFields);
_remoteLoaderMock->setCollectionRefreshReturnValue(collectionType);
_remoteLoaderMock->setChunkRefreshReturnValue(chunks);
auto collAndChunksRes = _shardLoader->getChunksSince(kNss, ChunkVersion::UNSHARDED()).get();
ASSERT(collAndChunksRes.timeseriesFields.is_initialized());
ASSERT(collAndChunksRes.timeseriesFields->getGranularity() ==
BucketGranularityEnum::Seconds);
}
{
auto& lastChunk = chunks.back();
const auto maxLoaderVersion = lastChunk.getVersion();
ChunkVersion newCollectionVersion = maxLoaderVersion;
newCollectionVersion.incMinor();
lastChunk.setVersion(newCollectionVersion);
TypeCollectionTimeseriesFields tsFields;
timeseriesOptions.setGranularity(BucketGranularityEnum::Hours);
tsFields.setTimeseriesOptions(timeseriesOptions);
collectionType.setTimeseriesFields(tsFields);
_remoteLoaderMock->setCollectionRefreshReturnValue(collectionType);
_remoteLoaderMock->setChunkRefreshReturnValue(std::vector{lastChunk});
auto collAndChunksRes = _shardLoader->getChunksSince(kNss, maxLoaderVersion).get();
ASSERT(collAndChunksRes.timeseriesFields.is_initialized());
ASSERT(collAndChunksRes.timeseriesFields->getGranularity() == BucketGranularityEnum::Hours);
}
}
void ShardServerCatalogCacheLoaderTest::refreshCollectionEpochOnRemoteLoader() {
ChunkVersion collectionVersion(1, 2, OID::gen(), Timestamp(1, 1));
CollectionType collectionType = makeCollectionType(collectionVersion);
vector<ChunkType> chunks = makeFiveChunks(collectionVersion);
_remoteLoaderMock->setCollectionRefreshReturnValue(collectionType);
_remoteLoaderMock->setChunkRefreshReturnValue(chunks);
}
TEST_F(ShardServerCatalogCacheLoaderTest, CollAndChunkTasksConsistency) {
// Put some metadata in the persisted cache (config.cache.chunks.*)
refreshCollectionEpochOnRemoteLoader();
_shardLoader->getChunksSince(kNss, ChunkVersion::UNSHARDED()).get();
_shardLoader->waitForCollectionFlush(operationContext(), kNss);
// Pause the thread processing the pending updates on metadata
FailPointEnableBlock failPoint("hangCollectionFlush");
// Put a first task in the list of pending updates on metadata (in-memory)
refreshCollectionEpochOnRemoteLoader();
_shardLoader->getChunksSince(kNss, ChunkVersion::UNSHARDED()).get();
// Bump the shard's term
_shardLoader->onStepUp();
// Putting a second task causes a verification of the contiguous versions in the list pending
// updates on metadata
refreshCollectionEpochOnRemoteLoader();
_shardLoader->getChunksSince(kNss, ChunkVersion::UNSHARDED()).get();
}
} // namespace
} // namespace mongo
|