diff options
Diffstat (limited to 'src')
10 files changed, 27 insertions, 17 deletions
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp index a57d269c2a2..3fdfc2deca6 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp @@ -1254,7 +1254,7 @@ void ReshardingCoordinatorService::ReshardingCoordinator::_onAbortCoordinatorAnd _updateCoordinatorDocStateAndCatalogEntries( CoordinatorStateEnum::kAborting, _coordinatorDoc, boost::none, boost::none, status); - _tellAllParticipantsToAbort(executor); + _tellAllParticipantsToAbort(executor, status == ErrorCodes::ReshardCollectionAborted); // Wait for all participants to acknowledge the operation reached an unrecoverable // error. @@ -1638,7 +1638,7 @@ void ReshardingCoordinatorService::ReshardingCoordinator::_tellAllParticipantsTo } void ReshardingCoordinatorService::ReshardingCoordinator::_tellAllParticipantsToAbort( - const std::shared_ptr<executor::ScopedTaskExecutor>& executor) { + const std::shared_ptr<executor::ScopedTaskExecutor>& executor, bool isUserAborted) { auto opCtx = _cancelableOpCtxFactory->makeOperationContext(&cc()); auto donorShardIds = extractShardIdsFromParticipantEntries(_coordinatorDoc.getDonorShards()); @@ -1647,7 +1647,7 @@ void ReshardingCoordinatorService::ReshardingCoordinator::_tellAllParticipantsTo std::set<ShardId> participantShardIds{donorShardIds.begin(), donorShardIds.end()}; participantShardIds.insert(recipientShardIds.begin(), recipientShardIds.end()); - ShardsvrAbortReshardCollection abortCmd(_coordinatorDoc.getReshardingUUID()); + ShardsvrAbortReshardCollection abortCmd(_coordinatorDoc.getReshardingUUID(), isUserAborted); abortCmd.setDbName("admin"); sharding_util::sendCommandToShards(opCtx.get(), diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.h b/src/mongo/db/s/resharding/resharding_coordinator_service.h index 074b51ad338..6f7a373c1c1 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_service.h +++ b/src/mongo/db/s/resharding/resharding_coordinator_service.h @@ -414,7 +414,8 @@ private: /** * Sends '_shardsvrAbortReshardCollection' to all participant shards. */ - void _tellAllParticipantsToAbort(const std::shared_ptr<executor::ScopedTaskExecutor>& executor); + void _tellAllParticipantsToAbort(const std::shared_ptr<executor::ScopedTaskExecutor>& executor, + bool isUserAborted); // The unique key for a given resharding operation. InstanceID is an alias for BSONObj. The // value of this is the UUID that will be used as the collection UUID for the new sharded diff --git a/src/mongo/db/s/resharding/resharding_donor_service.cpp b/src/mongo/db/s/resharding/resharding_donor_service.cpp index 684bf5475d1..c3769f74c89 100644 --- a/src/mongo/db/s/resharding/resharding_donor_service.cpp +++ b/src/mongo/db/s/resharding/resharding_donor_service.cpp @@ -422,7 +422,7 @@ boost::optional<BSONObj> ReshardingDonorService::DonorStateMachine::reportForCur void ReshardingDonorService::DonorStateMachine::onReshardingFieldsChanges( OperationContext* opCtx, const TypeCollectionReshardingFields& reshardingFields) { if (reshardingFields.getState() == CoordinatorStateEnum::kAborting) { - abort(); + abort(reshardingFields.getUserCanceled().get()); return; } @@ -883,7 +883,7 @@ CancellationToken ReshardingDonorService::DonorStateMachine::_initAbortSource( return _abortSource->token(); } -void ReshardingDonorService::DonorStateMachine::abort() { +void ReshardingDonorService::DonorStateMachine::abort(bool isUserCancelled) { auto abortSource = [&]() -> boost::optional<CancellationSource> { stdx::lock_guard<Latch> lk(_mutex); diff --git a/src/mongo/db/s/resharding/resharding_donor_service.h b/src/mongo/db/s/resharding/resharding_donor_service.h index 672dc5a3f09..f8ccd15cfc4 100644 --- a/src/mongo/db/s/resharding/resharding_donor_service.h +++ b/src/mongo/db/s/resharding/resharding_donor_service.h @@ -101,7 +101,7 @@ public: const ReshardingDonorDocument& donorDoc); // Initiates the cancellation of the resharding operation. - void abort(); + void abort(bool isUserCancelled); private: /** diff --git a/src/mongo/db/s/resharding/resharding_donor_service_test.cpp b/src/mongo/db/s/resharding/resharding_donor_service_test.cpp index ca72b6a2337..7ea3a8aca98 100644 --- a/src/mongo/db/s/resharding/resharding_donor_service_test.cpp +++ b/src/mongo/db/s/resharding/resharding_donor_service_test.cpp @@ -486,7 +486,7 @@ TEST_F(ReshardingDonorServiceTest, CompletesWithStepdownAfterAbort) { // The call to notifyToStartBlockingWrites() is skipped here because the donor is being // notified that the resharding operation is aborting before the donor would have // transitioned to kBlockingWrites. - donor->abort(); + donor->abort(false); // Step down before the transition to kDone can complete. doneTransitionGuard->wait(DonorStateEnum::kDone); @@ -504,7 +504,7 @@ TEST_F(ReshardingDonorServiceTest, CompletesWithStepdownAfterAbort) { donor = *maybeDonor; doneTransitionGuard.reset(); - donor->abort(); + donor->abort(false); ASSERT_OK(donor->getCompletionFuture().getNoThrow()); checkStateDocumentRemoved(opCtx.get()); @@ -543,7 +543,7 @@ TEST_F(ReshardingDonorServiceTest, RetainsSourceCollectionOnAbort) { ASSERT_EQ(coll->uuid(), doc.getSourceUUID()); } - donor->abort(); + donor->abort(false); ASSERT_OK(donor->getCompletionFuture().getNoThrow()); checkStateDocumentRemoved(opCtx.get()); diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.cpp b/src/mongo/db/s/resharding/resharding_recipient_service.cpp index 67a3b3ad4c4..be313078cf6 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service.cpp @@ -425,7 +425,7 @@ boost::optional<BSONObj> ReshardingRecipientService::RecipientStateMachine::repo void ReshardingRecipientService::RecipientStateMachine::onReshardingFieldsChanges( OperationContext* opCtx, const TypeCollectionReshardingFields& reshardingFields) { if (reshardingFields.getState() == CoordinatorStateEnum::kAborting) { - abort(); + abort(reshardingFields.getUserCanceled().get()); return; } @@ -951,7 +951,7 @@ CancellationToken ReshardingRecipientService::RecipientStateMachine::_initAbortS return _abortSource->token(); } -void ReshardingRecipientService::RecipientStateMachine::abort() { +void ReshardingRecipientService::RecipientStateMachine::abort(bool isUserCancelled) { auto abortSource = [&]() -> boost::optional<CancellationSource> { stdx::lock_guard<Latch> lk(_mutex); diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.h b/src/mongo/db/s/resharding/resharding_recipient_service.h index 9d5f3a91c20..bae2578ba97 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service.h +++ b/src/mongo/db/s/resharding/resharding_recipient_service.h @@ -146,7 +146,7 @@ public: const ReshardingRecipientDocument& recipientDoc); // Initiates the cancellation of the resharding operation. - void abort(); + void abort(bool isUserCancelled); private: /** diff --git a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp index c3de63bf8f5..2d73855743d 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp @@ -455,7 +455,7 @@ TEST_F(ReshardingRecipientServiceTest, DropsTemporaryReshardingCollectionOnAbort auto recipient = RecipientStateMachine::getOrCreate(opCtx.get(), _service, doc.toBSON()); notifyToStartCloning(opCtx.get(), *recipient, doc); - recipient->abort(); + recipient->abort(false); doneTransitionGuard->wait(RecipientStateEnum::kDone); stepDown(); @@ -471,7 +471,7 @@ TEST_F(ReshardingRecipientServiceTest, DropsTemporaryReshardingCollectionOnAbort recipient = *maybeRecipient; doneTransitionGuard.reset(); - recipient->abort(); + recipient->abort(false); ASSERT_OK(recipient->getCompletionFuture().getNoThrow()); checkStateDocumentRemoved(opCtx.get()); diff --git a/src/mongo/db/s/shardsvr_abort_reshard_collection_command.cpp b/src/mongo/db/s/shardsvr_abort_reshard_collection_command.cpp index 531e738f05d..416f792d483 100644 --- a/src/mongo/db/s/shardsvr_abort_reshard_collection_command.cpp +++ b/src/mongo/db/s/shardsvr_abort_reshard_collection_command.cpp @@ -76,7 +76,7 @@ public: LOGV2(5663800, "Aborting resharding recipient participant", "reshardingUUID"_attr = uuid()); - (*machine)->abort(); + (*machine)->abort(isUserCanceled()); } if (auto machine = resharding::tryGetReshardingStateMachine< @@ -88,7 +88,7 @@ public: LOGV2(5663801, "Aborting resharding donor participant", "reshardingUUID"_attr = uuid()); - (*machine)->abort(); + (*machine)->abort(isUserCanceled()); } for (auto doneFuture : futuresToWait) { @@ -122,6 +122,10 @@ public: } private: + bool isUserCanceled() const { + return request().getUserCanceled(); + } + UUID uuid() const { return request().getCommandParameter(); } diff --git a/src/mongo/s/request_types/abort_reshard_collection.idl b/src/mongo/s/request_types/abort_reshard_collection.idl index 1c786f76ad9..bbe3515b6bf 100644 --- a/src/mongo/s/request_types/abort_reshard_collection.idl +++ b/src/mongo/s/request_types/abort_reshard_collection.idl @@ -60,3 +60,8 @@ commands: namespace: type api_version: "" type: uuid + fields: + userCanceled: + type: bool + optional: false + description: "Determines whether the resharding opertion was user aborted." |