diff options
author | Benety Goh <benety@mongodb.com> | 2016-06-24 19:06:49 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2016-06-25 12:25:16 -0400 |
commit | 52f29d0dc82569e3fb8a008c418f50be2bc61844 (patch) | |
tree | 9547ab6333abbf2ad10f689b7d986f0e5c346c74 | |
parent | e48204e21c938a372c9cc6822b26ed0b1edbc3a0 (diff) | |
download | mongo-52f29d0dc82569e3fb8a008c418f50be2bc61844.tar.gz |
SERVER-24784 BackgroundSync checks local shutdown flag instead of global mongo::inShutdown()
-rw-r--r-- | src/mongo/db/repl/bgsync.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/repl/bgsync.h | 10 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp index bbd55204450..f01d1e4ac4b 100644 --- a/src/mongo/db/repl/bgsync.cpp +++ b/src/mongo/db/repl/bgsync.cpp @@ -56,7 +56,6 @@ #include "mongo/rpc/metadata/repl_set_metadata.h" #include "mongo/stdx/memory.h" #include "mongo/util/concurrency/thread_pool.h" -#include "mongo/util/exit.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" @@ -180,13 +179,14 @@ void BackgroundSync::shutdown(OperationContext* txn) { stdx::lock_guard<stdx::mutex> lock(_mutex); // Clear the buffer in case the producerThread is waiting in push() due to a full queue. - invariant(inShutdown()); clearBuffer(txn); _stopped = true; if (_oplogFetcher) { _oplogFetcher->shutdown(); } + + _inShutdown = true; } void BackgroundSync::join(OperationContext* txn) { @@ -196,6 +196,15 @@ void BackgroundSync::join(OperationContext* txn) { _oplogBuffer->shutdown(txn); } +bool BackgroundSync::inShutdown() const { + stdx::lock_guard<stdx::mutex> lock(_mutex); + return _inShutdown_inlock(); +} + +bool BackgroundSync::_inShutdown_inlock() const { + return _inShutdown; +} + void BackgroundSync::_run() { Client::initThread("rsBackgroundSync"); AuthorizationSession::get(cc())->grantInternalAuthorization(); @@ -279,7 +288,7 @@ void BackgroundSync::_produce(OperationContext* txn) { } if (_replCoord->isWaitingForApplierToDrain() || _replCoord->getMemberState().primary() || - inShutdownStrict()) { + _inShutdown_inlock()) { return; } } diff --git a/src/mongo/db/repl/bgsync.h b/src/mongo/db/repl/bgsync.h index f39edbe5f23..477d344ab2b 100644 --- a/src/mongo/db/repl/bgsync.h +++ b/src/mongo/db/repl/bgsync.h @@ -85,6 +85,11 @@ public: */ void join(OperationContext* txn); + /** + * Returns true if shutdown() has been called. + */ + bool inShutdown() const; + bool isStopped() const; // starts the sync target notifying thread @@ -123,6 +128,8 @@ public: void pushTestOpToBuffer(OperationContext* txn, const BSONObj& op); private: + bool _inShutdown_inlock() const; + /** * Starts the producer thread which runs until shutdown. Upon resolving the current sync source * the producer thread uses the OplogFetcher (which requires the replication coordinator @@ -197,6 +204,9 @@ private: // Thread running producerThread(). std::unique_ptr<stdx::thread> _producerThread; + // Set to true if shutdown() has been called. + bool _inShutdown = false; + // if producer thread should not be running bool _stopped = true; |