summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/transaction_coordinator_service.cpp
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2021-07-13 17:55:30 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-29 15:50:05 +0000
commitb77ce8da6f0c6fda2442dc214aea80420127140a (patch)
tree4d7b285d7f8431924032bb86bf801ebfc95500b4 /src/mongo/db/s/transaction_coordinator_service.cpp
parent6bf3ad77bb5bcc9c07ef38110e687d3a55ef40f7 (diff)
downloadmongo-b77ce8da6f0c6fda2442dc214aea80420127140a.tar.gz
SERVER-58487 Join TransactionCoordinatorService stepdown tasks during shutdown
Diffstat (limited to 'src/mongo/db/s/transaction_coordinator_service.cpp')
-rw-r--r--src/mongo/db/s/transaction_coordinator_service.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/mongo/db/s/transaction_coordinator_service.cpp b/src/mongo/db/s/transaction_coordinator_service.cpp
index 39f0ef4bef7..349db0ac079 100644
--- a/src/mongo/db/s/transaction_coordinator_service.cpp
+++ b/src/mongo/db/s/transaction_coordinator_service.cpp
@@ -179,6 +179,10 @@ void TransactionCoordinatorService::onStepUp(OperationContext* opCtx,
joinPreviousRound();
stdx::lock_guard<Latch> lg(_mutex);
+ if (_isShuttingDown) {
+ return;
+ }
+
invariant(!_catalogAndScheduler);
_catalogAndScheduler = std::make_shared<CatalogAndScheduler>(opCtx->getServiceContext());
@@ -264,12 +268,25 @@ void TransactionCoordinatorService::onStepDown() {
_catalogAndSchedulerToCleanup->onStepDown();
}
+void TransactionCoordinatorService::shutdown() {
+ {
+ stdx::lock_guard<Latch> lg(_mutex);
+ _isShuttingDown = true;
+ }
+
+ onStepDown();
+ joinPreviousRound();
+}
+
void TransactionCoordinatorService::onShardingInitialization(OperationContext* opCtx,
bool isPrimary) {
if (!isPrimary)
return;
stdx::lock_guard<Latch> lg(_mutex);
+ if (_isShuttingDown) {
+ return;
+ }
invariant(!_catalogAndScheduler);
_catalogAndScheduler = std::make_shared<CatalogAndScheduler>(opCtx->getServiceContext());
@@ -289,18 +306,26 @@ TransactionCoordinatorService::_getCatalogAndScheduler(OperationContext* opCtx)
}
void TransactionCoordinatorService::joinPreviousRound() {
+ stdx::unique_lock<Latch> ul(_mutex);
+
// onStepDown must have been called
invariant(!_catalogAndScheduler);
if (!_catalogAndSchedulerToCleanup)
return;
+ auto schedulerToCleanup = _catalogAndSchedulerToCleanup;
+
+ ul.unlock();
+
LOGV2(22454, "Waiting for coordinator tasks from previous term to complete");
// Block until all coordinators scheduled the previous time the service was primary to have
// drained. Because the scheduler was interrupted, it should be extremely rare for there to be
// any coordinators left, so if this actually causes blocking, it would most likely be a bug.
- _catalogAndSchedulerToCleanup->join();
+ schedulerToCleanup->join();
+
+ ul.lock();
_catalogAndSchedulerToCleanup.reset();
}