diff options
author | Jason Carey <jcarey@argv.me> | 2019-03-12 16:04:51 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2019-03-29 14:43:57 -0400 |
commit | bf4a3cff4dc5572f2e97cb5279fe63c8227187e0 (patch) | |
tree | 78da97f2f785cf191cc4fa87445f96cb2609c04d /src/mongo/embedded | |
parent | a6ddf1b828299cd695b69f5971eeafb0f74e0c58 (diff) | |
download | mongo-bf4a3cff4dc5572f2e97cb5279fe63c8227187e0.tar.gz |
SERVER-35114 Adjustable periods for PeriodicJobs
Add support for changing the period of a periodic job
Diffstat (limited to 'src/mongo/embedded')
-rw-r--r-- | src/mongo/embedded/periodic_runner_embedded.cpp | 27 | ||||
-rw-r--r-- | src/mongo/embedded/periodic_runner_embedded.h | 4 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/mongo/embedded/periodic_runner_embedded.cpp b/src/mongo/embedded/periodic_runner_embedded.cpp index 1f713bdd707..bb0c17c40a3 100644 --- a/src/mongo/embedded/periodic_runner_embedded.cpp +++ b/src/mongo/embedded/periodic_runner_embedded.cpp @@ -228,6 +228,23 @@ void PeriodicRunnerEmbedded::PeriodicJobImpl::stop() { _stopWithMasterAndJobLock(masterLock, lk); } +Milliseconds PeriodicRunnerEmbedded::PeriodicJobImpl::getPeriod() { + stdx::lock_guard<stdx::mutex> lk(_mutex); + return _job.interval; +} + +void PeriodicRunnerEmbedded::PeriodicJobImpl::setPeriod(Milliseconds ms) { + stdx::lock_guard<stdx::mutex> masterLk(_periodicRunner->_mutex); + stdx::lock_guard<stdx::mutex> lk(_mutex); + + _job.interval = ms; + + if (_execStatus == PeriodicJobImpl::ExecutionStatus::kRunning) { + std::make_heap( + _periodicRunner->_jobs.begin(), _periodicRunner->_jobs.end(), PeriodicJobSorter()); + } +} + void PeriodicRunnerEmbedded::PeriodicJobImpl::_stopWithMasterAndJobLock(WithLock masterLock, WithLock jobLock) { invariant(isAlive(jobLock)); @@ -258,4 +275,14 @@ void PeriodicRunnerEmbedded::PeriodicJobHandleImpl::resume() { job->resume(); } +Milliseconds PeriodicRunnerEmbedded::PeriodicJobHandleImpl::getPeriod() { + auto job = lockAndAssertExists(_jobWeak, kPeriodicJobHandleLifetimeErrMsg); + return job->getPeriod(); +} + +void PeriodicRunnerEmbedded::PeriodicJobHandleImpl::setPeriod(Milliseconds ms) { + auto job = lockAndAssertExists(_jobWeak, kPeriodicJobHandleLifetimeErrMsg); + job->setPeriod(ms); +} + } // namespace mongo diff --git a/src/mongo/embedded/periodic_runner_embedded.h b/src/mongo/embedded/periodic_runner_embedded.h index eca049659f6..a1e56079208 100644 --- a/src/mongo/embedded/periodic_runner_embedded.h +++ b/src/mongo/embedded/periodic_runner_embedded.h @@ -73,6 +73,8 @@ private: void pause(); void resume(); void stop(); + Milliseconds getPeriod(); + void setPeriod(Milliseconds ms); bool isAlive(WithLock lk); @@ -110,6 +112,8 @@ private: void stop() override; void pause() override; void resume() override; + Milliseconds getPeriod() override; + void setPeriod(Milliseconds ms) override; private: std::weak_ptr<PeriodicJobImpl> _jobWeak; |