summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorSergi Mateo Bellido <sergi.mateo-bellido@mongodb.com>2021-04-15 04:51:31 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-21 04:43:37 +0000
commit6f17871c955dbf98a5ffcd27dab2390d90b875d1 (patch)
tree5a13489c3a7aa7ac11d762222d4357275315d8bd /src/mongo/db/s
parent384c41b1f89412b5843b8546b8ddf4fcb837eff5 (diff)
downloadmongo-6f17871c955dbf98a5ffcd27dab2390d90b875d1.tar.gz
SERVER-55592 Add time-series fields to sharding catalog
* Adding IDL support to time-series fields + exposing its symbols in some class wrappers * Modifying the CatalogCacheLoader, CatalogCache and the ChunkManager to handle the new timeseries fields * Disallowing operations over sharded time-series collections * Fixing some tests + adding a new one
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/collection_metadata.h5
-rw-r--r--src/mongo/db/s/collection_metadata_filtering_test.cpp32
-rw-r--r--src/mongo/db/s/collection_metadata_test.cpp1
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.cpp6
-rw-r--r--src/mongo/db/s/collection_sharding_runtime_test.cpp1
-rw-r--r--src/mongo/db/s/metadata_manager_test.cpp1
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp1
-rw-r--r--src/mongo/db/s/op_observer_sharding_test.cpp1
-rw-r--r--src/mongo/db/s/range_deletion_util_test.cpp1
-rw-r--r--src/mongo/db/s/resharding/resharding_data_replication_test.cpp1
-rw-r--r--src/mongo/db/s/resharding/resharding_donor_recipient_common_test.h29
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp1
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_crud_application_test.cpp1
-rw-r--r--src/mongo/db/s/scoped_collection_metadata.h4
-rw-r--r--src/mongo/db/s/shard_server_catalog_cache_loader.cpp2
-rw-r--r--src/mongo/db/s/shard_server_catalog_cache_loader_test.cpp17
-rw-r--r--src/mongo/db/s/type_shard_collection.h2
-rw-r--r--src/mongo/db/s/type_shard_collection.idl6
18 files changed, 97 insertions, 15 deletions
diff --git a/src/mongo/db/s/collection_metadata.h b/src/mongo/db/s/collection_metadata.h
index a742b77726f..79f02080b19 100644
--- a/src/mongo/db/s/collection_metadata.h
+++ b/src/mongo/db/s/collection_metadata.h
@@ -261,6 +261,11 @@ public:
return _cm->getReshardingFields();
}
+ const boost::optional<TypeCollectionTimeseriesFields>& getTimeseriesFields() const {
+ invariant(isSharded());
+ return _cm->getTimeseriesFields();
+ }
+
private:
// The full routing table for the collection or boost::none if the collection is not sharded
boost::optional<ChunkManager> _cm;
diff --git a/src/mongo/db/s/collection_metadata_filtering_test.cpp b/src/mongo/db/s/collection_metadata_filtering_test.cpp
index e0559141e43..1db44836b11 100644
--- a/src/mongo/db/s/collection_metadata_filtering_test.cpp
+++ b/src/mongo/db/s/collection_metadata_filtering_test.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/s/operation_sharding_state.h"
#include "mongo/db/s/shard_server_test_fixture.h"
#include "mongo/s/catalog/type_chunk.h"
+#include "mongo/s/type_collection_timeseries_fields_gen.h"
namespace mongo {
namespace {
@@ -59,7 +60,8 @@ protected:
* time (75,25) shard0(chunk2, chunk4) shard1(chunk1, chunk3)
* time (25,0) - no history
*/
- void prepareTestData() {
+ void prepareTestData(
+ boost::optional<TypeCollectionTimeseriesFields> timeseriesFields = boost::none) {
const OID epoch = OID::gen();
const ShardKeyPattern shardKeyPattern(BSON("_id" << 1));
@@ -71,6 +73,7 @@ protected:
false,
epoch,
boost::none /* timestamp */,
+ timeseriesFields,
boost::none,
true,
[&] {
@@ -210,5 +213,32 @@ TEST_F(CollectionMetadataFilteringTest, FilterDocumentsTooFarInThePastThrowsStal
operationContext(), CollectionShardingState::OrphanCleanupPolicy::kAllowOrphanCleanup));
}
+TEST_F(CollectionMetadataFilteringTest, DisallowOpsOnShardedTimeseriesCollection) {
+ TypeCollectionTimeseriesFields timeseriesFields("fieldName");
+ prepareTestData(timeseriesFields);
+
+ BSONObj readConcern = BSON("readConcern" << BSON("level"
+ << "snapshot"
+ << "atClusterTime" << Timestamp(100, 0)));
+
+ auto&& readConcernArgs = repl::ReadConcernArgs::get(operationContext());
+ ASSERT_OK(readConcernArgs.initialize(readConcern["readConcern"]));
+
+ AutoGetCollection autoColl(operationContext(), kNss, MODE_IS);
+ auto* const css = CollectionShardingState::get(operationContext(), kNss);
+
+ auto check = [&](const DBException& ex) {
+ ASSERT_EQ(ex.code(), ErrorCodes::NotImplemented) << ex.toString();
+ ASSERT_STRING_CONTAINS(ex.reason(),
+ "Operations on sharded time-series collections are not supported");
+ };
+
+ ASSERT_THROWS_WITH_CHECK(
+ css->getOwnershipFilter(operationContext(),
+ CollectionShardingState::OrphanCleanupPolicy::kAllowOrphanCleanup),
+ AssertionException,
+ check);
+}
+
} // namespace
} // namespace mongo
diff --git a/src/mongo/db/s/collection_metadata_test.cpp b/src/mongo/db/s/collection_metadata_test.cpp
index b5f9e77045d..30187003857 100644
--- a/src/mongo/db/s/collection_metadata_test.cpp
+++ b/src/mongo/db/s/collection_metadata_test.cpp
@@ -94,6 +94,7 @@ CollectionMetadata makeCollectionMetadataImpl(
false,
epoch,
boost::none /* timestamp */,
+ boost::none /* timeseriesFields */,
std::move(reshardingFields),
true,
allChunks)),
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp
index 9edc8921fcd..21d5550a775 100644
--- a/src/mongo/db/s/collection_sharding_runtime.cpp
+++ b/src/mongo/db/s/collection_sharding_runtime.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/s/sharding_runtime_d_params_gen.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/logv2/log.h"
+#include "mongo/s/type_collection_timeseries_fields_gen.h"
#include "mongo/util/duration.h"
namespace mongo {
@@ -317,6 +318,11 @@ CollectionShardingRuntime::_getMetadataWithVersionCheckAt(
optCurrentMetadata);
const auto& currentMetadata = optCurrentMetadata->get();
+
+ uassert(ErrorCodes::NotImplemented,
+ "Operations on sharded time-series collections are not supported",
+ !currentMetadata.isSharded() || !currentMetadata.getTimeseriesFields());
+
auto wantedShardVersion = currentMetadata.getShardVersion();
{
diff --git a/src/mongo/db/s/collection_sharding_runtime_test.cpp b/src/mongo/db/s/collection_sharding_runtime_test.cpp
index d18ba119720..cb7cbf2b6fc 100644
--- a/src/mongo/db/s/collection_sharding_runtime_test.cpp
+++ b/src/mongo/db/s/collection_sharding_runtime_test.cpp
@@ -66,6 +66,7 @@ protected:
false,
epoch,
boost::none /* timestamp */,
+ boost::none /* timeseriesFields */,
boost::none,
true,
{std::move(chunk)})),
diff --git a/src/mongo/db/s/metadata_manager_test.cpp b/src/mongo/db/s/metadata_manager_test.cpp
index 106172047ab..b11ace72e72 100644
--- a/src/mongo/db/s/metadata_manager_test.cpp
+++ b/src/mongo/db/s/metadata_manager_test.cpp
@@ -86,6 +86,7 @@ protected:
false,
epoch,
boost::none /* timestamp */,
+ boost::none /* timeseriesFields */,
boost::none,
true,
{ChunkType{
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp
index ee7fd354c75..eeff0c7976b 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp
@@ -163,6 +163,7 @@ protected:
false,
epoch,
boost::none /* timestamp */,
+ boost::none /* timeseriesFields */,
boost::none,
true,
{ChunkType{kNss,
diff --git a/src/mongo/db/s/op_observer_sharding_test.cpp b/src/mongo/db/s/op_observer_sharding_test.cpp
index 2e88a2de050..93b0a5b58f9 100644
--- a/src/mongo/db/s/op_observer_sharding_test.cpp
+++ b/src/mongo/db/s/op_observer_sharding_test.cpp
@@ -75,6 +75,7 @@ protected:
false,
epoch,
boost::none /* timestamp */,
+ boost::none /* timeseriesFields */,
boost::none,
true,
{std::move(chunk)});
diff --git a/src/mongo/db/s/range_deletion_util_test.cpp b/src/mongo/db/s/range_deletion_util_test.cpp
index 77d14f9f53d..be8ed9635b8 100644
--- a/src/mongo/db/s/range_deletion_util_test.cpp
+++ b/src/mongo/db/s/range_deletion_util_test.cpp
@@ -103,6 +103,7 @@ public:
false,
epoch,
boost::none /* timestamp */,
+ boost::none /* timeseriesFields */,
boost::none,
true,
{ChunkType{kNss,
diff --git a/src/mongo/db/s/resharding/resharding_data_replication_test.cpp b/src/mongo/db/s/resharding/resharding_data_replication_test.cpp
index 10091b5f3df..dcbe12200b0 100644
--- a/src/mongo/db/s/resharding/resharding_data_replication_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_data_replication_test.cpp
@@ -85,6 +85,7 @@ public:
false /* unique */,
std::move(epoch),
boost::none /* timestamp */,
+ boost::none /* timeseriesFields */,
boost::none /* reshardingFields */,
true /* allowMigrations */,
chunks);
diff --git a/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.h b/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.h
index b8f4356bd17..bc0e4888e43 100644
--- a/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.h
+++ b/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.h
@@ -105,20 +105,21 @@ protected:
auto range = ChunkRange(BSON(shardKey << MINKEY), BSON(shardKey << MAXKEY));
auto chunk = ChunkType(
nss, std::move(range), ChunkVersion(1, 0, epoch, boost::none), shardThatChunkExistsOn);
- ChunkManager cm(
- kThisShard.getShardId(),
- DatabaseVersion(uuid),
- makeStandaloneRoutingTableHistory(RoutingTableHistory::makeNew(nss,
- uuid,
- shardKeyPattern,
- nullptr,
- false,
- epoch,
- boost::none,
- boost::none,
- true,
- {std::move(chunk)})),
- boost::none);
+ ChunkManager cm(kThisShard.getShardId(),
+ DatabaseVersion(uuid),
+ makeStandaloneRoutingTableHistory(
+ RoutingTableHistory::makeNew(nss,
+ uuid,
+ shardKeyPattern,
+ nullptr,
+ false,
+ epoch,
+ boost::none,
+ boost::none /* timeseriesFields */,
+ boost::none,
+ true,
+ {std::move(chunk)})),
+ boost::none);
if (!OperationShardingState::isOperationVersioned(opCtx)) {
const auto version = cm.getVersion(kThisShard.getShardId());
diff --git a/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp
index 786ab9e96de..d87a2164416 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp
@@ -189,6 +189,7 @@ public:
false,
epoch,
boost::none /* timestamp */,
+ boost::none /* timeseriesFields */,
boost::none,
false,
chunks);
diff --git a/src/mongo/db/s/resharding/resharding_oplog_crud_application_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_crud_application_test.cpp
index a8616102cdc..9a8c9231677 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_crud_application_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_crud_application_test.cpp
@@ -258,6 +258,7 @@ private:
false /* unique */,
std::move(epoch),
boost::none /* timestamp */,
+ boost::none /* timeseriesFields */,
boost::none /* reshardingFields */,
true /* allowMigrations */,
chunks);
diff --git a/src/mongo/db/s/scoped_collection_metadata.h b/src/mongo/db/s/scoped_collection_metadata.h
index 014f1a083da..6977e9733bf 100644
--- a/src/mongo/db/s/scoped_collection_metadata.h
+++ b/src/mongo/db/s/scoped_collection_metadata.h
@@ -101,6 +101,10 @@ public:
return _impl->get().getReshardingFields();
}
+ const boost::optional<TypeCollectionTimeseriesFields>& getTimeseriesFields() const {
+ return _impl->get().getTimeseriesFields();
+ }
+
protected:
std::shared_ptr<Impl> _impl;
};
diff --git a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
index f2c9a70828d..0c2addd5472 100644
--- a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
+++ b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
@@ -101,6 +101,7 @@ Status persistCollectionAndChangedChunks(OperationContext* opCtx,
collAndChunks.shardKeyPattern,
collAndChunks.shardKeyIsUnique);
update.setDefaultCollation(collAndChunks.defaultCollation);
+ update.setTimeseriesFields(collAndChunks.timeseriesFields);
update.setReshardingFields(collAndChunks.reshardingFields);
update.setAllowMigrations(collAndChunks.allowMigrations);
@@ -251,6 +252,7 @@ CollectionAndChangedChunks getPersistedMetadataSinceVersion(OperationContext* op
shardCollectionEntry.getKeyPattern().toBSON(),
shardCollectionEntry.getDefaultCollation(),
shardCollectionEntry.getUnique(),
+ shardCollectionEntry.getTimeseriesFields(),
shardCollectionEntry.getReshardingFields(),
shardCollectionEntry.getAllowMigrations(),
std::move(changedChunks)};
diff --git a/src/mongo/db/s/shard_server_catalog_cache_loader_test.cpp b/src/mongo/db/s/shard_server_catalog_cache_loader_test.cpp
index 026348146dd..2595b646e85 100644
--- a/src/mongo/db/s/shard_server_catalog_cache_loader_test.cpp
+++ b/src/mongo/db/s/shard_server_catalog_cache_loader_test.cpp
@@ -37,6 +37,7 @@
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/catalog/type_database.h"
#include "mongo/s/catalog_cache_loader_mock.h"
+#include "mongo/s/type_collection_timeseries_fields_gen.h"
namespace mongo {
namespace {
@@ -208,6 +209,7 @@ vector<ChunkType> ShardServerCatalogCacheLoaderTest::setUpChunkLoaderWithFiveChu
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());
}
@@ -506,5 +508,20 @@ TEST_F(ShardServerCatalogCacheLoaderTest, PrimaryLoadFromShardedAndFindDbMetadat
ASSERT_EQUALS(dbType.getVersion().getTimestamp(), newDbType.getVersion().getTimestamp());
}
+TEST_F(ShardServerCatalogCacheLoaderTest, TimeseriesFieldsAreProperlyPropagatedOnSSCCL) {
+ ChunkVersion collectionVersion(1, 0, OID::gen(), boost::none /* timestamp */);
+
+ CollectionType collectionType = makeCollectionType(collectionVersion);
+ collectionType.setTimeseriesFields(TypeCollectionTimeseriesFields("fieldName"));
+
+ vector<ChunkType> chunks = makeFiveChunks(collectionVersion);
+
+ _remoteLoaderMock->setCollectionRefreshReturnValue(collectionType);
+ _remoteLoaderMock->setChunkRefreshReturnValue(chunks);
+
+ auto collAndChunksRes = _shardLoader->getChunksSince(kNss, ChunkVersion::UNSHARDED()).get();
+ ASSERT(collAndChunksRes.timeseriesFields.is_initialized());
+}
+
} // namespace
} // namespace mongo
diff --git a/src/mongo/db/s/type_shard_collection.h b/src/mongo/db/s/type_shard_collection.h
index df51ee8db3c..1c805a31c63 100644
--- a/src/mongo/db/s/type_shard_collection.h
+++ b/src/mongo/db/s/type_shard_collection.h
@@ -58,6 +58,7 @@ public:
using ShardCollectionTypeBase::getNss;
using ShardCollectionTypeBase::getRefreshing;
using ShardCollectionTypeBase::getReshardingFields;
+ using ShardCollectionTypeBase::getTimeseriesFields;
using ShardCollectionTypeBase::getTimestamp;
using ShardCollectionTypeBase::getUnique;
using ShardCollectionTypeBase::getUuid;
@@ -69,6 +70,7 @@ public:
using ShardCollectionTypeBase::setNss;
using ShardCollectionTypeBase::setRefreshing;
using ShardCollectionTypeBase::setReshardingFields;
+ using ShardCollectionTypeBase::setTimeseriesFields;
using ShardCollectionTypeBase::setUnique;
using ShardCollectionTypeBase::setUuid;
diff --git a/src/mongo/db/s/type_shard_collection.idl b/src/mongo/db/s/type_shard_collection.idl
index e0ce20f6087..71b1aac4f39 100644
--- a/src/mongo/db/s/type_shard_collection.idl
+++ b/src/mongo/db/s/type_shard_collection.idl
@@ -75,6 +75,7 @@ imports:
- "mongo/db/keypattern.idl"
- "mongo/s/chunk_version.idl"
- "mongo/s/resharding/type_collection_fields.idl"
+ - "mongo/s/type_collection_timeseries_fields.idl"
structs:
ShardCollectionTypeBase:
@@ -161,3 +162,8 @@ structs:
It must be optional and not present when running in FCV 4.4, because
binaries prior to 5.0 use strict parsing and will fail."
optional: true
+ timeseriesFields:
+ type: TypeCollectionTimeseriesFields
+ description: "Time-series collection fields. Only set when this is a time-series
+ buckets collection."
+ optional: true