diff options
author | Randolph Tan <randolph@10gen.com> | 2021-03-18 17:51:59 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-22 15:26:56 +0000 |
commit | 939178eb77d25dc234de03ac7d5dc98210514c7a (patch) | |
tree | 6a034116a1d2c8c9b3ba0bc740dd7110c0ccda20 /src/mongo/db/repl | |
parent | d32175b3d1c3135de0ad016ba14f2c78a3f54c29 (diff) | |
download | mongo-939178eb77d25dc234de03ac7d5dc98210514c7a.tar.gz |
SERVER-55007 Deadlock between step down and MongoDOperationContextSession
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp | 11 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 6bb30d7535e..ddf3bbb9f8d 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -3582,6 +3582,11 @@ void ReplicationCoordinatorImpl::_finishReplSetReconfig(OperationContext* opCtx, _topCoord->prepareForUnconditionalStepDown(); lk.unlock(); + // To prevent a deadlock between session checkout and RSTL lock taking, disallow new + // sessions from being checked out. Existing sessions currently checked out will be killed + // by the killOpThread. + ScopedBlockSessionCheckouts blockSessions(opCtx); + // Primary node won't be electable or removed after the configuration change. // So, finish the reconfig under RSTL, so that the step down occurs safely. arsd.emplace(this, opCtx, ReplicationCoordinator::OpsKillingStateTransitionEnum::kStepDown); diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp index 8fafa45329f..0c38c4c4176 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp @@ -57,6 +57,7 @@ #include "mongo/db/repl/topology_coordinator.h" #include "mongo/db/repl/vote_requester.h" #include "mongo/db/service_context.h" +#include "mongo/db/session_catalog.h" #include "mongo/db/storage/control/journal_flusher.h" #include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" @@ -500,6 +501,11 @@ void ReplicationCoordinatorImpl::_stepDownFinish( auto opCtx = cc().makeOperationContext(); + // To prevent a deadlock between session checkout and RSTL lock taking, disallow new sessions + // from being checked out. Existing sessions currently checked out will be killed by the + // killOpThread. + ScopedBlockSessionCheckouts blockSessions(opCtx.get()); + // kill all write operations which are no longer safe to run on step down. Also, operations that // have taken global lock in S mode and operations blocked on prepare conflict will be killed to // avoid 3-way deadlock between read, prepared transaction and step down thread. @@ -781,6 +787,11 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigFinish( _topCoord->prepareForUnconditionalStepDown(); lk.unlock(); + // To prevent a deadlock between session checkout and RSTL lock taking, disallow new + // sessions from being checked out. Existing sessions currently checked out will be killed + // by the killOpThread. + ScopedBlockSessionCheckouts blockSessions(opCtx.get()); + // Primary node will be either unelectable or removed after the configuration change. // So, finish the reconfig under RSTL, so that the step down occurs safely. arsd.emplace( |