diff options
author | Samy Lanka <samy.lanka@mongodb.com> | 2020-10-05 22:13:53 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-10-23 14:40:38 +0000 |
commit | c4fd5f392d7e71fe49c84d8b939fa72f4809e48e (patch) | |
tree | 11b6f8cd68318de45bf468d052be553e3880d539 | |
parent | fbdda8cb4937b24f5afe6b3982e6df3940453453 (diff) | |
download | mongo-c4fd5f392d7e71fe49c84d8b939fa72f4809e48e.tar.gz |
SERVER-50869 Fix race condition in bgsync when clearing appliedThrough during stepUp
(cherry picked from commit 4fbb1f65e2ad712f6b4e761d3145191e744b1e7d)
-rw-r--r-- | src/mongo/db/repl/bgsync.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp index 0a30d72803a..6867269f138 100644 --- a/src/mongo/db/repl/bgsync.cpp +++ b/src/mongo/db/repl/bgsync.cpp @@ -40,6 +40,7 @@ #include "mongo/bson/util/bson_extract.h" #include "mongo/client/connection_pool.h" #include "mongo/db/auth/authorization_session.h" +#include "mongo/db/catalog_raii.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/replication_state_transition_lock_guard.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -50,6 +51,7 @@ #include "mongo/db/repl/oplog_interface_local.h" #include "mongo/db/repl/oplog_interface_remote.h" #include "mongo/db/repl/repl_server_parameters_gen.h" +#include "mongo/db/repl/replication_consistency_markers_impl.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/repl/replication_coordinator_impl.h" #include "mongo/db/repl/replication_process.h" @@ -485,6 +487,20 @@ void BackgroundSync::_produce() { // before the OplogWriter gets a chance to append to the oplog. { auto opCtx = cc().makeOperationContext(); + + // Check if the producer has been stopped so that we can prevent setting the applied point + // after step up has already cleared it. We need to acquire the collection lock before the + // mutex to preserve proper lock ordering. + AutoGetCollection autoColl( + opCtx.get(), + NamespaceString(ReplicationConsistencyMarkersImpl::kDefaultMinValidNamespace), + MODE_IX); + stdx::lock_guard<Latch> lock(_mutex); + + if (_state != ProducerState::Running) { + return; + } + if (_replicationProcess->getConsistencyMarkers()->getAppliedThrough(opCtx.get()).isNull()) { _replicationProcess->getConsistencyMarkers()->setAppliedThrough( opCtx.get(), _replCoord->getMyLastAppliedOpTime()); |