diff options
author | Sophia Tan <sophia_tll@hotmail.com> | 2022-03-31 19:11:31 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-31 20:39:27 +0000 |
commit | 2f2806eb4ca08b67392b6acc5d23c16e598c5f29 (patch) | |
tree | 971c02164d77b4b092f11c40d4a530d66fda9bab | |
parent | 307f3716159ff776f5d93250743620fd62d0ca08 (diff) | |
download | mongo-2f2806eb4ca08b67392b6acc5d23c16e598c5f29.tar.gz |
SERVER-64132 Make shardsvrs running in serverless mode always return "unsharded" filtering metadata
5 files changed, 60 insertions, 8 deletions
diff --git a/buildscripts/resmokeconfig/suites/talk_directly_to_shardsvrs_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/talk_directly_to_shardsvrs_jscore_passthrough.yml index 55797e90bbb..4aa38ff94dd 100644 --- a/buildscripts/resmokeconfig/suites/talk_directly_to_shardsvrs_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/talk_directly_to_shardsvrs_jscore_passthrough.yml @@ -41,11 +41,6 @@ selector: - requires_capped # In this suite the test talks directly to shardsvrs (doesn't go through mongos). - directly_against_shardsvrs_incompatible - # TODO (SERVER-64132): Remove these tests from the exclude list. They may currently fail because - # they create a collection via the renameCollection path, so are not created with kUnsharded - # filtering metadata. - - uses_$out - - uses_map_reduce_with_temp_collections executor: archive: diff --git a/buildscripts/resmokelib/testing/fixtures/talk_directly_to_shardsvrs.py b/buildscripts/resmokelib/testing/fixtures/talk_directly_to_shardsvrs.py index 8dcdc475b98..a241006f679 100644 --- a/buildscripts/resmokelib/testing/fixtures/talk_directly_to_shardsvrs.py +++ b/buildscripts/resmokelib/testing/fixtures/talk_directly_to_shardsvrs.py @@ -81,7 +81,7 @@ class TalkDirectlyToShardsvrsFixture(interface.MultiClusterFixture): # pylint: mongod_options = self.common_mongod_options.copy() mongod_options["shardsvr"] = "" mongod_options["dbpath"] = os.path.join(self._dbpath_prefix, rs_name) - mongod_options["replSet"] = rs_name + mongod_options["serverless"] = True self.replica_sets.append( self.fixturelib.make_fixture( diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp index dd8d6d5c491..d474782085c 100644 --- a/src/mongo/db/mongod_options.cpp +++ b/src/mongo/db/mongod_options.cpp @@ -624,8 +624,8 @@ Status storeMongodOptions(const moe::Environment& params) { } if (params.count("sharding.clusterRole")) { auto clusterRoleParam = params["sharding.clusterRole"].as<std::string>(); - const bool replicationEnabled = - params.count("replication.replSet") || params.count("replication.replSetName"); + const bool replicationEnabled = params.count("replication.replSet") || + params.count("replication.replSetName") || params.count("replication.serverless"); // Force to set up the node as a replica set, unless we're a shard and we're using queryable // backup mode. if ((clusterRoleParam == "configsvr" || !params.count("storage.queryableBackupMode")) && diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp index add8b71a260..e4cd8c2ffef 100644 --- a/src/mongo/db/s/collection_sharding_runtime.cpp +++ b/src/mongo/db/s/collection_sharding_runtime.cpp @@ -33,6 +33,7 @@ #include "mongo/base/checked_cast.h" #include "mongo/db/catalog_raii.h" +#include "mongo/db/global_settings.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/sharding_runtime_d_params_gen.h" #include "mongo/db/s/sharding_state.h" @@ -310,6 +311,12 @@ CollectionShardingRuntime::_getCurrentMetadataIfKnown( stdx::lock_guard lk(_metadataManagerLock); switch (_metadataType) { case MetadataType::kUnknown: + // Until user collections can be sharded in serverless, the sessions collection will be + // the only sharded collection. + if (getGlobalReplSettings().isServerless() && + _nss != NamespaceString::kLogicalSessionsNamespace) { + return kUnshardedCollection; + } return nullptr; case MetadataType::kUnsharded: return kUnshardedCollection; diff --git a/src/mongo/db/s/collection_sharding_runtime_test.cpp b/src/mongo/db/s/collection_sharding_runtime_test.cpp index fdbc20d9db5..dcee5b73ac0 100644 --- a/src/mongo/db/s/collection_sharding_runtime_test.cpp +++ b/src/mongo/db/s/collection_sharding_runtime_test.cpp @@ -34,6 +34,7 @@ #include "mongo/db/catalog_raii.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" +#include "mongo/db/global_settings.h" #include "mongo/db/persistent_task_store.h" #include "mongo/db/repl/wait_for_majority_service.h" #include "mongo/db/s/collection_sharding_runtime.h" @@ -187,6 +188,55 @@ TEST_F(CollectionShardingRuntimeTest, csr.getCollectionDescription(opCtx).uuidMatches(newMetadata.getChunkManager()->getUUID())); } +TEST_F(CollectionShardingRuntimeTest, ReturnUnshardedMetadataInServerlessMode) { + const NamespaceString testNss("TestDBForServerless", "TestColl"); + OperationContext* opCtx = operationContext(); + + // Enable serverless mode in global settings. + repl::ReplSettings severlessRs; + severlessRs.setServerlessMode(); + repl::ReplSettings originalRs = getGlobalReplSettings(); + setGlobalReplSettings(severlessRs); + ASSERT_TRUE(getGlobalReplSettings().isServerless()); + + // Enable sharding state and set shard version on the OSS for testNss. + ScopedSetShardRole scopedSetShardRole1{ + opCtx, + testNss, + ChunkVersion::UNSHARDED(), /* shardVersion */ + boost::none /* databaseVersion */ + }; + + CollectionShardingRuntime csr(getServiceContext(), testNss, executor()); + auto collectionFilter = csr.getOwnershipFilter( + opCtx, CollectionShardingRuntime::OrphanCleanupPolicy::kAllowOrphanCleanup, true); + ASSERT_FALSE(collectionFilter.isSharded()); + ASSERT_FALSE(csr.getCurrentMetadataIfKnown()->isSharded()); + ASSERT_FALSE(csr.getCollectionDescription(opCtx).isSharded()); + + // Enable sharding state and set shard version on the OSS for logical session nss. + ScopedSetShardRole scopedSetShardRole2{ + opCtx, + NamespaceString::kLogicalSessionsNamespace, + ChunkVersion(1, 0, OID::gen(), Timestamp(1, 1)), /* shardVersion */ + boost::none /* databaseVersion */ + }; + + CollectionShardingRuntime csrLogicalSession( + getServiceContext(), NamespaceString::kLogicalSessionsNamespace, executor()); + ASSERT(csrLogicalSession.getCurrentMetadataIfKnown() == boost::none); + ASSERT_THROWS_CODE( + csrLogicalSession.getCollectionDescription(opCtx), DBException, ErrorCodes::StaleConfig); + ASSERT_THROWS_CODE( + csrLogicalSession.getOwnershipFilter( + opCtx, CollectionShardingRuntime::OrphanCleanupPolicy::kAllowOrphanCleanup, true), + DBException, + ErrorCodes::StaleConfig); + + // Reset the global settings. + setGlobalReplSettings(originalRs); +} + class CollectionShardingRuntimeTestWithMockedLoader : public ShardServerTestFixture { public: const NamespaceString kNss{"test.foo"}; |