diff options
author | Benety Goh <benety@mongodb.com> | 2017-01-19 17:23:28 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2017-01-19 17:23:28 -0500 |
commit | 7bf2874d0fe92c5503f9cde86ac9e341d1889000 (patch) | |
tree | 9856cc4b59d867a19e3a550acec9604ea6a3ad43 /src/mongo/db/repl/data_replicator.cpp | |
parent | d3e67186d1f9c633e8e69ebb7bf2418d3850688a (diff) | |
download | mongo-7bf2874d0fe92c5503f9cde86ac9e341d1889000.tar.gz |
Revert "SERVER-27678 moved DataReplicator::OnCompletionGuard into its own library"
This reverts commit 9edfc4c8ba273d54ecdc31c1fc0eb8c6a42ccbc4.
Diffstat (limited to 'src/mongo/db/repl/data_replicator.cpp')
-rw-r--r-- | src/mongo/db/repl/data_replicator.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/mongo/db/repl/data_replicator.cpp b/src/mongo/db/repl/data_replicator.cpp index ee990aab967..5282b4c5687 100644 --- a/src/mongo/db/repl/data_replicator.cpp +++ b/src/mongo/db/repl/data_replicator.cpp @@ -1497,6 +1497,46 @@ Status DataReplicator::_enqueueDocuments(Fetcher::Documents::const_iterator begi return Status::OK(); } +DataReplicator::OnCompletionGuard::OnCompletionGuard( + const CancelRemainingWorkInLockFn& cancelRemainingWorkInLock, + const OnCompletionFn& onCompletion) + : _cancelRemainingWorkInLock(cancelRemainingWorkInLock), _onCompletion(onCompletion) {} + +DataReplicator::OnCompletionGuard::~OnCompletionGuard() { + MONGO_DESTRUCTOR_GUARD({ + if (!_lastAppliedSet) { + severe() << "It is a programming error to destroy this initial sync attempt completion " + "guard without the caller providing a result for '_lastApplied'"; + } + invariant(_lastAppliedSet); + // _onCompletion() must be called outside the DataReplicator's lock to avoid a deadlock. + _onCompletion(_lastApplied); + }); +} + +void DataReplicator::OnCompletionGuard::setResultAndCancelRemainingWork_inlock( + const stdx::lock_guard<stdx::mutex>&, const StatusWith<OpTimeWithHash>& lastApplied) { + _setResultAndCancelRemainingWork_inlock(lastApplied); +} + +void DataReplicator::OnCompletionGuard::setResultAndCancelRemainingWork_inlock( + const stdx::unique_lock<stdx::mutex>& lock, const StatusWith<OpTimeWithHash>& lastApplied) { + invariant(lock.owns_lock()); + _setResultAndCancelRemainingWork_inlock(lastApplied); +} + +void DataReplicator::OnCompletionGuard::_setResultAndCancelRemainingWork_inlock( + const StatusWith<OpTimeWithHash>& lastApplied) { + if (_lastAppliedSet) { + return; + } + _lastApplied = lastApplied; + _lastAppliedSet = true; + + // It is fine to call this multiple times. + _cancelRemainingWorkInLock(); +} + std::string DataReplicator::Stats::toString() const { return toBSON().toString(); } |