diff options
author | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2020-06-11 21:44:26 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-07 14:12:51 +0000 |
commit | 95ee10210b3b92b166410e70b33a5fce39ec0958 (patch) | |
tree | 57b02c652ab76e7ba2606d675e648868d99f37c7 | |
parent | e87f6f53c58a75229b40fff7b32de202f2dcccc7 (diff) | |
download | mongo-95ee10210b3b92b166410e70b33a5fce39ec0958.tar.gz |
SERVER-48734: Fix db_repl_test in TSAN
-rw-r--r-- | src/mongo/db/repl/oplog_fetcher_test.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/repl/scatter_gather_test.cpp | 18 | ||||
-rw-r--r-- | src/mongo/unittest/task_executor_proxy.cpp | 42 | ||||
-rw-r--r-- | src/mongo/unittest/task_executor_proxy.h | 2 | ||||
-rw-r--r-- | src/mongo/util/elapsed_tracker.cpp | 16 | ||||
-rw-r--r-- | src/mongo/util/elapsed_tracker.h | 5 |
6 files changed, 46 insertions, 45 deletions
diff --git a/src/mongo/db/repl/oplog_fetcher_test.cpp b/src/mongo/db/repl/oplog_fetcher_test.cpp index 61380e4c244..88086deaeeb 100644 --- a/src/mongo/db/repl/oplog_fetcher_test.cpp +++ b/src/mongo/db/repl/oplog_fetcher_test.cpp @@ -691,11 +691,11 @@ TEST_F(OplogFetcherTest, ASSERT_EQUALS(ReplicationProcess::kUninitializedRollbackId, shutdownState.getRBID()); } -bool sharedCallbackStateDestroyed = false; +AtomicWord<bool> sharedCallbackStateDestroyed{false}; bool sharedCallbackStateDestroyedSoon() { // Wait up to 10 seconds. for (auto i = 0; i < 100; i++) { - if (sharedCallbackStateDestroyed) { + if (sharedCallbackStateDestroyed.load()) { return true; } mongo::sleepmillis(100); @@ -710,7 +710,7 @@ class SharedCallbackState { public: SharedCallbackState() {} ~SharedCallbackState() { - sharedCallbackStateDestroyed = true; + sharedCallbackStateDestroyed.store(true); } }; @@ -725,7 +725,7 @@ TEST_F(OplogFetcherTest, OplogFetcherResetsOnShutdownCallbackFnOnCompletion) { }); sharedCallbackData.reset(); - ASSERT_FALSE(sharedCallbackStateDestroyed); + ASSERT_FALSE(sharedCallbackStateDestroyed.load()); // This will cause the initial attempt to create a cursor to fail. processSingleRequestResponse(oplogFetcher->getDBClientConnection_forTest(), diff --git a/src/mongo/db/repl/scatter_gather_test.cpp b/src/mongo/db/repl/scatter_gather_test.cpp index ef8fd02aeb1..2eb7d9fc94a 100644 --- a/src/mongo/db/repl/scatter_gather_test.cpp +++ b/src/mongo/db/repl/scatter_gather_test.cpp @@ -69,29 +69,29 @@ public: void processResponse(const RemoteCommandRequest& request, const RemoteCommandResponse& response) override { - _numResponses++; + _numResponses.fetchAndAdd(1); } void finish() { - _done = true; + _done.store(true); } virtual bool hasReceivedSufficientResponses() const { - if (_done) { - return _done; + if (_done.load()) { + return _done.load(); } - return _numResponses >= _maxResponses; + return _numResponses.load() >= _maxResponses.load(); } int getResponseCount() { - return _numResponses; + return _numResponses.load(); } private: - bool _done; - int64_t _numResponses; - int64_t _maxResponses; + AtomicWord<bool> _done; + AtomicWord<int64_t> _numResponses; + AtomicWord<int64_t> _maxResponses; }; /** diff --git a/src/mongo/unittest/task_executor_proxy.cpp b/src/mongo/unittest/task_executor_proxy.cpp index 75b75df23ff..823328acd1c 100644 --- a/src/mongo/unittest/task_executor_proxy.cpp +++ b/src/mongo/unittest/task_executor_proxy.cpp @@ -39,75 +39,75 @@ TaskExecutorProxy::TaskExecutorProxy(executor::TaskExecutor* executor) : _execut TaskExecutorProxy::~TaskExecutorProxy() = default; executor::TaskExecutor* TaskExecutorProxy::getExecutor() const { - return _executor; + return _executor.load(); } void TaskExecutorProxy::setExecutor(executor::TaskExecutor* executor) { - _executor = executor; + _executor.store(executor); } void TaskExecutorProxy::startup() { - _executor->startup(); + _executor.load()->startup(); } void TaskExecutorProxy::shutdown() { - _executor->shutdown(); + _executor.load()->shutdown(); } void TaskExecutorProxy::join() { - _executor->join(); + _executor.load()->join(); } SharedSemiFuture<void> TaskExecutorProxy::joinAsync() { - return _executor->joinAsync(); + return _executor.load()->joinAsync(); } void TaskExecutorProxy::appendDiagnosticBSON(mongo::BSONObjBuilder* builder) const { - _executor->appendDiagnosticBSON(builder); + _executor.load()->appendDiagnosticBSON(builder); } Date_t TaskExecutorProxy::now() { - return _executor->now(); + return _executor.load()->now(); } StatusWith<executor::TaskExecutor::EventHandle> TaskExecutorProxy::makeEvent() { - return _executor->makeEvent(); + return _executor.load()->makeEvent(); } void TaskExecutorProxy::signalEvent(const EventHandle& event) { - _executor->signalEvent(event); + _executor.load()->signalEvent(event); } StatusWith<executor::TaskExecutor::CallbackHandle> TaskExecutorProxy::onEvent( const EventHandle& event, CallbackFn&& work) { - return _executor->onEvent(event, std::move(work)); + return _executor.load()->onEvent(event, std::move(work)); } void TaskExecutorProxy::waitForEvent(const EventHandle& event) { - _executor->waitForEvent(event); + _executor.load()->waitForEvent(event); } StatusWith<stdx::cv_status> TaskExecutorProxy::waitForEvent(OperationContext* opCtx, const EventHandle& event, Date_t deadline) { - return _executor->waitForEvent(opCtx, event, deadline); + return _executor.load()->waitForEvent(opCtx, event, deadline); } StatusWith<executor::TaskExecutor::CallbackHandle> TaskExecutorProxy::scheduleWork( CallbackFn&& work) { - return _executor->scheduleWork(std::move(work)); + return _executor.load()->scheduleWork(std::move(work)); } StatusWith<executor::TaskExecutor::CallbackHandle> TaskExecutorProxy::scheduleWorkAt( Date_t when, CallbackFn&& work) { - return _executor->scheduleWorkAt(when, std::move(work)); + return _executor.load()->scheduleWorkAt(when, std::move(work)); } StatusWith<executor::TaskExecutor::CallbackHandle> TaskExecutorProxy::scheduleRemoteCommandOnAny( const executor::RemoteCommandRequestOnAny& request, const RemoteCommandOnAnyCallbackFn& cb, const BatonHandle& baton) { - return _executor->scheduleRemoteCommandOnAny(request, cb, baton); + return _executor.load()->scheduleRemoteCommandOnAny(request, cb, baton); } StatusWith<executor::TaskExecutor::CallbackHandle> @@ -115,23 +115,23 @@ TaskExecutorProxy::scheduleExhaustRemoteCommandOnAny( const executor::RemoteCommandRequestOnAny& request, const RemoteCommandOnAnyCallbackFn& cb, const BatonHandle& baton) { - return _executor->scheduleExhaustRemoteCommandOnAny(request, cb, baton); + return _executor.load()->scheduleExhaustRemoteCommandOnAny(request, cb, baton); } bool TaskExecutorProxy::hasTasks() { - return _executor->hasTasks(); + return _executor.load()->hasTasks(); } void TaskExecutorProxy::cancel(const CallbackHandle& cbHandle) { - _executor->cancel(cbHandle); + _executor.load()->cancel(cbHandle); } void TaskExecutorProxy::wait(const CallbackHandle& cbHandle, Interruptible* interruptible) { - _executor->wait(cbHandle, interruptible); + _executor.load()->wait(cbHandle, interruptible); } void TaskExecutorProxy::appendConnectionStats(executor::ConnectionPoolStats* stats) const { - _executor->appendConnectionStats(stats); + _executor.load()->appendConnectionStats(stats); } } // namespace unittest diff --git a/src/mongo/unittest/task_executor_proxy.h b/src/mongo/unittest/task_executor_proxy.h index 9fa9a9fbe8b..0e9f56bf892 100644 --- a/src/mongo/unittest/task_executor_proxy.h +++ b/src/mongo/unittest/task_executor_proxy.h @@ -82,7 +82,7 @@ public: private: // Not owned by us. - executor::TaskExecutor* _executor; + AtomicWord<executor::TaskExecutor*> _executor; }; } // namespace unittest diff --git a/src/mongo/util/elapsed_tracker.cpp b/src/mongo/util/elapsed_tracker.cpp index 791d377bcdc..0e0e807deca 100644 --- a/src/mongo/util/elapsed_tracker.cpp +++ b/src/mongo/util/elapsed_tracker.cpp @@ -45,16 +45,16 @@ ElapsedTracker::ElapsedTracker(ClockSource* cs, _last(cs->now()) {} bool ElapsedTracker::intervalHasElapsed() { - if (++_pings >= _hitsBetweenMarks) { - _pings = 0; - _last = _clock->now(); + if (_pings.addAndFetch(1) >= _hitsBetweenMarks) { + _pings.store(0); + _last.store(_clock->now()); return true; } const auto now = _clock->now(); - if (now - _last > _msBetweenMarks) { - _pings = 0; - _last = now; + if (now - _last.load() > _msBetweenMarks) { + _pings.store(0); + _last.store(now); return true; } @@ -62,8 +62,8 @@ bool ElapsedTracker::intervalHasElapsed() { } void ElapsedTracker::resetLastTime() { - _pings = 0; - _last = _clock->now(); + _pings.store(0); + _last.store(_clock->now()); } } // namespace mongo diff --git a/src/mongo/util/elapsed_tracker.h b/src/mongo/util/elapsed_tracker.h index f8779f168dc..5a05d5ea31d 100644 --- a/src/mongo/util/elapsed_tracker.h +++ b/src/mongo/util/elapsed_tracker.h @@ -31,6 +31,7 @@ #include <cstdint> +#include "mongo/platform/atomic_word.h" #include "mongo/util/time_support.h" namespace mongo { @@ -55,9 +56,9 @@ private: const int32_t _hitsBetweenMarks; const Milliseconds _msBetweenMarks; - int32_t _pings; + AtomicWord<int32_t> _pings; - Date_t _last; + AtomicWord<Date_t> _last; }; } // namespace mongo |