summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergi Mateo Bellido <sergi.mateo-bellido@mongodb.com>2021-10-04 09:36:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-04 10:31:15 +0000
commitf4aa2b0e25976facd7bda02872e2a46205975dcc (patch)
tree57c4217814fcaee99b02d5dbcb3843e9088f64f2
parent3008af2319af2098f4691612f31a431c52ccc52c (diff)
downloadmongo-f4aa2b0e25976facd7bda02872e2a46205975dcc.tar.gz
SERVER-60385 Timeseries fields aren't immutable anymore
-rw-r--r--src/mongo/db/s/metadata_manager_test.cpp3
-rw-r--r--src/mongo/s/catalog_cache.cpp3
-rw-r--r--src/mongo/s/catalog_cache_test.cpp53
-rw-r--r--src/mongo/s/chunk_manager.cpp3
-rw-r--r--src/mongo/s/chunk_manager.h10
-rw-r--r--src/mongo/s/chunk_manager_query_test.cpp11
-rw-r--r--src/mongo/s/chunk_manager_refresh_bm.cpp2
-rw-r--r--src/mongo/s/routing_table_history_test.cpp24
8 files changed, 78 insertions, 31 deletions
diff --git a/src/mongo/db/s/metadata_manager_test.cpp b/src/mongo/db/s/metadata_manager_test.cpp
index 948821e2f91..9af8c48a5bf 100644
--- a/src/mongo/db/s/metadata_manager_test.cpp
+++ b/src/mongo/db/s/metadata_manager_test.cpp
@@ -142,7 +142,7 @@ protected:
kOtherShard);
auto rt = cm->getRoutingTableHistory_ForTest().makeUpdated(
- boost::none, boost::none, true, splitChunks);
+ boost::none /* timeseriesFields */, boost::none, boost::none, true, splitChunks);
return CollectionMetadata(ChunkManager(cm->dbPrimary(),
cm->dbVersion(),
@@ -167,6 +167,7 @@ protected:
chunkVersion.incMajor();
auto rt = cm->getRoutingTableHistory_ForTest().makeUpdated(
+ boost::none /* timeseriesFields */,
boost::none,
boost::none,
true,
diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp
index ed6283dacf7..933ecbd0df1 100644
--- a/src/mongo/s/catalog_cache.cpp
+++ b/src/mongo/s/catalog_cache.cpp
@@ -672,7 +672,8 @@ CatalogCache::CollectionCache::LookupResult CatalogCache::CollectionCache::_look
// updating. Otherwise, we're making a whole new routing table.
if (isIncremental &&
existingHistory->optRt->getVersion().epoch() == collectionAndChunks.epoch) {
- return existingHistory->optRt->makeUpdated(collectionAndChunks.reshardingFields,
+ return existingHistory->optRt->makeUpdated(collectionAndChunks.timeseriesFields,
+ collectionAndChunks.reshardingFields,
maxChunkSize,
collectionAndChunks.allowMigrations,
collectionAndChunks.changedChunks);
diff --git a/src/mongo/s/catalog_cache_test.cpp b/src/mongo/s/catalog_cache_test.cpp
index 818cf2d38b0..0604d8b1f87 100644
--- a/src/mongo/s/catalog_cache_test.cpp
+++ b/src/mongo/s/catalog_cache_test.cpp
@@ -312,19 +312,52 @@ TEST_F(CatalogCacheTest, TimeseriesFieldsAreProperlyPropagatedOnCC) {
loadDatabases({DatabaseType(kNss.db().toString(), kShards[0], true, dbVersion)});
auto coll = makeCollectionType(version);
- TypeCollectionTimeseriesFields tsFields;
- tsFields.setTimeseriesOptions(TimeseriesOptions("fieldName"));
- coll.setTimeseriesFields(tsFields);
+ auto chunks = makeChunks(version);
+ auto timeseriesOptions = TimeseriesOptions("fieldName");
- const auto scopedCollProv = scopedCollectionProvider(coll);
- const auto scopedChunksProv = scopedChunksProvider(makeChunks(version));
+ // 1st refresh: we should find a bucket granularity of seconds (default)
+ {
+ TypeCollectionTimeseriesFields tsFields;
+ tsFields.setTimeseriesOptions(timeseriesOptions);
+ coll.setTimeseriesFields(tsFields);
- const auto swChunkManager =
- _catalogCache->getCollectionRoutingInfoWithRefresh(operationContext(), coll.getNss());
- ASSERT_OK(swChunkManager.getStatus());
+ const auto scopedCollProv = scopedCollectionProvider(coll);
+ const auto scopedChunksProv = scopedChunksProvider(chunks);
+
+ const auto swChunkManager =
+ _catalogCache->getCollectionRoutingInfoWithRefresh(operationContext(), coll.getNss());
+ ASSERT_OK(swChunkManager.getStatus());
+
+ const auto& chunkManager = swChunkManager.getValue();
+ ASSERT(chunkManager.getTimeseriesFields().is_initialized());
+ ASSERT(chunkManager.getTimeseriesFields()->getGranularity() ==
+ BucketGranularityEnum::Seconds);
+ }
- const auto& chunkManager = swChunkManager.getValue();
- ASSERT(chunkManager.getTimeseriesFields().is_initialized());
+ // 2nd refresh: we should find a bucket granularity of hours
+ {
+ TypeCollectionTimeseriesFields tsFields;
+ timeseriesOptions.setGranularity(BucketGranularityEnum::Hours);
+ tsFields.setTimeseriesOptions(timeseriesOptions);
+ coll.setTimeseriesFields(tsFields);
+
+ auto& lastChunk = chunks.back();
+ ChunkVersion newCollectionVersion = lastChunk.getVersion();
+ newCollectionVersion.incMinor();
+ lastChunk.setVersion(newCollectionVersion);
+
+ const auto scopedCollProv = scopedCollectionProvider(coll);
+ const auto scopedChunksProv = scopedChunksProvider(std::vector{lastChunk});
+
+ const auto swChunkManager =
+ _catalogCache->getCollectionRoutingInfoWithRefresh(operationContext(), coll.getNss());
+ ASSERT_OK(swChunkManager.getStatus());
+
+ const auto& chunkManager = swChunkManager.getValue();
+ ASSERT(chunkManager.getTimeseriesFields().is_initialized());
+ ASSERT(chunkManager.getTimeseriesFields()->getGranularity() ==
+ BucketGranularityEnum::Hours);
+ }
}
TEST_F(CatalogCacheTest, LookupCollectionWithInvalidOptions) {
diff --git a/src/mongo/s/chunk_manager.cpp b/src/mongo/s/chunk_manager.cpp
index d79a69b7b39..1e954d001b9 100644
--- a/src/mongo/s/chunk_manager.cpp
+++ b/src/mongo/s/chunk_manager.cpp
@@ -794,6 +794,7 @@ RoutingTableHistory RoutingTableHistory::makeNew(
// ShardServerCatalogCacheLoader::_getLoaderMetadata() and copied into the persisted metadata when
// it may overlap with the enqueued metadata.
RoutingTableHistory RoutingTableHistory::makeUpdated(
+ boost::optional<TypeCollectionTimeseriesFields> timeseriesFields,
boost::optional<TypeCollectionReshardingFields> reshardingFields,
boost::optional<uint64_t> maxChunkSizeBytes,
bool allowMigrations,
@@ -809,7 +810,7 @@ RoutingTableHistory RoutingTableHistory::makeUpdated(
getShardKeyPattern().getKeyPattern(),
CollatorInterface::cloneCollator(getDefaultCollator()),
isUnique(),
- _timeseriesFields,
+ std::move(timeseriesFields),
std::move(reshardingFields),
maxChunkSizeBytes,
allowMigrations,
diff --git a/src/mongo/s/chunk_manager.h b/src/mongo/s/chunk_manager.h
index eaf226a153d..9d48ccfb9eb 100644
--- a/src/mongo/s/chunk_manager.h
+++ b/src/mongo/s/chunk_manager.h
@@ -189,12 +189,14 @@ public:
* The changes in "changedChunks" must be sorted in ascending order by chunk version, and adhere
* to the requirements of the routing table update algorithm.
*
- * The existence of "reshardingFields" inside the optional implies that this field was present
- * inside the config.collections entry when refreshing. An uninitialized "reshardingFields"
- * parameter implies that the field was not present, and will clear any currently held
- * resharding fields inside the resulting RoutingTableHistory.
+ * The existence of timeseriesFields/reshardingFields inside the optional implies that this
+ * field was present inside the config.collections entry when refreshing. An uninitialized
+ * timeseriesFields/reshardingFields parameter implies that the field was not present, and will
+ * clear any currently held timeseries/resharding fields inside the resulting
+ * RoutingTableHistory.
*/
RoutingTableHistory makeUpdated(
+ boost::optional<TypeCollectionTimeseriesFields> timeseriesFields,
boost::optional<TypeCollectionReshardingFields> reshardingFields,
boost::optional<uint64_t> maxChunkSizeBytes,
bool allowMigrations,
diff --git a/src/mongo/s/chunk_manager_query_test.cpp b/src/mongo/s/chunk_manager_query_test.cpp
index a6018536321..a4c8b704932 100644
--- a/src/mongo/s/chunk_manager_query_test.cpp
+++ b/src/mongo/s/chunk_manager_query_test.cpp
@@ -533,11 +533,12 @@ TEST_F(ChunkManagerQueryTest, SnapshotQueryWithMoreShardsThanLatestMetadata) {
chunk1.setHistory({ChunkHistory(Timestamp(20, 0), ShardId("0")),
ChunkHistory(Timestamp(1, 0), ShardId("1"))});
- ChunkManager chunkManager(ShardId("0"),
- DatabaseVersion(UUID::gen(), Timestamp()),
- makeStandaloneRoutingTableHistory(oldRoutingTable.makeUpdated(
- boost::none, boost::none, true, {chunk1})),
- Timestamp(5, 0));
+ ChunkManager chunkManager(
+ ShardId("0"),
+ DatabaseVersion(UUID::gen(), Timestamp()),
+ makeStandaloneRoutingTableHistory(oldRoutingTable.makeUpdated(
+ boost::none /* timeseriesFields */, boost::none, boost::none, true, {chunk1})),
+ Timestamp(5, 0));
std::set<ShardId> shardIds;
chunkManager.getShardIdsForRange(BSON("x" << MINKEY), BSON("x" << MAXKEY), &shardIds);
diff --git a/src/mongo/s/chunk_manager_refresh_bm.cpp b/src/mongo/s/chunk_manager_refresh_bm.cpp
index f7c8a94095d..611b7826c7c 100644
--- a/src/mongo/s/chunk_manager_refresh_bm.cpp
+++ b/src/mongo/s/chunk_manager_refresh_bm.cpp
@@ -122,7 +122,7 @@ MONGO_COMPILER_NOINLINE auto makeChunkManagerWithOptimalBalancedDistribution(int
MONGO_COMPILER_NOINLINE auto runIncrementalUpdate(const CollectionMetadata& cm,
const std::vector<ChunkType>& newChunks) {
auto rt = cm.getChunkManager()->getRoutingTableHistory_ForTest().makeUpdated(
- boost::none, boost::none, true, newChunks);
+ boost::none /* timeseriesFields */, boost::none, boost::none, true, newChunks);
return CollectionMetadata(ChunkManager(ShardId("shard0"),
DatabaseVersion(UUID::gen(), Timestamp()),
makeStandaloneRoutingTableHistory(std::move(rt)),
diff --git a/src/mongo/s/routing_table_history_test.cpp b/src/mongo/s/routing_table_history_test.cpp
index 72de94f95f8..676dc94d021 100644
--- a/src/mongo/s/routing_table_history_test.cpp
+++ b/src/mongo/s/routing_table_history_test.cpp
@@ -71,7 +71,8 @@ RoutingTableHistory splitChunk(const RoutingTableHistory& rt,
newChunks.emplace_back(*rt.getUUID(), range, curVersion, kThisShard);
}
- return rt.makeUpdated(boost::none, boost::none, true, newChunks);
+ return rt.makeUpdated(
+ boost::none /* timeseriesFields */, boost::none, boost::none, true, newChunks);
}
/**
@@ -362,7 +363,8 @@ TEST_F(RoutingTableHistoryTest, TestSplits) {
ChunkVersion{2, 2, epoch, timestamp},
kThisShard}};
- auto rt1 = rt.makeUpdated(boost::none, boost::none, true, chunks1);
+ auto rt1 =
+ rt.makeUpdated(boost::none /* timeseriesFields */, boost::none, boost::none, true, chunks1);
auto v1 = ChunkVersion{2, 2, epoch, timestamp};
ASSERT_EQ(v1, rt1.getVersion(kThisShard));
@@ -380,7 +382,8 @@ TEST_F(RoutingTableHistoryTest, TestSplits) {
ChunkVersion{3, 2, epoch, timestamp},
kThisShard}};
- auto rt2 = rt1.makeUpdated(boost::none, boost::none, true, chunks2);
+ auto rt2 = rt1.makeUpdated(
+ boost::none /* timeseriesFields */, boost::none, boost::none, true, chunks2);
auto v2 = ChunkVersion{3, 2, epoch, timestamp};
ASSERT_EQ(v2, rt2.getVersion(kThisShard));
}
@@ -420,7 +423,8 @@ TEST_F(RoutingTableHistoryTest, TestReplaceEmptyChunk) {
ChunkVersion{2, 2, epoch, timestamp},
kThisShard}};
- auto rt1 = rt.makeUpdated(boost::none, boost::none, true, changedChunks);
+ auto rt1 = rt.makeUpdated(
+ boost::none /* timeseriesFields */, boost::none, boost::none, true, changedChunks);
auto v1 = ChunkVersion{2, 2, epoch, timestamp};
ASSERT_EQ(v1, rt1.getVersion(kThisShard));
ASSERT_EQ(rt1.numChunks(), 2);
@@ -478,7 +482,8 @@ TEST_F(RoutingTableHistoryTest, TestUseLatestVersions) {
ChunkVersion{2, 2, epoch, timestamp},
kThisShard}};
- auto rt1 = rt.makeUpdated(boost::none, boost::none, true, changedChunks);
+ auto rt1 = rt.makeUpdated(
+ boost::none /* timeseriesFields */, boost::none, boost::none, true, changedChunks);
auto v1 = ChunkVersion{2, 2, epoch, timestamp};
ASSERT_EQ(v1, rt1.getVersion(kThisShard));
ASSERT_EQ(rt1.numChunks(), 2);
@@ -523,7 +528,8 @@ TEST_F(RoutingTableHistoryTest, TestOutOfOrderVersion) {
ChunkVersion{3, 1, epoch, timestamp},
kThisShard}};
- auto rt1 = rt.makeUpdated(boost::none, boost::none, true, changedChunks);
+ auto rt1 = rt.makeUpdated(
+ boost::none /* timeseriesFields */, boost::none, boost::none, true, changedChunks);
auto v1 = ChunkVersion{3, 1, epoch, timestamp};
ASSERT_EQ(v1, rt1.getVersion(kThisShard));
ASSERT_EQ(rt1.numChunks(), 2);
@@ -578,7 +584,8 @@ TEST_F(RoutingTableHistoryTest, TestMergeChunks) {
ChunkVersion{3, 1, epoch, timestamp},
kThisShard}};
- auto rt1 = rt.makeUpdated(boost::none, boost::none, true, changedChunks);
+ auto rt1 = rt.makeUpdated(
+ boost::none /* timeseriesFields */, boost::none, boost::none, true, changedChunks);
auto v1 = ChunkVersion{3, 1, epoch, timestamp};
ASSERT_EQ(v1, rt1.getVersion(kThisShard));
ASSERT_EQ(rt1.numChunks(), 2);
@@ -628,7 +635,8 @@ TEST_F(RoutingTableHistoryTest, TestMergeChunksOrdering) {
ChunkVersion{3, 1, epoch, timestamp},
kThisShard}};
- auto rt1 = rt.makeUpdated(boost::none, boost::none, true, changedChunks);
+ auto rt1 = rt.makeUpdated(
+ boost::none /* timeseriesFields */, boost::none, boost::none, true, changedChunks);
auto v1 = ChunkVersion{3, 1, epoch, timestamp};
ASSERT_EQ(v1, rt1.getVersion(kThisShard));
ASSERT_EQ(rt1.numChunks(), 2);