diff options
author | Cheahuychou Mao <cheahuychou.mao@mongodb.com> | 2020-09-09 19:04:30 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-09 23:10:22 +0000 |
commit | ee106b978c7466bdd325cfb9f3f029d3769b1c1b (patch) | |
tree | 151f491d061120e2ee8cece4eb3ffa3520bef829 | |
parent | 4b2be90987a8300611277a3252ed6500e0fc5d64 (diff) | |
download | mongo-ee106b978c7466bdd325cfb9f3f029d3769b1c1b.tar.gz |
SERVER-50837 Make sure that donorForgetMigration command can be retried
-rw-r--r-- | jstests/replsets/tenant_migration_donor_state_machine.js | 26 | ||||
-rw-r--r-- | src/mongo/db/repl/tenant_migration_donor_service.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/repl/tenant_migration_donor_service.h | 6 |
3 files changed, 33 insertions, 6 deletions
diff --git a/jstests/replsets/tenant_migration_donor_state_machine.js b/jstests/replsets/tenant_migration_donor_state_machine.js index 7f21efef1c6..f626ce5d5b9 100644 --- a/jstests/replsets/tenant_migration_donor_state_machine.js +++ b/jstests/replsets/tenant_migration_donor_state_machine.js @@ -154,9 +154,6 @@ configDonorsColl.createIndex({expireAt: 1}, {expireAfterSeconds: 0}); jsTest.log("Test the case where the migration aborts"); const migrationId = UUID(); - let configDonorsColl = donorPrimary.getCollection(kConfigDonorsNS); - configDonorsColl.createIndex({expireAt: 1}, {expireAfterSeconds: 0}); - let abortFp = configureFailPoint(donorPrimary, "abortTenantMigrationAfterBlockingStarts"); assert.commandFailedWithCode(donorPrimary.adminCommand({ donorStartMigration: 1, @@ -187,6 +184,29 @@ configDonorsColl.createIndex({expireAt: 1}, {expireAfterSeconds: 0}); testDonorForgetMigration(donorRst, recipientRst, migrationId, kDBPrefix); })(); +// Drop the TTL index to make sure that the migration state is still available when the +// donorForgetMigration command is retried. +configDonorsColl.dropIndex({expireAt: 1}); + +(() => { + jsTest.log("Test that donorForgetMigration can be run multiple times"); + const migrationId = UUID(); + + assert.commandWorked(donorPrimary.adminCommand({ + donorStartMigration: 1, + migrationId: migrationId, + recipientConnectionString: kRecipientConnString, + databasePrefix: kDBPrefix, + readPreference: {mode: "primary"} + })); + + assert.commandWorked( + donorPrimary.adminCommand({donorForgetMigration: 1, migrationId: migrationId})); + + assert.commandWorked( + donorPrimary.adminCommand({donorForgetMigration: 1, migrationId: migrationId})); +})(); + donorRst.stopSet(); recipientRst.stopSet(); })(); diff --git a/src/mongo/db/repl/tenant_migration_donor_service.cpp b/src/mongo/db/repl/tenant_migration_donor_service.cpp index d821c6c3f26..a07833a2caf 100644 --- a/src/mongo/db/repl/tenant_migration_donor_service.cpp +++ b/src/mongo/db/repl/tenant_migration_donor_service.cpp @@ -90,6 +90,13 @@ Status TenantMigrationDonorService::Instance::checkIfOptionsConflict(BSONObj opt return Status::OK(); } +void TenantMigrationDonorService::Instance::onReceiveDonorForgetMigration() { + stdx::lock_guard<Latch> lg(_mutex); + if (!_receivedDonorForgetMigrationPromise.getFuture().isReady()) { + _receivedDonorForgetMigrationPromise.emplaceValue(); + } +} + repl::OpTime TenantMigrationDonorService::Instance::_insertStateDocument() { const auto stateDocBson = _stateDoc.toBSON(); diff --git a/src/mongo/db/repl/tenant_migration_donor_service.h b/src/mongo/db/repl/tenant_migration_donor_service.h index ddf178121e4..6d1da3ac6d4 100644 --- a/src/mongo/db/repl/tenant_migration_donor_service.h +++ b/src/mongo/db/repl/tenant_migration_donor_service.h @@ -87,9 +87,7 @@ public: return _decisionPromise.getFuture(); } - void onReceiveDonorForgetMigration() { - _receivedDonorForgetMigrationPromise.emplaceValue(); - } + void onReceiveDonorForgetMigration(); private: const NamespaceString _stateDocumentsNS = NamespaceString::kTenantMigrationDonorsNamespace; @@ -142,6 +140,8 @@ public: const std::shared_ptr<executor::ScopedTaskExecutor>& executor, RemoteCommandTargeter* recipientTargeter); + mutable Mutex _mutex = MONGO_MAKE_LATCH("TenantMigrationDonorService::_mutex"); + ServiceContext* _serviceContext; TenantMigrationDonorDocument _stateDoc; |