diff options
author | Didier Nadeau <didier.nadeau@mongodb.com> | 2022-07-15 14:09:48 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-15 15:13:28 +0000 |
commit | bee3babbf2ef6b75667fe4e8b00219d84fdd1136 (patch) | |
tree | 9caaf967f96b4b7030e3a2aa4cf26b97024e190e | |
parent | 84bbe8a09bad398a08a899405ad353c07c018993 (diff) | |
download | mongo-bee3babbf2ef6b75667fe4e8b00219d84fdd1136.tar.gz |
SERVER-67278 Write kAborted to disk when shard split cannot proceed due to an invalid config
-rw-r--r-- | src/mongo/db/serverless/shard_split_donor_service.cpp | 26 | ||||
-rw-r--r-- | src/mongo/db/serverless/shard_split_donor_service_test.cpp | 9 |
2 files changed, 21 insertions, 14 deletions
diff --git a/src/mongo/db/serverless/shard_split_donor_service.cpp b/src/mongo/db/serverless/shard_split_donor_service.cpp index 14d000b2b97..ae6317ff231 100644 --- a/src/mongo/db/serverless/shard_split_donor_service.cpp +++ b/src/mongo/db/serverless/shard_split_donor_service.cpp @@ -354,6 +354,11 @@ SemiFuture<void> ShardSplitDonorService::DonorStateMachine::run( .unsafeToInlineFuture(); } + LOGV2(6086506, + "Starting shard split.", + "id"_attr = _migrationId, + "timeout"_attr = repl::shardSplitTimeoutMS.load()); + auto isConfigValidWithStatus = [&]() { stdx::lock_guard<Latch> lg(_mutex); auto replCoord = repl::ReplicationCoordinator::get(cc().getServiceContext()); @@ -363,20 +368,15 @@ SemiFuture<void> ShardSplitDonorService::DonorStateMachine::run( }(); if (!isConfigValidWithStatus.isOK()) { + stdx::lock_guard<Latch> lg(_mutex); + LOGV2_ERROR(6395900, "Failed to validate recipient nodes for shard split.", "id"_attr = _migrationId, "status"_attr = isConfigValidWithStatus); - return ExecutorFuture( - **executor, - DurableState{ShardSplitDonorStateEnum::kAborted, isConfigValidWithStatus}) - .unsafeToInlineFuture(); - } - LOGV2(6086506, - "Starting shard split.", - "id"_attr = _migrationId, - "timeout"_attr = repl::shardSplitTimeoutMS.load()); + _abortReason = isConfigValidWithStatus; + } _initiateTimeout(executor, abortToken); return ExecutorFuture(**executor) @@ -614,7 +614,7 @@ ShardSplitDonorService::DonorStateMachine::_enterAbortIndexBuildsOrAbortedState( ShardSplitDonorStateEnum nextState; { stdx::lock_guard<Latch> lg(_mutex); - if (_stateDoc.getState() == ShardSplitDonorStateEnum::kAborted) { + if (_stateDoc.getState() == ShardSplitDonorStateEnum::kAborted || _abortReason) { if (isAbortedDocumentPersistent(lg, _stateDoc)) { // Node has step up and created an instance using a document in abort state. No // need to write the document as it already exists. @@ -623,8 +623,10 @@ ShardSplitDonorService::DonorStateMachine::_enterAbortIndexBuildsOrAbortedState( return ExecutorFuture(**executor); } - _abortReason = - Status(ErrorCodes::TenantMigrationAborted, "Aborted due to 'abortShardSplit'."); + if (!_abortReason) { + _abortReason = + Status(ErrorCodes::TenantMigrationAborted, "Aborted due to 'abortShardSplit'."); + } BSONObjBuilder bob; _abortReason->serializeErrorToBSON(&bob); _stateDoc.setAbortReason(bob.obj()); diff --git a/src/mongo/db/serverless/shard_split_donor_service_test.cpp b/src/mongo/db/serverless/shard_split_donor_service_test.cpp index 84d1f01d621..2068cebcf3c 100644 --- a/src/mongo/db/serverless/shard_split_donor_service_test.cpp +++ b/src/mongo/db/serverless/shard_split_donor_service_test.cpp @@ -841,9 +841,14 @@ TEST_F(ShardSplitDonorServiceTest, AbortDueToRecipientNodesValidation) { auto result = serviceInstance->decisionFuture().get(); ASSERT_EQ(result.state, mongo::ShardSplitDonorStateEnum::kAborted); + ASSERT(result.abortReason); + ASSERT_EQ(result.abortReason->code(), ErrorCodes::BadValue); + ASSERT_TRUE(serviceInstance->isGarbageCollectable()); - ASSERT_OK(serviceInstance->completionFuture().getNoThrow()); - ASSERT_FALSE(serviceInstance->isGarbageCollectable()); + auto statusWithDoc = getStateDocument(opCtx.get(), stateDocument.getId()); + ASSERT_OK(statusWithDoc.getStatus()); + + ASSERT_EQ(statusWithDoc.getValue().getState(), ShardSplitDonorStateEnum::kAborted); } TEST(RecipientAcceptSplitListenerTest, FutureReady) { |