diff options
Diffstat (limited to 'src')
19 files changed, 107 insertions, 50 deletions
diff --git a/src/mongo/db/query/plan_yield_policy.cpp b/src/mongo/db/query/plan_yield_policy.cpp index b03ec44920b..575ebf664b8 100644 --- a/src/mongo/db/query/plan_yield_policy.cpp +++ b/src/mongo/db/query/plan_yield_policy.cpp @@ -35,16 +35,28 @@ #include "mongo/db/operation_context.h" #include "mongo/db/query/query_knobs.h" #include "mongo/db/query/query_yield.h" +#include "mongo/db/service_context.h" #include "mongo/util/scopeguard.h" +#include "mongo/util/time_support.h" namespace mongo { PlanYieldPolicy::PlanYieldPolicy(PlanExecutor* exec, PlanExecutor::YieldPolicy policy) : _policy(policy), _forceYield(false), - _elapsedTracker(internalQueryExecYieldIterations, internalQueryExecYieldPeriodMS), + _elapsedTracker(exec->getOpCtx()->getServiceContext()->getFastClockSource(), + internalQueryExecYieldIterations, + Milliseconds(internalQueryExecYieldPeriodMS)), _planYielding(exec) {} + +PlanYieldPolicy::PlanYieldPolicy(PlanExecutor::YieldPolicy policy, ClockSource* cs) + : _policy(policy), + _forceYield(false), + _elapsedTracker( + cs, internalQueryExecYieldIterations, Milliseconds(internalQueryExecYieldPeriodMS)), + _planYielding(nullptr) {} + bool PlanYieldPolicy::shouldYield() { if (!allowedToYield()) return false; diff --git a/src/mongo/db/query/plan_yield_policy.h b/src/mongo/db/query/plan_yield_policy.h index 0de47c608cd..ec6dca7a0f2 100644 --- a/src/mongo/db/query/plan_yield_policy.h +++ b/src/mongo/db/query/plan_yield_policy.h @@ -34,6 +34,7 @@ namespace mongo { +class ClockSource; class RecordFetcher; class PlanYieldPolicy { @@ -44,6 +45,12 @@ public: * locks. */ PlanYieldPolicy(PlanExecutor* exec, PlanExecutor::YieldPolicy policy); + /** + * Only used in dbtests since we don't have access to a PlanExecutor. Since we don't have + * access to the PlanExecutor to grab a ClockSource from, we pass in a ClockSource directly + * in the constructor instead. + */ + PlanYieldPolicy(PlanExecutor::YieldPolicy policy, ClockSource* cs); /** * Used by YIELD_AUTO plan executors in order to check whether it is time to yield. diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp index 4fdef19c6b6..c70a869a4f1 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp +++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp @@ -43,6 +43,7 @@ #include "mongo/db/index/index_descriptor.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/s/start_chunk_clone_request.h" +#include "mongo/db/service_context.h" #include "mongo/executor/remote_command_request.h" #include "mongo/executor/remote_command_response.h" #include "mongo/executor/task_executor.h" @@ -54,6 +55,7 @@ #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" #include "mongo/util/scopeguard.h" +#include "mongo/util/time_support.h" namespace mongo { namespace { @@ -395,7 +397,9 @@ Status MigrationChunkClonerSourceLegacy::nextCloneBatch(OperationContext* txn, BSONArrayBuilder* arrBuilder) { dassert(txn->lockState()->isCollectionLockedForMode(_args.getNss().ns(), MODE_IS)); - ElapsedTracker tracker(internalQueryExecYieldIterations, internalQueryExecYieldPeriodMS); + ElapsedTracker tracker(txn->getServiceContext()->getFastClockSource(), + internalQueryExecYieldIterations, + Milliseconds(internalQueryExecYieldPeriodMS)); stdx::lock_guard<stdx::mutex> sl(_mutex); diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine_test.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine_test.cpp index def552757b1..903e70b5037 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine_test.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine_test.cpp @@ -51,7 +51,7 @@ private: std::unique_ptr<EphemeralForTestEngine> _engine; }; -KVHarnessHelper* KVHarnessHelper::create() { +KVHarnessHelper* KVHarnessHelper::create(ClockSource* cs) { return new EphemeralForTestKVHarnessHelper(); } } diff --git a/src/mongo/db/storage/kv/SConscript b/src/mongo/db/storage/kv/SConscript index b00678c3d26..2d4a63498fa 100644 --- a/src/mongo/db/storage/kv/SConscript +++ b/src/mongo/db/storage/kv/SConscript @@ -89,6 +89,7 @@ env.Library( '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/storage/storage_options', '$BUILD_DIR/mongo/unittest/unittest', + '$BUILD_DIR/mongo/util/clock_source_mock', 'kv_engine_core', ], LIBDEPS_TAGS=[ diff --git a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp index c225fb7ada3..ae6964d6d98 100644 --- a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp +++ b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp @@ -30,7 +30,6 @@ #include "mongo/db/storage/kv/kv_engine_test_harness.h" - #include "mongo/db/operation_context_noop.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/storage/kv/kv_catalog.h" @@ -38,6 +37,7 @@ #include "mongo/db/storage/record_store.h" #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/unittest/unittest.h" +#include "mongo/util/clock_source_mock.h" namespace mongo { @@ -49,10 +49,12 @@ class MyOperationContext : public OperationContextNoop { public: MyOperationContext(KVEngine* engine) : OperationContextNoop(engine->newRecoveryUnit()) {} }; + +const std::unique_ptr<ClockSource> clock = stdx::make_unique<ClockSourceMock>(); } TEST(KVEngineTestHarness, SimpleRS1) { - unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create()); + unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create(clock.get())); KVEngine* engine = helper->getEngine(); ASSERT(engine); @@ -90,7 +92,7 @@ TEST(KVEngineTestHarness, SimpleRS1) { } TEST(KVEngineTestHarness, Restart1) { - unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create()); + unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create(clock.get())); KVEngine* engine = helper->getEngine(); ASSERT(engine); @@ -134,7 +136,7 @@ TEST(KVEngineTestHarness, Restart1) { TEST(KVEngineTestHarness, SimpleSorted1) { - unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create()); + unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create(clock.get())); KVEngine* engine = helper->getEngine(); ASSERT(engine); @@ -162,7 +164,7 @@ TEST(KVEngineTestHarness, SimpleSorted1) { } TEST(KVCatalogTest, Coll1) { - unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create()); + unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create(clock.get())); KVEngine* engine = helper->getEngine(); unique_ptr<RecordStore> rs; @@ -206,7 +208,7 @@ TEST(KVCatalogTest, Coll1) { TEST(KVCatalogTest, Idx1) { - unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create()); + unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create(clock.get())); KVEngine* engine = helper->getEngine(); unique_ptr<RecordStore> rs; @@ -279,7 +281,7 @@ TEST(KVCatalogTest, Idx1) { } TEST(KVCatalogTest, DirectoryPerDb1) { - unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create()); + unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create(clock.get())); KVEngine* engine = helper->getEngine(); unique_ptr<RecordStore> rs; @@ -321,7 +323,7 @@ TEST(KVCatalogTest, DirectoryPerDb1) { } TEST(KVCatalogTest, Split1) { - unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create()); + unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create(clock.get())); KVEngine* engine = helper->getEngine(); unique_ptr<RecordStore> rs; @@ -363,7 +365,7 @@ TEST(KVCatalogTest, Split1) { } TEST(KVCatalogTest, DirectoryPerAndSplit1) { - unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create()); + unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create(clock.get())); KVEngine* engine = helper->getEngine(); unique_ptr<RecordStore> rs; diff --git a/src/mongo/db/storage/kv/kv_engine_test_harness.h b/src/mongo/db/storage/kv/kv_engine_test_harness.h index 15ed43a1249..a5f61060765 100644 --- a/src/mongo/db/storage/kv/kv_engine_test_harness.h +++ b/src/mongo/db/storage/kv/kv_engine_test_harness.h @@ -33,6 +33,9 @@ #include "mongo/db/storage/kv/kv_engine.h" namespace mongo { + +class ClockSource; + class KVHarnessHelper { public: virtual ~KVHarnessHelper() {} @@ -42,6 +45,6 @@ public: virtual KVEngine* restartEngine() = 0; - static KVHarnessHelper* create(); + static KVHarnessHelper* create(ClockSource* cs); }; } diff --git a/src/mongo/db/storage/kv/kv_engine_test_snapshots.cpp b/src/mongo/db/storage/kv/kv_engine_test_snapshots.cpp index 0af84c354de..6ff5cb2eeb3 100644 --- a/src/mongo/db/storage/kv/kv_engine_test_snapshots.cpp +++ b/src/mongo/db/storage/kv/kv_engine_test_snapshots.cpp @@ -36,7 +36,9 @@ #include "mongo/db/storage/kv/kv_engine.h" #include "mongo/db/storage/record_store.h" #include "mongo/db/storage/snapshot_manager.h" +#include "mongo/stdx/memory.h" #include "mongo/unittest/unittest.h" +#include "mongo/util/clock_source_mock.h" namespace mongo { namespace { @@ -171,7 +173,8 @@ public: } void setUp() override { - helper.reset(KVHarnessHelper::create()); + service.setFastClockSource(stdx::make_unique<ClockSourceMock>()); + helper.reset(KVHarnessHelper::create(service.getFastClockSource())); engine = helper->getEngine(); snapshotManager = helper->getEngine()->getSnapshotManager(); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp index 783983aa93b..fc60f082ea6 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp @@ -63,14 +63,16 @@ public: size_t cacheMB = WiredTigerUtil::getCacheSizeMB(wiredTigerGlobalOptions.cacheSizeGB); const bool ephemeral = false; - WiredTigerKVEngine* kv = new WiredTigerKVEngine(getCanonicalName().toString(), - params.dbpath, - wiredTigerGlobalOptions.engineConfig, - cacheMB, - params.dur, - ephemeral, - params.repair, - params.readOnly); + WiredTigerKVEngine* kv = + new WiredTigerKVEngine(getCanonicalName().toString(), + params.dbpath, + getGlobalServiceContext()->getFastClockSource(), + wiredTigerGlobalOptions.engineConfig, + cacheMB, + params.dur, + ephemeral, + params.repair, + params.readOnly); kv->setRecordStoreExtraOptions(wiredTigerGlobalOptions.collectionConfig); kv->setSortedDataInterfaceExtraOptions(wiredTigerGlobalOptions.indexConfig); // Intentionally leaked. diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index d8547c421f9..d57415233f8 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -170,6 +170,7 @@ TicketServerParameter openReadTransactionParam(&openReadTransaction, WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, const std::string& path, + ClockSource* cs, const std::string& extraOpenOptions, size_t cacheSizeMB, bool durable, @@ -179,7 +180,7 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, : _eventHandler(WiredTigerUtil::defaultEventHandlers()), _canonicalName(canonicalName), _path(path), - _sizeStorerSyncTracker(100000, 60 * 1000), + _sizeStorerSyncTracker(cs, 100000, Seconds(60)), _durable(durable), _ephemeral(ephemeral), _readOnly(readOnly) { diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h index 6daafffe12d..16ca9311cd3 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h @@ -44,6 +44,7 @@ namespace mongo { +class ClockSource; class JournalListener; class WiredTigerSessionCache; class WiredTigerSizeStorer; @@ -52,6 +53,7 @@ class WiredTigerKVEngine final : public KVEngine { public: WiredTigerKVEngine(const std::string& canonicalName, const std::string& path, + ClockSource* cs, const std::string& extraOpenOptions, size_t cacheSizeGB, bool durable, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp index ae93eecc93b..7f18c8f8478 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp @@ -39,9 +39,9 @@ namespace mongo { class WiredTigerKVHarnessHelper : public KVHarnessHelper { public: - WiredTigerKVHarnessHelper() : _dbpath("wt-kv-harness") { + WiredTigerKVHarnessHelper(ClockSource* cs) : _clock(cs), _dbpath("wt-kv-harness") { _engine.reset(new WiredTigerKVEngine( - kWiredTigerEngineName, _dbpath.path(), "", 1, false, false, false, false)); + kWiredTigerEngineName, _dbpath.path(), _clock, "", 1, false, false, false, false)); } virtual ~WiredTigerKVHarnessHelper() { @@ -51,7 +51,7 @@ public: virtual KVEngine* restartEngine() { _engine.reset(NULL); _engine.reset(new WiredTigerKVEngine( - kWiredTigerEngineName, _dbpath.path(), "", 1, false, false, false, false)); + kWiredTigerEngineName, _dbpath.path(), _clock, "", 1, false, false, false, false)); return _engine.get(); } @@ -60,11 +60,12 @@ public: } private: + ClockSource* _clock; unittest::TempDir _dbpath; std::unique_ptr<WiredTigerKVEngine> _engine; }; -KVHarnessHelper* KVHarnessHelper::create() { - return new WiredTigerKVHarnessHelper(); +KVHarnessHelper* KVHarnessHelper::create(ClockSource* cs) { + return new WiredTigerKVHarnessHelper(cs); } } diff --git a/src/mongo/dbtests/SConscript b/src/mongo/dbtests/SConscript index 6192a75b556..7f5a55f45ed 100644 --- a/src/mongo/dbtests/SConscript +++ b/src/mongo/dbtests/SConscript @@ -117,6 +117,7 @@ dbtest = env.Program( "$BUILD_DIR/mongo/bson/mutable/mutable_bson_test_utils", "$BUILD_DIR/mongo/platform/platform", "$BUILD_DIR/mongo/db/serveronly", + '$BUILD_DIR/mongo/util/clock_source_mock', "$BUILD_DIR/mongo/util/concurrency/rwlock", "$BUILD_DIR/mongo/util/net/network", "mocklib", diff --git a/src/mongo/dbtests/plan_ranking.cpp b/src/mongo/dbtests/plan_ranking.cpp index 9c9d52bccf4..a9dc89e1144 100644 --- a/src/mongo/dbtests/plan_ranking.cpp +++ b/src/mongo/dbtests/plan_ranking.cpp @@ -50,10 +50,13 @@ #include "mongo/db/query/query_planner_test_lib.h" #include "mongo/db/query/stage_builder.h" #include "mongo/dbtests/dbtests.h" - +#include "mongo/stdx/memory.h" +#include "mongo/util/clock_source_mock.h" namespace mongo { +const std::unique_ptr<ClockSource> clockSource = stdx::make_unique<ClockSourceMock>(); + // How we access the external setParameter testing bool. extern std::atomic<bool> internalQueryForceIntersectionPlans; // NOLINT @@ -129,7 +132,7 @@ public: _mps->addPlan(solutions[i], root, ws.get()); } // This is what sets a backup plan, should we test for it. - PlanYieldPolicy yieldPolicy(NULL, PlanExecutor::YIELD_MANUAL); + PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, clockSource.get()); _mps->pickBestPlan(&yieldPolicy); ASSERT(_mps->bestPlanChosen()); diff --git a/src/mongo/dbtests/query_stage_cached_plan.cpp b/src/mongo/dbtests/query_stage_cached_plan.cpp index 865ee18dacc..32550bc2172 100644 --- a/src/mongo/dbtests/query_stage_cached_plan.cpp +++ b/src/mongo/dbtests/query_stage_cached_plan.cpp @@ -47,9 +47,11 @@ #include "mongo/db/query/query_planner_params.h" #include "mongo/dbtests/dbtests.h" #include "mongo/stdx/memory.h" +#include "mongo/util/clock_source_mock.h" namespace QueryStageCachedPlan { +const std::unique_ptr<ClockSource> clockSource = stdx::make_unique<ClockSourceMock>(); static const NamespaceString nss("unittests.QueryStageCachedPlan"); class QueryStageCachedPlanBase { @@ -141,7 +143,7 @@ public: &_txn, collection, &_ws, cq.get(), plannerParams, decisionWorks, mockChild.release()); // This should succeed after triggering a replan. - PlanYieldPolicy yieldPolicy(nullptr, PlanExecutor::YIELD_MANUAL); + PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, clockSource.get()); ASSERT_OK(cachedPlanStage.pickBestPlan(&yieldPolicy)); // Make sure that we get 2 legit results back. @@ -210,7 +212,7 @@ public: &_txn, collection, &_ws, cq.get(), plannerParams, decisionWorks, mockChild.release()); // This should succeed after triggering a replan. - PlanYieldPolicy yieldPolicy(nullptr, PlanExecutor::YIELD_MANUAL); + PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, clockSource.get()); ASSERT_OK(cachedPlanStage.pickBestPlan(&yieldPolicy)); // Make sure that we get 2 legit results back. diff --git a/src/mongo/dbtests/query_stage_multiplan.cpp b/src/mongo/dbtests/query_stage_multiplan.cpp index 250eb5c380f..ae5b128824a 100644 --- a/src/mongo/dbtests/query_stage_multiplan.cpp +++ b/src/mongo/dbtests/query_stage_multiplan.cpp @@ -51,9 +51,12 @@ #include "mongo/db/query/stage_builder.h" #include "mongo/dbtests/dbtests.h" #include "mongo/stdx/memory.h" +#include "mongo/util/clock_source_mock.h" namespace mongo { +const std::unique_ptr<ClockSource> clockSource = stdx::make_unique<ClockSourceMock>(); + // How we access the external setParameter testing bool. extern std::atomic<bool> internalQueryForceIntersectionPlans; // NOLINT @@ -171,7 +174,7 @@ public: mps->addPlan(createQuerySolution(), secondRoot.release(), sharedWs.get()); // Plan 0 aka the first plan aka the index scan should be the best. - PlanYieldPolicy yieldPolicy(NULL, PlanExecutor::YIELD_MANUAL); + PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, clockSource.get()); mps->pickBestPlan(&yieldPolicy); ASSERT(mps->bestPlanChosen()); ASSERT_EQUALS(0, mps->bestPlanIdx()); @@ -255,7 +258,7 @@ public: } // This sets a backup plan. - PlanYieldPolicy yieldPolicy(NULL, PlanExecutor::YIELD_MANUAL); + PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, clockSource.get()); mps->pickBestPlan(&yieldPolicy); ASSERT(mps->bestPlanChosen()); ASSERT(mps->hasBackupPlan()); diff --git a/src/mongo/dbtests/query_stage_subplan.cpp b/src/mongo/dbtests/query_stage_subplan.cpp index 09f27a679e4..b703c0bf74c 100644 --- a/src/mongo/dbtests/query_stage_subplan.cpp +++ b/src/mongo/dbtests/query_stage_subplan.cpp @@ -43,9 +43,11 @@ #include "mongo/db/query/canonical_query.h" #include "mongo/db/query/get_executor.h" #include "mongo/dbtests/dbtests.h" +#include "mongo/util/clock_source_mock.h" namespace QueryStageSubplan { +const std::unique_ptr<ClockSource> clockSource = stdx::make_unique<ClockSourceMock>(); static const NamespaceString nss("unittests.QueryStageSubplan"); class QueryStageSubplanBase { @@ -124,7 +126,7 @@ public: new SubplanStage(&_txn, collection, &ws, plannerParams, cq.get())); // Plan selection should succeed due to falling back on regular planning. - PlanYieldPolicy yieldPolicy(NULL, PlanExecutor::YIELD_MANUAL); + PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, clockSource.get()); ASSERT_OK(subplan->pickBestPlan(&yieldPolicy)); } }; @@ -165,7 +167,7 @@ public: std::unique_ptr<SubplanStage> subplan( new SubplanStage(&_txn, collection, &ws, plannerParams, cq.get())); - PlanYieldPolicy yieldPolicy(NULL, PlanExecutor::YIELD_MANUAL); + PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, clockSource.get()); ASSERT_OK(subplan->pickBestPlan(&yieldPolicy)); // Nothing is in the cache yet, so neither branch should have been planned from @@ -221,7 +223,7 @@ public: std::unique_ptr<SubplanStage> subplan( new SubplanStage(&_txn, collection, &ws, plannerParams, cq.get())); - PlanYieldPolicy yieldPolicy(nullptr, PlanExecutor::YIELD_MANUAL); + PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, clockSource.get()); ASSERT_OK(subplan->pickBestPlan(&yieldPolicy)); // Nothing is in the cache yet, so neither branch should have been planned from @@ -278,7 +280,7 @@ public: std::unique_ptr<SubplanStage> subplan( new SubplanStage(&_txn, collection, &ws, plannerParams, cq.get())); - PlanYieldPolicy yieldPolicy(nullptr, PlanExecutor::YIELD_MANUAL); + PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, clockSource.get()); ASSERT_OK(subplan->pickBestPlan(&yieldPolicy)); // Nothing is in the cache yet, so neither branch should have been planned from @@ -533,7 +535,7 @@ public: new SubplanStage(&_txn, collection, &ws, plannerParams, cq.get())); // Plan selection should succeed due to falling back on regular planning. - PlanYieldPolicy yieldPolicy(nullptr, PlanExecutor::YIELD_MANUAL); + PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, clockSource.get()); ASSERT_OK(subplan->pickBestPlan(&yieldPolicy)); // Work the stage until it produces all results. @@ -591,7 +593,7 @@ public: std::unique_ptr<SubplanStage> subplan( new SubplanStage(&_txn, collection, &ws, plannerParams, cq.get())); - PlanYieldPolicy yieldPolicy(nullptr, PlanExecutor::YIELD_MANUAL); + PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, clockSource.get()); ASSERT_OK(subplan->pickBestPlan(&yieldPolicy)); size_t numResults = 0; diff --git a/src/mongo/util/elapsed_tracker.cpp b/src/mongo/util/elapsed_tracker.cpp index 0d0b2026fb7..660a52bf134 100644 --- a/src/mongo/util/elapsed_tracker.cpp +++ b/src/mongo/util/elapsed_tracker.cpp @@ -32,24 +32,27 @@ #include "mongo/util/elapsed_tracker.h" -#include "mongo/util/net/listen.h" +#include "mongo/util/clock_source.h" namespace mongo { -ElapsedTracker::ElapsedTracker(int32_t hitsBetweenMarks, int32_t msBetweenMarks) - : _hitsBetweenMarks(hitsBetweenMarks), +ElapsedTracker::ElapsedTracker(ClockSource* cs, + int32_t hitsBetweenMarks, + Milliseconds msBetweenMarks) + : _clock(cs), + _hitsBetweenMarks(hitsBetweenMarks), _msBetweenMarks(msBetweenMarks), _pings(0), - _last(Listener::getElapsedTimeMillis()) {} + _last(cs->now()) {} bool ElapsedTracker::intervalHasElapsed() { if (++_pings >= _hitsBetweenMarks) { _pings = 0; - _last = Listener::getElapsedTimeMillis(); + _last = _clock->now(); return true; } - long long now = Listener::getElapsedTimeMillis(); + const auto now = _clock->now(); if (now - _last > _msBetweenMarks) { _pings = 0; _last = now; @@ -61,7 +64,7 @@ bool ElapsedTracker::intervalHasElapsed() { void ElapsedTracker::resetLastTime() { _pings = 0; - _last = Listener::getElapsedTimeMillis(); + _last = _clock->now(); } } // namespace mongo diff --git a/src/mongo/util/elapsed_tracker.h b/src/mongo/util/elapsed_tracker.h index 2b14d0abf83..ee087d75c84 100644 --- a/src/mongo/util/elapsed_tracker.h +++ b/src/mongo/util/elapsed_tracker.h @@ -32,12 +32,16 @@ #include <cstdint> +#include "mongo/util/time_support.h" + namespace mongo { +class ClockSource; + /** Keep track of elapsed time. After a set amount of time, tells you to do something. */ class ElapsedTracker { public: - ElapsedTracker(int32_t hitsBetweenMarks, int32_t msBetweenMarks); + ElapsedTracker(ClockSource* cs, int32_t hitsBetweenMarks, Milliseconds msBetweenMarks); /** * Call this for every iteration. @@ -48,12 +52,13 @@ public: void resetLastTime(); private: + ClockSource* const _clock; const int32_t _hitsBetweenMarks; - const int32_t _msBetweenMarks; + const Milliseconds _msBetweenMarks; int32_t _pings; - int64_t _last; + Date_t _last; }; } // namespace mongo |