summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorWaley Chen <waleycz@gmail.com>2016-05-02 21:40:41 -0400
committerWaley Chen <waleycz@gmail.com>2016-05-02 21:40:41 -0400
commit8abd5682f551ad79dec3557f721eebd45b21be0f (patch)
treee3430994fdf46a4cce8f40ce2f6e621c477065f3 /src/mongo/db
parent21cfba12a005431b08a8c69dcdb1f262622ea780 (diff)
downloadmongo-8abd5682f551ad79dec3557f721eebd45b21be0f.tar.gz
SERVER-23243 Replace Listener::getElapsedTimeMillis() in elapsed_tracker.cpp
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/query/plan_yield_policy.cpp14
-rw-r--r--src/mongo/db/query/plan_yield_policy.h7
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp6
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine_test.cpp2
-rw-r--r--src/mongo/db/storage/kv/SConscript1
-rw-r--r--src/mongo/db/storage/kv/kv_engine_test_harness.cpp20
-rw-r--r--src/mongo/db/storage/kv/kv_engine_test_harness.h5
-rw-r--r--src/mongo/db/storage/kv/kv_engine_test_snapshots.cpp5
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp18
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp3
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp11
12 files changed, 66 insertions, 28 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);
}
}