diff options
author | samantharitter <samantha.ritter@10gen.com> | 2017-08-01 15:50:37 -0400 |
---|---|---|
committer | samantharitter <samantha.ritter@10gen.com> | 2017-08-02 19:21:34 -0400 |
commit | 68051585b17682c1e13acdf440b2c78868054513 (patch) | |
tree | 1b677a81d5ef5d801a69cd9ce7fa7a9d7aac6295 /src/mongo/util | |
parent | 0eea3fc035718c7ae6fc570670f1c51f8f3d71a5 (diff) | |
download | mongo-68051585b17682c1e13acdf440b2c78868054513.tar.gz |
SERVER-29201 Implement SessionsCollectionStandalone
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/periodic_runner.h | 6 | ||||
-rw-r--r-- | src/mongo/util/periodic_runner_asio.cpp | 9 | ||||
-rw-r--r-- | src/mongo/util/periodic_runner_asio.h | 3 | ||||
-rw-r--r-- | src/mongo/util/periodic_runner_asio_test.cpp | 13 |
4 files changed, 23 insertions, 8 deletions
diff --git a/src/mongo/util/periodic_runner.h b/src/mongo/util/periodic_runner.h index 21e37d0e438..6b80226aa55 100644 --- a/src/mongo/util/periodic_runner.h +++ b/src/mongo/util/periodic_runner.h @@ -34,6 +34,8 @@ namespace mongo { +class Client; + /** * An interface for objects that run work items at specified intervals. * @@ -41,10 +43,12 @@ namespace mongo { * model they wish. Implementations may choose when to stop running * scheduled jobs (for example, some implementations may stop running * when the server is in global shutdown). + * + * The runner will create client objects that it passes to jobs to use. */ class PeriodicRunner { public: - using Job = stdx::function<void()>; + using Job = stdx::function<void(Client* client)>; struct PeriodicJob { PeriodicJob(Job callable, Milliseconds period) diff --git a/src/mongo/util/periodic_runner_asio.cpp b/src/mongo/util/periodic_runner_asio.cpp index 9fadfc67124..5ff42019340 100644 --- a/src/mongo/util/periodic_runner_asio.cpp +++ b/src/mongo/util/periodic_runner_asio.cpp @@ -95,7 +95,7 @@ void PeriodicRunnerASIO::_scheduleJob(std::weak_ptr<PeriodicJobASIO> job) { } lockedJob->start = _timerFactory->now(); - lockedJob->job(); + lockedJob->job(_client); _io_service.post([this, job]() mutable { _scheduleJob(job); }); }); @@ -110,11 +110,16 @@ Status PeriodicRunnerASIO::startup() { _state = State::kRunning; _thread = stdx::thread([this]() { try { - Client::initThread("PeriodicRunnerASIO"); + auto client = getGlobalServiceContext()->makeClient("PeriodicRunnerASIO"); + _client = client.get(); + Client::setCurrent(std::move(client)); asio::io_service::work workItem(_io_service); std::error_code ec; _io_service.run(ec); + + client = Client::releaseCurrent(); + if (ec) { severe() << "Failure in PeriodicRunnerASIO: " << ec.message(); fassertFailed(40438); diff --git a/src/mongo/util/periodic_runner_asio.h b/src/mongo/util/periodic_runner_asio.h index e5be509f0ea..dcf11429594 100644 --- a/src/mongo/util/periodic_runner_asio.h +++ b/src/mongo/util/periodic_runner_asio.h @@ -37,6 +37,8 @@ namespace mongo { +class Client; + /** * A PeriodicRunner implementation that uses the ASIO library's eventing system * to schedule and run jobs at regular intervals. @@ -106,6 +108,7 @@ private: asio::io_service _io_service; asio::io_service::strand _strand; + Client* _client; stdx::thread _thread; std::unique_ptr<executor::AsyncTimerFactoryInterface> _timerFactory; diff --git a/src/mongo/util/periodic_runner_asio_test.cpp b/src/mongo/util/periodic_runner_asio_test.cpp index 7a5e7b5fc04..86397801b11 100644 --- a/src/mongo/util/periodic_runner_asio_test.cpp +++ b/src/mongo/util/periodic_runner_asio_test.cpp @@ -38,6 +38,9 @@ #include "mongo/util/periodic_runner_asio.h" namespace mongo { + +class Client; + namespace { class PeriodicRunnerASIOTestNoSetup : public unittest::Test { @@ -91,7 +94,7 @@ TEST_F(PeriodicRunnerASIOTest, OneJobTest) { // Add a job, ensure that it runs once PeriodicRunner::PeriodicJob job( - [&count, &mutex, &cv] { + [&count, &mutex, &cv](Client*) { { stdx::unique_lock<stdx::mutex> lk(mutex); count++; @@ -128,7 +131,7 @@ TEST_F(PeriodicRunnerASIOTestNoSetup, ScheduleBeforeStartupTest) { // Schedule a job before startup PeriodicRunner::PeriodicJob job( - [&count, &mutex, &cv] { + [&count, &mutex, &cv](Client*) { { stdx::unique_lock<stdx::mutex> lk(mutex); count++; @@ -153,7 +156,7 @@ TEST_F(PeriodicRunnerASIOTest, ScheduleAfterShutdownTest) { Milliseconds interval{5}; // Schedule a job before shutdown - PeriodicRunner::PeriodicJob job([&count] { count++; }, interval); + PeriodicRunner::PeriodicJob job([&count](Client*) { count++; }, interval); runner()->scheduleJob(std::move(job)); @@ -185,7 +188,7 @@ TEST_F(PeriodicRunnerASIOTest, TwoJobsTest) { // Add two jobs, ensure they both run the proper number of times PeriodicRunner::PeriodicJob jobA( - [&countA, &mutex, &cv] { + [&countA, &mutex, &cv](Client*) { { stdx::unique_lock<stdx::mutex> lk(mutex); countA++; @@ -195,7 +198,7 @@ TEST_F(PeriodicRunnerASIOTest, TwoJobsTest) { intervalA); PeriodicRunner::PeriodicJob jobB( - [&countB, &mutex, &cv] { + [&countB, &mutex, &cv](Client*) { { stdx::unique_lock<stdx::mutex> lk(mutex); countB++; |