summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authornandinibhartiyaMDB <nandini.bhartiya@mongodb.com>2022-10-12 21:53:46 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-10-14 17:48:37 +0000
commita67309066f0b6f67f052e2453fc02bbcceb953df (patch)
tree79893d1d3788bb5ca0ecb3bab50b6766773b3def /src/mongo/db
parent199173d18b9af33156290967dc50d1af3e0c34b3 (diff)
downloadmongo-a67309066f0b6f67f052e2453fc02bbcceb953df.tar.gz
SERVER-69756: Abort a resharding operation immediately.
(cherry picked from commit befe8bb9cf767db458149afca838823d2fd4876c)
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_service.cpp24
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_service.h11
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp11
3 files changed, 44 insertions, 2 deletions
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
index ccfcbd8cb24..6241ef98254 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
@@ -94,6 +94,7 @@ MONGO_FAIL_POINT_DEFINE(reshardingPauseCoordinatorBeforeStartingErrorFlow);
MONGO_FAIL_POINT_DEFINE(reshardingPauseCoordinatorBeforePersistingStateTransition);
MONGO_FAIL_POINT_DEFINE(pauseBeforeTellDonorToRefresh);
MONGO_FAIL_POINT_DEFINE(pauseBeforeInsertCoordinatorDoc);
+MONGO_FAIL_POINT_DEFINE(pauseBeforeCTHolderInitialization);
const std::string kReshardingCoordinatorActiveIndexName = "ReshardingCoordinatorActiveIndex";
const Backoff kExponentialBackoff(Seconds(1), Milliseconds::max());
@@ -1298,7 +1299,18 @@ ReshardingCoordinatorService::ReshardingCoordinator::_commitAndFinishReshardOper
SemiFuture<void> ReshardingCoordinatorService::ReshardingCoordinator::run(
std::shared_ptr<executor::ScopedTaskExecutor> executor,
const CancellationToken& stepdownToken) noexcept {
- _ctHolder = std::make_unique<CoordinatorCancellationTokenHolder>(stepdownToken);
+ pauseBeforeCTHolderInitialization.pauseWhileSet();
+
+ auto abortCalled = [&] {
+ stdx::lock_guard<Latch> lk(_abortCalledMutex);
+ _ctHolder = std::make_unique<CoordinatorCancellationTokenHolder>(stepdownToken);
+ return _abortCalled;
+ }();
+
+ if (abortCalled) {
+ _ctHolder->abort();
+ }
+
_markKilledExecutor->startup();
_cancelableOpCtxFactory.emplace(_ctHolder->getAbortToken(), _markKilledExecutor);
@@ -1454,7 +1466,15 @@ ReshardingCoordinatorService::ReshardingCoordinator::_onAbortCoordinatorAndParti
}
void ReshardingCoordinatorService::ReshardingCoordinator::abort() {
- _ctHolder->abort();
+ auto ctHolderInitialized = [&] {
+ stdx::lock_guard<Latch> lk(_abortCalledMutex);
+ _abortCalled = true;
+ return !(_ctHolder == nullptr);
+ }();
+
+ if (ctHolderInitialized) {
+ _ctHolder->abort();
+ }
}
boost::optional<BSONObj> ReshardingCoordinatorService::ReshardingCoordinator::reportForCurrentOp(
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.h b/src/mongo/db/s/resharding/resharding_coordinator_service.h
index 9759078eda1..6a012407b25 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.h
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.h
@@ -536,6 +536,13 @@ private:
MONGO_MAKE_LATCH("ReshardingCoordinatorService::_fulfillmentMutex");
/**
+ * Must be locked while the _abortCalled is being set to true.
+ */
+ mutable Mutex _abortCalledMutex =
+ MONGO_MAKE_LATCH("ReshardingCoordinatorService::_abortCalledMutex");
+
+
+ /**
* Coordinator does not enter the critical section until this is fulfilled.
* Can be set by "commitReshardCollection" command or by metrics determining
* that it's okay to proceed.
@@ -555,6 +562,10 @@ private:
std::shared_ptr<resharding::CoordinatorCommitMonitor> _commitMonitor;
std::shared_ptr<ReshardingCoordinatorExternalState> _reshardingCoordinatorExternalState;
+
+ // Used to catch the case when an abort() is called but the cancellation source (_ctHolder) has
+ // not been initialized.
+ bool _abortCalled{false};
};
} // namespace mongo
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp
index 6a5197b4c41..188fc400e29 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp
@@ -923,5 +923,16 @@ TEST_F(ReshardingCoordinatorServiceTest, ReshardingCoordinatorFailsIfMigrationNo
}
}
+TEST_F(ReshardingCoordinatorServiceTest, SuccessfullyAbortReshardOperationImmediately) {
+ auto pauseBeforeCTHolderInitialization =
+ globalFailPointRegistry().find("pauseBeforeCTHolderInitialization");
+ auto timesEnteredFailPoint = pauseBeforeCTHolderInitialization->setMode(FailPoint::alwaysOn, 0);
+ auto coordinator = initializeAndGetCoordinator();
+ coordinator->abort();
+ pauseBeforeCTHolderInitialization->waitForTimesEntered(timesEnteredFailPoint + 1);
+ pauseBeforeCTHolderInitialization->setMode(FailPoint::off, 0);
+ coordinator->getCompletionFuture().wait();
+}
+
} // namespace
} // namespace mongo