From 36064ad537d6f49c324b3cd13849a6267048209b Mon Sep 17 00:00:00 2001 From: Jason Zhang Date: Tue, 6 Apr 2021 20:46:33 +0000 Subject: SERVER-55312 Only set up tenant migration primary only services and op observers on non sharded servers (cherry picked from commit fd6a8c685088f7e5552f1feb17b6e64530adb755) --- ...nant_migration_disallowed_in_sharded_cluster.js | 119 +++++++++++++++++++++ .../db/commands/tenant_migration_donor_cmds.cpp | 12 +++ .../commands/tenant_migration_recipient_cmds.cpp | 9 ++ src/mongo/db/mongod_main.cpp | 12 ++- 4 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 jstests/sharding/tenant_migration_disallowed_in_sharded_cluster.js diff --git a/jstests/sharding/tenant_migration_disallowed_in_sharded_cluster.js b/jstests/sharding/tenant_migration_disallowed_in_sharded_cluster.js new file mode 100644 index 00000000000..9798f182b21 --- /dev/null +++ b/jstests/sharding/tenant_migration_disallowed_in_sharded_cluster.js @@ -0,0 +1,119 @@ +/** + * Tests that tenant migration commands cannot be run on sharded clusters. + * + * @tags: [requires_fcv_47, requires_majority_read_concern, requires_persistence, + * incompatible_with_eft, incompatible_with_windows_tls] + */ + +(function() { +"use strict"; + +load("jstests/replsets/libs/tenant_migration_test.js"); + +const st = new ShardingTest({shards: 1, config: 1}); +const donorRstShard = st.rs0; +const donorRstConfig = st.configRS; +const recipientRst = new ReplSetTest({nodes: 1}); +recipientRst.startSet(); +recipientRst.initiate(); + +const tenantMigrationTest = + new TenantMigrationTest({name: jsTestName(), donorRst: donorRstShard, recipientRst}); + +if (!tenantMigrationTest.isFeatureFlagEnabled()) { + jsTestLog("Skipping test because the tenant migrations feature flag is disabled"); + st.stop(); + recipientRst.stopSet(); + return; +} + +// Run tenant migration commands on shards. +let donorPrimary = donorRstShard.getPrimary(); + +let cmdObj = { + donorStartMigration: 1, + tenantId: "kTenantTest", + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getRecipientConnString(), + readPreference: {mode: "primary"} +}; +assert.commandFailedWithCode(donorPrimary.adminCommand(cmdObj), ErrorCodes.IllegalOperation); + +cmdObj = { + donorForgetMigration: 1, + migrationId: UUID() +}; +assert.commandFailedWithCode(donorPrimary.adminCommand(cmdObj), ErrorCodes.IllegalOperation); + +cmdObj = { + donorAbortMigration: 1, + migrationId: UUID() +}; +assert.commandFailedWithCode(donorPrimary.adminCommand(cmdObj), ErrorCodes.IllegalOperation); + +cmdObj = { + recipientSyncData: 1, + migrationId: UUID(), + donorConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + tenantId: "kTenantTest", + readPreference: {mode: "primary"}, + startMigrationDonorTimestamp: Timestamp(1, 1) +}; +assert.commandFailedWithCode(donorPrimary.adminCommand(cmdObj), ErrorCodes.IllegalOperation); + +cmdObj = { + recipientForgetMigration: 1, + migrationId: UUID(), + donorConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + tenantId: "kTenantTest", + readPreference: {mode: "primary"}, +}; +assert.commandFailedWithCode(donorPrimary.adminCommand(cmdObj), ErrorCodes.IllegalOperation); + +// Run tenant migration commands on config servers. +donorPrimary = donorRstConfig.getPrimary(); + +cmdObj = { + donorStartMigration: 1, + tenantId: "kTenantTest", + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getRecipientConnString(), + readPreference: {mode: "primary"} +}; +assert.commandFailedWithCode(donorPrimary.adminCommand(cmdObj), ErrorCodes.IllegalOperation); + +cmdObj = { + donorForgetMigration: 1, + migrationId: UUID() +}; +assert.commandFailedWithCode(donorPrimary.adminCommand(cmdObj), ErrorCodes.IllegalOperation); + +cmdObj = { + donorAbortMigration: 1, + migrationId: UUID() +}; +assert.commandFailedWithCode(donorPrimary.adminCommand(cmdObj), ErrorCodes.IllegalOperation); + +cmdObj = { + recipientSyncData: 1, + migrationId: UUID(), + donorConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + tenantId: "kTenantTest", + readPreference: {mode: "primary"}, + startMigrationDonorTimestamp: Timestamp(1, 1) +}; +assert.commandFailedWithCode(donorPrimary.adminCommand(cmdObj), ErrorCodes.IllegalOperation); + +cmdObj = { + recipientForgetMigration: 1, + migrationId: UUID(), + donorConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + tenantId: "kTenantTest", + readPreference: {mode: "primary"}, +}; +assert.commandFailedWithCode(donorPrimary.adminCommand(cmdObj), ErrorCodes.IllegalOperation); + +tenantMigrationTest.stop(); +recipientRst.stopSet(); +st.stop(); +})(); diff --git a/src/mongo/db/commands/tenant_migration_donor_cmds.cpp b/src/mongo/db/commands/tenant_migration_donor_cmds.cpp index 1d3a74b60fc..4dee89efc4b 100644 --- a/src/mongo/db/commands/tenant_migration_donor_cmds.cpp +++ b/src/mongo/db/commands/tenant_migration_donor_cmds.cpp @@ -61,6 +61,10 @@ public: repl::feature_flags::gTenantMigrations.isEnabled( serverGlobalParams.featureCompatibility)); + uassert(ErrorCodes::IllegalOperation, + "tenant migrations are not available in sharded clusters", + serverGlobalParams.clusterRole == ClusterRole::None); + // (Generic FCV reference): This FCV reference should exist across LTS binary versions. uassert( 5356100, @@ -171,6 +175,10 @@ public: repl::feature_flags::gTenantMigrations.isEnabled( serverGlobalParams.featureCompatibility)); + uassert(ErrorCodes::IllegalOperation, + "tenant migrations are not available in sharded clusters", + serverGlobalParams.clusterRole == ClusterRole::None); + const auto& cmd = request(); auto donorService = @@ -239,6 +247,10 @@ public: repl::feature_flags::gTenantMigrations.isEnabled( serverGlobalParams.featureCompatibility)); + uassert(ErrorCodes::IllegalOperation, + "tenant migrations are not available in sharded clusters", + serverGlobalParams.clusterRole == ClusterRole::None); + const RequestType& cmd = request(); auto donorService = diff --git a/src/mongo/db/commands/tenant_migration_recipient_cmds.cpp b/src/mongo/db/commands/tenant_migration_recipient_cmds.cpp index 6a26c8c9fec..3d42735fd65 100644 --- a/src/mongo/db/commands/tenant_migration_recipient_cmds.cpp +++ b/src/mongo/db/commands/tenant_migration_recipient_cmds.cpp @@ -63,6 +63,10 @@ public: repl::feature_flags::gTenantMigrations.isEnabled( serverGlobalParams.featureCompatibility)); + uassert(ErrorCodes::IllegalOperation, + "tenant migrations are not available in sharded clusters", + serverGlobalParams.clusterRole == ClusterRole::None); + // (Generic FCV reference): This FCV reference should exist across LTS binary versions. uassert( 5356101, @@ -179,6 +183,11 @@ public: "recipientForgetMigration command not enabled", repl::feature_flags::gTenantMigrations.isEnabled( serverGlobalParams.featureCompatibility)); + + uassert(ErrorCodes::IllegalOperation, + "tenant migrations are not available in sharded clusters", + serverGlobalParams.clusterRole == ClusterRole::None); + const auto& cmd = request(); auto recipientService = diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp index e47c9c4d96f..fed12fe6c3f 100644 --- a/src/mongo/db/mongod_main.cpp +++ b/src/mongo/db/mongod_main.cpp @@ -313,8 +313,6 @@ void registerPrimaryOnlyServices(ServiceContext* serviceContext) { auto registry = repl::PrimaryOnlyServiceRegistry::get(serviceContext); std::vector> services; - services.push_back(std::make_unique(serviceContext)); - services.push_back(std::make_unique(serviceContext)); if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { services.push_back(std::make_unique(serviceContext)); @@ -322,6 +320,10 @@ void registerPrimaryOnlyServices(ServiceContext* serviceContext) { services.push_back(std::make_unique(serviceContext)); services.push_back(std::make_unique(serviceContext)); services.push_back(std::make_unique(serviceContext)); + } else { + // Tenant migrations are not supported in sharded clusters. + services.push_back(std::make_unique(serviceContext)); + services.push_back(std::make_unique(serviceContext)); } for (auto& service : services) { @@ -1020,12 +1022,14 @@ void setUpObservers(ServiceContext* serviceContext) { opObserverRegistry->addObserver(std::make_unique()); } else { opObserverRegistry->addObserver(std::make_unique()); + // Tenant migrations are not supported in sharded clusters. + opObserverRegistry->addObserver(std::make_unique()); + opObserverRegistry->addObserver( + std::make_unique()); } opObserverRegistry->addObserver(std::make_unique()); opObserverRegistry->addObserver( std::make_unique(serviceContext)); - opObserverRegistry->addObserver(std::make_unique()); - opObserverRegistry->addObserver(std::make_unique()); opObserverRegistry->addObserver(std::make_unique()); setupFreeMonitoringOpObserver(opObserverRegistry.get()); -- cgit v1.2.1