diff options
author | Jason Zhang <jason.zhang@mongodb.com> | 2021-04-06 20:46:33 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-04-19 20:51:50 +0000 |
commit | 36064ad537d6f49c324b3cd13849a6267048209b (patch) | |
tree | 9738236a87ad2a8e407d3505c7553c46b77b40d3 | |
parent | b4a0ebefb58469fb86ff98bd6f1cc0a3e8eb3d00 (diff) | |
download | mongo-36064ad537d6f49c324b3cd13849a6267048209b.tar.gz |
SERVER-55312 Only set up tenant migration primary only services and op observers on non sharded servers
(cherry picked from commit fd6a8c685088f7e5552f1feb17b6e64530adb755)
-rw-r--r-- | jstests/sharding/tenant_migration_disallowed_in_sharded_cluster.js | 119 | ||||
-rw-r--r-- | src/mongo/db/commands/tenant_migration_donor_cmds.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/commands/tenant_migration_recipient_cmds.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/mongod_main.cpp | 12 |
4 files changed, 148 insertions, 4 deletions
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<std::unique_ptr<repl::PrimaryOnlyService>> services; - services.push_back(std::make_unique<TenantMigrationDonorService>(serviceContext)); - services.push_back(std::make_unique<repl::TenantMigrationRecipientService>(serviceContext)); if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { services.push_back(std::make_unique<ReshardingCoordinatorService>(serviceContext)); @@ -322,6 +320,10 @@ void registerPrimaryOnlyServices(ServiceContext* serviceContext) { services.push_back(std::make_unique<ShardingDDLCoordinatorService>(serviceContext)); services.push_back(std::make_unique<ReshardingDonorService>(serviceContext)); services.push_back(std::make_unique<ReshardingRecipientService>(serviceContext)); + } else { + // Tenant migrations are not supported in sharded clusters. + services.push_back(std::make_unique<TenantMigrationDonorService>(serviceContext)); + services.push_back(std::make_unique<repl::TenantMigrationRecipientService>(serviceContext)); } for (auto& service : services) { @@ -1020,12 +1022,14 @@ void setUpObservers(ServiceContext* serviceContext) { opObserverRegistry->addObserver(std::make_unique<ReshardingOpObserver>()); } else { opObserverRegistry->addObserver(std::make_unique<OpObserverImpl>()); + // Tenant migrations are not supported in sharded clusters. + opObserverRegistry->addObserver(std::make_unique<repl::TenantMigrationDonorOpObserver>()); + opObserverRegistry->addObserver( + std::make_unique<repl::TenantMigrationRecipientOpObserver>()); } opObserverRegistry->addObserver(std::make_unique<AuthOpObserver>()); opObserverRegistry->addObserver( std::make_unique<repl::PrimaryOnlyServiceOpObserver>(serviceContext)); - opObserverRegistry->addObserver(std::make_unique<repl::TenantMigrationDonorOpObserver>()); - opObserverRegistry->addObserver(std::make_unique<repl::TenantMigrationRecipientOpObserver>()); opObserverRegistry->addObserver(std::make_unique<FcvOpObserver>()); setupFreeMonitoringOpObserver(opObserverRegistry.get()); |