diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-01-30 22:18:26 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-01-30 22:18:26 +0000 |
commit | c9418858a4a1c8848114564007e743f1f9d51247 (patch) | |
tree | 25f0af5292b31e2b903418c02c663f6ec59c188e | |
parent | 3d20dde708032ac70ab4cb24fa8284686a0001f3 (diff) |
Use vespalib::duration for time.
4 files changed, 26 insertions, 26 deletions
diff --git a/searchcore/src/tests/proton/flushengine/flushengine_test.cpp b/searchcore/src/tests/proton/flushengine/flushengine_test.cpp index a675a45aa54..fae2e9f2d52 100644 --- a/searchcore/src/tests/proton/flushengine/flushengine_test.cpp +++ b/searchcore/src/tests/proton/flushengine/flushengine_test.cpp @@ -31,9 +31,9 @@ using searchcorespi::IFlushTarget; using searchcorespi::FlushTask; using vespalib::Slime; -const long LONG_TIMEOUT = 66666; -const long SHORT_TIMEOUT = 1; -const uint32_t IINTERVAL = 1000; +constexpr long LONG_TIMEOUT = 66666; +constexpr long SHORT_TIMEOUT = 1; +constexpr vespalib::duration IINTERVAL = 1s; class SimpleExecutor : public vespalib::Executor { public: @@ -426,15 +426,15 @@ struct Fixture SimpleStrategy::SP strategy; FlushEngine engine; - Fixture(uint32_t numThreads, uint32_t idleIntervalMS, SimpleStrategy::SP strategy_) + Fixture(uint32_t numThreads, vespalib::duration idleInterval, SimpleStrategy::SP strategy_) : tlsStatsFactory(std::make_shared<SimpleTlsStatsFactory>()), strategy(strategy_), - engine(tlsStatsFactory, strategy, numThreads, idleIntervalMS) + engine(tlsStatsFactory, strategy, numThreads, idleInterval) { } - Fixture(uint32_t numThreads, uint32_t idleIntervalMS) - : Fixture(numThreads, idleIntervalMS, std::make_shared<SimpleStrategy>()) + Fixture(uint32_t numThreads, vespalib::duration idleInterval) + : Fixture(numThreads, idleInterval, std::make_shared<SimpleStrategy>()) { } @@ -488,12 +488,12 @@ TEST_F("require that strategy controls flush target", Fixture(1, IINTERVAL)) EXPECT_EQUAL("bar", order[1]); } -TEST_F("require that zero handlers does not core", Fixture(2, 50)) +TEST_F("require that zero handlers does not core", Fixture(2, 50ms)) { f.engine.start(); } -TEST_F("require that zero targets does not core", Fixture(2, 50)) +TEST_F("require that zero targets does not core", Fixture(2, 50ms)) { f.putFlushHandler("foo", std::make_shared<SimpleHandler>(Targets(), "foo")); f.putFlushHandler("bar", std::make_shared<SimpleHandler>(Targets(), "bar")); @@ -692,7 +692,7 @@ assertThatHandlersInCurrentSet(FlushEngine & engine, const std::vector<const cha } } -TEST_F("require that concurrency works", Fixture(2, 1)) +TEST_F("require that concurrency works", Fixture(2, 1ms)) { auto target1 = std::make_shared<SimpleTarget>("target1", 1, false); auto target2 = std::make_shared<SimpleTarget>("target2", 2, false); @@ -713,7 +713,7 @@ TEST_F("require that concurrency works", Fixture(2, 1)) target2->_proceed.countDown(); } -TEST_F("require that state explorer can list flush targets", Fixture(1, 1)) +TEST_F("require that state explorer can list flush targets", Fixture(1, 1ms)) { auto target = std::make_shared<SimpleTarget>("target1", 100, false); f.putFlushHandler("handler", @@ -744,7 +744,7 @@ TEST_F("require that state explorer can list flush targets", Fixture(1, 1)) target->_taskDone.await(LONG_TIMEOUT); } -TEST_F("require that oldest serial is updated when closing engine", Fixture(1, 100)) +TEST_F("require that oldest serial is updated when closing engine", Fixture(1, 100ms)) { auto target1 = std::make_shared<SimpleTarget>("target1", 10, false); auto handler = f.addSimpleHandler({ target1 }); @@ -754,7 +754,7 @@ TEST_F("require that oldest serial is updated when closing engine", Fixture(1, 1 EXPECT_EQUAL(20u, handler->_oldestSerial); } -TEST_F("require that oldest serial is updated when finishing priority flush strategy", Fixture(1, 100, std::make_shared<NoFlushStrategy>())) +TEST_F("require that oldest serial is updated when finishing priority flush strategy", Fixture(1, 100ms, std::make_shared<NoFlushStrategy>())) { auto target1 = std::make_shared<SimpleTarget>("target1", 10, true); auto handler = f.addSimpleHandler({ target1 }); diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp index 42b38bec821..b4ab34d6866 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp +++ b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp @@ -77,10 +77,10 @@ FlushEngine::FlushInfo::FlushInfo(uint32_t taskId, const IFlushTarget::SP &targe } FlushEngine::FlushEngine(std::shared_ptr<flushengine::ITlsStatsFactory> tlsStatsFactory, - IFlushStrategy::SP strategy, uint32_t numThreads, uint32_t idleIntervalMS) + IFlushStrategy::SP strategy, uint32_t numThreads, vespalib::duration idleInterval) : _closed(false), _maxConcurrent(numThreads), - _idleIntervalMS(idleIntervalMS), + _idleInterval(idleInterval), _taskId(0), _threadPool(128 * 1024), _strategy(std::move(strategy)), @@ -151,11 +151,11 @@ FlushEngine::canFlushMore(const std::unique_lock<std::mutex> &guard) const } bool -FlushEngine::wait(size_t minimumWaitTimeIfReady) +FlushEngine::wait(vespalib::duration minimumWaitTimeIfReady) { std::unique_lock<std::mutex> guard(_lock); - if ( (minimumWaitTimeIfReady > 0) && canFlushMore(guard) && _pendingPrune.empty()) { - _cond.wait_for(guard, std::chrono::milliseconds(minimumWaitTimeIfReady)); + if ( (minimumWaitTimeIfReady != vespalib::duration::zero()) && canFlushMore(guard) && _pendingPrune.empty()) { + _cond.wait_for(guard, minimumWaitTimeIfReady); } while ( ! canFlushMore(guard) && _pendingPrune.empty()) { _cond.wait_for(guard, 1s); // broadcast when flush done @@ -168,7 +168,7 @@ FlushEngine::Run(FastOS_ThreadInterface *, void *) { bool shouldIdle = false; vespalib::string prevFlushName; - while (wait(shouldIdle ? _idleIntervalMS : 0)) { + while (wait(shouldIdle ? _idleInterval : vespalib::duration::zero())) { shouldIdle = false; if (prune()) { continue; // Prune attempted on one or more handlers @@ -181,8 +181,8 @@ FlushEngine::Run(FastOS_ThreadInterface *, void *) } else { shouldIdle = true; } - LOG(debug, "Making another wait(idle=%s, timeMS=%d) last was '%s'", - shouldIdle ? "true" : "false", shouldIdle ? _idleIntervalMS : 0, prevFlushName.c_str()); + LOG(debug, "Making another wait(idle=%s, timeS=%1.3f) last was '%s'", + shouldIdle ? "true" : "false", shouldIdle ? vespalib::to_s(_idleInterval) : 0, prevFlushName.c_str()); } _executor.sync(); prune(); @@ -307,7 +307,7 @@ FlushEngine::flushAll(const FlushContext::List &lst) { LOG(debug, "%ld targets to flush.", lst.size()); for (const FlushContext::SP & ctx : lst) { - if (wait(0)) { + if (wait(vespalib::duration::zero())) { if (ctx->initFlush(get_flush_token(*ctx))) { logTarget("initiated", *ctx); _executor.execute(std::make_unique<FlushTask>(initFlush(*ctx), *this, ctx)); diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h index f51e93f0fbd..e4d9e269215 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h +++ b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h @@ -50,7 +50,7 @@ private: typedef HandlerMap<IFlushHandler> FlushHandlerMap; bool _closed; const uint32_t _maxConcurrent; - const uint32_t _idleIntervalMS; + const vespalib::duration _idleInterval; uint32_t _taskId; FastOS_ThreadPool _threadPool; IFlushStrategy::SP _strategy; @@ -79,7 +79,7 @@ private: uint32_t initFlush(const IFlushHandler::SP &handler, const IFlushTarget::SP &target); void flushDone(const FlushContext &ctx, uint32_t taskId); bool canFlushMore(const std::unique_lock<std::mutex> &guard) const; - bool wait(size_t minimumWaitTimeIfReady); + bool wait(vespalib::duration minimumWaitTimeIfReady); bool isFlushing(const std::lock_guard<std::mutex> &guard, const vespalib::string & name) const; friend class FlushTask; @@ -102,7 +102,7 @@ public: * @param idleInterval The interval between when flushes are checked whne there are no one progressing. */ FlushEngine(std::shared_ptr<flushengine::ITlsStatsFactory> tlsStatsFactory, - IFlushStrategy::SP strategy, uint32_t numThreads, uint32_t idleIntervalMS); + IFlushStrategy::SP strategy, uint32_t numThreads, vespalib::duration idleIntervalMS); /** * Destructor. Waits for all pending tasks to complete. diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp index 5aa5d88eda9..1b615d765f0 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp @@ -304,7 +304,7 @@ Proton::init(const BootstrapConfig::SP & configSnapshot) vespalib::chdir(protonConfig.basedir); _tls->start(); _flushEngine = std::make_unique<FlushEngine>(std::make_shared<flushengine::TlsStatsFactory>(_tls->getTransLogServer()), - strategy, flush.maxconcurrent, flush.idleinterval*1000); + strategy, flush.maxconcurrent, vespalib::from_s(flush.idleinterval)); _metricsEngine->addExternalMetrics(_summaryEngine->getMetrics()); char tmp[1024]; |