summaryrefslogtreecommitdiff
path: root/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp
diff options
context:
space:
mode:
authorBen Caimano <ben.caimano@10gen.com>2019-04-26 15:03:46 -0400
committerBen Caimano <ben.caimano@10gen.com>2019-06-21 17:02:30 -0400
commit1eff33bd1a8d48eb607675f87faf1836ba325006 (patch)
tree80149c8ff06158f7fdaaa0014500c06d080575a4 /src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp
parent8c4dfc2ba0568bd128a27f6481994758ce5f1c10 (diff)
downloadmongo-1eff33bd1a8d48eb607675f87faf1836ba325006.tar.gz
SERVER-39936 Use PeriodicRunner handles to simplify shutdown ordering
Diffstat (limited to 'src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp')
-rw-r--r--src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp53
1 files changed, 36 insertions, 17 deletions
diff --git a/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp b/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp
index 8e4f6594bab..c27418d948f 100644
--- a/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp
+++ b/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp
@@ -43,11 +43,30 @@
namespace mongo {
-void startPeriodicThreadToDecreaseSnapshotHistoryIfNotNeeded(ServiceContext* serviceContext) {
- // Enforce calling this function once, and only once.
- static bool firstCall = true;
- invariant(firstCall);
- firstCall = false;
+auto PeriodicThreadToDecreaseSnapshotHistoryIfNotNeeded::get(ServiceContext* serviceContext)
+ -> PeriodicThreadToDecreaseSnapshotHistoryIfNotNeeded& {
+ auto& jobContainer = _serviceDecoration(serviceContext);
+ jobContainer._init(serviceContext);
+ return jobContainer;
+}
+
+auto PeriodicThreadToDecreaseSnapshotHistoryIfNotNeeded::operator-> () const noexcept
+ -> PeriodicJobAnchor* {
+ stdx::lock_guard lk(_mutex);
+ return _anchor.get();
+}
+
+auto PeriodicThreadToDecreaseSnapshotHistoryIfNotNeeded::operator*() const noexcept
+ -> PeriodicJobAnchor& {
+ stdx::lock_guard lk(_mutex);
+ return *_anchor;
+}
+
+void PeriodicThreadToDecreaseSnapshotHistoryIfNotNeeded::_init(ServiceContext* serviceContext) {
+ stdx::lock_guard lk(_mutex);
+ if (_anchor) {
+ return;
+ }
auto periodicRunner = serviceContext->getPeriodicRunner();
invariant(periodicRunner);
@@ -71,19 +90,19 @@ void startPeriodicThreadToDecreaseSnapshotHistoryIfNotNeeded(ServiceContext* ser
},
Seconds(snapshotWindowParams.decreaseHistoryIfNotNeededPeriodSeconds.load()));
- auto handle = periodicRunner->makeJob(std::move(job));
- handle->start();
+ _anchor = std::make_shared<PeriodicJobAnchor>(periodicRunner->makeJob(std::move(job)));
- SnapshotWindowParams::observeDecreaseHistoryIfNotNeededPeriodSeconds
- .addObserver([handle = std::move(handle)](const auto& secs) {
- try {
- handle->setPeriod(Seconds(secs));
- } catch (const DBException& ex) {
- log() << "Failed to update the period of the thread which decreases data history "
- "target window size if there have been no new SnapshotTooOld errors."
- << ex.toStatus();
- }
- });
+ SnapshotWindowParams::observeDecreaseHistoryIfNotNeededPeriodSeconds.addObserver([anchor =
+ _anchor](
+ const auto& secs) {
+ try {
+ anchor->setPeriod(Seconds(secs));
+ } catch (const DBException& ex) {
+ log() << "Failed to update the period of the thread which decreases data history "
+ "target window size if there have been no new SnapshotTooOld errors."
+ << ex.toStatus();
+ }
+ });
}
} // namespace mongo