summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorJamie Anderson <jamie.anderson@mongodb.com>2021-05-10 22:54:31 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-12 20:53:21 +0000
commit0de67b8e4634af6d614773ec1e55ca8cd5d961f3 (patch)
tree1c24a8835ebf7e9783242462c7bd2a6e5292468a /src/mongo
parent78d5ecce93e88f754ef1bbe11e4c5f9367c2983a (diff)
downloadmongo-0de67b8e4634af6d614773ec1e55ca8cd5d961f3.tar.gz
SERVER-55685: Remove reshardingFields.abortReason from the config.collections document
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_test.cpp12
-rw-r--r--src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp2
-rw-r--r--src/mongo/db/s/resharding/resharding_donor_service.cpp15
-rw-r--r--src/mongo/db/s/resharding/resharding_donor_service.h4
-rw-r--r--src/mongo/db/s/resharding/resharding_donor_service_test.cpp45
-rw-r--r--src/mongo/db/s/resharding/resharding_recipient_service.cpp5
-rw-r--r--src/mongo/db/s/resharding/resharding_recipient_service_test.cpp1
-rw-r--r--src/mongo/s/resharding/type_collection_fields.idl3
8 files changed, 30 insertions, 57 deletions
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
index 7ed4369bde5..4f5110177fc 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
@@ -351,10 +351,6 @@ protected:
0);
if (auto expectedAbortReason = expectedCoordinatorDoc.getAbortReason()) {
- ASSERT(onDiskReshardingFields.getAbortReason());
- ASSERT_BSONOBJ_EQ(expectedAbortReason.get(),
- onDiskReshardingFields.getAbortReason().get());
-
auto userCanceled = getStatusFromAbortReason(expectedCoordinatorDoc) ==
ErrorCodes::ReshardCollectionAborted;
ASSERT(onDiskReshardingFields.getUserCanceled() == userCanceled);
@@ -416,11 +412,6 @@ protected:
ASSERT(onDiskReshardingFields.getUserCanceled() ==
expectedReshardingFields.getUserCanceled());
- if (onDiskReshardingFields.getState() == CoordinatorStateEnum::kError) {
- // Confirm 'reshardingFields.abortReason' exists on the temporary collection.
- ASSERT(onDiskReshardingFields.getAbortReason());
- }
-
// 'donorFields' should not exist for the temporary collection.
ASSERT(!onDiskReshardingFields.getDonorFields());
}
@@ -488,9 +479,6 @@ protected:
extractShardIdsFromParticipantEntries(expectedCoordinatorDoc.getRecipientShards()));
expectedReshardingFields.setDonorFields(donorField);
if (auto abortReason = expectedCoordinatorDoc.getAbortReason()) {
- AbortReason abortReasonStruct;
- abortReasonStruct.setAbortReason(abortReason);
- expectedReshardingFields.setAbortReasonStruct(std::move(abortReasonStruct));
expectedReshardingFields.setUserCanceled(
getStatusFromAbortReason(expectedCoordinatorDoc) ==
ErrorCodes::ReshardCollectionAborted);
diff --git a/src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp b/src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp
index c7d16720f94..077419c3add 100644
--- a/src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp
+++ b/src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp
@@ -283,7 +283,7 @@ void processReshardingFieldsForCollection(OperationContext* opCtx,
const NamespaceString& nss,
const CollectionMetadata& metadata,
const ReshardingFields& reshardingFields) {
- if (reshardingFields.getAbortReason()) {
+ if (reshardingFields.getState() == CoordinatorStateEnum::kError) {
// The coordinator encountered an unrecoverable error, both donors and recipients should be
// made aware.
processReshardingFieldsForDonorCollection(opCtx, nss, metadata, reshardingFields);
diff --git a/src/mongo/db/s/resharding/resharding_donor_service.cpp b/src/mongo/db/s/resharding/resharding_donor_service.cpp
index 844359ce207..5e03aeb3867 100644
--- a/src/mongo/db/s/resharding/resharding_donor_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_donor_service.cpp
@@ -423,8 +423,8 @@ boost::optional<BSONObj> ReshardingDonorService::DonorStateMachine::reportForCur
void ReshardingDonorService::DonorStateMachine::onReshardingFieldsChanges(
OperationContext* opCtx, const TypeCollectionReshardingFields& reshardingFields) {
- if (reshardingFields.getAbortReason()) {
- auto abortReason = getStatusFromAbortReason(reshardingFields);
+ if (reshardingFields.getState() == CoordinatorStateEnum::kError) {
+ auto abortReason = Status(ErrorCodes::ReshardCollectionAborted, "aborted");
_onAbortEncountered(abortReason);
return;
}
@@ -851,11 +851,7 @@ void ReshardingDonorService::DonorStateMachine::_removeDonorDocument() {
opCtx->recoveryUnit()->onCommit([this](boost::optional<Timestamp> unusedCommitTime) {
stdx::lock_guard<Latch> lk(_mutex);
- if (_abortReason) {
- ensureFulfilledPromise(lk, _completionPromise, _abortReason.get());
- } else {
- ensureFulfilledPromise(lk, _completionPromise);
- }
+ _completionPromise.emplaceValue();
});
deleteObjects(opCtx.get(),
@@ -893,8 +889,7 @@ CancellationToken ReshardingDonorService::DonorStateMachine::_initAbortSource(
void ReshardingDonorService::DonorStateMachine::_onAbortEncountered(const Status& abortReason) {
auto abortSource = [&]() -> boost::optional<CancellationSource> {
stdx::lock_guard<Latch> lk(_mutex);
- _abortReason = abortReason;
- invariant(!_abortReason->isOK());
+ invariant(!abortReason.isOK());
if (_abortSource) {
return _abortSource;
@@ -902,7 +897,7 @@ void ReshardingDonorService::DonorStateMachine::_onAbortEncountered(const Status
// run() hasn't been called, notify the operation should be aborted by setting an
// error.
invariant(!_coordinatorHasDecisionPersisted.getFuture().isReady());
- _coordinatorHasDecisionPersisted.setError(_abortReason.get());
+ _coordinatorHasDecisionPersisted.setError(abortReason);
return boost::none;
}
}();
diff --git a/src/mongo/db/s/resharding/resharding_donor_service.h b/src/mongo/db/s/resharding/resharding_donor_service.h
index de2c99b8b96..d30abc62e32 100644
--- a/src/mongo/db/s/resharding/resharding_donor_service.h
+++ b/src/mongo/db/s/resharding/resharding_donor_service.h
@@ -213,10 +213,6 @@ private:
// cancels the parent CancellationSource upon stepdown/failover.
boost::optional<CancellationSource> _abortSource;
- // Holds the unrecoverable error reported by the coordinator that caused the entire resharding
- // operation to fail.
- boost::optional<Status> _abortReason;
-
// The identifier associated to the recoverable critical section.
const BSONObj _critSecReason;
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 312024e0223..68cac99f66e 100644
--- a/src/mongo/db/s/resharding/resharding_donor_service_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_donor_service_test.cpp
@@ -171,32 +171,30 @@ public:
_onReshardingFieldsChanges(opCtx, donor, donorDoc, CoordinatorStateEnum::kBlockingWrites);
}
- void notifyReshardingOutcomeDecided(OperationContext* opCtx,
- DonorStateMachine& donor,
- const ReshardingDonorDocument& donorDoc,
- Status outcome) {
- if (outcome.isOK()) {
- _onReshardingFieldsChanges(
- opCtx, donor, donorDoc, CoordinatorStateEnum::kDecisionPersisted);
- } else {
- _onReshardingFieldsChanges(
- opCtx, donor, donorDoc, CoordinatorStateEnum::kError, std::move(outcome));
- }
+ void notifyReshardingCommitting(OperationContext* opCtx,
+ DonorStateMachine& donor,
+ const ReshardingDonorDocument& donorDoc) {
+ _onReshardingFieldsChanges(
+ opCtx, donor, donorDoc, CoordinatorStateEnum::kDecisionPersisted);
+ }
+
+ void notifyReshardingAborting(OperationContext* opCtx,
+ DonorStateMachine& donor,
+ const ReshardingDonorDocument& donorDoc) {
+ _onReshardingFieldsChanges(opCtx, donor, donorDoc, CoordinatorStateEnum::kError);
}
private:
void _onReshardingFieldsChanges(OperationContext* opCtx,
DonorStateMachine& donor,
const ReshardingDonorDocument& donorDoc,
- CoordinatorStateEnum coordinatorState,
- boost::optional<Status> abortReason = boost::none) {
+ CoordinatorStateEnum coordinatorState) {
auto reshardingFields = TypeCollectionReshardingFields{donorDoc.getReshardingUUID()};
auto donorFields = TypeCollectionDonorFields{donorDoc.getTempReshardingNss(),
donorDoc.getReshardingKey(),
donorDoc.getRecipientShards()};
reshardingFields.setDonorFields(donorFields);
reshardingFields.setState(coordinatorState);
- emplaceAbortReasonIfExists(reshardingFields, std::move(abortReason));
donor.onReshardingFieldsChanges(opCtx, reshardingFields);
}
@@ -211,7 +209,7 @@ TEST_F(ReshardingDonorServiceTest, CanTransitionThroughEachStateToCompletion) {
notifyRecipientsDoneCloning(opCtx.get(), *donor, doc);
notifyToStartBlockingWrites(opCtx.get(), *donor, doc);
- notifyReshardingOutcomeDecided(opCtx.get(), *donor, doc, Status::OK());
+ notifyReshardingCommitting(opCtx.get(), *donor, doc);
ASSERT_OK(donor->getCompletionFuture().getNoThrow());
}
@@ -331,7 +329,7 @@ TEST_F(ReshardingDonorServiceTest, StepDownStepUpEachTransition) {
break;
}
case DonorStateEnum::kDone: {
- notifyReshardingOutcomeDecided(opCtx.get(), *donor, doc, Status::OK());
+ notifyReshardingCommitting(opCtx.get(), *donor, doc);
break;
}
default:
@@ -357,7 +355,7 @@ TEST_F(ReshardingDonorServiceTest, StepDownStepUpEachTransition) {
auto donor = DonorStateMachine::getOrCreate(opCtx.get(), _service, doc.toBSON());
stateTransitionsGuard.unset(DonorStateEnum::kDone);
- notifyReshardingOutcomeDecided(opCtx.get(), *donor, doc, Status::OK());
+ notifyReshardingCommitting(opCtx.get(), *donor, doc);
ASSERT_OK(donor->getCompletionFuture().getNoThrow());
}
}
@@ -380,7 +378,7 @@ TEST_F(ReshardingDonorServiceTest, DropsSourceCollectionWhenDone) {
ASSERT_EQ(coll->uuid(), doc.getSourceUUID());
}
- notifyReshardingOutcomeDecided(opCtx.get(), *donor, doc, Status::OK());
+ notifyReshardingCommitting(opCtx.get(), *donor, doc);
ASSERT_OK(donor->getCompletionFuture().getNoThrow());
{
@@ -401,7 +399,7 @@ TEST_F(ReshardingDonorServiceTest, CompletesWithStepdownAfterError) {
auto donor = DonorStateMachine::getOrCreate(opCtx.get(), _service, doc.toBSON());
notifyRecipientsDoneCloning(opCtx.get(), *donor, doc);
- notifyReshardingOutcomeDecided(opCtx.get(), *donor, doc, {ErrorCodes::InternalError, ""});
+ notifyReshardingAborting(opCtx.get(), *donor, doc);
stateTransitionsGuard.wait(DonorStateEnum::kDone);
stepDown();
@@ -416,8 +414,9 @@ TEST_F(ReshardingDonorServiceTest, CompletesWithStepdownAfterError) {
stateTransitionsGuard.unset(DonorStateEnum::kDone);
- notifyReshardingOutcomeDecided(opCtx.get(), *donor, doc, {ErrorCodes::InternalError, ""});
- ASSERT_EQ(donor->getCompletionFuture().getNoThrow(), ErrorCodes::InternalError);
+ notifyReshardingAborting(opCtx.get(), *donor, doc);
+ ASSERT_OK(donor->getCompletionFuture().getNoThrow());
+
{
// Verify original collection still exists even with stepdown.
AutoGetCollection coll(opCtx.get(), doc.getSourceNss(), MODE_IS);
@@ -445,8 +444,8 @@ TEST_F(ReshardingDonorServiceTest, RetainsSourceCollectionOnError) {
ASSERT_EQ(coll->uuid(), doc.getSourceUUID());
}
- notifyReshardingOutcomeDecided(opCtx.get(), *donor, doc, {ErrorCodes::InternalError, ""});
- ASSERT_EQ(donor->getCompletionFuture().getNoThrow(), ErrorCodes::InternalError);
+ notifyReshardingAborting(opCtx.get(), *donor, doc);
+ ASSERT_OK(donor->getCompletionFuture().getNoThrow());
{
AutoGetCollection coll(opCtx.get(), doc.getSourceNss(), MODE_IS);
diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.cpp b/src/mongo/db/s/resharding/resharding_recipient_service.cpp
index 50e2abe232d..0ee9732d92d 100644
--- a/src/mongo/db/s/resharding/resharding_recipient_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_recipient_service.cpp
@@ -298,9 +298,8 @@ boost::optional<BSONObj> ReshardingRecipientService::RecipientStateMachine::repo
void ReshardingRecipientService::RecipientStateMachine::onReshardingFieldsChanges(
OperationContext* opCtx, const TypeCollectionReshardingFields& reshardingFields) {
stdx::lock_guard<Latch> lk(_mutex);
- if (reshardingFields.getAbortReason()) {
- auto status = getStatusFromAbortReason(reshardingFields);
- invariant(!status.isOK());
+ if (reshardingFields.getState() == CoordinatorStateEnum::kError) {
+ auto status = Status(ErrorCodes::ReshardCollectionAborted, "aborted");
_abortStatus.emplace(status);
if (_abortSource) {
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 5d27cefe5f3..a88acc83619 100644
--- a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp
@@ -254,7 +254,6 @@ private:
auto reshardingFields = TypeCollectionReshardingFields{recipientDoc.getReshardingUUID()};
reshardingFields.setRecipientFields(_makeRecipientFields(recipientDoc));
reshardingFields.setState(coordinatorState);
- emplaceAbortReasonIfExists(reshardingFields, std::move(abortReason));
recipient.onReshardingFieldsChanges(opCtx, reshardingFields);
}
};
diff --git a/src/mongo/s/resharding/type_collection_fields.idl b/src/mongo/s/resharding/type_collection_fields.idl
index cc86cb52976..6b5ecaaa991 100644
--- a/src/mongo/s/resharding/type_collection_fields.idl
+++ b/src/mongo/s/resharding/type_collection_fields.idl
@@ -84,9 +84,6 @@ structs:
TypeCollectionReshardingFields:
description: "Resharding-related fields meant to be stored in a config.collections
document."
- inline_chained_structs: true
- chained_structs:
- AbortReason: AbortReasonStruct
# Use strict:false to avoid complications around upgrade/downgrade. This isn't technically
# required for resharding because durable state from all resharding operations is cleaned up
# before the upgrade or downgrade can complete.