diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-20 03:51:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-20 03:51:23 +0100 |
commit | aaf261ce16113144842d12ccb334c4a58dbb6173 (patch) | |
tree | 6de2ce6687140c364180f7190fb49e766a322a5a | |
parent | 04677306ef130fad59efa29141b6fe7b185927fe (diff) | |
parent | 2af81c503afcc2bfd9524b17eaec8b8a49c5217f (diff) |
Merge pull request #11575 from vespa-engine/balder/reduce-timestamp-usage
Balder/reduce timestamp usage
150 files changed, 773 insertions, 1335 deletions
diff --git a/config/src/tests/configfetcher/configfetcher.cpp b/config/src/tests/configfetcher/configfetcher.cpp index be25e913980..856b1198ce8 100644 --- a/config/src/tests/configfetcher/configfetcher.cpp +++ b/config/src/tests/configfetcher/configfetcher.cpp @@ -2,7 +2,6 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/helper/configfetcher.h> #include <vespa/vespalib/util/exception.h> -#include <vespa/fastos/timestamp.h> #include "config-my.h" #include <atomic> @@ -65,8 +64,8 @@ TEST("requireThatConfigUpdatesArePerformed") { writeFile("test1.cfg", "bar"); cb._configured = false; - fastos::StopWatch timer; - while (!cb._configured && timer.elapsed().ms() < 20000.0) { + vespalib::Timer timer; + while (!cb._configured && timer.elapsed() < 20s) { if (cb._configured) break; std::this_thread::sleep_for(1s); @@ -145,12 +144,12 @@ TEST_F("verify that config generation can be obtained from config fetcher", Conf f1.builder.myField = "bar"; cb._configured = false; f1.context->reload(); - fastos::StopWatch timer; - while (timer.elapsed().ms() < 120000) { + vespalib::Timer timer; + while (timer.elapsed() < 120s) { if (cb._configured) { break; } - std::this_thread::sleep_for(std::chrono::milliseconds(10));; + std::this_thread::sleep_for(10ms);; } EXPECT_EQUAL(2, fetcher.getGeneration()); EXPECT_EQUAL("bar", cb._config.get()->myField); diff --git a/config/src/tests/configholder/configholder.cpp b/config/src/tests/configholder/configholder.cpp index ce7e4f0531d..d69ad8022f9 100644 --- a/config/src/tests/configholder/configholder.cpp +++ b/config/src/tests/configholder/configholder.cpp @@ -1,15 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/common/configholder.h> -#include <vespa/fastos/timestamp.h> using namespace config; -using namespace std::chrono_literals; namespace { -constexpr long ONE_SEC = 1000; -constexpr long ONE_MINUTE = 60 * ONE_SEC; +constexpr vespalib::duration ONE_SEC = 1s; +constexpr vespalib::duration ONE_MINUTE = 60s; } @@ -34,10 +32,10 @@ TEST("Require that waiting is done") ConfigValue value; ConfigHolder holder; - fastos::StopWatch timer; + vespalib::Timer timer; holder.wait(1000ms); - EXPECT_GREATER_EQUAL(timer.elapsed().ms(), ONE_SEC); - EXPECT_LESS(timer.elapsed().ms(), ONE_MINUTE); + EXPECT_GREATER_EQUAL(timer.elapsed(), ONE_SEC); + EXPECT_LESS(timer.elapsed(), ONE_MINUTE); holder.handle(std::make_unique<ConfigUpdate>(value, true, 0)); ASSERT_TRUE(holder.wait(100ms)); @@ -57,23 +55,23 @@ TEST("Require that polling for elements work") TEST("Require that negative time does not mean forever.") { ConfigHolder holder; - fastos::StopWatch timer; + vespalib::Timer timer; ASSERT_FALSE(holder.poll()); ASSERT_FALSE(holder.wait(10ms)); ASSERT_FALSE(holder.wait(0ms)); ASSERT_FALSE(holder.wait(-1ms)); ASSERT_FALSE(holder.wait(-7ms)); - EXPECT_LESS(timer.elapsed().ms(), ONE_MINUTE); + EXPECT_LESS(timer.elapsed(), ONE_MINUTE); } TEST_MT_F("Require that wait is interrupted", 2, ConfigHolder) { if (thread_id == 0) { - fastos::StopWatch timer; + vespalib::Timer timer; TEST_BARRIER(); f.wait(1000ms); - EXPECT_LESS(timer.elapsed().ms(), ONE_MINUTE); - EXPECT_GREATER(timer.elapsed().ms(), 400.0); + EXPECT_LESS(timer.elapsed(), ONE_MINUTE); + EXPECT_GREATER(timer.elapsed(), 400ms); TEST_BARRIER(); } else { TEST_BARRIER(); diff --git a/config/src/tests/configretriever/configretriever.cpp b/config/src/tests/configretriever/configretriever.cpp index 87f189ad7d3..d929e816740 100644 --- a/config/src/tests/configretriever/configretriever.cpp +++ b/config/src/tests/configretriever/configretriever.cpp @@ -9,7 +9,6 @@ #include <vespa/config/common/configholder.h> #include <vespa/config/subscription/configsubscription.h> #include <vespa/config/common/exceptions.h> -#include <vespa/fastos/timestamp.h> #include "config-bootstrap.h" #include "config-foo.h" #include "config-bar.h" @@ -245,9 +244,9 @@ public: snap = snapshot; configured = true; } - bool waitUntilConfigured(int64_t timeoutInMillis) { - fastos::StopWatch timer; - while (timer.elapsed().ms() < timeoutInMillis) { + bool waitUntilConfigured(vespalib::duration timeout) { + vespalib::Timer timer; + while (timer.elapsed() < timeout) { if (configured) { return true; } @@ -296,7 +295,7 @@ TEST_F("require that SimpleConfigurer usage works", ConfigurableFixture()) { f1.configured = false; fooBuilder.fooValue = "bimz"; ctx->reload(); - ASSERT_TRUE(f1.waitUntilConfigured(60000)); + ASSERT_TRUE(f1.waitUntilConfigured(60s)); snap = f1.snap; foo = snap.getConfig<FooConfig>("id"); ASSERT_EQUAL("bimz", foo->fooValue); @@ -304,7 +303,7 @@ TEST_F("require that SimpleConfigurer usage works", ConfigurableFixture()) { fooBuilder.fooValue = "bamz"; f1.configured = false; ctx->reload(); - ASSERT_FALSE(f1.waitUntilConfigured(2000)); + ASSERT_FALSE(f1.waitUntilConfigured(2s)); SimpleConfigurer configurer2(SimpleConfigRetriever::UP(new SimpleConfigRetriever(sub, ctx)), &f1); f1.throwException = true; diff --git a/config/src/tests/file_subscription/file_subscription.cpp b/config/src/tests/file_subscription/file_subscription.cpp index 9c40e2ffd77..ceaf16c9191 100644 --- a/config/src/tests/file_subscription/file_subscription.cpp +++ b/config/src/tests/file_subscription/file_subscription.cpp @@ -12,8 +12,6 @@ #include <config-bar.h> #include <config-foobar.h> #include <vespa/log/log.h> -#include <vespa/fastos/timestamp.h> - LOG_SETUP(".filesubscription_test"); using namespace config; @@ -103,8 +101,8 @@ TEST("requireThatReconfigIsCalledWhenConfigChanges") { writeFile("my.cfg", "bar"); context->reload(); bool correctValue = false; - fastos::StopWatch timer; - while (!correctValue && timer.elapsed().ms() < 20000.0) { + vespalib::Timer timer; + while (!correctValue && timer.elapsed() < 20s) { LOG(info, "Testing value..."); if (s.nextConfig(1000ms)) { break; diff --git a/config/src/tests/frt/frt.cpp b/config/src/tests/frt/frt.cpp index 28dea82bfe7..cf1ff9eca37 100644 --- a/config/src/tests/frt/frt.cpp +++ b/config/src/tests/frt/frt.cpp @@ -14,7 +14,6 @@ #include <vespa/fnet/frt/frt.h> #include <vespa/fnet/frt/error.h> #include <vespa/config/frt/protocol.h> -#include <vespa/fastos/timestamp.h> #include <lz4.h> #include "config-my.h" #include "config-bar.h" @@ -43,10 +42,10 @@ namespace { bool poll() override { return notified; } void interrupt() override { } - bool waitUntilResponse(int timeoutInMillis) + bool waitUntilResponse(vespalib::duration timeout) { - fastos::StopWatch timer; - while (timer.elapsed().ms() < timeoutInMillis) { + vespalib::Timer timer; + while (timer.elapsed() < timeout) { if (notified) break; std::this_thread::sleep_for(100ms); @@ -255,8 +254,8 @@ TEST_FF("require that request is config task is scheduled", SourceFixture(), FRT f2.src.getConfig(); ASSERT_TRUE(f2.result.notified); f2.result.notified = false; - fastos::StopWatch timer; - while (timer.elapsed().ms() < 10000) { + vespalib::Timer timer; + while (timer.elapsed() < 10s) { f1.conn.scheduler.CheckTasks(); if (f2.result.notified) break; diff --git a/config/src/tests/subscriber/subscriber.cpp b/config/src/tests/subscriber/subscriber.cpp index 0c14928521e..9d5aeddaf37 100644 --- a/config/src/tests/subscriber/subscriber.cpp +++ b/config/src/tests/subscriber/subscriber.cpp @@ -5,7 +5,6 @@ #include <vespa/config/common/configholder.h> #include <vespa/config/subscription/configsubscription.h> #include <vespa/config/common/exceptions.h> -#include <vespa/fastos/timestamp.h> #include "config-foo.h" #include "config-bar.h" #include "config-baz.h" @@ -274,10 +273,10 @@ TEST_FFF("requireThatCorrectConfigIsReturnedAfterTimestampUpdate", MyManager, AP TEST_MT_FFF("requireThatConfigIsReturnedWhenUpdatedDuringNextConfig", 2, MyManager, APIFixture(f1), StandardFixture(f1, f2)) { if (thread_id == 0) { - fastos::StopWatch timer; + vespalib::Timer timer; ASSERT_TRUE(f3.s.nextConfig(10000ms)); - ASSERT_TRUE(timer.elapsed().ms() > 250); - ASSERT_TRUE(timer.elapsed().ms() <= 5000); + ASSERT_TRUE(timer.elapsed() > 250ms); + ASSERT_TRUE(timer.elapsed() <= 5s); verifyConfig("foo2", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); } else { @@ -289,14 +288,14 @@ TEST_MT_FFF("requireThatConfigIsReturnedWhenUpdatedDuringNextConfig", 2, MyManag } TEST_FFF("requireThatConfigIsReturnedWhenUpdatedBeforeNextConfig", MyManager, APIFixture(f1), StandardFixture(f1, f2)) { - fastos::StopWatch timer; + vespalib::Timer timer; ASSERT_FALSE(f3.s.nextConfig(1000ms)); - ASSERT_TRUE(timer.elapsed().ms() > 850); + ASSERT_TRUE(timer.elapsed() > 850ms); f1.updateGeneration(0, 2); f1.updateGeneration(1, 2); - timer.restart(); + timer = vespalib::Timer(); ASSERT_TRUE(f3.s.nextGeneration(10000ms)); - ASSERT_TRUE(timer.elapsed().ms() <= 5000); + ASSERT_TRUE(timer.elapsed() <= 5s); verifyConfig("foo", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); } @@ -324,10 +323,10 @@ TEST_FFF("requireThatNothingCanBeCalledAfterClose", MyManager, APIFixture(f1), S TEST_MT_FFF("requireThatNextConfigIsInterruptedOnClose", 2, MyManager, APIFixture(f1), StandardFixture(f1, f2)) { if (thread_id == 0) { - fastos::StopWatch timer; + vespalib::Timer timer; ASSERT_FALSE(f3.s.nextConfig(5000ms)); - ASSERT_TRUE(timer.elapsed().ms() >= 500.0); - ASSERT_TRUE(timer.elapsed().ms() < 60000.0); + ASSERT_TRUE(timer.elapsed() >= 500ms); + ASSERT_TRUE(timer.elapsed() < 60s); } else { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); f3.s.close(); diff --git a/config/src/tests/subscription/subscription.cpp b/config/src/tests/subscription/subscription.cpp index 5b8fc22bf4e..9583111a2f7 100644 --- a/config/src/tests/subscription/subscription.cpp +++ b/config/src/tests/subscription/subscription.cpp @@ -3,7 +3,6 @@ #include <vespa/config/common/misc.h> #include <vespa/config/common/configholder.h> #include <vespa/config/subscription/configsubscription.h> -#include <vespa/fastos/timestamp.h> #include <config-my.h> using namespace config; @@ -66,18 +65,18 @@ TEST_F("requireThatNextUpdateBlocks", SubscriptionFixture(ConfigKey::create<MyCo { ASSERT_FALSE(f1.sub.nextUpdate(0, 0ms)); f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(), 1, 1)); - fastos::StopWatch timer; + vespalib::Timer timer; ASSERT_FALSE(f1.sub.nextUpdate(1, 500ms)); - ASSERT_TRUE(timer.elapsed().ms() > 400.0); + ASSERT_TRUE(timer.elapsed() > 400ms); } TEST_MT_F("requireThatNextUpdateReturnsWhenNotified", 2, SubscriptionFixture(ConfigKey::create<MyConfig>("myid"))) { if (thread_id == 0) { - fastos::StopWatch timer; + vespalib::Timer timer; f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(), 1, 1)); ASSERT_TRUE(f1.sub.nextUpdate(2, 5000ms)); - ASSERT_TRUE(timer.elapsed().ms() > 200.0); + ASSERT_TRUE(timer.elapsed() > 200ms); } else { std::this_thread::sleep_for(std::chrono::milliseconds(500)); f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(), 1, 1)); @@ -88,10 +87,10 @@ TEST_MT_F("requireThatNextUpdateReturnsWhenNotified", 2, SubscriptionFixture(Con TEST_MT_F("requireThatNextUpdateReturnsInterrupted", 2, SubscriptionFixture(ConfigKey::create<MyConfig>("myid"))) { if (thread_id == 0) { - fastos::StopWatch timer; + vespalib::Timer timer; f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(), 1, 1)); ASSERT_TRUE(f1.sub.nextUpdate(1, 5000ms)); - ASSERT_TRUE(timer.elapsed().ms() > 300.0); + ASSERT_TRUE(timer.elapsed() > 300ms); } else { std::this_thread::sleep_for(std::chrono::milliseconds(500)); f1.sub.close(); diff --git a/configd/src/apps/sentinel/config-handler.cpp b/configd/src/apps/sentinel/config-handler.cpp index 3e7b9ef0ea0..d4600471904 100644 --- a/configd/src/apps/sentinel/config-handler.cpp +++ b/configd/src/apps/sentinel/config-handler.cpp @@ -5,7 +5,6 @@ #include <vespa/vespalib/net/socket_address.h> #include <vespa/vespalib/util/exceptions.h> -#include <vespa/fastos/timestamp.h> #include <string> #include <fcntl.h> #include <sys/wait.h> @@ -44,24 +43,22 @@ ConfigHandler::ConfigHandler() _startMetrics(), _stateApi() { - _startMetrics.startedTime = fastos::time(); + _startMetrics.startedTime = vespalib::steady_clock::now(); } ConfigHandler::~ConfigHandler() { terminateServices(false); - std::list<OutputConnection *>::iterator it; - for (it = _outputConnections.begin(); it != _outputConnections.end(); ++it) - { - delete *it; + for (OutputConnection * conn : _outputConnections) { + delete conn; } } void ConfigHandler::terminateServices(bool catchable, bool printDebug) { - for (ServiceMap::iterator it(_services.begin()), mt(_services.end()); it != mt; it++) { - Service *service = it->second.get(); + for (const auto & entry : _services) { + Service *service = entry.second.get(); if (printDebug && service->isRunning()) { LOG(info, "%s: killing", service->name().c_str()); } @@ -77,34 +74,10 @@ ConfigHandler::terminate() // Give them 58 seconds to exit cleanly, then terminate(false) all // of them. terminateServices(true); - struct timeval endTime; - gettimeofday(&endTime, nullptr); - endTime.tv_sec += 58; - struct timeval tv = {0, 0}; - - while (tv.tv_sec >= 0 && doWork()) { - gettimeofday(&tv, nullptr); - tv.tv_sec = endTime.tv_sec - tv.tv_sec; - tv.tv_usec = endTime.tv_usec - tv.tv_usec; - - if (tv.tv_usec >= 1000000) { - tv.tv_usec -= 1000000; - tv.tv_sec += 1; - } else if (tv.tv_usec < 0) { - tv.tv_usec += 100000; - tv.tv_sec -= 1; - } - - if (tv.tv_sec < 0) { - break; - } - - if (tv.tv_sec > 0 || tv.tv_usec > 200000) { - // Never wait more than 200ms per select regardless - tv.tv_sec = 0; - tv.tv_usec = 200000; - } + vespalib::steady_time endTime = vespalib::steady_clock::now() + 58s; + while ((vespalib::steady_clock::now() < endTime) && doWork()) { + struct timeval tv {0, 200000}; // Any child exiting will send SIGCHLD and break this select so // we handle the children exiting even quicker.. select(0, nullptr, nullptr, nullptr, &tv); @@ -112,8 +85,7 @@ ConfigHandler::terminate() for (int retry = 0; retry < 10 && doWork(); ++retry) { LOG(warning, "some services refuse to terminate cleanly, sending KILL"); terminateServices(false, true); - tv.tv_sec = 0; - tv.tv_usec = 200000; + struct timeval tv {0, 200000}; select(0, nullptr, nullptr, nullptr, &tv); } return !doWork(); @@ -146,9 +118,9 @@ ConfigHandler::doConfigure() for (unsigned int i = 0; i < config.service.size(); ++i) { const SentinelConfig::Service& serviceConfig = config.service[i]; const vespalib::string name(serviceConfig.name); - ServiceMap::iterator found(_services.find(name)); + auto found(_services.find(name)); if (found == _services.end()) { - services[name] = Service::UP(new Service(serviceConfig, config.application, _outputConnections, _startMetrics)); + services[name] = std::make_unique<Service>(serviceConfig, config.application, _outputConnections, _startMetrics); } else { found->second->reconfigure(serviceConfig); services[name] = std::move(found->second); @@ -182,8 +154,8 @@ ConfigHandler::doWork() _startMetrics.maybeLog(); // Check for active services. - for (ServiceMap::iterator it(_services.begin()), mt(_services.end()); it != mt; it++) { - if (it->second->isRunning()) { + for (const auto & service : _services) { + if (service.second->isRunning()) { return true; } } @@ -227,12 +199,8 @@ ConfigHandler::handleChildDeaths() void ConfigHandler::updateActiveFdset(fd_set *fds, int *maxNum) { - std::list<OutputConnection *>::const_iterator - src = _outputConnections.begin(); // ### _Possibly put an assert here if fd is > 1023??? - while (src != _outputConnections.end()) { - OutputConnection *c = *src; - ++src; + for (OutputConnection *c : _outputConnections) { int fd = c->fd(); if (fd >= 0) { FD_SET(fd, fds); @@ -280,10 +248,9 @@ ConfigHandler::handleCommands() Service * ConfigHandler::serviceByPid(pid_t pid) { - for (ServiceMap::iterator it(_services.begin()), mt(_services.end()); it != mt; it++) { - Service *service = it->second.get(); - if (service->pid() == pid) { - return service; + for (const auto & service : _services) { + if (service.second->pid() == pid) { + return service.second.get(); } } for (const auto & it : _orphans) { @@ -298,7 +265,7 @@ ConfigHandler::serviceByPid(pid_t pid) Service * ConfigHandler::serviceByName(const vespalib::string & name) { - ServiceMap::iterator found(_services.find(name)); + auto found(_services.find(name)); if (found != _services.end()) { return found->second.get(); } @@ -316,8 +283,8 @@ ConfigHandler::handleCmd(const Cmd& cmd) size_t left = 65536; size_t pos = 0; retbuf[pos] = 0; - for (ServiceMap::iterator it(_services.begin()), mt(_services.end()); it != mt; it++) { - Service *service = it->second.get(); + for (const auto & entry : _services) { + const Service *service = entry.second.get(); const SentinelConfig::Service& config = service->serviceConfig(); int sz = snprintf(retbuf + pos, left, "%s state=%s mode=%s pid=%d exitstatus=%d id=\"%s\"\n", diff --git a/configd/src/apps/sentinel/metrics.cpp b/configd/src/apps/sentinel/metrics.cpp index bb10c94ae12..ed31e7a4d80 100644 --- a/configd/src/apps/sentinel/metrics.cpp +++ b/configd/src/apps/sentinel/metrics.cpp @@ -2,7 +2,6 @@ #include "metrics.h" #include <vespa/vespalib/metrics/simple_metrics.h> -#include <vespa/fastos/timestamp.h> namespace config::sentinel { @@ -14,7 +13,7 @@ StartMetrics::StartMetrics() producer(metrics), currentlyRunningServices(0), totalRestartsCounter(0), - startedTime(fastos::time()), + startedTime(vespalib::steady_clock::now()), sentinel_restarts(metrics->counter("sentinel.restarts", "how many times sentinel restarted a service")), sentinel_totalRestarts(metrics->gauge("sentinel.totalRestarts", @@ -33,10 +32,10 @@ StartMetrics::~StartMetrics() = default; void StartMetrics::maybeLog() { - uint32_t curTime = fastos::time(); + vespalib::steady_time curTime = vespalib::steady_clock::now(); sentinel_totalRestarts.sample(totalRestartsCounter); sentinel_running.sample(currentlyRunningServices); - sentinel_uptime.sample(curTime - startedTime); + sentinel_uptime.sample(vespalib::to_s(curTime - startedTime)); } } diff --git a/configd/src/apps/sentinel/metrics.h b/configd/src/apps/sentinel/metrics.h index 2263d70fb60..365b7cc2ecf 100644 --- a/configd/src/apps/sentinel/metrics.h +++ b/configd/src/apps/sentinel/metrics.h @@ -1,8 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <sys/time.h> #include <vespa/vespalib/metrics/simple_metrics.h> +#include <vespa/vespalib/util/time.h> namespace config::sentinel { @@ -15,7 +15,7 @@ struct StartMetrics { vespalib::metrics::Producer producer; unsigned long currentlyRunningServices; unsigned long totalRestartsCounter; - long startedTime; + vespalib::steady_time startedTime; Counter sentinel_restarts; Gauge sentinel_totalRestarts; Gauge sentinel_running; diff --git a/configd/src/apps/sentinel/service.cpp b/configd/src/apps/sentinel/service.cpp index 22f9681a2ff..9f4196a2457 100644 --- a/configd/src/apps/sentinel/service.cpp +++ b/configd/src/apps/sentinel/service.cpp @@ -4,7 +4,6 @@ #include "output-connection.h" #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/signalhandler.h> -#include <vespa/fastos/timestamp.h> #include <csignal> #include <unistd.h> @@ -44,7 +43,7 @@ Service::Service(const SentinelConfig::Service& service, const SentinelConfig::A _config(new SentinelConfig::Service(service)), _isAutomatic(true), _restartPenalty(0), - _last_start(0), + _last_start(vespalib::steady_time::min()), _application(application), _outputConnections(ocs), _metrics(metrics) @@ -157,8 +156,7 @@ Service::start() LOG(warning, "tried to start '%s' in REMOVING state", name().c_str()); return; } - time_t now = fastos::time(); - _last_start = now; + _last_start = vespalib::steady_clock::now(); // make a pipe, close the good ends of it, mark it close-on-exec // if exec fails, write a complaint on the fd (which will then be read @@ -323,8 +321,8 @@ Service::youExited(int status) if (! expectedDeath) { // make sure the service does not restart in a tight loop: - time_t now = fastos::time(); - unsigned int diff = now - _last_start; + vespalib::steady_time now = vespalib::steady_clock::now(); + vespalib::duration diff = now - _last_start; if (diff < MAX_RESTART_PENALTY) { incrementRestartPenalty(); } @@ -332,7 +330,7 @@ Service::youExited(int status) resetRestartPenalty(); } if (diff < _restartPenalty) { - LOG(info, "%s: will delay start by %u seconds", name().c_str(), _restartPenalty - diff); + LOG(info, "%s: will delay start by %2.3f seconds", name().c_str(), vespalib::to_s(_restartPenalty - diff)); } } if (_isAutomatic && !stop()) { @@ -421,8 +419,7 @@ bool Service::wantsRestart() const { if (_state == RESTARTING) { - time_t now = fastos::time(); - if (now > _last_start + _restartPenalty) { + if (vespalib::steady_clock::now() > _last_start + _restartPenalty) { return true; } } @@ -441,12 +438,12 @@ Service::setAutomatic(bool autoStatus) void Service::incrementRestartPenalty() { - _restartPenalty += 1; + _restartPenalty += 1s; _restartPenalty *= 2; if (_restartPenalty > MAX_RESTART_PENALTY) { _restartPenalty = MAX_RESTART_PENALTY; } - LOG(info, "%s: incremented restart penalty to %u seconds", name().c_str(), _restartPenalty); + LOG(info, "%s: incremented restart penalty to %2.3f seconds", name().c_str(), vespalib::to_s(_restartPenalty)); } diff --git a/configd/src/apps/sentinel/service.h b/configd/src/apps/sentinel/service.h index 5a188f217ff..7b7321fb5c6 100644 --- a/configd/src/apps/sentinel/service.h +++ b/configd/src/apps/sentinel/service.h @@ -3,6 +3,7 @@ #include "metrics.h" #include <vespa/vespalib/stllike/string.h> +#include <vespa/vespalib/util/time.h> #include <vespa/config-sentinel.h> #include <list> @@ -27,9 +28,9 @@ private: SentinelConfig::Service *_config; bool _isAutomatic; - static const unsigned int MAX_RESTART_PENALTY = 1800; - unsigned int _restartPenalty; - time_t _last_start; + static constexpr vespalib::duration MAX_RESTART_PENALTY = 1800s; + vespalib::duration _restartPenalty; + vespalib::steady_time _last_start; void runChild(int pipes[2]) __attribute__((noreturn)); void ensureChildRuns(int fd); @@ -67,7 +68,7 @@ public: const SentinelConfig::Service& serviceConfig() const { return *_config; } void setAutomatic(bool autoStatus); bool isAutomatic() const { return _isAutomatic; } - void resetRestartPenalty() { _restartPenalty = 0; } + void resetRestartPenalty() { _restartPenalty = vespalib::duration::zero(); } void incrementRestartPenalty(); }; diff --git a/fastos/src/tests/processtest.cpp b/fastos/src/tests/processtest.cpp index 5a78eff1d36..e39b6461a29 100644 --- a/fastos/src/tests/processtest.cpp +++ b/fastos/src/tests/processtest.cpp @@ -1,9 +1,9 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "tests.h" #include <vespa/fastos/process.h> -#include <vespa/fastos/timestamp.h> using namespace std::chrono_literals; +using namespace std::chrono; class MyListener : public FastOS_ProcessRedirectListener { @@ -213,7 +213,7 @@ public: if(waitKill) timeOut = 1; - fastos::StopWatch timer; + steady_clock::time_point start = steady_clock::now(); int returnCode; if(!xproc->Wait(&returnCode, timeOut)) @@ -228,11 +228,11 @@ public: } if (waitKill) { - double milliSecs = timer.elapsed().ms(); - if((milliSecs < 900) || - (milliSecs > 3500)) + nanoseconds elapsed = steady_clock::now() - start; + if((elapsed < 900ms) || + (elapsed > 3500ms)) { - Progress(false, "WaitKill time = %d", int(milliSecs)); + Progress(false, "WaitKill time = %d", duration_cast<milliseconds>(elapsed).count()); } } diff --git a/fastos/src/tests/thread_bounce_test.cpp b/fastos/src/tests/thread_bounce_test.cpp index 84506938455..488002341e9 100644 --- a/fastos/src/tests/thread_bounce_test.cpp +++ b/fastos/src/tests/thread_bounce_test.cpp @@ -3,7 +3,8 @@ #include "tests.h" #include "job.h" #include "thread_test_base.hpp" -#include <vespa/fastos/timestamp.h> + +using namespace std::chrono; class Thread_Bounce_Test : public ThreadTestBase { @@ -39,12 +40,12 @@ class Thread_Bounce_Test : public ThreadTestBase lastcntsum = -1; for (int iter = 0; iter < 8; iter++) { - fastos::StopWatch checkTime; + steady_clock::time_point start = steady_clock::now(); - int left = static_cast<int>(checkTime.elapsed().ms()); - while (left < 1000) { - std::this_thread::sleep_for(std::chrono::milliseconds(1000 - left)); - left = static_cast<int>(checkTime.elapsed().ms()); + nanoseconds left = steady_clock::now() - start; + while (left < 1000ms) { + std::this_thread::sleep_for(1000ms - left); + left = steady_clock::now() - start; } mutex1.lock(); diff --git a/fastos/src/tests/threadtest.cpp b/fastos/src/tests/threadtest.cpp index 0a8a0d2bf02..1fa9820c8d7 100644 --- a/fastos/src/tests/threadtest.cpp +++ b/fastos/src/tests/threadtest.cpp @@ -3,13 +3,15 @@ #include "tests.h" #include "job.h" #include "thread_test_base.hpp" -#include <vespa/fastos/timestamp.h> #include <cstdlib> #include <chrono> #define MUTEX_TEST_THREADS 6 #define MAX_THREADS 7 +using namespace std::chrono; +using namespace std::chrono_literals; + class ThreadTest : public ThreadTestBase { int Main () override; @@ -202,7 +204,7 @@ class ThreadTest : public ThreadTestBase Job *jobs = new Job[count]; threadsok = 0; - fastos::StopWatch timer; + steady_clock::time_point start = steady_clock::now(); for (i = 0; i < count; i++) { jobs[i].code = SILENTNOP; jobs[i].ownThread = pool->NewThread(this, &jobs[i]); @@ -225,13 +227,13 @@ class ThreadTest : public ThreadTestBase if (jobs[i].ownThread != nullptr) jobs[i].ownThread->Join(); } - fastos::TimeStamp used = timer.elapsed(); + nanoseconds used = steady_clock::now() - start; if (!silent) { - Progress(true, "Used time: %2.3f", used.sec()); + double timeused = used.count() / 1000000000.0; - double timeused = used.sec(); - ProgressFloat(true, "Threads/s: %6.1f", + Progress(true, "Used time: %2.3f", timeused); + ProgressFloat(true, "Threads/s: %6.1f", static_cast<float>(static_cast<double>(threadsok) / timeused)); } if (threadsok != ((outercount + 1) * count)) @@ -517,12 +519,13 @@ class ThreadTest : public ThreadTestBase std::mutex **mutexes = new std::mutex*[allocCount]; - fastos::StopWatch timer; + steady_clock::time_point start = steady_clock::now(); for (i=0; i<allocCount; i++) mutexes[i] = new std::mutex; - Progress(true, "Allocated %d mutexes at time: %ld ms", allocCount, timer.elapsed().ms()); + nanoseconds elapsed = steady_clock::now() - start; + Progress(true, "Allocated %d mutexes at time: %ld ms", allocCount, duration_cast<milliseconds>(elapsed).count()); for (int e=0; e<4; e++) { for(i=0; i<allocCount; i++) @@ -531,12 +534,14 @@ class ThreadTest : public ThreadTestBase for(i=0; i<allocCount; i++) mutexes[i]->unlock(); - Progress(true, "Tested %d mutexes at time: %d ms", allocCount, timer.elapsed().ms()); + elapsed = steady_clock::now() - start; + Progress(true, "Tested %d mutexes at time: %d ms", allocCount, duration_cast<milliseconds>(elapsed).count()); } for (i=0; i<allocCount; i++) delete mutexes[i]; - Progress(true, "Deleted %d mutexes at time: %d ms", allocCount, timer.elapsed().ms()); + elapsed = steady_clock::now() - start; + Progress(true, "Deleted %d mutexes at time: %d ms", allocCount, duration_cast<milliseconds>(elapsed).count()); delete [] mutexes; diff --git a/fastos/src/vespa/fastos/CMakeLists.txt b/fastos/src/vespa/fastos/CMakeLists.txt index fb5e7b2901e..1437f5c55f3 100644 --- a/fastos/src/vespa/fastos/CMakeLists.txt +++ b/fastos/src/vespa/fastos/CMakeLists.txt @@ -7,7 +7,6 @@ vespa_add_library(fastos_objects OBJECT linux_file.cpp process.cpp thread.cpp - timestamp.cpp unix_app.cpp unix_dynamiclibrary.cpp unix_file.cpp diff --git a/fastos/src/vespa/fastos/timestamp.cpp b/fastos/src/vespa/fastos/timestamp.cpp deleted file mode 100644 index ef206067900..00000000000 --- a/fastos/src/vespa/fastos/timestamp.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "timestamp.h" -#include <cmath> -#include <thread> -#include <sys/time.h> - -using std::chrono::system_clock; -using std::chrono::steady_clock; -using std::chrono::nanoseconds; -using std::chrono::duration_cast; - -namespace fastos { - -const TimeStamp::TimeT TimeStamp::MILLI; -const TimeStamp::TimeT TimeStamp::MICRO; -const TimeStamp::TimeT TimeStamp::NANO; -const TimeStamp::TimeT TimeStamp::SEC; - -using seconds = std::chrono::duration<double>; - -std::string -TimeStamp::asString(double timeInSeconds) -{ - double intpart; - double fractpart = std::modf(timeInSeconds, &intpart); - time_t timeStamp = (time_t)intpart; - struct tm timeStruct; - gmtime_r(&timeStamp, &timeStruct); - char timeString[128]; - strftime(timeString, sizeof(timeString), "%F %T", &timeStruct); - char retval[160]; - uint32_t milliSeconds = std::min((uint32_t)(fractpart * 1000.0), 999u); - snprintf(retval, sizeof(retval), "%s.%03u UTC", timeString, milliSeconds); - return std::string(retval); -} - -std::string -TimeStamp::asString(std::chrono::system_clock::time_point ns) { - return asString(seconds(ns.time_since_epoch()).count()); -} - -time_t -time() { - return system_clock::to_time_t(system_clock::now()); -} - -namespace { - -SteadyTimeStamp -steady_now() { - return SteadyTimeStamp(duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count()); -} - -} - -StopWatch::StopWatch() - : _startTime(steady_now()) -{ } - -void -StopWatch::restart() { - _startTime = steady_now(); -} - -TimeStamp -StopWatch::elapsed() const { - return (steady_now() - _startTime); -} - -void -StopWatch::waitAtLeast(std::chrono::microseconds us, bool busyWait) { - if (busyWait) { - steady_clock::time_point deadline = steady_clock::now() + us; - while (steady_clock::now() < deadline) { - for (int i = 0; i < 1000; i++) { } - } - } else { - std::this_thread::sleep_for(us); - } -} - -} diff --git a/fastos/src/vespa/fastos/timestamp.h b/fastos/src/vespa/fastos/timestamp.h deleted file mode 100644 index 0d23cf7151f..00000000000 --- a/fastos/src/vespa/fastos/timestamp.h +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include <cstdint> -#include <limits> -#include <string> -#include <chrono> - -namespace fastos { - -class TimeStamp -{ -public: - typedef int64_t TimeT; - static const TimeT MILLI = 1000LL; - static const TimeT MICRO = 1000*MILLI; - static const TimeT NANO = 1000*MICRO; - static const TimeT SEC = NANO; - class Seconds { - public: - explicit Seconds(double v) : _v(v * NANO) {} - TimeT val() const { return _v; } - private: - TimeT _v; - }; - TimeStamp() : _time(0) { } - TimeStamp(const timeval & tv) : _time(tv.tv_sec*SEC + tv.tv_usec*MILLI) { } - TimeStamp(int v) : _time(v) { } - TimeStamp(unsigned int v) : _time(v) { } - TimeStamp(long v) : _time(v) { } - TimeStamp(unsigned long v) : _time(v) { } - TimeStamp(long long v) : _time(v) { } - TimeStamp(unsigned long long v) : _time(v) { } - TimeStamp(Seconds v) : _time(v.val()) { } - TimeT val() const { return _time; } - operator TimeT () const { return val(); } - TimeStamp & operator += (TimeStamp b) { _time += b._time; return *this; } - TimeStamp & operator -= (TimeStamp b) { _time -= b._time; return *this; } - TimeT time() const { return val()/NANO; } - TimeT ms() const { return val()/1000000; } - TimeT us() const { return val()/1000; } - TimeT ns() const { return val(); } - double sec() const { return val()/1000000000.0; } - std::string toString() const { return asString(sec()); } - static std::string asString(double timeInSeconds); - static std::string asString(std::chrono::system_clock::time_point time); -private: - TimeT _time; -}; - -inline TimeStamp operator +(TimeStamp a, TimeStamp b) { return TimeStamp(a.val() + b.val()); } -inline TimeStamp operator -(TimeStamp a, TimeStamp b) { return TimeStamp(a.val() - b.val()); } -inline TimeStamp operator *(long a, TimeStamp b) { return TimeStamp(a * b.val()); } -inline TimeStamp operator *(double a, TimeStamp b) { return TimeStamp(static_cast<int64_t>(a * b.val())); } - -class SteadyTimeStamp { -public: - SteadyTimeStamp() : _timeStamp() { } - explicit SteadyTimeStamp(TimeStamp timeStamp) : _timeStamp(timeStamp) { } - - friend TimeStamp operator -(SteadyTimeStamp a, SteadyTimeStamp b) { - return a._timeStamp - b._timeStamp; - } - friend SteadyTimeStamp operator -(SteadyTimeStamp a, TimeStamp b) { - return SteadyTimeStamp(a._timeStamp - b); - } - friend SteadyTimeStamp operator +(SteadyTimeStamp a, TimeStamp b) { - return SteadyTimeStamp(a._timeStamp + b); - } - friend bool operator != (SteadyTimeStamp a, SteadyTimeStamp b) { - return a._timeStamp != b._timeStamp; - } - friend bool operator == (SteadyTimeStamp a, SteadyTimeStamp b) { - return a._timeStamp == b._timeStamp; - } - friend bool operator < (SteadyTimeStamp a, SteadyTimeStamp b) { - return a._timeStamp < b._timeStamp; - } - friend bool operator > (SteadyTimeStamp a, SteadyTimeStamp b) { - return a._timeStamp > b._timeStamp; - } - std::string toString() const { return _timeStamp.toString(); }; -private: - TimeStamp _timeStamp; -}; - -class StopWatch -{ -public: - StopWatch(); - void restart(); - TimeStamp elapsed() const; - static void waitAtLeast(std::chrono::microseconds us, bool busyWait); -private: - SteadyTimeStamp _startTime; -}; - -time_t time(); - -} - diff --git a/fastos/src/vespa/fastos/unix_process.cpp b/fastos/src/vespa/fastos/unix_process.cpp index 4d4197f5354..087f800e668 100644 --- a/fastos/src/vespa/fastos/unix_process.cpp +++ b/fastos/src/vespa/fastos/unix_process.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "process.h" #include "unix_ipc.h" -#include "timestamp.h" #include "ringbuffer.h" #include <vector> #include <cstring> @@ -41,6 +40,7 @@ extern char **environ; #endif using namespace std::chrono_literals; +using namespace std::chrono; static pid_t safe_fork () { @@ -1600,7 +1600,7 @@ FastOS_UNIX_ProcessStarter::Wait(FastOS_UNIX_Process *process, bool timeOutKillAttempted = false; - fastos::StopWatch timer; + steady_clock::time_point start = steady_clock::now(); if (pollStillRunning != nullptr) *pollStillRunning = true; @@ -1625,7 +1625,7 @@ FastOS_UNIX_ProcessStarter::Wait(FastOS_UNIX_Process *process, if ((timeOutSeconds != -1) && !timeOutKillAttempted) { - if (timer.elapsed().ms() >= (timeOutSeconds * 1000)) { + if ((steady_clock::now() - start) >= seconds(timeOutSeconds)) { process->Kill(); timeOutKillAttempted = true; } diff --git a/logd/src/logd/config_subscriber.cpp b/logd/src/logd/config_subscriber.cpp index 1e6c9a040d3..3a6af0c54e4 100644 --- a/logd/src/logd/config_subscriber.cpp +++ b/logd/src/logd/config_subscriber.cpp @@ -50,7 +50,7 @@ ConfigSubscriber::configure(std::unique_ptr<LogdConfig> cfg) LOG(config, "bad rotate.size=%d must be positive", newconf.rotate.size); } if (newconf.rotate.age > 0) { - _rotate_age = newconf.rotate.age; + _rotate_age = std::chrono::seconds(newconf.rotate.age); } else { LOG(config, "bad rotate.age=%d must be positive", newconf.rotate.age); } @@ -60,7 +60,7 @@ ConfigSubscriber::configure(std::unique_ptr<LogdConfig> cfg) LOG(config, "bad remove.totalmegabytes=%d must be positive", newconf.remove.totalmegabytes); } if (newconf.remove.age > 0) { - _remove_age = newconf.remove.age; + _remove_age = std::chrono::hours(newconf.remove.age * 24); } else { LOG(config, "bad remove.age=%d must be positive", newconf.remove.age); } @@ -90,9 +90,9 @@ ConfigSubscriber::ConfigSubscriber(const config::ConfigUri& configUri) _state_port(0), _forward_filter(), _rotate_size(INT_MAX), - _rotate_age(INT_MAX), + _rotate_age(vespalib::duration::max()), _remove_meg(INT_MAX), - _remove_age(3650), + _remove_age(std::chrono::hours(30*24)), _use_logserver(true), _subscriber(configUri.getContext()), _handle(), diff --git a/logd/src/logd/config_subscriber.h b/logd/src/logd/config_subscriber.h index 507952319d6..fcda0ac1e11 100644 --- a/logd/src/logd/config_subscriber.h +++ b/logd/src/logd/config_subscriber.h @@ -5,6 +5,7 @@ #include <logd/config-logd.h> #include <vespa/config/config.h> #include <vespa/fnet/frt/supervisor.h> +#include <vespa/vespalib/util/time.h> namespace logdemon { @@ -20,9 +21,9 @@ private: int _state_port; ForwardMap _forward_filter; int _rotate_size; - int _rotate_age; + vespalib::duration _rotate_age; int _remove_meg; - int _remove_age; + vespalib::duration _remove_age; bool _use_logserver; config::ConfigSubscriber _subscriber; config::ConfigHandle<cloud::config::log::LogdConfig>::UP _handle; @@ -39,9 +40,9 @@ public: int getStatePort() const { return _state_port; } int getRotateSize() const { return _rotate_size; } - int getRotateAge() const { return _rotate_age; } + vespalib::duration getRotateAge() const { return _rotate_age; } int getRemoveMegabytes() const { return _remove_meg; } - int getRemoveAge() const { return _remove_age; } + vespalib::duration getRemoveAge() const { return _remove_age; } bool need_new_forwarder() const { return _need_new_forwarder; } std::unique_ptr<Forwarder> make_forwarder(Metrics& metrics); diff --git a/logd/src/logd/watcher.cpp b/logd/src/logd/watcher.cpp index 2bb8973f052..e481d64f721 100644 --- a/logd/src/logd/watcher.cpp +++ b/logd/src/logd/watcher.cpp @@ -4,57 +4,29 @@ #include "exceptions.h" #include "forwarder.h" #include "watcher.h" -#include <vespa/log/log.h> #include <vespa/vespalib/util/sig_catch.h> -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> +#include <thread> #include <fcntl.h> #include <glob.h> #include <sys/stat.h> -#include <sys/time.h> #include <unistd.h> +#include <vespa/log/log.h> LOG_SETUP(""); namespace logdemon { namespace { // wait until 1 second has passed since "start" -void snooze(const struct timeval &start) +void snooze(vespalib::Timer & timer) { - struct timeval sincestart; - gettimeofday(&sincestart, 0); - // compute time elapsed since start: - sincestart.tv_sec -= start.tv_sec; - sincestart.tv_usec -= start.tv_usec; - - // how many microseconds to wait: - long wait_usecs = (1000000 - sincestart.tv_usec); - wait_usecs -= (1000000 * sincestart.tv_sec); - - if (wait_usecs <= 0) { + if (timer.elapsed() > 1000ms) { // already used enough time, no sleep return; } - struct timespec tsp; - tsp.tv_sec = (wait_usecs / 1000000); - tsp.tv_nsec = (wait_usecs % 1000000) * 1000; - - if (nanosleep(&tsp, nullptr) != 0 && errno != EINTR) { - LOG(error, "nanosleep %ld s %ld ns failed: %s", - (long)tsp.tv_sec, (long)tsp.tv_nsec, strerror(errno)); - throw SomethingBad("nanosleep failed"); - } -} - -int elapsed(struct timeval &start) { - struct timeval now; - gettimeofday(&now, 0); - int diffsecs = now.tv_sec - start.tv_sec; - if (now.tv_usec < start.tv_usec) { - --diffsecs; - } - return diffsecs; + std::this_thread::sleep_for(1000ms - timer.elapsed()); } constexpr size_t G_BUFSIZE = 1024*1024; @@ -164,7 +136,7 @@ Watcher::watchfile() vespalib::SigCatch catcher; int sleepcount = 0; - time_t created = 0; + vespalib::system_time created = vespalib::system_time::min(); again: // XXX should close and/or check _wfd first ? @@ -175,17 +147,17 @@ Watcher::watchfile() } bool rotate = false; - struct timeval rotStart; + vespalib::Timer rotTimer; off_t offset = 0; - while (1) { + while (true) { struct stat sb; if (fstat(_wfd, &sb) != 0) { LOG(error, "fstat(%s) failed: %s", filename, strerror(errno)); throw SomethingBad("fstat failed"); } - if (created == 0) { - created = sb.st_ctime; + if (created == vespalib::system_time::min()) { + created = vespalib::system_time(std::chrono::seconds(sb.st_ctime)); } if (already.valid) { if (sb.st_dev == already.st_dev && @@ -204,8 +176,7 @@ Watcher::watchfile() return; } - struct timeval tickStart; - gettimeofday(&tickStart, 0); + vespalib::Timer timer; if (sb.st_size > offset) { lseek(_wfd, offset, SEEK_SET); @@ -219,7 +190,7 @@ Watcher::watchfile() LOG(error, "no newline in %ld bytes, skipping", static_cast<long>(rsize)); offset += rsize; } - while (nnl != nullptr && elapsed(tickStart) < 1) { + while (nnl != nullptr && (timer.elapsed() < 1000ms)) { ++nnl; _forwarder.forwardLine(std::string_view(l, (nnl - l) - 1)); ssize_t wsize = nnl - l; @@ -237,19 +208,19 @@ Watcher::watchfile() already.st_dev = sb.st_dev; already.st_ino = sb.st_ino; - time_t now = fastos::time(); + vespalib::system_time now = vespalib::system_clock::now(); bool wantrotate = (now > created + _confsubscriber.getRotateAge()) || (sb.st_size > _confsubscriber.getRotateSize()); if (rotate) { - int rotTime = elapsed(rotStart); - if (rotTime > 59 || (sb.st_size == offset && rotTime > 4)) { + vespalib::duration rotTime = rotTimer.elapsed(); + if (rotTime > 59s || (sb.st_size == offset && rotTime > 4s)) { removeOldLogs(filename); if (sb.st_size != offset) { - LOG(warning, "logfile rotation incomplete after %d s (dropping %" PRIu64 " bytes)", - rotTime, static_cast<uint64_t>(sb.st_size - offset)); + LOG(warning, "logfile rotation incomplete after %2.3f s (dropping %" PRIu64 " bytes)", + vespalib::to_s(rotTime), static_cast<uint64_t>(sb.st_size - offset)); } else { - LOG(debug, "logfile rotation complete after %d s", rotTime); + LOG(debug, "logfile rotation complete after %2.3f s", vespalib::to_s(rotTime)); } created = now; rotate = false; @@ -266,13 +237,14 @@ Watcher::watchfile() goto again; } else if (wantrotate) { rotate = true; - gettimeofday(&rotStart, 0); - LOG(debug, "preparing to rotate logfile, old logfile size %d, age %d seconds", - (int)offset, (int)(now-created)); + rotTimer = vespalib::Timer(); + LOG(debug, "preparing to rotate logfile, old logfile size %d, age %2.3f seconds", + (int)offset, vespalib::to_s(now-created)); char newfn[FILENAME_MAX]; int l = strlen(filename); strcpy(newfn, filename); - struct tm *nowtm = gmtime(&now); + time_t seconds = vespalib::count_s(now.time_since_epoch()); + struct tm *nowtm = gmtime(&seconds); if (strftime(newfn+l, FILENAME_MAX-l-1, "-%Y-%m-%d.%H-%M-%S", nowtm) < 10) { LOG(error, "could not strftime"); @@ -298,7 +270,7 @@ Watcher::watchfile() if (catcher.receivedStopSignal()) { throw SigTermException("caught signal"); } - snooze(tickStart); + snooze(timer); if (catcher.receivedStopSignal()) { throw SigTermException("caught signal"); } @@ -351,15 +323,13 @@ Watcher::removeOldLogs(const char *prefix) continue; } if (S_ISREG(sb.st_mode)) { - if (sb.st_mtime + - _confsubscriber.getRemoveAge() * 86400 < fastos::time()) - { - LOG(info, "removing %s, too old (%f days)", fname, - (double)(fastos::time()-sb.st_mtime)/86400.0); + vespalib::system_time mtime = vespalib::system_time(std::chrono::seconds(sb.st_mtime)); + vespalib::system_time now = vespalib::system_clock::now(); + if ((mtime + _confsubscriber.getRemoveAge()) < now) { + LOG(info, "removing %s, too old (%f days)", fname, vespalib::to_s(now - mtime)/86400.0); if (unlink(fname) != 0) { - LOG(warning, "cannot remove %s: %s", - fname, strerror(errno)); + LOG(warning, "cannot remove %s: %s", fname, strerror(errno)); } continue; } diff --git a/messagebus_test/src/tests/speed/cpp-client.cpp b/messagebus_test/src/tests/speed/cpp-client.cpp index ff00128037a..b5829c76c08 100644 --- a/messagebus_test/src/tests/speed/cpp-client.cpp +++ b/messagebus_test/src/tests/speed/cpp-client.cpp @@ -9,7 +9,6 @@ #include <vespa/messagebus/testlib/simplereply.h> #include <vespa/vespalib/util/time.h> #include <thread> -#include <vespa/fastos/timestamp.h> #include <vespa/fastos/app.h> using namespace mbus; @@ -112,7 +111,7 @@ App::Main() // let the system 'warm up' std::this_thread::sleep_for(5s); - fastos::StopWatch stopWatch; + vespalib::Timer timer; uint32_t okBefore = 0; uint32_t okAfter = 0; uint32_t failBefore = 0; @@ -120,9 +119,9 @@ App::Main() client.sample(okBefore, failBefore); std::this_thread::sleep_for(10s); // Benchmark time - fastos::TimeStamp elapsed = stopWatch.elapsed(); + vespalib::duration elapsed = timer.elapsed(); client.sample(okAfter, failAfter); - double time = elapsed.ms(); + double time = vespalib::count_ms(elapsed); double msgCnt = (double)(okAfter - okBefore); double throughput = (msgCnt / time) * 1000.0; fprintf(stdout, "CPP-CLIENT: %g msg/s\n", throughput); diff --git a/metrics/src/vespa/metrics/metricmanager.cpp b/metrics/src/vespa/metrics/metricmanager.cpp index 74842801909..fd1c0f10d27 100644 --- a/metrics/src/vespa/metrics/metricmanager.cpp +++ b/metrics/src/vespa/metrics/metricmanager.cpp @@ -8,9 +8,9 @@ #include <vespa/vespalib/text/stringtokenizer.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/exceptions.h> +#include <vespa/vespalib/util/time.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/stllike/hashtable.hpp> -#include <vespa/fastos/timestamp.h> #include <sstream> #include <algorithm> @@ -26,7 +26,7 @@ MetricManager::ConsumerSpec::~ConsumerSpec() = default; time_t MetricManager::Timer::getTime() const { - return fastos::time(); + return vespalib::count_s(vespalib::steady_clock::now().time_since_epoch()); } void @@ -70,9 +70,9 @@ MetricManager::MetricManager(std::unique_ptr<Timer> timer) _consumerConfig(), _logPeriod(5 * 60, 0), _snapshots(), - _totalMetrics(MetricSnapshot::SP(new MetricSnapshot( + _totalMetrics(std::make_shared<MetricSnapshot>( "Empty metrics before init", 0, _activeMetrics.getMetrics(), - false))), + false)), _timer(std::move(timer)), _lastProcessedTime(0), _forceEventLogging(false), diff --git a/metrics/src/vespa/metrics/metricsnapshot.h b/metrics/src/vespa/metrics/metricsnapshot.h index b00c001505c..7c9fe492ac1 100644 --- a/metrics/src/vespa/metrics/metricsnapshot.h +++ b/metrics/src/vespa/metrics/metricsnapshot.h @@ -11,6 +11,7 @@ #include <map> #include <vespa/metrics/metric.h> #include <vespa/metrics/metricset.h> +#include <vespa/vespalib/util/time.h> namespace metrics { diff --git a/metrics/src/vespa/metrics/state_api_adapter.cpp b/metrics/src/vespa/metrics/state_api_adapter.cpp index f2e5108872e..ec5705eed91 100644 --- a/metrics/src/vespa/metrics/state_api_adapter.cpp +++ b/metrics/src/vespa/metrics/state_api_adapter.cpp @@ -3,7 +3,6 @@ #include "state_api_adapter.h" #include "metricmanager.h" #include <vespa/vespalib/stllike/asciistream.h> -#include <vespa/fastos/timestamp.h> namespace metrics { @@ -30,7 +29,7 @@ StateApiAdapter::getTotalMetrics(const vespalib::string &consumer) _manager.updateMetrics(true); metrics::MetricLockGuard guard(_manager.getMetricLock()); _manager.checkMetricsAltered(guard); - time_t currentTime = fastos::time(); + time_t currentTime = vespalib::count_s(vespalib::steady_clock::now().time_since_epoch()); auto generated = std::make_unique<metrics::MetricSnapshot>( "Total metrics from start until current time", 0, _manager.getTotalMetricSnapshot(guard).getMetrics(), diff --git a/searchcommon/src/tests/schema/schema_test.cpp b/searchcommon/src/tests/schema/schema_test.cpp index 3d35b11a51a..ff4c22bad84 100644 --- a/searchcommon/src/tests/schema/schema_test.cpp +++ b/searchcommon/src/tests/schema/schema_test.cpp @@ -243,55 +243,16 @@ TEST(SchemaTest, test_load_and_save) } } -TEST(SchemaTest, require_that_schema_can_save_and_load_timestamps_for_fields) -{ - const fastos::TimeStamp timestamp(42); - const std::string file_name = "schema-with-timestamps.txt"; - Schema s; - Schema::IndexField f("foo", DataType::STRING); - f.setTimestamp(timestamp); - s.addIndexField(f); - ASSERT_TRUE(s.saveToFile(file_name)); - Schema s2; - ASSERT_TRUE(s2.loadFromFile(file_name)); - ASSERT_EQ(1u, s2.getNumIndexFields()); - EXPECT_EQ(timestamp, s2.getIndexField(0).getTimestamp()); -} - -TEST(SchemaTest, require_that_timestamps_are_omitted_when_0) -{ - const std::string file_name = "schema-without-timestamps.txt"; - Schema s; - s.addIndexField(Schema::IndexField("foo", DataType::STRING)); - ASSERT_TRUE(s.saveToFile(file_name)); - - std::ifstream file(file_name.c_str()); - ASSERT_TRUE(file.good()); - while (file) { - std::string line; - getline(file, line); - EXPECT_NE("indexfield[0].timestamp 0", line); - } - - Schema s2; - ASSERT_TRUE(s2.loadFromFile(file_name)); - ASSERT_EQ(1u, s2.getNumIndexFields()); -} - void -addAllFieldTypes(const string& name, Schema& schema, - fastos::TimeStamp timestamp) +addAllFieldTypes(const string& name, Schema& schema) { Schema::IndexField index_field(name, DataType::STRING); - index_field.setTimestamp(timestamp); schema.addIndexField(index_field); Schema::AttributeField attribute_field(name, DataType::STRING); - attribute_field.setTimestamp(timestamp); schema.addAttributeField(attribute_field); Schema::SummaryField summary_field(name, DataType::STRING); - summary_field.setTimestamp(timestamp); schema.addSummaryField(summary_field); schema.addFieldSet(Schema::FieldSet(name)); @@ -301,12 +262,10 @@ TEST(SchemaTest, require_that_schemas_can_be_added) { const string name1 = "foo"; const string name2 = "bar"; - const fastos::TimeStamp timestamp1(42); - const fastos::TimeStamp timestamp2(84); Schema s1; - addAllFieldTypes(name1, s1, timestamp1); + addAllFieldTypes(name1, s1); Schema s2; - addAllFieldTypes(name2, s2, timestamp2); + addAllFieldTypes(name2, s2); Schema::UP sum = Schema::make_union(s1, s2); ASSERT_EQ(2u, sum->getNumIndexFields()); @@ -334,7 +293,7 @@ TEST(SchemaTest, require_that_schemas_can_be_added) TEST(SchemaTest, require_that_S_union_S_equals_S_for_schema_S) { Schema schema; - addAllFieldTypes("foo", schema, 42); + addAllFieldTypes("foo", schema); Schema::UP sum = Schema::make_union(schema, schema); EXPECT_TRUE(schema == *sum); @@ -344,56 +303,35 @@ TEST(SchemaTest, require_that_schema_can_calculate_set_difference) { const string name1 = "foo"; const string name2 = "bar"; - const fastos::TimeStamp timestamp1(42); - const fastos::TimeStamp timestamp2(84); Schema s1; - addAllFieldTypes(name1, s1, timestamp1); - addAllFieldTypes(name2, s1, timestamp2); + addAllFieldTypes(name1, s1); + addAllFieldTypes(name2, s1); Schema s2; - addAllFieldTypes(name2, s2, timestamp2); + addAllFieldTypes(name2, s2); Schema::UP schema = Schema::set_difference(s1, s2); Schema expected; - addAllFieldTypes(name1, expected, timestamp1); + addAllFieldTypes(name1, expected); EXPECT_TRUE(expected == *schema); } -TEST(SchemaTest, require_that_get_old_fields_returns_a_subset_of_a_schema) -{ - Schema schema; - const int64_t limit_timestamp = 1000; - - addAllFieldTypes("bar", schema, fastos::TimeStamp(limit_timestamp - 1)); - addAllFieldTypes("foo", schema, fastos::TimeStamp(limit_timestamp + 1)); - - Schema::UP old_fields = - schema.getOldFields(fastos::TimeStamp(limit_timestamp)); - - EXPECT_EQ(1u, old_fields->getNumIndexFields()); - EXPECT_EQ("bar", old_fields->getIndexField(0).getName()); - EXPECT_EQ(1u, old_fields->getNumAttributeFields()); - EXPECT_EQ(1u, old_fields->getNumSummaryFields()); -} - TEST(SchemaTest, require_that_schema_can_calculate_intersection) { const string name1 = "foo"; const string name2 = "bar"; const string name3 = "baz"; - const fastos::TimeStamp timestamp1(42); - const fastos::TimeStamp timestamp2(84); Schema s1; - addAllFieldTypes(name1, s1, timestamp1); - addAllFieldTypes(name2, s1, timestamp2); + addAllFieldTypes(name1, s1); + addAllFieldTypes(name2, s1); Schema s2; - addAllFieldTypes(name2, s2, timestamp2); - addAllFieldTypes(name3, s2, timestamp2); + addAllFieldTypes(name2, s2); + addAllFieldTypes(name3, s2); Schema::UP schema = Schema::intersect(s1, s2); Schema expected; - addAllFieldTypes(name2, expected, timestamp2); + addAllFieldTypes(name2, expected); EXPECT_TRUE(expected == *schema); } diff --git a/searchcommon/src/vespa/searchcommon/common/schema.cpp b/searchcommon/src/vespa/searchcommon/common/schema.cpp index afc023a68d7..19d69b0c541 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.cpp +++ b/searchcommon/src/vespa/searchcommon/common/schema.cpp @@ -72,33 +72,26 @@ const uint32_t Schema::UNKNOWN_FIELD_ID(std::numeric_limits<uint32_t>::max()); Schema::Field::Field(vespalib::stringref n, DataType dt) : _name(n), _dataType(dt), - _collectionType(schema::CollectionType::SINGLE), - _timestamp(0) + _collectionType(schema::CollectionType::SINGLE) { } -Schema::Field::Field(vespalib::stringref n, - DataType dt, CollectionType ct) +Schema::Field::Field(vespalib::stringref n, DataType dt, CollectionType ct) : _name(n), _dataType(dt), - _collectionType(ct), - _timestamp(0) + _collectionType(ct) { } // XXX: Resource leak if exception is thrown. Schema::Field::Field(const std::vector<vespalib::string> & lines) : _name(ConfigParser::parse<vespalib::string>("name", lines)), - _dataType(schema::dataTypeFromName(ConfigParser::parse<vespalib::string>( - "datatype", lines))), - _collectionType( - schema::collectionTypeFromName(ConfigParser::parse<vespalib::string>( - "collectiontype", lines))), - _timestamp(ConfigParser::parse<int64_t>("timestamp", lines, 0)) + _dataType(schema::dataTypeFromName(ConfigParser::parse<vespalib::string>("datatype", lines))), + _collectionType(schema::collectionTypeFromName(ConfigParser::parse<vespalib::string>("collectiontype", lines))) { } -Schema::Field::~Field() { } +Schema::Field::~Field() = default; void Schema::Field::write(vespalib::asciistream & os, vespalib::stringref prefix) const @@ -106,27 +99,22 @@ Schema::Field::write(vespalib::asciistream & os, vespalib::stringref prefix) con os << prefix << "name " << _name << "\n"; os << prefix << "datatype " << getTypeName(_dataType) << "\n"; os << prefix << "collectiontype " << getTypeName(_collectionType) << "\n"; - if (_timestamp) { - os << prefix << "timestamp " << _timestamp.val() << "\n"; - } } bool Schema::Field::operator==(const Field &rhs) const { return _name == rhs._name && - _dataType == rhs._dataType && - _collectionType == rhs._collectionType && - _timestamp == rhs._timestamp; + _dataType == rhs._dataType && + _collectionType == rhs._collectionType; } bool Schema::Field::operator!=(const Field &rhs) const { return _name != rhs._name || - _dataType != rhs._dataType || - _collectionType != rhs._collectionType || - _timestamp != rhs._timestamp; + _dataType != rhs._dataType || + _collectionType != rhs._collectionType; } Schema::IndexField::IndexField(vespalib::stringref name, DataType dt) @@ -236,7 +224,7 @@ Schema::Schema(const Schema & rhs) = default; Schema & Schema::operator=(const Schema & rhs) = default; Schema::Schema(Schema && rhs) = default; Schema & Schema::operator=(Schema && rhs) = default; -Schema::~Schema() { } +Schema::~Schema() = default; bool Schema::loadFromFile(const vespalib::string & fileName) @@ -488,14 +476,11 @@ struct IntersectHelper { }; template <> -bool IntersectHelper::is_matching(const Schema::FieldSet &f1, - const Schema::FieldSet &f2) { +bool IntersectHelper::is_matching(const Schema::FieldSet &f1, const Schema::FieldSet &f2) { if (f1.getFields() != f2.getFields()) return false; - const std::vector<vespalib::string> fields = f1.getFields(); - for (std::vector<vespalib::string>::const_iterator - i = fields.begin(), ie = fields.end(); i != ie; ++i) { - if (schema->getIndexFieldId(*i) == Schema::UNKNOWN_FIELD_ID) { + for (const vespalib::string & field : f1.getFields()) { + if (schema->getIndexFieldId(field) == Schema::UNKNOWN_FIELD_ID) { return false; } } @@ -503,26 +488,11 @@ bool IntersectHelper::is_matching(const Schema::FieldSet &f1, } template <typename T, typename Map> -void addOldEntries(const std::vector<T> &entries, - fastos::TimeStamp limit_timestamp, - std::vector<T> &v, Map &name2id_map) { - for (typename std::vector<T>::const_iterator - it = entries.begin(); it != entries.end(); ++it) { - if (it->getTimestamp() < limit_timestamp) { - name2id_map[it->getName()] = v.size(); - v.push_back(*it); - } - } -} - -template <typename T, typename Map> -void addEntries(const std::vector<T> &entries, std::vector<T> &v, - Map &name2id_map) { - for (typename std::vector<T>::const_iterator - it = entries.begin(); it != entries.end(); ++it) { - if (name2id_map.find(it->getName()) == name2id_map.end()) { - name2id_map[it->getName()] = v.size(); - v.push_back(*it); +void addEntries(const std::vector<T> &entries, std::vector<T> &v, Map &name2id_map) { + for (const T & key : entries) { + if (name2id_map.find(key.getName()) == name2id_map.end()) { + name2id_map[key.getName()] = v.size(); + v.push_back(key); } } } @@ -530,30 +500,16 @@ void addEntries(const std::vector<T> &entries, std::vector<T> &v, template <typename T, typename Map> void difference(const std::vector<T> &minuend, const Map &subtrahend_map, std::vector<T> &diff, Map &diff_map) { - for (typename std::vector<T>::const_iterator - it = minuend.begin(); it != minuend.end(); ++it) { - if (subtrahend_map.find(it->getName()) == subtrahend_map.end()) { - diff_map[it->getName()] = diff.size(); - diff.push_back(*it); + for (const T & key : minuend){ + if (subtrahend_map.find(key.getName()) == subtrahend_map.end()) { + diff_map[key.getName()] = diff.size(); + diff.push_back(key); } } } } // namespace Schema::UP -Schema::getOldFields(fastos::TimeStamp limit_timestamp) -{ - Schema::UP schema(new Schema); - addOldEntries(_indexFields, limit_timestamp, - schema->_indexFields, schema->_indexIds); - addOldEntries(_attributeFields, limit_timestamp, - schema->_attributeFields, schema->_attributeIds); - addOldEntries(_summaryFields, limit_timestamp, - schema->_summaryFields, schema->_summaryIds); - return schema; -} - -Schema::UP Schema::intersect(const Schema &lhs, const Schema &rhs) { IntersectHelper h; diff --git a/searchcommon/src/vespa/searchcommon/common/schema.h b/searchcommon/src/vespa/searchcommon/common/schema.h index 0b675710e8b..d71c14c90b1 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.h +++ b/searchcommon/src/vespa/searchcommon/common/schema.h @@ -6,7 +6,6 @@ #include <vespa/vespalib/stllike/string.h> #include <vespa/vespalib/stllike/hash_map.h> #include <vespa/vespalib/util/ptrholder.h> -#include <vespa/fastos/timestamp.h> #include <vector> namespace vespalib { class asciistream; } @@ -36,7 +35,6 @@ public: vespalib::string _name; DataType _dataType; CollectionType _collectionType; - fastos::TimeStamp _timestamp; public: Field(vespalib::stringref n, DataType dt); @@ -49,8 +47,6 @@ public: virtual ~Field(); - void setTimestamp(fastos::TimeStamp ts) { _timestamp = ts; } - virtual void write(vespalib::asciistream & os, vespalib::stringref prefix) const; @@ -58,7 +54,6 @@ public: const vespalib::string &getName() const { return _name; } DataType getDataType() const { return _dataType; } CollectionType getCollectionType() const { return _collectionType; } - fastos::TimeStamp getTimestamp() const { return _timestamp; } bool matchingTypes(const Field &rhs) const { return getDataType() == rhs.getDataType() && @@ -389,8 +384,6 @@ public: void swap(Schema &rhs); void clear(); - Schema::UP getOldFields(fastos::TimeStamp limit_timestamp); - static Schema::UP intersect(const Schema &lhs, const Schema &rhs); static Schema::UP make_union(const Schema &lhs, const Schema &rhs); static Schema::UP set_difference(const Schema &lhs, const Schema &rhs); diff --git a/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp b/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp index 5775c31b205..ca8274aab00 100644 --- a/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp +++ b/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp @@ -177,11 +177,11 @@ public: _counter(0) { } - virtual void replay(const PutOperation &op) override { print(op); } - virtual void replay(const RemoveOperation &op) override { print(op); } - virtual void replay(const UpdateOperation &op) override { print(op); } - virtual void replay(const NoopOperation &op) override { print(op); } - virtual void replay(const NewConfigOperation &op) override + void replay(const PutOperation &op) override { print(op); } + void replay(const RemoveOperation &op) override { print(op); } + void replay(const UpdateOperation &op) override { print(op); } + void replay(const NoopOperation &op) override { print(op); } + void replay(const NewConfigOperation &op) override { print(op); typedef std::map<std::string, ConfigFile>::const_iterator I; @@ -191,18 +191,17 @@ public: } } - virtual void replay(const WipeHistoryOperation &op) override { print(op); } - virtual void replay(const DeleteBucketOperation &op) override { print(op); } - virtual void replay(const SplitBucketOperation &op) override { print(op); } - virtual void replay(const JoinBucketsOperation &op) override { print(op); } - virtual void replay(const PruneRemovedDocumentsOperation &op) override { print(op); } - virtual void replay(const MoveOperation &op) override { print(op); } - virtual void replay(const CreateBucketOperation &op) override { print(op); } - virtual void replay(const CompactLidSpaceOperation &op) override { print(op); } - virtual NewConfigOperation::IStreamHandler &getNewConfigStreamHandler() override { + void replay(const DeleteBucketOperation &op) override { print(op); } + void replay(const SplitBucketOperation &op) override { print(op); } + void replay(const JoinBucketsOperation &op) override { print(op); } + void replay(const PruneRemovedDocumentsOperation &op) override { print(op); } + void replay(const MoveOperation &op) override { print(op); } + void replay(const CreateBucketOperation &op) override { print(op); } + void replay(const CompactLidSpaceOperation &op) override { print(op); } + NewConfigOperation::IStreamHandler &getNewConfigStreamHandler() override { return _streamHandler; } - virtual document::DocumentTypeRepo &getDeserializeRepo() override { + document::DocumentTypeRepo &getDeserializeRepo() override { return _repo; } }; @@ -272,7 +271,6 @@ public: } virtual void replay(const NoopOperation &) override { } virtual void replay(const NewConfigOperation &) override { } - virtual void replay(const WipeHistoryOperation &) override { } virtual void replay(const DeleteBucketOperation &) override { } virtual void replay(const SplitBucketOperation &) override { } virtual void replay(const JoinBucketsOperation &) override { } diff --git a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp index 1ad6b6cdc43..3c3ed33b8ea 100644 --- a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp +++ b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp @@ -40,7 +40,6 @@ using namespace vespa::config::search::summary; using namespace vespa::config::search; using namespace vespalib; -using fastos::TimeStamp; using proton::matching::SessionManager; using searchcorespi::IndexSearchable; using searchcorespi::index::IThreadingService; @@ -144,7 +143,7 @@ struct MyDocumentDBReferenceResolver : public IDocumentDBReferenceResolver { std::unique_ptr<ImportedAttributesRepo> resolve(const search::IAttributeManager &, const search::IAttributeManager &, const std::shared_ptr<search::IDocumentMetaStoreContext> &, - fastos::TimeStamp) override { + vespalib::duration) override { return std::make_unique<ImportedAttributesRepo>(); } void teardown(const search::IAttributeManager &) override { } diff --git a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp index 7dca5493b15..7139eb0d82d 100644 --- a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp +++ b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp @@ -115,7 +115,7 @@ struct MyDocumentDBReferenceResolver : public IDocumentDBReferenceResolver { std::unique_ptr<ImportedAttributesRepo> resolve(const search::IAttributeManager &, const search::IAttributeManager &, const std::shared_ptr<search::IDocumentMetaStoreContext> &, - fastos::TimeStamp) override { + vespalib::duration) override { return std::make_unique<ImportedAttributesRepo>(); } void teardown(const search::IAttributeManager &) override { } diff --git a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp index f99668a13f8..30fed6fa49e 100644 --- a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp +++ b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/persistence/spi/result.h> -#include <vespa/document/base/exceptions.h> #include <vespa/document/datatype/tensor_data_type.h> #include <vespa/document/update/assignvalueupdate.h> #include <vespa/document/repo/documenttyperepo.h> @@ -16,7 +15,6 @@ #include <vespa/searchcore/proton/feedoperation/putoperation.h> #include <vespa/searchcore/proton/feedoperation/removeoperation.h> #include <vespa/searchcore/proton/feedoperation/updateoperation.h> -#include <vespa/searchcore/proton/feedoperation/wipehistoryoperation.h> #include <vespa/searchcore/proton/persistenceengine/i_resource_write_filter.h> #include <vespa/searchcore/proton/server/configstore.h> #include <vespa/searchcore/proton/server/ddbstate.h> @@ -28,10 +26,8 @@ #include <vespa/searchlib/common/idestructorcallback.h> #include <vespa/searchlib/index/docbuilder.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> -#include <vespa/searchlib/transactionlog/translogclient.h> #include <vespa/searchlib/transactionlog/translogserver.h> #include <vespa/vespalib/testkit/testapp.h> -#include <vespa/vespalib/util/closuretask.h> #include <vespa/vespalib/util/lambdatask.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/io/fileutil.h> @@ -63,7 +59,6 @@ using vespalib::BlockingThreadStackExecutor; using vespalib::ThreadStackExecutor; using vespalib::ThreadStackExecutorBase; using vespalib::makeClosure; -using vespalib::makeTask; using vespalib::eval::TensorSpec; using vespalib::eval::ValueType; using vespalib::tensor::test::makeTensor; diff --git a/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp b/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp index ca513cb1cfb..f380ce03152 100644 --- a/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp +++ b/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp @@ -33,7 +33,6 @@ using document::BucketId; using document::Document; using document::DocumentId; using document::DocumentUpdate; -using fastos::TimeStamp; using proton::matching::SessionManager; using proton::test::MockGidToLidChangeHandler; using search::AttributeVector; diff --git a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp index d2d9f573326..2782117d8ae 100644 --- a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp +++ b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp @@ -175,10 +175,7 @@ TEST_F("requireThatVisibilityDelayIsPropagated", cm.setProtonConfig(ProtonConfigSP(new ProtonConfig(protonConfigBuilder))); cm.loadConfig(*esnap, 70, esnap); } - EXPECT_EQUAL(61.0, esnap->getMaintenanceConfigSP()->getVisibilityDelay().sec()); + EXPECT_EQUAL(61s, esnap->getMaintenanceConfigSP()->getVisibilityDelay()); } - - TEST_MAIN() { TEST_RUN_ALL(); } - diff --git a/searchcore/src/tests/proton/documentdb/job_tracked_maintenance_job/job_tracked_maintenance_job_test.cpp b/searchcore/src/tests/proton/documentdb/job_tracked_maintenance_job/job_tracked_maintenance_job_test.cpp index 8c1ad7bf551..3f39c872ea7 100644 --- a/searchcore/src/tests/proton/documentdb/job_tracked_maintenance_job/job_tracked_maintenance_job_test.cpp +++ b/searchcore/src/tests/proton/documentdb/job_tracked_maintenance_job/job_tracked_maintenance_job_test.cpp @@ -33,17 +33,17 @@ struct MyMaintenanceJob : public IBlockableMaintenanceJob size_t _runIdx; bool _blocked; MyMaintenanceJob(size_t numRuns) - : IBlockableMaintenanceJob("myjob", 10, 20), + : IBlockableMaintenanceJob("myjob", 10s, 20s), _runGates(getGateVector(numRuns)), _runIdx(0), _blocked(false) {} void block() { setBlocked(BlockedReason::RESOURCE_LIMITS); } void unBlock() { unBlock(BlockedReason::RESOURCE_LIMITS); } - virtual void setBlocked(BlockedReason) override { _blocked = true; } - virtual void unBlock(BlockedReason) override { _blocked = false; } - virtual bool isBlocked() const override { return _blocked; } - virtual bool run() override { + void setBlocked(BlockedReason) override { _blocked = true; } + void unBlock(BlockedReason) override { _blocked = false; } + bool isBlocked() const override { return _blocked; } + bool run() override { _runGates[_runIdx++]->await(5000); return _runIdx == _runGates.size(); } @@ -90,8 +90,8 @@ struct Fixture TEST_F("require that maintenance job name, delay and interval are preserved", Fixture) { EXPECT_EQUAL("myjob", f._trackedJob->getName()); - EXPECT_EQUAL(10, f._trackedJob->getDelay()); - EXPECT_EQUAL(20, f._trackedJob->getInterval()); + EXPECT_EQUAL(10s, f._trackedJob->getDelay()); + EXPECT_EQUAL(20s, f._trackedJob->getInterval()); } TEST_F("require that maintenance job that needs 1 run is tracked", Fixture) diff --git a/searchcore/src/tests/proton/documentdb/lid_space_compaction/lid_space_compaction_test.cpp b/searchcore/src/tests/proton/documentdb/lid_space_compaction/lid_space_compaction_test.cpp index 93f3299e121..50d4106282c 100644 --- a/searchcore/src/tests/proton/documentdb/lid_space_compaction/lid_space_compaction_test.cpp +++ b/searchcore/src/tests/proton/documentdb/lid_space_compaction/lid_space_compaction_test.cpp @@ -26,10 +26,10 @@ using BlockedReason = IBlockableMaintenanceJob::BlockedReason; using TimePoint = LidUsageStats::TimePoint; constexpr uint32_t SUBDB_ID = 2; -constexpr double JOB_DELAY = 1.0; +constexpr vespalib::duration JOB_DELAY = 1s; constexpr uint32_t ALLOWED_LID_BLOAT = 1; constexpr double ALLOWED_LID_BLOAT_FACTOR = 0.3; -constexpr double REMOVE_BATCH_BLOCK_DELAY = 20.0; +constexpr vespalib::duration REMOVE_BATCH_BLOCK_DELAY = 20s; constexpr uint32_t MAX_DOCS_TO_SCAN = 100; constexpr double RESOURCE_LIMIT_FACTOR = 1.0; constexpr uint32_t MAX_OUTSTANDING_MOVE_OPS = 10; @@ -257,7 +257,7 @@ struct JobTestBase : public ::testing::Test { double allowedLidBloatFactor = ALLOWED_LID_BLOAT_FACTOR, uint32_t maxDocsToScan = MAX_DOCS_TO_SCAN, double resourceLimitFactor = RESOURCE_LIMIT_FACTOR, - double interval = JOB_DELAY, + vespalib::duration interval = JOB_DELAY, bool nodeRetired = false, uint32_t maxOutstandingMoveOps = MAX_OUTSTANDING_MOVE_OPS) { @@ -366,13 +366,13 @@ struct JobTest : public JobTestBase { double allowedLidBloatFactor = ALLOWED_LID_BLOAT_FACTOR, uint32_t maxDocsToScan = MAX_DOCS_TO_SCAN, double resourceLimitFactor = RESOURCE_LIMIT_FACTOR, - double interval = JOB_DELAY, + vespalib::duration interval = JOB_DELAY, bool nodeRetired = false, uint32_t maxOutstandingMoveOps = MAX_OUTSTANDING_MOVE_OPS) { JobTestBase::init(allowedLidBloat, allowedLidBloatFactor, maxDocsToScan, resourceLimitFactor, interval, nodeRetired, maxOutstandingMoveOps); _jobRunner = std::make_unique<MyDirectJobRunner>(*_job); } - void init_with_interval(double interval) { + void init_with_interval(vespalib::duration interval) { init(ALLOWED_LID_BLOAT, ALLOWED_LID_BLOAT_FACTOR, MAX_DOCS_TO_SCAN, RESOURCE_LIMIT_FACTOR, interval); } void init_with_node_retired(bool retired) { @@ -580,16 +580,16 @@ TEST_F(JobTest, resource_limit_factor_adjusts_limit) TEST_F(JobTest, delay_is_set_based_on_interval_and_is_max_300_secs) { - init_with_interval(301); - EXPECT_EQ(300, _job->getDelay()); - EXPECT_EQ(301, _job->getInterval()); + init_with_interval(301s); + EXPECT_EQ(300s, _job->getDelay()); + EXPECT_EQ(301s, _job->getInterval()); } TEST_F(JobTest, delay_is_set_based_on_interval_and_can_be_less_than_300_secs) { - init_with_interval(299); - EXPECT_EQ(299, _job->getDelay()); - EXPECT_EQ(299, _job->getInterval()); + init_with_interval(299s); + EXPECT_EQ(299s, _job->getDelay()); + EXPECT_EQ(299s, _job->getInterval()); } TEST_F(JobTest, job_is_disabled_when_node_is_retired) @@ -649,7 +649,7 @@ TEST_F(JobTest, job_is_re_enabled_when_remove_batch_is_no_longer_ongoing) EXPECT_TRUE(run()); // job is disabled assertJobContext(2, 9, 1, 0, 0); - _handler->set_last_remove_batch(last_remove_batch - std::chrono::seconds(static_cast<long>(REMOVE_BATCH_BLOCK_DELAY))); + _handler->set_last_remove_batch(last_remove_batch - REMOVE_BATCH_BLOCK_DELAY); EXPECT_FALSE(run()); // job executed as normal (with more work to do) assertJobContext(3, 8, 2, 0, 0); } diff --git a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp index 0720f59471b..d4aebd0b8a7 100644 --- a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp +++ b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp @@ -47,7 +47,6 @@ using document::Document; using document::DocumentId; using document::test::makeBucketSpace; using vespalib::system_clock; -using fastos::TimeStamp; using proton::bucketdb::BucketCreateNotifier; using proton::matching::ISessionCachePruner; using search::AttributeGuard; @@ -67,7 +66,7 @@ typedef BucketId::List BucketIdVector; typedef std::set<BucketId> BucketIdSet; constexpr int TIMEOUT_MS = 60000; -constexpr double TIMEOUT_SEC = 60.0; +constexpr vespalib::duration TIMEOUT_SEC = 60s; namespace { @@ -251,7 +250,7 @@ public: ~MyExecutor(); bool isIdle(); - bool waitIdle(double timeout); + bool waitIdle(vespalib::duration timeout); }; @@ -281,8 +280,8 @@ struct MySimpleJob : public BlockableMaintenanceJob vespalib::CountDownLatch _latch; size_t _runCnt; - MySimpleJob(double delay, - double interval, + MySimpleJob(vespalib::duration delay, + vespalib::duration interval, uint32_t finishCount) : BlockableMaintenanceJob("my_job", delay, interval), _latch(finishCount), @@ -300,8 +299,8 @@ struct MySimpleJob : public BlockableMaintenanceJob struct MySplitJob : public MySimpleJob { - MySplitJob(double delay, - double interval, + MySplitJob(vespalib::duration delay, + vespalib::duration interval, uint32_t finishCount) : MySimpleJob(delay, interval, finishCount) { @@ -318,8 +317,8 @@ struct MyLongRunningJob : public BlockableMaintenanceJob { vespalib::Gate _firstRun; - MyLongRunningJob(double delay, - double interval) + MyLongRunningJob(vespalib::duration delay, + vespalib::duration interval) : BlockableMaintenanceJob("long_running_job", delay, interval), _firstRun() { @@ -380,51 +379,24 @@ public: MaintenanceControllerFixture(); - virtual - ~MaintenanceControllerFixture(); - - void - syncSubDBs(); - - void commit() override { - } - - void commitAndWait() override { - } - - void - performSyncSubDBs(); - - void - notifyClusterStateChanged(); - - void - performNotifyClusterStateChanged(); - - void - startMaintenance(); + virtual ~MaintenanceControllerFixture(); + void syncSubDBs(); + void commit() override { } + void commitAndWait() override { } + void performSyncSubDBs(); + void notifyClusterStateChanged(); + void performNotifyClusterStateChanged(); + void startMaintenance(); void injectMaintenanceJobs(); + void performStartMaintenance(); + void stopMaintenance(); + void forwardMaintenanceConfig(); + void performForwardMaintenanceConfig(); - void - performStartMaintenance(); + void insertDocs(const test::UserDocuments &docs, MyDocumentSubDB &subDb); - void - stopMaintenance(); - - void - forwardMaintenanceConfig(); - - void - performForwardMaintenanceConfig(); - - void - insertDocs(const test::UserDocuments &docs, - MyDocumentSubDB &subDb); - - void - removeDocs(const test::UserDocuments &docs, - Timestamp timestamp); + void removeDocs(const test::UserDocuments &docs, Timestamp timestamp); void setPruneConfig(const DocumentDBPruneRemovedDocumentsConfig &pruneConfig) @@ -463,7 +435,7 @@ public: } void - setGroupingSessionPruneInterval(double groupingSessionPruneInterval) + setGroupingSessionPruneInterval(vespalib::duration groupingSessionPruneInterval) { DocumentDBMaintenanceConfig::SP newCfg(new DocumentDBMaintenanceConfig( @@ -800,11 +772,11 @@ MyExecutor::isIdle() bool -MyExecutor::waitIdle(double timeout) +MyExecutor::waitIdle(vespalib::duration timeout) { - fastos::StopWatch timer; + vespalib::Timer timer; while (!isIdle()) { - if (timer.elapsed().sec() >= timeout) + if (timer.elapsed() >= timeout) return false; } return true; @@ -1062,7 +1034,7 @@ TEST_F("require that document pruner is active", EXPECT_EQUAL(10u, f._removed.getNumUsedLids()); EXPECT_EQUAL(10u, f._removed.getDocumentCount()); MyFrozenBucket::UP frozen3(new MyFrozenBucket(f._mc, bucketId3)); - f.setPruneConfig(DocumentDBPruneRemovedDocumentsConfig(0.2, 900.0)); + f.setPruneConfig(DocumentDBPruneRemovedDocumentsConfig(200ms, 900s)); for (uint32_t i = 0; i < 6; ++i) { std::this_thread::sleep_for(100ms); ASSERT_TRUE(f._executor.waitIdle(TIMEOUT_SEC)); @@ -1087,7 +1059,7 @@ TEST_F("require that heartbeats are scheduled", { f.notifyClusterStateChanged(); f.startMaintenance(); - f.setHeartBeatConfig(DocumentDBHeartBeatConfig(0.2)); + f.setHeartBeatConfig(DocumentDBHeartBeatConfig(200ms)); for (uint32_t i = 0; i < 600; ++i) { std::this_thread::sleep_for(100ms); if (f._fh.getHeartBeats() != 0u) @@ -1102,7 +1074,7 @@ TEST_F("require that periodic session prunings are scheduled", ASSERT_FALSE(f._gsp.isInvoked); f.notifyClusterStateChanged(); f.startMaintenance(); - f.setGroupingSessionPruneInterval(0.2); + f.setGroupingSessionPruneInterval(200ms); for (uint32_t i = 0; i < 600; ++i) { std::this_thread::sleep_for(100ms); if (f._gsp.isInvoked) { @@ -1182,7 +1154,7 @@ TEST_F("require that active bucket is not moved until de-activated", Maintenance TEST_F("require that a simple maintenance job is executed", MaintenanceControllerFixture) { - IMaintenanceJob::UP job(new MySimpleJob(0.2, 0.2, 3)); + IMaintenanceJob::UP job(new MySimpleJob(200ms, 200ms, 3)); MySimpleJob &myJob = static_cast<MySimpleJob &>(*job); f._mc.registerJobInMasterThread(std::move(job)); f._injectDefaultJobs = false; @@ -1194,7 +1166,7 @@ TEST_F("require that a simple maintenance job is executed", MaintenanceControlle TEST_F("require that a split maintenance job is executed", MaintenanceControllerFixture) { - IMaintenanceJob::UP job(new MySplitJob(0.2, TIMEOUT_SEC * 2, 3)); + IMaintenanceJob::UP job(new MySplitJob(200ms, TIMEOUT_SEC * 2, 3)); MySplitJob &myJob = static_cast<MySplitJob &>(*job); f._mc.registerJobInMasterThread(std::move(job)); f._injectDefaultJobs = false; @@ -1239,7 +1211,7 @@ TEST_F("require that a blocked job is unblocked and executed after thaw bucket", TEST_F("require that blocked jobs are not executed", MaintenanceControllerFixture) { - IMaintenanceJob::UP job(new MySimpleJob(0.2, 0.2, 0)); + IMaintenanceJob::UP job(new MySimpleJob(200ms, 200ms, 0)); MySimpleJob &myJob = static_cast<MySimpleJob &>(*job); myJob.block(); f._mc.registerJobInMasterThread(std::move(job)); @@ -1253,7 +1225,7 @@ TEST_F("require that maintenance controller state list jobs", MaintenanceControl { { IMaintenanceJob::UP job1(new MySimpleJob(TIMEOUT_SEC * 2, TIMEOUT_SEC * 2, 0)); - IMaintenanceJob::UP job2(new MyLongRunningJob(0.2, 0.2)); + IMaintenanceJob::UP job2(new MyLongRunningJob(200ms, 200ms)); MyLongRunningJob &longRunningJob = static_cast<MyLongRunningJob &>(*job2); f._mc.registerJobInMasterThread(std::move(job1)); f._mc.registerJobInMasterThread(std::move(job2)); @@ -1365,9 +1337,9 @@ TEST_F("require that maintenance jobs are run by correct executor", MaintenanceC } void -assertPruneRemovedDocumentsConfig(double expDelay, double expInterval, double interval, MaintenanceControllerFixture &f) +assertPruneRemovedDocumentsConfig(vespalib::duration expDelay, vespalib::duration expInterval, vespalib::duration interval, MaintenanceControllerFixture &f) { - f.setPruneConfig(DocumentDBPruneRemovedDocumentsConfig(interval, 1000)); + f.setPruneConfig(DocumentDBPruneRemovedDocumentsConfig(interval, 1000s)); const auto *job = findJob(f._mc.getJobList(), "prune_removed_documents.searchdocument"); EXPECT_EQUAL(expDelay, job->getJob().getDelay()); EXPECT_EQUAL(expInterval, job->getJob().getInterval()); @@ -1375,8 +1347,8 @@ assertPruneRemovedDocumentsConfig(double expDelay, double expInterval, double in TEST_F("require that delay for prune removed documents is set based on interval and is max 300 secs", MaintenanceControllerFixture) { - assertPruneRemovedDocumentsConfig(300, 301, 301, f); - assertPruneRemovedDocumentsConfig(299, 299, 299, f); + assertPruneRemovedDocumentsConfig(300s, 301s, 301s, f); + assertPruneRemovedDocumentsConfig(299s, 299s, 299s, f); } TEST_MAIN() diff --git a/searchcore/src/tests/proton/documentdb/move_operation_limiter/move_operation_limiter_test.cpp b/searchcore/src/tests/proton/documentdb/move_operation_limiter/move_operation_limiter_test.cpp index df9aaab675c..77150370406 100644 --- a/searchcore/src/tests/proton/documentdb/move_operation_limiter/move_operation_limiter_test.cpp +++ b/searchcore/src/tests/proton/documentdb/move_operation_limiter/move_operation_limiter_test.cpp @@ -12,20 +12,20 @@ using namespace proton; struct MyBlockableMaintenanceJob : public IBlockableMaintenanceJob { bool blocked; MyBlockableMaintenanceJob() - : IBlockableMaintenanceJob("my_job", 1.0, 1.0), + : IBlockableMaintenanceJob("my_job", 1s, 1s), blocked(false) {} - virtual void setBlocked(BlockedReason reason) override { + void setBlocked(BlockedReason reason) override { ASSERT_TRUE(reason == BlockedReason::OUTSTANDING_OPS); EXPECT_FALSE(blocked); blocked = true; } - virtual void unBlock(BlockedReason reason) override { + void unBlock(BlockedReason reason) override { ASSERT_TRUE(reason == BlockedReason::OUTSTANDING_OPS); EXPECT_TRUE(blocked); blocked = false; } - virtual bool run() override { return true; } + bool run() override { return true; } }; struct Fixture { diff --git a/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp b/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp index 20cfb7c6dcb..c59e95a79eb 100644 --- a/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp +++ b/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp @@ -13,7 +13,6 @@ #include <vespa/searchcore/proton/feedoperation/removeoperation.h> #include <vespa/searchcore/proton/feedoperation/splitbucketoperation.h> #include <vespa/searchcore/proton/feedoperation/updateoperation.h> -#include <vespa/searchcore/proton/feedoperation/wipehistoryoperation.h> #include <vespa/searchlib/query/base.h> #include <persistence/spi/types.h> #include <vespa/document/base/documentid.h> @@ -218,10 +217,6 @@ TEST("require that toString() on derived classes are meaningful") "prevDbdId=(subDbId=0, lid=0), prevMarkedAsRemoved=false, prevTimestamp=0, serialNum=0)", UpdateOperation(bucket_id1, timestamp, update).toString()); - EXPECT_EQUAL("WipeHistory(wipeTimeLimit=0, serialNum=0)", - WipeHistoryOperation().toString()); - EXPECT_EQUAL("WipeHistory(wipeTimeLimit=20, serialNum=10)", - WipeHistoryOperation(10, 20).toString()); EXPECT_EQUAL("CompactLidSpace(subDbId=2, lidLimit=99, serialNum=0)", CompactLidSpaceOperation(2, 99).toString()); } diff --git a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp index 870be2ab409..a947074a917 100644 --- a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp +++ b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp @@ -13,7 +13,6 @@ #include <vespa/fileacquirer/config-filedistributorrpc.h> #include <vespa/vespalib/util/varholder.h> #include <vespa/vespalib/testkit/testapp.h> -#include <vespa/fastos/timestamp.h> #include <vespa/config-bucketspaces.h> #include <vespa/config-attributes.h> #include <vespa/config-imported-fields.h> @@ -170,9 +169,9 @@ struct ProtonConfigOwner : public proton::IProtonConfigurer VarHolder<std::shared_ptr<ProtonConfigSnapshot>> _config; ProtonConfigOwner() : _configured(false), _config() { } - bool waitUntilConfigured(int64_t timeout) { - fastos::StopWatch timer; - while (timer.elapsed().ms() < timeout) { + bool waitUntilConfigured(vespalib::duration timeout) { + vespalib::Timer timer; + while (timer.elapsed() < timeout) { if (getConfigured()) return true; std::this_thread::sleep_for(100ms); @@ -290,14 +289,14 @@ TEST_FF("require that documentdb config manager builds schema with imported attr TEST_FFF("require that proton config fetcher follows changes to bootstrap", ConfigTestFixture("search"), ProtonConfigOwner(), - ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60000ms)) { + ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60s)) { f3.start(); ASSERT_TRUE(f2._configured); ASSERT_TRUE(f1.configEqual(f2.getBootstrapConfig())); f2._configured = false; f1.protonBuilder.rpcport = 9010; f1.reload(); - ASSERT_TRUE(f2.waitUntilConfigured(120000)); + ASSERT_TRUE(f2.waitUntilConfigured(120s)); ASSERT_TRUE(f1.configEqual(f2.getBootstrapConfig())); f3.close(); } @@ -305,19 +304,19 @@ TEST_FFF("require that proton config fetcher follows changes to bootstrap", TEST_FFF("require that proton config fetcher follows changes to doctypes", ConfigTestFixture("search"), ProtonConfigOwner(), - ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60000ms)) { + ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60s)) { f3.start(); f2._configured = false; f1.addDocType("typea"); f1.reload(); - ASSERT_TRUE(f2.waitUntilConfigured(60000)); + ASSERT_TRUE(f2.waitUntilConfigured(60s)); ASSERT_TRUE(f1.configEqual(f2.getBootstrapConfig())); f2._configured = false; f1.removeDocType("typea"); f1.reload(); - ASSERT_TRUE(f2.waitUntilConfigured(60000)); + ASSERT_TRUE(f2.waitUntilConfigured(60s)); ASSERT_TRUE(f1.configEqual(f2.getBootstrapConfig())); f3.close(); } @@ -325,7 +324,7 @@ TEST_FFF("require that proton config fetcher follows changes to doctypes", TEST_FFF("require that proton config fetcher reconfigures dbowners", ConfigTestFixture("search"), ProtonConfigOwner(), - ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60000ms)) { + ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60s)) { f3.start(); ASSERT_FALSE(f2.getDocumentDBConfig("typea")); @@ -333,7 +332,7 @@ TEST_FFF("require that proton config fetcher reconfigures dbowners", f2._configured = false; f1.addDocType("typea"); f1.reload(); - ASSERT_TRUE(f2.waitUntilConfigured(60000)); + ASSERT_TRUE(f2.waitUntilConfigured(60s)); ASSERT_TRUE(f1.configEqual(f2.getBootstrapConfig())); ASSERT_TRUE(static_cast<bool>(f2.getDocumentDBConfig("typea"))); ASSERT_TRUE(f1.configEqual("typea", f2.getDocumentDBConfig("typea"))); @@ -342,7 +341,7 @@ TEST_FFF("require that proton config fetcher reconfigures dbowners", f2._configured = false; f1.removeDocType("typea"); f1.reload(); - ASSERT_TRUE(f2.waitUntilConfigured(60000)); + ASSERT_TRUE(f2.waitUntilConfigured(60s)); ASSERT_FALSE(f2.getDocumentDBConfig("typea")); f3.close(); } @@ -364,7 +363,7 @@ TEST_FF("require that prune removed documents interval can be set based on age", f1.protonBuilder.pruneremoveddocumentsinterval = 0; f1.addDocType("test"); auto config = getDocumentDBConfig(f1, f2); - EXPECT_EQUAL(20, config->getMaintenanceConfigSP()->getPruneRemovedDocumentsConfig().getInterval()); + EXPECT_EQUAL(20s, config->getMaintenanceConfigSP()->getPruneRemovedDocumentsConfig().getInterval()); } TEST_FF("require that docstore config computes cachesize automatically if unset", diff --git a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp index 062586b1d0f..b77d9b3f5ab 100644 --- a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp +++ b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp @@ -230,18 +230,18 @@ struct Fixture { oldAttrMgr.addReferenceAttribute("parent2_ref"); oldAttrMgr.addReferenceAttribute("parent3_ref"); } - ImportedAttributesRepo::UP resolve(fastos::TimeStamp visibilityDelay, bool useReferences) { + ImportedAttributesRepo::UP resolve(vespalib::duration visibilityDelay, bool useReferences) { DocumentDBReferenceResolver resolver(registry, docModel.childDocType, importedFieldsCfg, docModel.childDocType, _gidToLidChangeListenerRefCount, _attributeFieldWriter, useReferences); return resolver.resolve(attrMgr, oldAttrMgr, std::shared_ptr<search::IDocumentMetaStoreContext>(), visibilityDelay); } - ImportedAttributesRepo::UP resolve(fastos::TimeStamp visibilityDelay) { + ImportedAttributesRepo::UP resolve(vespalib::duration visibilityDelay) { return resolve(visibilityDelay, true); } ImportedAttributesRepo::UP resolveReplay() { - return resolve(fastos::TimeStamp(0), false); + return resolve(vespalib::duration::zero(), false); } ImportedAttributesRepo::UP resolve() { - return resolve(fastos::TimeStamp(0)); + return resolve(vespalib::duration::zero()); } void teardown() { DocumentDBReferenceResolver resolver(registry, docModel.childDocType, importedFieldsCfg, docModel.childDocType, _gidToLidChangeListenerRefCount, _attributeFieldWriter, false); @@ -306,7 +306,7 @@ TEST_F("require that imported attributes are instantiated without search cache a TEST_F("require that imported attributes are instantiated with search cache if visibility delay > 0", Fixture) { - auto repo = f.resolve(fastos::TimeStamp::Seconds(1.0)); + auto repo = f.resolve(1s); EXPECT_EQUAL(2u, repo->size()); f.assertImportedAttribute("imported_a", "ref", "target_a", true, repo->get("imported_a")); f.assertImportedAttribute("imported_b", "other_ref", "target_b", true, repo->get("imported_b")); diff --git a/searchcore/src/tests/proton/server/memoryflush/memoryflush_test.cpp b/searchcore/src/tests/proton/server/memoryflush/memoryflush_test.cpp index 549b2d2626a..7f650847183 100644 --- a/searchcore/src/tests/proton/server/memoryflush/memoryflush_test.cpp +++ b/searchcore/src/tests/proton/server/memoryflush/memoryflush_test.cpp @@ -5,9 +5,7 @@ #include <vespa/searchcore/proton/flushengine/tls_stats_map.h> #include <vespa/searchcore/proton/test/dummy_flush_target.h> #include <vespa/searchcore/proton/server/memoryflush.h> -#include <vespa/fastos/timestamp.h> -using fastos::TimeStamp; using vespalib::system_time; using search::SerialNum; using namespace proton; diff --git a/searchcore/src/tests/proton/server/visibility_handler/visibility_handler_test.cpp b/searchcore/src/tests/proton/server/visibility_handler/visibility_handler_test.cpp index 33ee3eb6105..ca8d0a1d26a 100644 --- a/searchcore/src/tests/proton/server/visibility_handler/visibility_handler_test.cpp +++ b/searchcore/src/tests/proton/server/visibility_handler/visibility_handler_test.cpp @@ -16,7 +16,6 @@ using proton::test::ThreadingServiceObserver; using proton::IFeedView; using proton::VisibilityHandler; using vespalib::makeLambdaTask; -using fastos::TimeStamp; namespace { @@ -28,7 +27,7 @@ public: : _serialNum(0u) { } - virtual SerialNum getSerialNum() const override { return _serialNum; } + SerialNum getSerialNum() const override { return _serialNum; } void setSerialNum(SerialNum serialNum) { _serialNum = serialNum; } }; @@ -98,14 +97,14 @@ public: } void - testCommit(double visibilityDelay, bool internal, + testCommit(vespalib::duration visibilityDelay, bool internal, uint32_t expForceCommitCount, SerialNum expCommittedSerialNum, uint32_t expMasterExecuteCnt, uint32_t expAttributeFieldWriterSyncCnt, SerialNum currSerialNum = 10u) { _getSerialNum.setSerialNum(currSerialNum); - _visibilityHandler.setVisibilityDelay(TimeStamp::Seconds(visibilityDelay)); + _visibilityHandler.setVisibilityDelay(visibilityDelay); if (internal) { VisibilityHandler *visibilityHandler = &_visibilityHandler; auto task = makeLambdaTask([=]() { visibilityHandler->commit(); }); @@ -121,7 +120,7 @@ public: } void - testCommitAndWait(double visibilityDelay, bool internal, + testCommitAndWait(vespalib::duration visibilityDelay, bool internal, uint32_t expForceCommitCount, SerialNum expCommittedSerialNum, uint32_t expMasterExecuteCnt, @@ -129,11 +128,10 @@ public: SerialNum currSerialNum = 10u) { _getSerialNum.setSerialNum(currSerialNum); - _visibilityHandler.setVisibilityDelay(TimeStamp::Seconds(visibilityDelay)); + _visibilityHandler.setVisibilityDelay(visibilityDelay); if (internal) { VisibilityHandler *visibilityHandler = &_visibilityHandler; - auto task = - makeLambdaTask([=]() { visibilityHandler->commitAndWait(); }); + auto task = makeLambdaTask([=]() { visibilityHandler->commitAndWait(); }); _writeService.master().execute(std::move(task)); _writeService.master().sync(); } else { @@ -150,62 +148,62 @@ public: TEST_F("Check external commit with zero visibility delay", Fixture) { - f.testCommit(0.0, false, 0u, 0u, 0u, 0u); + f.testCommit(0s, false, 0u, 0u, 0u, 0u); } TEST_F("Check external commit with nonzero visibility delay", Fixture) { - f.testCommit(1.0, false, 1u, 10u, 1u, 0u); + f.testCommit(1s, false, 1u, 10u, 1u, 0u); } TEST_F("Check external commit with nonzero visibility delay and no new feed operation", Fixture) { - f.testCommit(1.0, false, 1u, 0u, 1u, 0u, 0u); + f.testCommit(1s, false, 1u, 0u, 1u, 0u, 0u); } TEST_F("Check internal commit with zero visibility delay", Fixture) { - f.testCommit(0.0, true, 0u, 0u, 1u, 0u); + f.testCommit(0s, true, 0u, 0u, 1u, 0u); } TEST_F("Check internal commit with nonzero visibility delay", Fixture) { - f.testCommit(1.0, true, 1u, 10u, 1u, 0u); + f.testCommit(1s, true, 1u, 10u, 1u, 0u); } TEST_F("Check internal commit with nonzero visibility delay and no new feed operation", Fixture) { - f.testCommit(1.0, true, 1u, 0u, 1u, 0u, 0u); + f.testCommit(1s, true, 1u, 0u, 1u, 0u, 0u); } TEST_F("Check external commitAndWait with zero visibility delay", Fixture) { - f.testCommitAndWait(0.0, false, 0u, 0u, 0u, 1u); + f.testCommitAndWait(0s, false, 0u, 0u, 0u, 1u); } TEST_F("Check external commitAndWait with nonzero visibility delay", Fixture) { - f.testCommitAndWait(1.0, false, 1u, 10u, 1u, 1u); + f.testCommitAndWait(1s, false, 1u, 10u, 1u, 1u); } TEST_F("Check external commitAndWait with nonzero visibility delay and no new feed operation", Fixture) { - f.testCommitAndWait(1.0, false, 0u, 0u, 0u, 1u, 0u); + f.testCommitAndWait(1s, false, 0u, 0u, 0u, 1u, 0u); } TEST_F("Check internal commitAndWait with zero visibility delay", Fixture) { - f.testCommitAndWait(0.0, true, 0u, 0u, 1u, 1u); + f.testCommitAndWait(0s, true, 0u, 0u, 1u, 1u); } TEST_F("Check internal commitAndWait with nonzero visibility delay", Fixture) { - f.testCommitAndWait(1.0, true, 1u, 10u, 1u, 1u); + f.testCommitAndWait(1s, true, 1u, 10u, 1u, 1u); } TEST_F("Check internal commitAndWait with nonzero visibility delay and no new feed operation", Fixture) { - f.testCommitAndWait(1.0, true, 0u, 0u, 1u, 1u, 0u); + f.testCommitAndWait(1s, true, 0u, 0u, 1u, 1u, 0u); } TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h b/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h index f759154eefe..ed370b000f3 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h @@ -6,7 +6,6 @@ #include <vespa/vespalib/util/time.h> #include <vespa/searchlib/common/indexmetainfo.h> #include <vespa/searchlib/common/serialnum.h> -#include <vespa/fastos/timestamp.h> #include <mutex> #include <condition_variable> diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp index bb41004d834..0ccebd34a39 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp @@ -175,7 +175,7 @@ AttributeInitializer::loadAttribute(const AttributeVectorSP &attr, search::SerialNum serialNum) const { assert(attr->hasLoadData()); - fastos::StopWatch stopWatch; + vespalib::Timer timer; EventLogger::loadAttributeStart(_documentSubDbName, attr->getName()); if (!attr->load()) { LOG(warning, "Could not load attribute vector '%s' from disk. Returning empty attribute vector", @@ -183,7 +183,7 @@ AttributeInitializer::loadAttribute(const AttributeVectorSP &attr, return false; } else { attr->commit(serialNum, serialNum); - EventLogger::loadAttributeComplete(_documentSubDbName, attr->getName(), stopWatch.elapsed().ms()); + EventLogger::loadAttributeComplete(_documentSubDbName, attr->getName(), vespalib::count_ms(timer.elapsed())); } return true; } diff --git a/searchcore/src/vespa/searchcore/proton/common/commit_time_tracker.h b/searchcore/src/vespa/searchcore/proton/common/commit_time_tracker.h index 02bf87f0a08..dda9d43ce67 100644 --- a/searchcore/src/vespa/searchcore/proton/common/commit_time_tracker.h +++ b/searchcore/src/vespa/searchcore/proton/common/commit_time_tracker.h @@ -17,13 +17,9 @@ private: public: CommitTimeTracker(vespalib::duration visibilityDelay); - bool needCommit() const; - void setVisibilityDelay(vespalib::duration visibilityDelay); - bool hasVisibilityDelay() const { return _visibilityDelay != vespalib::duration::zero(); } - void setReplayDone() { _replayDone = true; } }; diff --git a/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp b/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp index 1915d9107cc..2f29231577a 100644 --- a/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp +++ b/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp @@ -28,8 +28,8 @@ SummaryManagerInitializer(const search::GrowStrategy &grow, _tuneFile(tuneFile), _fileHeaderContext(fileHeaderContext), _tlSyncer(tlSyncer), - _bucketizer(bucketizer), - _result(result) + _bucketizer(std::move(bucketizer)), + _result(std::move(result)) { } SummaryManagerInitializer::~SummaryManagerInitializer() = default; @@ -38,12 +38,12 @@ void SummaryManagerInitializer::run() { vespalib::mkdir(_baseDir, false); - fastos::StopWatch stopWatch; + vespalib::Timer timer; EventLogger::loadDocumentStoreStart(_subDbName); *_result = std::make_shared<SummaryManager> (_summaryExecutor, _storeCfg, _grow, _baseDir, _docTypeName, _tuneFile, _fileHeaderContext, _tlSyncer, _bucketizer); - EventLogger::loadDocumentStoreComplete(_subDbName, stopWatch.elapsed().ms()); + EventLogger::loadDocumentStoreComplete(_subDbName, vespalib::count_ms(timer.elapsed())); } } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_reuse_delayer_config.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_reuse_delayer_config.cpp index 5ba6a805a8e..0cdb97271b1 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_reuse_delayer_config.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_reuse_delayer_config.cpp @@ -6,19 +6,16 @@ namespace proton::documentmetastore { LidReuseDelayerConfig::LidReuseDelayerConfig() - : _visibilityDelay(0), + : _visibilityDelay(vespalib::duration::zero()), _hasIndexedOrAttributeFields(false) { } -LidReuseDelayerConfig::LidReuseDelayerConfig(const DocumentDBConfig & - configSnapshot) +LidReuseDelayerConfig::LidReuseDelayerConfig(const DocumentDBConfig & configSnapshot) : _visibilityDelay(configSnapshot.getMaintenanceConfigSP()->getVisibilityDelay()), _hasIndexedOrAttributeFields(configSnapshot.getSchemaSP()->getNumIndexFields() > 0 || configSnapshot.getSchemaSP()->getNumAttributeFields() > 0) { } - -} // namespace proton::documentmetastore - +} diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_reuse_delayer_config.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_reuse_delayer_config.h index a11f5ff1f24..867eccb6b20 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_reuse_delayer_config.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_reuse_delayer_config.h @@ -2,7 +2,7 @@ #pragma once -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> namespace proton { class DocumentDBConfig; } @@ -14,12 +14,12 @@ namespace proton::documentmetastore { class LidReuseDelayerConfig { private: - fastos::TimeStamp _visibilityDelay; - bool _hasIndexedOrAttributeFields; + vespalib::duration _visibilityDelay; + bool _hasIndexedOrAttributeFields; public: LidReuseDelayerConfig(); explicit LidReuseDelayerConfig(const DocumentDBConfig &configSnapshot); - fastos::TimeStamp visibilityDelay() const { return _visibilityDelay; } + vespalib::duration visibilityDelay() const { return _visibilityDelay; } bool hasIndexedOrAttributeFields() const { return _hasIndexedOrAttributeFields; } }; diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lidreusedelayer.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/lidreusedelayer.cpp index 3824516eec3..bf1ea25b589 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lidreusedelayer.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lidreusedelayer.cpp @@ -22,9 +22,7 @@ LidReuseDelayer::LidReuseDelayer(IThreadingService &writeService, } -LidReuseDelayer::~LidReuseDelayer() -{ -} +LidReuseDelayer::~LidReuseDelayer() = default; bool diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lidreusedelayer.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/lidreusedelayer.h index cb42e4ce152..df142890207 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lidreusedelayer.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lidreusedelayer.h @@ -4,23 +4,9 @@ #include "ilidreusedelayer.h" -namespace searchcorespi -{ - -namespace index -{ - -struct IThreadingService; +namespace searchcorespi::index { struct IThreadingService; } -} - -} - -namespace proton -{ - -namespace documentmetastore -{ +namespace proton::documentmetastore { struct IStore; @@ -46,15 +32,13 @@ class LidReuseDelayer : public ILidReuseDelayer public: LidReuseDelayer(searchcorespi::index::IThreadingService &writeService, IStore &documentMetaStore); - virtual ~LidReuseDelayer(); - virtual bool delayReuse(uint32_t lid) override; - virtual bool delayReuse(const std::vector<uint32_t> &lids) override; - virtual void setImmediateCommit(bool immediateCommit) override; - virtual bool getImmediateCommit() const override; - virtual void setHasIndexedOrAttributeFields(bool hasIndexedOrAttributeFields) override; - virtual std::vector<uint32_t> getReuseLids() override; + ~LidReuseDelayer() override; + bool delayReuse(uint32_t lid) override; + bool delayReuse(const std::vector<uint32_t> &lids) override; + void setImmediateCommit(bool immediateCommit) override; + bool getImmediateCommit() const override; + void setHasIndexedOrAttributeFields(bool hasIndexedOrAttributeFields) override; + std::vector<uint32_t> getReuseLids() override; }; } - -} diff --git a/searchcore/src/vespa/searchcore/proton/feedoperation/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/feedoperation/CMakeLists.txt index f5e09b81313..4f384d1894c 100644 --- a/searchcore/src/vespa/searchcore/proton/feedoperation/CMakeLists.txt +++ b/searchcore/src/vespa/searchcore/proton/feedoperation/CMakeLists.txt @@ -17,6 +17,5 @@ vespa_add_library(searchcore_feedoperation STATIC removeoperation.cpp splitbucketoperation.cpp updateoperation.cpp - wipehistoryoperation.cpp DEPENDS ) diff --git a/searchcore/src/vespa/searchcore/proton/feedoperation/operations.h b/searchcore/src/vespa/searchcore/proton/feedoperation/operations.h index df9f22b2462..8250ddd8b0e 100644 --- a/searchcore/src/vespa/searchcore/proton/feedoperation/operations.h +++ b/searchcore/src/vespa/searchcore/proton/feedoperation/operations.h @@ -16,5 +16,4 @@ #include "removeoperation.h" #include "splitbucketoperation.h" #include "updateoperation.h" -#include "wipehistoryoperation.h" diff --git a/searchcore/src/vespa/searchcore/proton/feedoperation/wipehistoryoperation.cpp b/searchcore/src/vespa/searchcore/proton/feedoperation/wipehistoryoperation.cpp deleted file mode 100644 index c5e6acd80ed..00000000000 --- a/searchcore/src/vespa/searchcore/proton/feedoperation/wipehistoryoperation.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "wipehistoryoperation.h" -#include <vespa/vespalib/objects/nbostream.h> -#include <vespa/vespalib/util/stringfmt.h> - -using vespalib::make_string; - -namespace proton { - -WipeHistoryOperation::WipeHistoryOperation() - : FeedOperation(FeedOperation::WIPE_HISTORY), - _wipeTimeLimit(0) -{ -} - -WipeHistoryOperation::WipeHistoryOperation(SerialNum serialNum, - fastos::TimeStamp wipeTimeLimit) - : FeedOperation(FeedOperation::WIPE_HISTORY), - _wipeTimeLimit(wipeTimeLimit) -{ - setSerialNum(serialNum); -} - -void WipeHistoryOperation::serialize(vespalib::nbostream &str) const { - str << _wipeTimeLimit; -} -void WipeHistoryOperation::deserialize(vespalib::nbostream &str, const document::DocumentTypeRepo &) { - fastos::TimeStamp::TimeT t; - str >> t; - _wipeTimeLimit = t; -} - -vespalib::string WipeHistoryOperation::toString() const { - return make_string("WipeHistory(wipeTimeLimit=%" PRIu64 ", serialNum=%" PRIu64 ")", - _wipeTimeLimit.ns(), getSerialNum()); -} - -} // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/feedoperation/wipehistoryoperation.h b/searchcore/src/vespa/searchcore/proton/feedoperation/wipehistoryoperation.h deleted file mode 100644 index 0cf7256bf27..00000000000 --- a/searchcore/src/vespa/searchcore/proton/feedoperation/wipehistoryoperation.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include "feedoperation.h" -#include <vespa/fastos/timestamp.h> - -namespace proton { - -class WipeHistoryOperation : public FeedOperation { - fastos::TimeStamp _wipeTimeLimit; - -public: - WipeHistoryOperation(); - WipeHistoryOperation(SerialNum serialNum, fastos::TimeStamp wipeTimeLimit); - ~WipeHistoryOperation() override {} - - fastos::TimeStamp getWipeTimeLimit() const { return _wipeTimeLimit; } - - void serialize(vespalib::nbostream &str) const override; - void deserialize(vespalib::nbostream &str, const document::DocumentTypeRepo &) override; - vespalib::string toString() const override; -}; - -} // namespace proton - diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/flush_engine_explorer.cpp b/searchcore/src/vespa/searchcore/proton/flushengine/flush_engine_explorer.cpp index 5baccda279c..2a447957334 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/flush_engine_explorer.cpp +++ b/searchcore/src/vespa/searchcore/proton/flushengine/flush_engine_explorer.cpp @@ -20,9 +20,8 @@ convertToSlime(const FlushEngine::FlushMetaSet &flushingTargets, Cursor &array) for (const auto &target : flushingTargets) { Cursor &object = array.addObject(); object.setString("name", target.getName()); - object.setString("startTime", fastos::TimeStamp::asString(target.getStart())); - fastos::TimeStamp elapsedTime = target.elapsed(); - object.setDouble("elapsedTime", elapsedTime.sec()); + object.setString("startTime", vespalib::to_string(target.getStart())); + object.setDouble("elapsedTime", vespalib::to_s(target.elapsed())); } } @@ -48,7 +47,7 @@ convertToSlime(const FlushContext::List &allTargets, object.setLong("flushedSerialNum", target->getFlushedSerialNum()); object.setLong("memoryGain", target->getApproxMemoryGain().gain()); object.setLong("diskGain", target->getApproxDiskGain().gain()); - object.setString("lastFlushTime", fastos::TimeStamp::asString(target->getLastFlushTime())); + object.setString("lastFlushTime", vespalib::to_string(target->getLastFlushTime())); vespalib::duration timeSinceLastFlush = now - target->getLastFlushTime(); object.setDouble("timeSinceLastFlush", vespalib::to_s(timeSinceLastFlush)); object.setBool("needUrgentFlush", target->needUrgentFlush()); diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp index 1922b906075..2a0b767a87c 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp +++ b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp @@ -53,7 +53,7 @@ logTarget(const char * text, const FlushContext & ctx) { FlushEngine::FlushMeta::FlushMeta(const vespalib::string & name, uint32_t id) : _name(name), - _stopWatch(), + _timer(), _id(id) { } FlushEngine::FlushMeta::~FlushMeta() = default; @@ -348,17 +348,17 @@ FlushEngine::initFlush(const FlushContext &ctx) void FlushEngine::flushDone(const FlushContext &ctx, uint32_t taskId) { - fastos::TimeStamp duration; + vespalib::duration duration = vespalib::duration::zero(); { std::lock_guard<std::mutex> guard(_lock); duration = _flushing[taskId].elapsed(); } if (LOG_WOULD_LOG(event)) { FlushStats stats = ctx.getTarget()->getLastFlushStats(); - EventLogger::flushComplete(ctx.getName(), duration.ms(), ctx.getTarget()->getFlushedSerialNum(), + EventLogger::flushComplete(ctx.getName(), vespalib::count_ms(duration), ctx.getTarget()->getFlushedSerialNum(), stats.getPath(), stats.getPathElementsToLog()); } - LOG(debug, "FlushEngine::flushDone(taskId='%d') took '%f' secs", taskId, duration.sec()); + LOG(debug, "FlushEngine::flushDone(taskId='%d') took '%f' secs", taskId, vespalib::to_s(duration)); std::lock_guard<std::mutex> guard(_lock); _flushing.erase(taskId); assert(ctx.getHandler()); diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h index 0a4fcabb746..36822a6da65 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h +++ b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h @@ -7,7 +7,6 @@ #include <vespa/searchcore/proton/common/doctypename.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/vespalib/util/time.h> -#include <vespa/fastos/timestamp.h> #include <vespa/fastos/thread.h> #include <set> #include <mutex> @@ -25,13 +24,13 @@ public: FlushMeta(const vespalib::string & name, uint32_t id); ~FlushMeta(); const vespalib::string & getName() const { return _name; } - vespalib::system_time getStart() const { return vespalib::system_clock::now() - vespalib::duration(elapsed()); } - fastos::TimeStamp elapsed() const { return _stopWatch.elapsed(); } + vespalib::system_time getStart() const { return vespalib::system_clock::now() - elapsed(); } + vespalib::duration elapsed() const { return _timer.elapsed(); } uint32_t getId() const { return _id; } bool operator < (const FlushMeta & rhs) const { return _id < rhs._id; } private: vespalib::string _name; - fastos::StopWatch _stopWatch; + vespalib::Timer _timer; uint32_t _id; }; typedef std::set<FlushMeta> FlushMetaSet; diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/shrink_lid_space_flush_target.cpp b/searchcore/src/vespa/searchcore/proton/flushengine/shrink_lid_space_flush_target.cpp index e7e005e2d95..e9c2554f13c 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/shrink_lid_space_flush_target.cpp +++ b/searchcore/src/vespa/searchcore/proton/flushengine/shrink_lid_space_flush_target.cpp @@ -2,7 +2,6 @@ #include "shrink_lid_space_flush_target.h" #include <vespa/searchlib/common/i_compactable_lid_space.h> -#include <vespa/fastos/timestamp.h> namespace proton { diff --git a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp index 0be67a424ee..2ec3488fe3c 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp @@ -185,7 +185,7 @@ Matcher::match(const SearchRequest &request, vespalib::ThreadBundle &threadBundl ISearchContext &searchContext, IAttributeContext &attrContext, SessionManager &sessionMgr, const search::IDocumentMetaStore &metaStore, SearchSession::OwnershipBundle &&owned_objects) { - fastos::StopWatch total_matching_time; + vespalib::Timer total_matching_time; MatchingStats my_stats; SearchReply::UP reply = std::make_unique<SearchReply>(); size_t covered = 0; @@ -286,7 +286,7 @@ Matcher::match(const SearchRequest &request, vespalib::ThreadBundle &threadBundl numThreadsPerSearch, _rankSetup->getNumThreadsPerSearch(), estHits, reply->totalHitCount, request.ranking.c_str()); } - my_stats.queryCollateralTime(total_matching_time.elapsed().sec() - my_stats.queryLatencyAvg()); + my_stats.queryCollateralTime(vespalib::to_s(total_matching_time.elapsed()) - my_stats.queryLatencyAvg()); { vespalib::duration duration = request.getTimeUsed(); std::lock_guard<std::mutex> guard(_statsLock); diff --git a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp index ec48ee7164b..fe0f6aaff91 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp @@ -39,7 +39,7 @@ const search::fef::ITermData * QueryEnvironment::getTerm(uint32_t idx) const { if (idx >= _terms.size()) { - return 0; + return nullptr; } return _terms[idx]; } diff --git a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h index 8f958870d52..575694ae079 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h +++ b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h @@ -80,7 +80,7 @@ public: // inherited from search::fef::IQueryEnvironment const search::fef::IIndexEnvironment & getIndexEnvironment() const override; - ~QueryEnvironment(); + ~QueryEnvironment() override; }; } diff --git a/searchcore/src/vespa/searchcore/proton/matching/session_manager_explorer.cpp b/searchcore/src/vespa/searchcore/proton/matching/session_manager_explorer.cpp index 785ceadba9a..faf0cde4491 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/session_manager_explorer.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/session_manager_explorer.cpp @@ -3,7 +3,6 @@ #include "session_manager_explorer.h" #include "sessionmanager.h" #include <vespa/vespalib/data/slime/slime.h> -#include <vespa/fastos/timestamp.h> using vespalib::slime::Inserter; using vespalib::slime::Cursor; @@ -31,8 +30,8 @@ public: for (const auto &session: sessions) { Cursor &entry = array.addObject(); entry.setString("id", session.id); - entry.setString("created", fastos::TimeStamp::asString(vespalib::to_utc(session.created))); - entry.setString("doom", fastos::TimeStamp::asString(vespalib::to_utc(session.doom))); + entry.setString("created", vespalib::to_string(vespalib::to_utc(session.created))); + entry.setString("doom", vespalib::to_string(vespalib::to_utc(session.doom))); } } } diff --git a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp index 0d83eea261a..592dc26623d 100644 --- a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp +++ b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp @@ -182,14 +182,14 @@ ImportedAttributesRepo::UP DocumentDBReferenceResolver::resolve(const IAttributeManager &newAttrMgr, const IAttributeManager &oldAttrMgr, const std::shared_ptr<search::IDocumentMetaStoreContext> &documentMetaStore, - fastos::TimeStamp visibilityDelay) + vespalib::duration visibilityDelay) { detectOldListeners(oldAttrMgr); if (_useReferences) { connectReferenceAttributesToGidMapper(newAttrMgr); listenToGidToLidChanges(newAttrMgr); } - return createImportedAttributesRepo(newAttrMgr, documentMetaStore, (visibilityDelay > 0)); + return createImportedAttributesRepo(newAttrMgr, documentMetaStore, (visibilityDelay > vespalib::duration::zero())); } void diff --git a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h index c23669cfc12..6ac804f538a 100644 --- a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h +++ b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h @@ -52,13 +52,13 @@ public: MonitoredRefCount &refCount, search::ISequencedTaskExecutor &attributeFieldWriter, bool useReferences); - ~DocumentDBReferenceResolver(); + ~DocumentDBReferenceResolver() override; - virtual std::unique_ptr<ImportedAttributesRepo> resolve(const search::IAttributeManager &newAttrMgr, - const search::IAttributeManager &oldAttrMgr, - const std::shared_ptr<search::IDocumentMetaStoreContext> &documentMetaStore, - fastos::TimeStamp visibilityDelay) override; - virtual void teardown(const search::IAttributeManager &oldAttrMgr) override; + std::unique_ptr<ImportedAttributesRepo> resolve(const search::IAttributeManager &newAttrMgr, + const search::IAttributeManager &oldAttrMgr, + const std::shared_ptr<search::IDocumentMetaStoreContext> &documentMetaStore, + vespalib::duration visibilityDelay) override; + void teardown(const search::IAttributeManager &oldAttrMgr) override; }; } diff --git a/searchcore/src/vespa/searchcore/proton/reference/i_document_db_reference_resolver.h b/searchcore/src/vespa/searchcore/proton/reference/i_document_db_reference_resolver.h index 8db24855de4..681538d9e34 100644 --- a/searchcore/src/vespa/searchcore/proton/reference/i_document_db_reference_resolver.h +++ b/searchcore/src/vespa/searchcore/proton/reference/i_document_db_reference_resolver.h @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> #include <memory> namespace search { class IAttributeManager; struct IDocumentMetaStoreContext; } @@ -18,7 +18,7 @@ struct IDocumentDBReferenceResolver { virtual std::unique_ptr<ImportedAttributesRepo> resolve(const search::IAttributeManager &newAttrMgr, const search::IAttributeManager &oldAttrMgr, const std::shared_ptr<search::IDocumentMetaStoreContext> &documentMetaStore, - fastos::TimeStamp visibilityDelay) = 0; + vespalib::duration visibilityDelay) = 0; virtual void teardown(const search::IAttributeManager &oldAttrMgr) = 0; }; diff --git a/searchcore/src/vespa/searchcore/proton/server/blockable_maintenance_job.cpp b/searchcore/src/vespa/searchcore/proton/server/blockable_maintenance_job.cpp index 50f638c4dd6..d8b5aa7b129 100644 --- a/searchcore/src/vespa/searchcore/proton/server/blockable_maintenance_job.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/blockable_maintenance_job.cpp @@ -27,15 +27,15 @@ BlockableMaintenanceJob::internalNotifyDiskMemUsage(const DiskMemUsageState &sta } BlockableMaintenanceJob::BlockableMaintenanceJob(const vespalib::string &name, - double delay, - double interval) + vespalib::duration delay, + vespalib::duration interval) : BlockableMaintenanceJob(name, delay, interval, BlockableMaintenanceJobConfig()) { } BlockableMaintenanceJob::BlockableMaintenanceJob(const vespalib::string &name, - double delay, - double interval, + vespalib::duration delay, + vespalib::duration interval, const BlockableMaintenanceJobConfig &config) : IBlockableMaintenanceJob(name, delay, interval), _mutex(), diff --git a/searchcore/src/vespa/searchcore/proton/server/blockable_maintenance_job.h b/searchcore/src/vespa/searchcore/proton/server/blockable_maintenance_job.h index 72405855690..db7b8d05ca2 100644 --- a/searchcore/src/vespa/searchcore/proton/server/blockable_maintenance_job.h +++ b/searchcore/src/vespa/searchcore/proton/server/blockable_maintenance_job.h @@ -22,11 +22,11 @@ private: using LockGuard = std::lock_guard<std::mutex>; using ReasonSet = std::unordered_set<BlockedReason>; - mutable std::mutex _mutex; - ReasonSet _blockReasons; - bool _blocked; + mutable std::mutex _mutex; + ReasonSet _blockReasons; + bool _blocked; IMaintenanceJobRunner *_runner; - double _resourceLimitFactor; + double _resourceLimitFactor; void updateBlocked(const LockGuard &guard); @@ -37,23 +37,23 @@ protected: public: BlockableMaintenanceJob(const vespalib::string &name, - double delay, - double interval); + vespalib::duration delay, + vespalib::duration interval); BlockableMaintenanceJob(const vespalib::string &name, - double delay, - double interval, + vespalib::duration delay, + vespalib::duration interval, const BlockableMaintenanceJobConfig &config); - virtual ~BlockableMaintenanceJob(); + ~BlockableMaintenanceJob() override; bool isBlocked(BlockedReason reason); void considerRun(); - virtual void setBlocked(BlockedReason reason) override; - virtual void unBlock(BlockedReason reason) override; - virtual bool isBlocked() const override; - virtual void registerRunner(IMaintenanceJobRunner *runner) override { _runner = runner; } + void setBlocked(BlockedReason reason) override; + void unBlock(BlockedReason reason) override; + bool isBlocked() const override; + void registerRunner(IMaintenanceJobRunner *runner) override { _runner = runner; } }; diff --git a/searchcore/src/vespa/searchcore/proton/server/bucketmovejob.cpp b/searchcore/src/vespa/searchcore/proton/server/bucketmovejob.cpp index 4848c5a5d47..17b8b9e30e0 100644 --- a/searchcore/src/vespa/searchcore/proton/server/bucketmovejob.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/bucketmovejob.cpp @@ -162,7 +162,7 @@ BucketMoveJob(const IBucketStateCalculator::SP &calc, const BlockableMaintenanceJobConfig &blockableConfig, const vespalib::string &docTypeName, document::BucketSpace bucketSpace) - : BlockableMaintenanceJob("move_buckets." + docTypeName, 0.0, 0.0, blockableConfig), + : BlockableMaintenanceJob("move_buckets." + docTypeName, vespalib::duration::zero(), vespalib::duration::zero(), blockableConfig), IClusterStateChangedHandler(), IBucketFreezeListener(), bucketdb::IBucketCreateListener(), diff --git a/searchcore/src/vespa/searchcore/proton/server/disk_mem_usage_sampler.cpp b/searchcore/src/vespa/searchcore/proton/server/disk_mem_usage_sampler.cpp index 8a4cb1682a6..10ee33df019 100644 --- a/searchcore/src/vespa/searchcore/proton/server/disk_mem_usage_sampler.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/disk_mem_usage_sampler.cpp @@ -9,11 +9,10 @@ using vespalib::makeLambdaTask; namespace proton { -DiskMemUsageSampler::DiskMemUsageSampler(const std::string &path_in, - const Config &config) +DiskMemUsageSampler::DiskMemUsageSampler(const std::string &path_in, const Config &config) : _filter(config.hwInfo), _path(path_in), - _sampleInterval(60.0), + _sampleInterval(60s), _periodicTimer() { setConfig(config); diff --git a/searchcore/src/vespa/searchcore/proton/server/disk_mem_usage_sampler.h b/searchcore/src/vespa/searchcore/proton/server/disk_mem_usage_sampler.h index 2ab13f2f48a..ba204cc1d0f 100644 --- a/searchcore/src/vespa/searchcore/proton/server/disk_mem_usage_sampler.h +++ b/searchcore/src/vespa/searchcore/proton/server/disk_mem_usage_sampler.h @@ -2,6 +2,7 @@ #pragma once +#include <vespa/vespalib/util/time.h> #include "disk_mem_usage_filter.h" namespace vespalib { class ScheduledExecutor; } @@ -14,7 +15,7 @@ namespace proton { class DiskMemUsageSampler { DiskMemUsageFilter _filter; std::filesystem::path _path; - double _sampleInterval; + vespalib::duration _sampleInterval; std::unique_ptr<vespalib::ScheduledExecutor> _periodicTimer; void sampleUsage(); @@ -23,19 +24,19 @@ class DiskMemUsageSampler { public: struct Config { DiskMemUsageFilter::Config filterConfig; - double sampleInterval; + vespalib::duration sampleInterval; HwInfo hwInfo; Config() : filterConfig(), - sampleInterval(60.0), + sampleInterval(60s), hwInfo() { } Config(double memoryLimit_in, double diskLimit_in, - double sampleInterval_in, + vespalib::duration sampleInterval_in, const HwInfo &hwInfo_in) : filterConfig(memoryLimit_in, diskLimit_in), sampleInterval(sampleInterval_in), diff --git a/searchcore/src/vespa/searchcore/proton/server/document_db_flush_config.h b/searchcore/src/vespa/searchcore/proton/server/document_db_flush_config.h index 316d0716477..438b2b13759 100644 --- a/searchcore/src/vespa/searchcore/proton/server/document_db_flush_config.h +++ b/searchcore/src/vespa/searchcore/proton/server/document_db_flush_config.h @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once +#include <cstdint> + namespace proton { /* diff --git a/searchcore/src/vespa/searchcore/proton/server/document_db_maintenance_config.cpp b/searchcore/src/vespa/searchcore/proton/server/document_db_maintenance_config.cpp index b470a390b50..b967e745b1f 100644 --- a/searchcore/src/vespa/searchcore/proton/server/document_db_maintenance_config.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/document_db_maintenance_config.cpp @@ -4,19 +4,18 @@ namespace proton { -constexpr double MAX_DELAY_SEC = 300; +constexpr vespalib::duration MAX_DELAY_SEC = 300s; DocumentDBPruneConfig:: DocumentDBPruneConfig() : _delay(MAX_DELAY_SEC), - _interval(21600.0), - _age(1209600.0) + _interval(21600s), + _age(1209600s) { } DocumentDBPruneConfig:: -DocumentDBPruneConfig(double interval, - double age) +DocumentDBPruneConfig(vespalib::duration interval, vespalib::duration age) : _delay(std::min(MAX_DELAY_SEC, interval)), _interval(interval), _age(age) @@ -33,11 +32,11 @@ operator==(const DocumentDBPruneConfig &rhs) const } DocumentDBHeartBeatConfig::DocumentDBHeartBeatConfig() - : _interval(60.0) + : _interval(60s) { } -DocumentDBHeartBeatConfig::DocumentDBHeartBeatConfig(double interval) +DocumentDBHeartBeatConfig::DocumentDBHeartBeatConfig(vespalib::duration interval) : _interval(interval) { } @@ -51,19 +50,19 @@ operator==(const DocumentDBHeartBeatConfig &rhs) const DocumentDBLidSpaceCompactionConfig::DocumentDBLidSpaceCompactionConfig() : _delay(MAX_DELAY_SEC), - _interval(3600), + _interval(3600s), _allowedLidBloat(1000000000), _allowedLidBloatFactor(1.0), - _remove_batch_block_delay(5.0), + _remove_batch_block_delay(5s), _disabled(false), _maxDocsToScan(10000) { } -DocumentDBLidSpaceCompactionConfig::DocumentDBLidSpaceCompactionConfig(double interval, +DocumentDBLidSpaceCompactionConfig::DocumentDBLidSpaceCompactionConfig(vespalib::duration interval, uint32_t allowedLidBloat, double allowedLidBloatFactor, - double remove_batch_block_delay, + vespalib::duration remove_batch_block_delay, bool disabled, uint32_t maxDocsToScan) : _delay(std::min(MAX_DELAY_SEC, interval)), @@ -116,25 +115,24 @@ BlockableMaintenanceJobConfig::operator==(const BlockableMaintenanceJobConfig &r DocumentDBMaintenanceConfig::DocumentDBMaintenanceConfig() : _pruneRemovedDocuments(), _heartBeat(), - _sessionCachePruneInterval(900.0), - _visibilityDelay(0), + _sessionCachePruneInterval(900s), + _visibilityDelay(vespalib::duration::zero()), _lidSpaceCompaction(), _attributeUsageFilterConfig(), - _attributeUsageSampleInterval(60.0), + _attributeUsageSampleInterval(60s), _blockableJobConfig(), _flushConfig() { } DocumentDBMaintenanceConfig:: -DocumentDBMaintenanceConfig(const DocumentDBPruneRemovedDocumentsConfig & - pruneRemovedDocuments, +DocumentDBMaintenanceConfig(const DocumentDBPruneRemovedDocumentsConfig &pruneRemovedDocuments, const DocumentDBHeartBeatConfig &heartBeat, - double groupingSessionPruneInterval, - fastos::TimeStamp visibilityDelay, + vespalib::duration groupingSessionPruneInterval, + vespalib::duration visibilityDelay, const DocumentDBLidSpaceCompactionConfig &lidSpaceCompaction, const AttributeUsageFilterConfig &attributeUsageFilterConfig, - double attributeUsageSampleInterval, + vespalib::duration attributeUsageSampleInterval, const BlockableMaintenanceJobConfig &blockableJobConfig, const DocumentDBFlushConfig &flushConfig) : _pruneRemovedDocuments(pruneRemovedDocuments), diff --git a/searchcore/src/vespa/searchcore/proton/server/document_db_maintenance_config.h b/searchcore/src/vespa/searchcore/proton/server/document_db_maintenance_config.h index 4b458765f3c..283d66e8295 100644 --- a/searchcore/src/vespa/searchcore/proton/server/document_db_maintenance_config.h +++ b/searchcore/src/vespa/searchcore/proton/server/document_db_maintenance_config.h @@ -1,28 +1,28 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <vespa/vespalib/stllike/string.h> -#include <vespa/searchcore/proton/attribute/attribute_usage_filter_config.h> -#include <vespa/fastos/timestamp.h> #include "document_db_flush_config.h" +#include <vespa/searchcore/proton/attribute/attribute_usage_filter_config.h> +#include <vespa/vespalib/stllike/string.h> +#include <vespa/vespalib/util/time.h> namespace proton { class DocumentDBPruneConfig { private: - double _delay; - double _interval; - double _age; + vespalib::duration _delay; + vespalib::duration _interval; + vespalib::duration _age; public: DocumentDBPruneConfig(); - DocumentDBPruneConfig(double interval, double age); + DocumentDBPruneConfig(vespalib::duration interval, vespalib::duration age); bool operator==(const DocumentDBPruneConfig &rhs) const; - double getDelay() const { return _delay; } - double getInterval() const { return _interval; } - double getAge() const { return _age; } + vespalib::duration getDelay() const { return _delay; } + vespalib::duration getInterval() const { return _interval; } + vespalib::duration getAge() const { return _age; } }; typedef DocumentDBPruneConfig DocumentDBPruneRemovedDocumentsConfig; @@ -30,43 +30,43 @@ typedef DocumentDBPruneConfig DocumentDBPruneRemovedDocumentsConfig; class DocumentDBHeartBeatConfig { private: - double _interval; + vespalib::duration _interval; public: DocumentDBHeartBeatConfig(); - DocumentDBHeartBeatConfig(double interval); + DocumentDBHeartBeatConfig(vespalib::duration interval); bool operator==(const DocumentDBHeartBeatConfig &rhs) const; - double getInterval() const { return _interval; } + vespalib::duration getInterval() const { return _interval; } }; class DocumentDBLidSpaceCompactionConfig { private: - double _delay; - double _interval; - uint32_t _allowedLidBloat; - double _allowedLidBloatFactor; - double _remove_batch_block_delay; - bool _disabled; - uint32_t _maxDocsToScan; + vespalib::duration _delay; + vespalib::duration _interval; + uint32_t _allowedLidBloat; + double _allowedLidBloatFactor; + vespalib::duration _remove_batch_block_delay; + bool _disabled; + uint32_t _maxDocsToScan; public: DocumentDBLidSpaceCompactionConfig(); - DocumentDBLidSpaceCompactionConfig(double interval, + DocumentDBLidSpaceCompactionConfig(vespalib::duration interval, uint32_t allowedLidBloat, double allowwedLidBloatFactor, - double remove_batch_block_delay, + vespalib::duration remove_batch_block_delay, bool disabled, uint32_t maxDocsToScan = 10000); static DocumentDBLidSpaceCompactionConfig createDisabled(); bool operator==(const DocumentDBLidSpaceCompactionConfig &rhs) const; - double getDelay() const { return _delay; } - double getInterval() const { return _interval; } + vespalib::duration getDelay() const { return _delay; } + vespalib::duration getInterval() const { return _interval; } uint32_t getAllowedLidBloat() const { return _allowedLidBloat; } double getAllowedLidBloatFactor() const { return _allowedLidBloatFactor; } - double get_remove_batch_block_delay() const { return _remove_batch_block_delay; } + vespalib::duration get_remove_batch_block_delay() const { return _remove_batch_block_delay; } bool isDisabled() const { return _disabled; } uint32_t getMaxDocsToScan() const { return _maxDocsToScan; } }; @@ -93,11 +93,11 @@ public: private: DocumentDBPruneRemovedDocumentsConfig _pruneRemovedDocuments; DocumentDBHeartBeatConfig _heartBeat; - double _sessionCachePruneInterval; - fastos::TimeStamp _visibilityDelay; + vespalib::duration _sessionCachePruneInterval; + vespalib::duration _visibilityDelay; DocumentDBLidSpaceCompactionConfig _lidSpaceCompaction; AttributeUsageFilterConfig _attributeUsageFilterConfig; - double _attributeUsageSampleInterval; + vespalib::duration _attributeUsageSampleInterval; BlockableMaintenanceJobConfig _blockableJobConfig; DocumentDBFlushConfig _flushConfig; @@ -106,11 +106,11 @@ public: DocumentDBMaintenanceConfig(const DocumentDBPruneRemovedDocumentsConfig &pruneRemovedDocuments, const DocumentDBHeartBeatConfig &heartBeat, - double sessionCachePruneInterval, - fastos::TimeStamp visibilityDelay, + vespalib::duration sessionCachePruneInterval, + vespalib::duration visibilityDelay, const DocumentDBLidSpaceCompactionConfig &lidSpaceCompaction, const AttributeUsageFilterConfig &attributeUsageFilterConfig, - double attributeUsageSampleInterval, + vespalib::duration attributeUsageSampleInterval, const BlockableMaintenanceJobConfig &blockableJobConfig, const DocumentDBFlushConfig &flushConfig); @@ -123,17 +123,18 @@ public: const DocumentDBHeartBeatConfig &getHeartBeatConfig() const { return _heartBeat; } - double getSessionCachePruneInterval() const { + vespalib::duration getSessionCachePruneInterval() const { return _sessionCachePruneInterval; } - fastos::TimeStamp getVisibilityDelay() const { return _visibilityDelay; } + vespalib::duration getVisibilityDelay() const { return _visibilityDelay; } + bool hasVisibilityDelay() const { return _visibilityDelay > vespalib::duration::zero(); } const DocumentDBLidSpaceCompactionConfig &getLidSpaceCompactionConfig() const { return _lidSpaceCompaction; } const AttributeUsageFilterConfig &getAttributeUsageFilterConfig() const { return _attributeUsageFilterConfig; } - double getAttributeUsageSampleInterval() const { + vespalib::duration getAttributeUsageSampleInterval() const { return _attributeUsageSampleInterval; } const BlockableMaintenanceJobConfig &getBlockableJobConfig() const { diff --git a/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer.h b/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer.h index a2ae11346f5..66ab54cf4a6 100644 --- a/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer.h +++ b/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer.h @@ -45,7 +45,7 @@ public: return _documentMetaStoreInitTask; } - virtual void run() override; + void run() override; }; } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp index 1532ab35c26..1b182c3e618 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp @@ -13,7 +13,6 @@ #include "maintenance_jobs_injector.h" #include "reconfig_params.h" #include <vespa/document/repo/documenttyperepo.h> -#include <vespa/searchcommon/common/schemaconfigurer.h> #include <vespa/searchcore/proton/attribute/attribute_writer.h> #include <vespa/searchcore/proton/attribute/imported_attributes_repo.h> #include <vespa/searchcore/proton/common/eventlogger.h> @@ -26,12 +25,10 @@ #include <vespa/searchcore/proton/metrics/metricswireservice.h> #include <vespa/searchcore/proton/reference/document_db_reference_resolver.h> #include <vespa/searchcore/proton/reference/i_document_db_reference_registry.h> -#include <vespa/searchcore/proton/reference/i_document_db_reference_resolver.h> #include <vespa/searchlib/attribute/attributefactory.h> #include <vespa/searchlib/attribute/configconverter.h> #include <vespa/searchlib/engine/docsumreply.h> #include <vespa/searchlib/engine/searchreply.h> -#include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/util/closuretask.h> #include <vespa/vespalib/util/exceptions.h> @@ -42,7 +39,6 @@ LOG_SETUP(".proton.server.documentdb"); using vespa::config::search::AttributesConfig; using vespa::config::search::core::ProtonConfig; -using search::index::SchemaBuilder; using vespalib::JSONStringer; using vespalib::Executor; using vespalib::IllegalStateException; @@ -212,9 +208,9 @@ DocumentDB::DocumentDB(const vespalib::string &baseDir, _lidSpaceCompactionHandlers.push_back(std::make_unique<LidSpaceCompactionHandler>(_maintenanceController.getNotReadySubDB(), _docTypeName.getName())); _writeFilter.setConfig(loaded_config->getMaintenanceConfigSP()->getAttributeUsageFilterConfig()); - fastos::TimeStamp visibilityDelay = loaded_config->getMaintenanceConfigSP()->getVisibilityDelay(); + vespalib::duration visibilityDelay = loaded_config->getMaintenanceConfigSP()->getVisibilityDelay(); _visibility.setVisibilityDelay(visibilityDelay); - if (_visibility.getVisibilityDelay() > 0) { + if (_visibility.hasVisibilityDelay()) { _writeService.setTaskLimit(_writeServiceConfig.semiUnboundTaskLimit(), _writeServiceConfig.defaultTaskLimit()); } } @@ -453,11 +449,11 @@ DocumentDB::applyConfig(DocumentDBConfig::SP configSnapshot, SerialNum serialNum // Flush changes to attributes and memory index, cf. visibilityDelay _feedView.get()->forceCommit(elidedConfigSave ? serialNum : serialNum - 1); _writeService.sync(); - fastos::TimeStamp visibilityDelay = configSnapshot->getMaintenanceConfigSP()->getVisibilityDelay(); + vespalib::duration visibilityDelay = configSnapshot->getMaintenanceConfigSP()->getVisibilityDelay(); hasVisibilityDelayChanged = (visibilityDelay != _visibility.getVisibilityDelay()); _visibility.setVisibilityDelay(visibilityDelay); } - if (_visibility.getVisibilityDelay() > 0) { + if (_visibility.hasVisibilityDelay()) { _writeService.setTaskLimit(_writeServiceConfig.semiUnboundTaskLimit(), _writeServiceConfig.defaultTaskLimit()); } else { _writeService.setTaskLimit(_writeServiceConfig.defaultTaskLimit(), _writeServiceConfig.defaultTaskLimit()); diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.h b/searchcore/src/vespa/searchcore/proton/server/documentdb.h index d6448c0b515..02ad144af68 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.h +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.h @@ -100,7 +100,6 @@ private: InitializeThreads _initializeThreads; typedef search::SerialNum SerialNum; - typedef fastos::TimeStamp TimeStamp; typedef vespalib::Closure Closure; typedef search::index::Schema Schema; using lock_guard = std::lock_guard<std::mutex>; diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb_commit_job.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb_commit_job.cpp index 51126faa090..81979bbfb94 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb_commit_job.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb_commit_job.cpp @@ -5,8 +5,8 @@ namespace proton { -DocumentDBCommitJob::DocumentDBCommitJob(ICommitable & committer, fastos::TimeStamp visibilityDelay) : - IMaintenanceJob("documentdb_commit", visibilityDelay.sec(), visibilityDelay.sec()), +DocumentDBCommitJob::DocumentDBCommitJob(ICommitable & committer, vespalib::duration visibilityDelay) : + IMaintenanceJob("documentdb_commit", visibilityDelay, visibilityDelay), _committer(committer) { } diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb_commit_job.h b/searchcore/src/vespa/searchcore/proton/server/documentdb_commit_job.h index 62307566857..c375d513276 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb_commit_job.h +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb_commit_job.h @@ -2,7 +2,7 @@ #pragma once #include "i_maintenance_job.h" -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> namespace proton { @@ -17,7 +17,7 @@ private: ICommitable & _committer; public: - DocumentDBCommitJob(ICommitable & committer, fastos::TimeStamp visibilityDelay); + DocumentDBCommitJob(ICommitable & committer, vespalib::duration visibilityDelay); bool run() override; }; diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp index 20d11c43a68..7a1989c8d7b 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp @@ -26,7 +26,6 @@ using namespace vespa::config::search::summary; using namespace vespa::config::search; using document::DocumentTypeRepo; -using fastos::TimeStamp; using search::TuneFileDocumentDB; using search::index::Schema; using search::index::SchemaBuilder; @@ -105,7 +104,7 @@ buildMaintenanceConfig(const BootstrapConfig::SP &bootstrapConfig, typedef ProtonConfig::Documentdb DdbConfig; ProtonConfig &proton(bootstrapConfig->getProtonConfig()); - TimeStamp visibilityDelay; + vespalib::duration visibilityDelay = vespalib::duration::zero(); bool isDocumentTypeGlobal = false; // Use document type to find document db config in proton config uint32_t index; @@ -114,13 +113,14 @@ buildMaintenanceConfig(const BootstrapConfig::SP &bootstrapConfig, if (docTypeName == ddbConfig.inputdoctypename) break; } - double pruneRemovedDocumentsAge = proton.pruneremoveddocumentsage; - double pruneRemovedDocumentsInterval = (proton.pruneremoveddocumentsinterval == 0) ? - (pruneRemovedDocumentsAge / 100) : proton.pruneremoveddocumentsinterval; + vespalib::duration pruneRemovedDocumentsAge = vespalib::from_s(proton.pruneremoveddocumentsage); + vespalib::duration pruneRemovedDocumentsInterval = (proton.pruneremoveddocumentsinterval == 0) + ? (pruneRemovedDocumentsAge / 100) + : vespalib::from_s(proton.pruneremoveddocumentsinterval); if (index < proton.documentdb.size()) { const DdbConfig &ddbConfig = proton.documentdb[index]; - visibilityDelay = TimeStamp::Seconds(std::min(proton.maxvisibilitydelay, ddbConfig.visibilitydelay)); + visibilityDelay = vespalib::from_s(std::min(proton.maxvisibilitydelay, ddbConfig.visibilitydelay)); isDocumentTypeGlobal = ddbConfig.global; } return std::make_shared<DocumentDBMaintenanceConfig>( @@ -128,18 +128,18 @@ buildMaintenanceConfig(const BootstrapConfig::SP &bootstrapConfig, pruneRemovedDocumentsInterval, pruneRemovedDocumentsAge), DocumentDBHeartBeatConfig(), - proton.grouping.sessionmanager.pruning.interval, + vespalib::from_s(proton.grouping.sessionmanager.pruning.interval), visibilityDelay, DocumentDBLidSpaceCompactionConfig( - proton.lidspacecompaction.interval, + vespalib::from_s(proton.lidspacecompaction.interval), proton.lidspacecompaction.allowedlidbloat, proton.lidspacecompaction.allowedlidbloatfactor, - proton.lidspacecompaction.removebatchblockdelay, + vespalib::from_s(proton.lidspacecompaction.removebatchblockdelay), isDocumentTypeGlobal), AttributeUsageFilterConfig( proton.writefilter.attribute.enumstorelimit, proton.writefilter.attribute.multivaluelimit), - proton.writefilter.sampleinterval, + vespalib::from_s(proton.writefilter.sampleinterval), BlockableMaintenanceJobConfig( proton.maintenancejobs.resourcelimitfactor, proton.maintenancejobs.maxoutstandingmoveops), diff --git a/searchcore/src/vespa/searchcore/proton/server/feedstates.cpp b/searchcore/src/vespa/searchcore/proton/server/feedstates.cpp index e45e3d7e423..5a6a990df9b 100644 --- a/searchcore/src/vespa/searchcore/proton/server/feedstates.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/feedstates.cpp @@ -10,7 +10,6 @@ #include <vespa/searchcore/proton/common/eventlogger.h> #include <vespa/searchlib/common/idestructorcallback.h> #include <vespa/vespalib/util/closuretask.h> -#include <vespa/vespalib/util/exceptions.h> #include <vespa/log/log.h> @@ -20,7 +19,6 @@ using search::transactionlog::Packet; using search::transactionlog::RPC; using search::SerialNum; using vespalib::Executor; -using vespalib::IllegalStateException; using vespalib::makeClosure; using vespalib::makeTask; using vespalib::make_string; @@ -56,7 +54,7 @@ handlePacket(PacketWrapper::SP wrap, EntryHandler entryHandler) Packet::Entry entry; entry.deserialize(handle); entryHandler->call(entry); - if (wrap->progress != NULL) { + if (wrap->progress != nullptr) { handleProgress(*wrap->progress, entry.serial()); } } @@ -70,8 +68,6 @@ class TransactionLogReplayPacketHandler : public IReplayPacketHandler { IReplayConfig &_replay_config; FeedConfigStore &_config_store; - void handleTransactionLogEntry(const Packet::Entry &entry); - public: TransactionLogReplayPacketHandler(IFeedView *& feed_view_ptr, IBucketDBHandler &bucketDBHandler, @@ -83,53 +79,51 @@ public: _config_store(config_store) { } - virtual void replay(const PutOperation &op) override { + void replay(const PutOperation &op) override { _feed_view_ptr->handlePut(FeedToken(), op); } - virtual void replay(const RemoveOperation &op) override { + void replay(const RemoveOperation &op) override { _feed_view_ptr->handleRemove(FeedToken(), op); } - virtual void replay(const UpdateOperation &op) override { + void replay(const UpdateOperation &op) override { _feed_view_ptr->handleUpdate(FeedToken(), op); } - virtual void replay(const NoopOperation &) override {} // ignored - virtual void replay(const NewConfigOperation &op) override { + void replay(const NoopOperation &) override {} // ignored + void replay(const NewConfigOperation &op) override { _replay_config.replayConfig(op.getSerialNum()); } - virtual void replay(const WipeHistoryOperation &) override { - } - virtual void replay(const DeleteBucketOperation &op) override { + + void replay(const DeleteBucketOperation &op) override { _feed_view_ptr->handleDeleteBucket(op); } - virtual void replay(const SplitBucketOperation &op) override { + void replay(const SplitBucketOperation &op) override { _bucketDBHandler.handleSplit(op.getSerialNum(), op.getSource(), op.getTarget1(), op.getTarget2()); } - virtual void replay(const JoinBucketsOperation &op) override { + void replay(const JoinBucketsOperation &op) override { _bucketDBHandler.handleJoin(op.getSerialNum(), op.getSource1(), op.getSource2(), op.getTarget()); } - virtual void replay(const PruneRemovedDocumentsOperation &op) override { + void replay(const PruneRemovedDocumentsOperation &op) override { _feed_view_ptr->handlePruneRemovedDocuments(op); } - virtual void replay(const MoveOperation &op) override { + void replay(const MoveOperation &op) override { _feed_view_ptr->handleMove(op, search::IDestructorCallback::SP()); } - virtual void replay(const CreateBucketOperation &) override { + void replay(const CreateBucketOperation &) override { } - virtual void replay(const CompactLidSpaceOperation &op) override { + void replay(const CompactLidSpaceOperation &op) override { _feed_view_ptr->handleCompactLidSpace(op); } - virtual NewConfigOperation::IStreamHandler &getNewConfigStreamHandler() override { + NewConfigOperation::IStreamHandler &getNewConfigStreamHandler() override { return _config_store; } - virtual const document::DocumentTypeRepo &getDeserializeRepo() override { + const document::DocumentTypeRepo &getDeserializeRepo() override { return *_feed_view_ptr->getDocumentTypeRepo(); } }; -void startDispatch(IReplayPacketHandler *packet_handler, - const Packet::Entry &entry) { +void startDispatch(IReplayPacketHandler *packet_handler, const Packet::Entry &entry) { // Called by handlePacket() in executor thread. LOG(spam, "replay packet entry: entrySerial(%" PRIu64 "), entryType(%u)", @@ -154,8 +148,7 @@ ReplayTransactionLogState::ReplayTransactionLogState( replay_config, config_store)) { } -void ReplayTransactionLogState::receive(const PacketWrapper::SP &wrap, - Executor &executor) { +void ReplayTransactionLogState::receive(const PacketWrapper::SP &wrap, Executor &executor) { EntryHandler closure = makeClosure(&startDispatch, _packet_handler.get()); executor.execute(makeTask(makeClosure(&handlePacket, wrap, std::move(closure)))); } diff --git a/searchcore/src/vespa/searchcore/proton/server/i_blockable_maintenance_job.h b/searchcore/src/vespa/searchcore/proton/server/i_blockable_maintenance_job.h index 9544485cc86..c70a6c502f1 100644 --- a/searchcore/src/vespa/searchcore/proton/server/i_blockable_maintenance_job.h +++ b/searchcore/src/vespa/searchcore/proton/server/i_blockable_maintenance_job.h @@ -2,7 +2,6 @@ #pragma once #include "i_maintenance_job.h" -#include <string> namespace proton { @@ -20,8 +19,8 @@ public: }; IBlockableMaintenanceJob(const vespalib::string &name, - double delay, - double interval) + vespalib::duration delay, + vespalib::duration interval) : IMaintenanceJob(name, delay, interval) {} diff --git a/searchcore/src/vespa/searchcore/proton/server/i_maintenance_job.h b/searchcore/src/vespa/searchcore/proton/server/i_maintenance_job.h index e32fd01df63..6d0739e1aed 100644 --- a/searchcore/src/vespa/searchcore/proton/server/i_maintenance_job.h +++ b/searchcore/src/vespa/searchcore/proton/server/i_maintenance_job.h @@ -2,6 +2,7 @@ #pragma once #include <vespa/vespalib/stllike/string.h> +#include <vespa/vespalib/util/time.h> namespace proton { @@ -15,16 +16,16 @@ class IMaintenanceJobRunner; class IMaintenanceJob { private: - const vespalib::string _name; - const double _delay; - const double _interval; + const vespalib::string _name; + const vespalib::duration _delay; + const vespalib::duration _interval; public: typedef std::unique_ptr<IMaintenanceJob> UP; IMaintenanceJob(const vespalib::string &name, - double delay, - double interval) + vespalib::duration delay, + vespalib::duration interval) : _name(name), _delay(delay), _interval(interval) @@ -33,8 +34,8 @@ public: virtual ~IMaintenanceJob() {} virtual const vespalib::string &getName() const { return _name; } - virtual double getDelay() const { return _delay; } - virtual double getInterval() const { return _interval; } + virtual vespalib::duration getDelay() const { return _delay; } + virtual vespalib::duration getInterval() const { return _interval; } virtual bool isBlocked() const { return false; } virtual IBlockableMaintenanceJob *asBlockable() { return nullptr; } diff --git a/searchcore/src/vespa/searchcore/proton/server/ireplaypackethandler.h b/searchcore/src/vespa/searchcore/proton/server/ireplaypackethandler.h index 8df51780c9f..6de61e5eeb7 100644 --- a/searchcore/src/vespa/searchcore/proton/server/ireplaypackethandler.h +++ b/searchcore/src/vespa/searchcore/proton/server/ireplaypackethandler.h @@ -11,7 +11,6 @@ class RemoveOperation; class UpdateOperation; struct NoopOperation; class NewConfigOperation; -class WipeHistoryOperation; class DeleteBucketOperation; class SplitBucketOperation; class JoinBucketsOperation; @@ -34,7 +33,6 @@ struct IReplayPacketHandler virtual void replay(const UpdateOperation &op) = 0; virtual void replay(const NoopOperation &op) = 0; virtual void replay(const NewConfigOperation &op) = 0; - virtual void replay(const WipeHistoryOperation &op) = 0; virtual void replay(const DeleteBucketOperation &op) = 0; virtual void replay(const SplitBucketOperation &op) = 0; virtual void replay(const JoinBucketsOperation &op) = 0; diff --git a/searchcore/src/vespa/searchcore/proton/server/maintenance_controller_explorer.cpp b/searchcore/src/vespa/searchcore/proton/server/maintenance_controller_explorer.cpp index c20ddd77887..6ab7fe373c4 100644 --- a/searchcore/src/vespa/searchcore/proton/server/maintenance_controller_explorer.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/maintenance_controller_explorer.cpp @@ -28,8 +28,8 @@ convertAllJobsToSlime(const std::vector<MaintenanceJobRunner::SP> &jobs, Cursor Cursor &object = array.addObject(); const IMaintenanceJob &job = jobRunner->getJob(); object.setString("name", job.getName()); - object.setDouble("delay", job.getDelay()); - object.setDouble("interval", job.getInterval()); + object.setDouble("delay", vespalib::to_s(job.getDelay())); + object.setDouble("interval", vespalib::to_s(job.getInterval())); object.setBool("blocked", job.isBlocked()); } } diff --git a/searchcore/src/vespa/searchcore/proton/server/maintenance_jobs_injector.cpp b/searchcore/src/vespa/searchcore/proton/server/maintenance_jobs_injector.cpp index b9a5bb65e45..483497eb008 100644 --- a/searchcore/src/vespa/searchcore/proton/server/maintenance_jobs_injector.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/maintenance_jobs_injector.cpp @@ -11,17 +11,15 @@ #include "sample_attribute_usage_job.h" using vespalib::system_clock; -using fastos::TimeStamp; namespace proton { namespace { IMaintenanceJob::UP -trackJob(const IJobTracker::SP &tracker, - IMaintenanceJob::UP job) +trackJob(const IJobTracker::SP &tracker, IMaintenanceJob::UP job) { - return IMaintenanceJob::UP(new JobTrackedMaintenanceJob(tracker, std::move(job))); + return std::make_unique<JobTrackedMaintenanceJob>(tracker, std::move(job)); } void @@ -62,8 +60,7 @@ injectBucketMoveJob(MaintenanceController &controller, IDiskMemUsageNotifier &diskMemUsageNotifier, const BlockableMaintenanceJobConfig &blockableConfig) { - IMaintenanceJob::UP bmj; - bmj.reset(new BucketMoveJob(calc, + auto bmj = std::make_unique<BucketMoveJob>(calc, moveHandler, bucketModifiedHandler, controller.getReadySubDB(), @@ -74,9 +71,8 @@ injectBucketMoveJob(MaintenanceController &controller, bucketStateChangedNotifier, diskMemUsageNotifier, blockableConfig, - docTypeName, bucketSpace)); - controller.registerJobInMasterThread(trackJob(jobTrackers.getBucketMove(), - std::move(bmj))); + docTypeName, bucketSpace); + controller.registerJobInMasterThread(trackJob(jobTrackers.getBucketMove(), std::move(bmj))); } } @@ -104,15 +100,14 @@ MaintenanceJobsInjector::injectJobs(MaintenanceController &controller, IAttributeManagerSP readyAttributeManager, IAttributeManagerSP notReadyAttributeManager, AttributeUsageFilter &attributeUsageFilter) { - typedef IMaintenanceJob::UP MUP; - controller.registerJobInMasterThread(MUP(new HeartBeatJob(hbHandler, config.getHeartBeatConfig()))); - controller.registerJobInDefaultPool(MUP(new PruneSessionCacheJob(scPruner, config.getSessionCachePruneInterval()))); - if (config.getVisibilityDelay() > 0) { - controller.registerJobInMasterThread(MUP(new DocumentDBCommitJob(commit, config.getVisibilityDelay()))); + controller.registerJobInMasterThread(std::make_unique<HeartBeatJob>(hbHandler, config.getHeartBeatConfig())); + controller.registerJobInDefaultPool(std::make_unique<PruneSessionCacheJob>(scPruner, config.getSessionCachePruneInterval())); + if (config.hasVisibilityDelay()) { + controller.registerJobInMasterThread(std::make_unique<DocumentDBCommitJob>(commit, config.getVisibilityDelay())); } const MaintenanceDocumentSubDB &mRemSubDB(controller.getRemSubDB()); - MUP pruneRDjob(new PruneRemovedDocumentsJob(config.getPruneRemovedDocumentsConfig(), *mRemSubDB.meta_store(), - mRemSubDB.sub_db_id(), docTypeName, prdHandler, fbHandler)); + auto pruneRDjob = std::make_unique<PruneRemovedDocumentsJob>(config.getPruneRemovedDocumentsConfig(), *mRemSubDB.meta_store(), + mRemSubDB.sub_db_id(), docTypeName, prdHandler, fbHandler); controller.registerJobInMasterThread( trackJob(jobTrackers.getRemovedDocumentsPrune(), std::move(pruneRDjob))); if (!config.getLidSpaceCompactionConfig().isDisabled()) { diff --git a/searchcore/src/vespa/searchcore/proton/server/maintenancecontroller.cpp b/searchcore/src/vespa/searchcore/proton/server/maintenancecontroller.cpp index 893748ae49e..f29e54ba725 100644 --- a/searchcore/src/vespa/searchcore/proton/server/maintenancecontroller.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/maintenancecontroller.cpp @@ -179,8 +179,8 @@ MaintenanceController::addJobsToPeriodicTimer() for (const auto &jw : _jobs) { const IMaintenanceJob &job = jw->getJob(); LOG(debug, "addJobsToPeriodicTimer(): docType='%s', job.name='%s', job.delay=%f, job.interval=%f", - _docTypeName.getName().c_str(), job.getName().c_str(), job.getDelay(), job.getInterval()); - if (job.getInterval() == 0.0) { + _docTypeName.getName().c_str(), job.getName().c_str(), vespalib::to_s(job.getDelay()), vespalib::to_s(job.getInterval())); + if (job.getInterval() == vespalib::duration::zero()) { jw->run(); continue; } diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp index 48cede5943d..4daf3e895af 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp @@ -96,7 +96,7 @@ diskMemUsageSamplerConfig(const ProtonConfig &proton, const HwInfo &hwInfo) return DiskMemUsageSampler::Config( proton.writefilter.memorylimit, proton.writefilter.disklimit, - proton.writefilter.sampleinterval, + vespalib::from_s(proton.writefilter.sampleinterval), hwInfo); } diff --git a/searchcore/src/vespa/searchcore/proton/server/prune_session_cache_job.cpp b/searchcore/src/vespa/searchcore/proton/server/prune_session_cache_job.cpp index 70ed5b29541..afbabfcd0be 100644 --- a/searchcore/src/vespa/searchcore/proton/server/prune_session_cache_job.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/prune_session_cache_job.cpp @@ -5,7 +5,7 @@ namespace proton { using matching::ISessionCachePruner; -PruneSessionCacheJob::PruneSessionCacheJob(ISessionCachePruner &pruner, double jobInterval) +PruneSessionCacheJob::PruneSessionCacheJob(ISessionCachePruner &pruner, vespalib::duration jobInterval) : IMaintenanceJob("prune_session_cache", jobInterval, jobInterval), _pruner(pruner) { diff --git a/searchcore/src/vespa/searchcore/proton/server/prune_session_cache_job.h b/searchcore/src/vespa/searchcore/proton/server/prune_session_cache_job.h index 531707bf4f3..99a2a41f114 100644 --- a/searchcore/src/vespa/searchcore/proton/server/prune_session_cache_job.h +++ b/searchcore/src/vespa/searchcore/proton/server/prune_session_cache_job.h @@ -15,11 +15,9 @@ private: matching::ISessionCachePruner &_pruner; public: - PruneSessionCacheJob(matching::ISessionCachePruner &pruner, - double jobInterval); + PruneSessionCacheJob(matching::ISessionCachePruner &pruner, vespalib::duration jobInterval); - // Implements IMaintenanceJob - virtual bool run() override; + bool run() override; }; } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp b/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp index 8be58311798..43be4e9accd 100644 --- a/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp @@ -37,8 +37,7 @@ PruneRemovedDocumentsJob(const Config &config, void -PruneRemovedDocumentsJob::flush(DocId lowLid, DocId nextLowLid, - const Timestamp ageLimit) +PruneRemovedDocumentsJob::flush(DocId lowLid, DocId nextLowLid, const Timestamp ageLimit) { if (_pruneLids.empty()) return; @@ -65,10 +64,9 @@ PruneRemovedDocumentsJob::flush(DocId lowLid, DocId nextLowLid, bool PruneRemovedDocumentsJob::run() { - uint64_t tshz = 1000000; vespalib::system_time now = vespalib::system_clock::now(); const Timestamp ageLimit(static_cast<Timestamp::Type> - ((vespalib::to_s(now.time_since_epoch()) - _cfgAgeLimit) * tshz)); + (vespalib::count_us(now.time_since_epoch() - _cfgAgeLimit))); DocId lid(_nextLid); const DocId olid(lid); const DocId docIdLimit(_metaStore.getCommittedDocIdLimit()); diff --git a/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.h b/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.h index 42c5d964aed..76967635f4a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.h +++ b/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.h @@ -20,7 +20,7 @@ class PruneRemovedDocumentsJob : public BlockableMaintenanceJob private: const IDocumentMetaStore &_metaStore; // external ownership uint32_t _subDbId; - double _cfgAgeLimit; + vespalib::duration _cfgAgeLimit; const vespalib::string &_docTypeName; IPruneRemovedDocumentsHandler &_handler; IFrozenBucketHandler &_frozenHandler; diff --git a/searchcore/src/vespa/searchcore/proton/server/replaypacketdispatcher.cpp b/searchcore/src/vespa/searchcore/proton/server/replaypacketdispatcher.cpp index 92b59a678cc..fcf1cf2a58c 100644 --- a/searchcore/src/vespa/searchcore/proton/server/replaypacketdispatcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/replaypacketdispatcher.cpp @@ -2,7 +2,6 @@ #include "replaypacketdispatcher.h" #include <vespa/searchcore/proton/feedoperation/operations.h> -#include <vespa/vespalib/util/exceptions.h> #include <vespa/document/util/serializableexceptions.h> using vespalib::make_string; @@ -53,10 +52,6 @@ ReplayPacketDispatcher::replayEntry(const Packet::Entry &entry) op.deserialize(is, _handler.getDeserializeRepo()); _handler.replay(op); break; - } case FeedOperation::WIPE_HISTORY: { - WipeHistoryOperation op; - replay(op, is, entry); - break; } case FeedOperation::DELETE_BUCKET: { DeleteBucketOperation op; replay(op, is, entry); @@ -87,8 +82,7 @@ ReplayPacketDispatcher::replayEntry(const Packet::Entry &entry) break; } default: throw IllegalStateException - (make_string("Got packet entry with unknown type id '%u' from TLS", - entry.type())); + (make_string("Got packet entry with unknown type id '%u' from TLS", entry.type())); } if (is.size() > 0) { throw document::DeserializeException diff --git a/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.cpp b/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.cpp index 309dd44391d..c724e1065e9 100644 --- a/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.cpp @@ -13,7 +13,6 @@ LOG_SETUP(".proton.server.rtchooks"); using namespace vespalib; using vespalib::compression::CompressionConfig; -using fastos::TimeStamp; namespace { diff --git a/searchcore/src/vespa/searchcore/proton/server/sample_attribute_usage_job.cpp b/searchcore/src/vespa/searchcore/proton/server/sample_attribute_usage_job.cpp index 13f2934f161..1f5f29c7708 100644 --- a/searchcore/src/vespa/searchcore/proton/server/sample_attribute_usage_job.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/sample_attribute_usage_job.cpp @@ -13,8 +13,8 @@ SampleAttributeUsageJob(IAttributeManagerSP readyAttributeManager, IAttributeManagerSP notReadyAttributeManager, AttributeUsageFilter &attributeUsageFilter, const vespalib::string &docTypeName, - double interval) - : IMaintenanceJob("sample_attribute_usage." + docTypeName, 0.0, interval), + vespalib::duration interval) + : IMaintenanceJob("sample_attribute_usage." + docTypeName, vespalib::duration::zero(), interval), _readyAttributeManager(readyAttributeManager), _notReadyAttributeManager(notReadyAttributeManager), _attributeUsageFilter(attributeUsageFilter) diff --git a/searchcore/src/vespa/searchcore/proton/server/sample_attribute_usage_job.h b/searchcore/src/vespa/searchcore/proton/server/sample_attribute_usage_job.h index 4f2b6155cb1..72a0bf1a665 100644 --- a/searchcore/src/vespa/searchcore/proton/server/sample_attribute_usage_job.h +++ b/searchcore/src/vespa/searchcore/proton/server/sample_attribute_usage_job.h @@ -26,8 +26,8 @@ public: IAttributeManagerSP notReadyAttributeManager, AttributeUsageFilter &attributeUsageFilter, const vespalib::string &docTypeName, - double interval); - ~SampleAttributeUsageJob(); + vespalib::duration interval); + ~SampleAttributeUsageJob() override; bool run() override; }; diff --git a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp index fc21621bee3..77852dcc918 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp @@ -13,13 +13,10 @@ #include <vespa/searchcore/proton/matching/sessionmanager.h> #include <vespa/searchcore/proton/reference/document_db_reference.h> #include <vespa/searchcore/proton/reference/gid_to_lid_change_handler.h> -#include <vespa/searchcorespi/plugin/iindexmanagerfactory.h> #include <vespa/searchlib/fef/indexproperties.h> #include <vespa/searchlib/fef/properties.h> -#include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/util/closuretask.h> #include <vespa/eval/tensor/default_tensor_engine.h> -#include <vespa/vespalib/util/exceptions.h> using vespa::config::search::RankProfilesConfig; using proton::matching::MatchingStats; @@ -30,7 +27,6 @@ using search::GrowStrategy; using search::TuneFileDocumentDB; using search::index::Schema; using search::SerialNum; -using vespalib::IllegalStateException; using vespalib::ThreadStackExecutorBase; using namespace searchcorespi; @@ -320,7 +316,7 @@ SearchableDocSubDB::getSearchableStats() const IDocumentRetriever::UP SearchableDocSubDB::getDocumentRetriever() { - return IDocumentRetriever::UP(new FastAccessDocumentRetriever(_rFeedView.get(), _rSearchView.get()->getAttributeManager())); + return std::make_unique<FastAccessDocumentRetriever>(_rFeedView.get(), _rSearchView.get()->getAttributeManager()); } MatchingStats diff --git a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp index 4f55d7fc127..646346d53ad 100644 --- a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp @@ -18,7 +18,6 @@ #include <vespa/searchcore/proton/flushengine/threadedflushtarget.h> #include <vespa/searchcore/proton/index/index_writer.h> #include <vespa/searchcore/proton/matching/sessionmanager.h> -#include <vespa/searchcore/proton/metrics/metricswireservice.h> #include <vespa/searchcore/proton/reference/dummy_gid_to_lid_change_handler.h> #include <vespa/searchlib/attribute/configconverter.h> #include <vespa/searchlib/docstore/document_store_visitor_progress.h> @@ -45,7 +44,6 @@ using proton::matching::SessionManager; using vespalib::GenericHeader; using search::common::FileHeaderContext; using proton::documentmetastore::LidReuseDelayer; -using fastos::TimeStamp; using proton::initializer::InitializerTask; using searchcorespi::IFlushTarget; @@ -87,7 +85,7 @@ StoreOnlyDocSubDB::Context::Context(IDocumentSubDBOwner &owner, _getSerialNum(getSerialNum), _fileHeaderContext(fileHeaderContext), _writeService(writeService), - _bucketDB(bucketDB), + _bucketDB(std::move(bucketDB)), _bucketDBHandlerInitializer(bucketDBHandlerInitializer), _metrics(metrics), _configMutex(configMutex), @@ -232,13 +230,13 @@ createSummaryManagerInitializer(const search::LogDocumentStore::Config & storeCf vespalib::string baseDir(_baseDir + "/summary"); return std::make_shared<SummaryManagerInitializer> (grow, baseDir, getSubDbName(), _docTypeName, _writeService.shared(), - storeCfg, tuneFile, _fileHeaderContext, _tlSyncer, bucketizer, result); + storeCfg, tuneFile, _fileHeaderContext, _tlSyncer, std::move(bucketizer), std::move(result)); } void StoreOnlyDocSubDB::setupSummaryManager(SummaryManager::SP summaryManager) { - _rSummaryMgr = summaryManager; + _rSummaryMgr = std::move(summaryManager); _iSummaryMgr = _rSummaryMgr; // Upcast allowed with std::shared_ptr _flushedDocumentStoreSerialNum = _iSummaryMgr->getBackingStore().lastSyncToken(); _summaryAdapter.reset(new SummaryAdapter(_rSummaryMgr)); @@ -317,7 +315,7 @@ StoreOnlyDocSubDB::setup(const DocumentSubDbInitializerResult &initResult) { setupDocumentMetaStore(initResult.documentMetaStore()); setupSummaryManager(initResult.summaryManager()); - _lidReuseDelayer.reset(new LidReuseDelayer(_writeService, *_dms)); + _lidReuseDelayer = std::make_unique<LidReuseDelayer>(_writeService, *_dms); updateLidReuseDelayer(initResult.lidReuseDelayerConfig()); } @@ -394,14 +392,14 @@ StoreOnlyDocSubDB::updateLidReuseDelayer(const DocumentDBConfig * newConfigSnaps void StoreOnlyDocSubDB::updateLidReuseDelayer(const LidReuseDelayerConfig &config) { - bool immediateCommit = config.visibilityDelay() == 0; + bool immediateCommit = (config.visibilityDelay() == vespalib::duration::zero()); /* * The lid reuse delayer should not have any pending lids stored at this * time, since DocumentDB::applyConfig() calls forceCommit() on the * feed view before applying the new config to the sub dbs. */ _lidReuseDelayer->setImmediateCommit(immediateCommit); - _commitTimeTracker.setVisibilityDelay(vespalib::from_s(config.visibilityDelay())); + _commitTimeTracker.setVisibilityDelay(config.visibilityDelay()); } IReprocessingTask::List diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp index 271393ea3c8..3ad98cba3ac 100644 --- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp @@ -18,9 +18,9 @@ namespace proton { void TransactionLogManager::doLogReplayComplete(const vespalib::string &domainName, - std::chrono::milliseconds elapsedTime) const + vespalib::duration elapsedTime) const { - EventLogger::transactionLogReplayComplete(domainName, elapsedTime.count()); + EventLogger::transactionLogReplayComplete(domainName, vespalib::count_ms(elapsedTime)); } diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h index 82c4f9f7449..15666c38483 100644 --- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h +++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h @@ -18,7 +18,7 @@ class TransactionLogManager : public TransactionLogManagerBase { TransLogClient::Visitor::UP _visitor; - void doLogReplayComplete(const vespalib::string &domainName, std::chrono::milliseconds elapsedTime) const override; + void doLogReplayComplete(const vespalib::string &domainName, vespalib::duration elapsedTime) const override; public: /** @@ -28,7 +28,7 @@ public: * @param domainName the name of the domain this manager should handle. **/ TransactionLogManager(const vespalib::string &tlsSpec, const vespalib::string &domainName); - ~TransactionLogManager(); + ~TransactionLogManager() override; /** * Init the transaction log. diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp index 985e042c97b..8b18a7ae566 100644 --- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp @@ -69,7 +69,7 @@ TransactionLogManagerBase::internalStartReplay() std::lock_guard<std::mutex> guard(_replayLock); _replayStarted = true; _replayDone = false; - _replayStopWatch.restart(); + _replayStopWatch = vespalib::Timer(); } void TransactionLogManagerBase::changeReplayDone() @@ -117,7 +117,7 @@ bool TransactionLogManagerBase::isDoingReplay() const { } void TransactionLogManagerBase::logReplayComplete() const { - doLogReplayComplete(_domainName, std::chrono::milliseconds(_replayStopWatch.elapsed().ms())); + doLogReplayComplete(_domainName, _replayStopWatch.elapsed()); } } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h index 8c4bc2bbfa3..4b5d001a28e 100644 --- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h +++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h @@ -3,9 +3,9 @@ #pragma once #include <vespa/searchlib/transactionlog/translogclient.h> +#include <vespa/vespalib/util/time.h> #include <mutex> #include <condition_variable> -#include <vespa/fastos/timestamp.h> namespace proton { @@ -23,7 +23,7 @@ private: mutable std::condition_variable _replayCond; volatile bool _replayDone; bool _replayStarted; - fastos::StopWatch _replayStopWatch; + vespalib::Timer _replayStopWatch; protected: typedef search::SerialNum SerialNum; @@ -38,7 +38,7 @@ protected: StatusResult init(); void internalStartReplay(); - virtual void doLogReplayComplete(const vespalib::string &domainName, std::chrono::milliseconds elapsedTime) const = 0; + virtual void doLogReplayComplete(const vespalib::string &domainName, vespalib::duration elapsedTime) const = 0; public: TransactionLogManagerBase(const TransactionLogManagerBase &) = delete; diff --git a/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.cpp b/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.cpp index 71197a5c530..58000348ecf 100644 --- a/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.cpp @@ -15,7 +15,7 @@ VisibilityHandler::VisibilityHandler(const IGetSerialNum & serial, : _serial(serial), _writeService(writeService), _feedView(feedView), - _visibilityDelay(0), + _visibilityDelay(vespalib::duration::zero()), _lastCommitSerialNum(0), _lock() { @@ -23,7 +23,7 @@ VisibilityHandler::VisibilityHandler(const IGetSerialNum & serial, void VisibilityHandler::commit() { - if (_visibilityDelay != 0) { + if (hasVisibilityDelay()) { if (_writeService.master().isCurrentThread()) { performCommit(true); } else { @@ -35,7 +35,7 @@ void VisibilityHandler::commit() void VisibilityHandler::commitAndWait() { - if (_visibilityDelay != 0) { + if (hasVisibilityDelay()) { if (_writeService.master().isCurrentThread()) { performCommit(false); } else { diff --git a/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.h b/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.h index 25add844d25..3bcdca5fc40 100644 --- a/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.h +++ b/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.h @@ -2,12 +2,11 @@ #pragma once -#include <vespa/searchcore/proton/server/ifeedview.h> -#include <vespa/searchcore/proton/server/icommitable.h> -#include <vespa/searchcore/proton/server/igetserialnum.h> +#include "ifeedview.h" +#include "icommitable.h" +#include "igetserialnum.h" #include <vespa/searchcorespi/index/ithreadingservice.h> #include <vespa/vespalib/util/varholder.h> -#include <vespa/fastos/timestamp.h> #include <mutex> namespace proton { @@ -18,7 +17,6 @@ namespace proton { **/ class VisibilityHandler : public ICommitable { - typedef fastos::TimeStamp TimeStamp; using IThreadingService = searchcorespi::index::IThreadingService; typedef vespalib::ThreadExecutor ThreadExecutor; typedef vespalib::VarHolder<IFeedView::SP> FeedViewHolder; @@ -27,17 +25,18 @@ public: VisibilityHandler(const IGetSerialNum &serial, IThreadingService &threadingService, const FeedViewHolder &feedView); - void setVisibilityDelay(TimeStamp visibilityDelay) { _visibilityDelay = visibilityDelay; } - TimeStamp getVisibilityDelay() const { return _visibilityDelay; } + void setVisibilityDelay(vespalib::duration visibilityDelay) { _visibilityDelay = visibilityDelay; } + vespalib::duration getVisibilityDelay() const { return _visibilityDelay; } + bool hasVisibilityDelay() const { return _visibilityDelay != vespalib::duration::zero(); } void commit() override; - virtual void commitAndWait() override; + void commitAndWait() override; private: bool startCommit(const std::lock_guard<std::mutex> &unused, bool force); void performCommit(bool force); const IGetSerialNum & _serial; IThreadingService & _writeService; const FeedViewHolder & _feedView; - TimeStamp _visibilityDelay; + vespalib::duration _visibilityDelay; SerialNum _lastCommitSerialNum; std::mutex _lock; }; diff --git a/searchcorespi/src/vespa/searchcorespi/index/fusionrunner.cpp b/searchcorespi/src/vespa/searchcorespi/index/fusionrunner.cpp index ca709362152..841b24af576 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/fusionrunner.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/fusionrunner.cpp @@ -107,7 +107,7 @@ FusionRunner::fuse(const FusionSpec &fusion_spec, if (LOG_WOULD_LOG(event)) { EventLogger::diskFusionStart(sources, fusion_dir); } - fastos::StopWatch stopWatch; + vespalib::Timer timer; const string selector_name = IndexDiskLayout::getSelectorFileName(_diskLayout.getFlushDir(fusion_id)); SelectorArray selector_array; @@ -124,7 +124,7 @@ FusionRunner::fuse(const FusionSpec &fusion_spec, } if (LOG_WOULD_LOG(event)) { - EventLogger::diskFusionComplete(fusion_dir, stopWatch.elapsed().ms()); + EventLogger::diskFusionComplete(fusion_dir, vespalib::count_ms(timer.elapsed())); } return fusion_id; } diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp index fc05a5bbc4c..32dc2531061 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp @@ -277,13 +277,13 @@ IndexMaintainer::loadDiskIndex(const string &indexDir) if (LOG_WOULD_LOG(event)) { EventLogger::diskIndexLoadStart(indexDir); } - fastos::StopWatch stopWatch; + vespalib::Timer timer; _active_indexes->setActive(indexDir); IDiskIndex::SP retval(new DiskIndexWithDestructorClosure (_operations.loadDiskIndex(indexDir), makeClosure(this, &IndexMaintainer::deactivateDiskIndexes, indexDir))); if (LOG_WOULD_LOG(event)) { - EventLogger::diskIndexLoadComplete(indexDir, stopWatch.elapsed().ms()); + EventLogger::diskIndexLoadComplete(indexDir, vespalib::count_ms(timer.elapsed())); } return retval; } @@ -296,7 +296,7 @@ IndexMaintainer::reloadDiskIndex(const IDiskIndex &oldIndex) if (LOG_WOULD_LOG(event)) { EventLogger::diskIndexLoadStart(indexDir); } - fastos::StopWatch stopWatch; + vespalib::Timer timer; _active_indexes->setActive(indexDir); const IDiskIndex &wrappedDiskIndex = (dynamic_cast<const DiskIndexWithDestructorClosure &>(oldIndex)).getWrapped(); @@ -304,7 +304,7 @@ IndexMaintainer::reloadDiskIndex(const IDiskIndex &oldIndex) (_operations.reloadDiskIndex(wrappedDiskIndex), makeClosure(this, &IndexMaintainer::deactivateDiskIndexes, indexDir))); if (LOG_WOULD_LOG(event)) { - EventLogger::diskIndexLoadComplete(indexDir, stopWatch.elapsed().ms()); + EventLogger::diskIndexLoadComplete(indexDir, vespalib::count_ms(timer.elapsed())); } return retval; } diff --git a/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp b/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp index 72ac28bfd8c..39f6a489908 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp @@ -12,7 +12,6 @@ LOG_SETUP(".searchcorespi.index.warmupindexcollection"); namespace searchcorespi { -using fastos::TimeStamp; using index::IDiskIndex; using search::fef::MatchDataLayout; using search::index::FieldLengthInfo; @@ -36,18 +35,18 @@ WarmupIndexCollection::WarmupIndexCollection(const WarmupConfig & warmupConfig, vespalib::SyncableThreadExecutor & executor, IWarmupDone & warmupDone) : _warmupConfig(warmupConfig), - _prev(prev), - _next(next), + _prev(std::move(prev)), + _next(std::move(next)), _warmup(warmup), _executor(executor), _warmupDone(warmupDone), _warmupEndTime(vespalib::steady_clock::now() + warmupConfig.getDuration()), _handledTerms(std::make_unique<FieldTermMap>()) { - if (next->valid()) { - setCurrentIndex(next->getCurrentIndex()); + if (_next->valid()) { + setCurrentIndex(_next->getCurrentIndex()); } else { - LOG(warning, "Next index is not valid, Dangerous !! : %s", next->toString().c_str()); + LOG(warning, "Next index is not valid, Dangerous !! : %s", _next->toString().c_str()); } LOG(debug, "For %g seconds I will warm up '%s' %s unpack.", vespalib::to_s(warmupConfig.getDuration()), typeid(_warmup).name(), warmupConfig.getUnpack() ? "with" : "without"); LOG(debug, "%s", toString().c_str()); diff --git a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp index 18bcde35020..ef55ea60c2b 100644 --- a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp +++ b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp @@ -16,7 +16,7 @@ #include <vespa/searchlib/diskindex/pagedict4file.h> #include <vespa/searchlib/diskindex/pagedict4randread.h> #include <vespa/vespalib/stllike/asciistream.h> -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> #include <openssl/sha.h> #include <vespa/fastos/app.h> #include <vespa/log/log.h> @@ -364,7 +364,7 @@ writeField(FakeWordSet &wordSet, namepref.c_str(), dynamicKStr, bool_to_str(encode_interleaved_features)); - fastos::StopWatch tv; + vespalib::Timer tv; WrappedFieldWriter ostate(namepref, dynamicK, encode_interleaved_features, wordSet.getNumWords(), docIdLimit); @@ -388,7 +388,7 @@ writeField(FakeWordSet &wordSet, namepref.c_str(), dynamicKStr, bool_to_str(encode_interleaved_features), - tv.elapsed().sec()); + vespalib::to_s(tv.elapsed())); } @@ -406,7 +406,7 @@ readField(FakeWordSet &wordSet, LOG(info, "enter readField, namepref=%s, dynamicK=%s, decode_interleaved_features=%s", namepref.c_str(), dynamicKStr, bool_to_str(decode_interleaved_features)); - fastos::StopWatch tv; + vespalib::Timer tv; istate.open(); if (istate._fieldReader->isValid()) istate._fieldReader->read(); @@ -432,7 +432,7 @@ readField(FakeWordSet &wordSet, LOG(info, "leave readField, namepref=%s, dynamicK=%s, decode_interleaved_features=%s elapsed=%10.6f", namepref.c_str(), dynamicKStr, bool_to_str(decode_interleaved_features), - tv.elapsed().sec()); + vespalib::to_s(tv.elapsed())); } @@ -450,13 +450,12 @@ randReadField(FakeWordSet &wordSet, LOG(info, "enter randReadField, namepref=%s, dynamicK=%s, decode_interleaved_features=%s", namepref.c_str(), dynamicKStr, bool_to_str(decode_interleaved_features)); - fastos::StopWatch tv; + vespalib::Timer tv; std::string cname = dirprefix + namepref; cname += "dictionary"; - std::unique_ptr<search::index::DictionaryFileRandRead> dictFile; - dictFile.reset(new PageDict4RandRead); + auto dictFile = std::make_unique<PageDict4RandRead>(); search::index::PostingListFileRandRead *postingFile = nullptr; if (dynamicK) @@ -529,7 +528,7 @@ randReadField(FakeWordSet &wordSet, namepref.c_str(), dynamicKStr, bool_to_str(decode_interleaved_features), - tv.elapsed().sec()); + vespalib::to_s(tv.elapsed())); } @@ -558,7 +557,7 @@ fusionField(uint32_t numWordIds, WrappedFieldWriter ostate(opref, dynamicK, encode_interleaved_features, numWordIds, docIdLimit); WrappedFieldReader istate(ipref, numWordIds, docIdLimit); - fastos::StopWatch tv; + vespalib::Timer tv; ostate.open(); istate.open(); @@ -587,7 +586,7 @@ fusionField(uint32_t numWordIds, opref.c_str(), rawStr, dynamicKStr, bool_to_str(encode_interleaved_features), - tv.elapsed().sec()); + vespalib::to_s(tv.elapsed())); } diff --git a/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp b/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp index bed5d656b93..419b5261510 100644 --- a/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp +++ b/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp @@ -1,12 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/testapp.h> - -#include <iomanip> -#include <iostream> #include <vespa/searchlib/fef/matchdatalayout.h> #include <vespa/searchlib/fef/phrasesplitter.h> #include <vespa/searchlib/fef/test/queryenvironment.h> -#include <vespa/fastos/timestamp.h> +#include <iomanip> +#include <iostream> #include <vespa/log/log.h> LOG_SETUP("phrasesplitter_test"); @@ -16,10 +14,10 @@ namespace search::fef { class Benchmark : public vespalib::TestApp { private: - fastos::StopWatch _timer; - fastos::TimeStamp _sample; + vespalib::Timer _timer; + vespalib::duration _sample; - void start() { _timer.restart(); } + void start() { _timer = vespalib::Timer(); } void sample() { _sample = _timer.elapsed(); } void run(size_t numRuns, size_t numPositions); @@ -74,8 +72,8 @@ Benchmark::Main() run(numRuns, numPositions); - std::cout << "TET: " << _sample.ms() << " (ms)" << std::endl; - std::cout << "ETPD: " << std::fixed << std::setprecision(10) << _sample.ms() / numRuns << " (ms)" << std::endl; + std::cout << "TET: " << vespalib::count_ms(_sample) << " (ms)" << std::endl; + std::cout << "ETPD: " << std::fixed << std::setprecision(10) << (vespalib::count_ns(_sample) / (numRuns * 1000000.0)) << " (ms)" << std::endl; TEST_DONE(); } diff --git a/searchlib/src/tests/grouping/grouping_test.cpp b/searchlib/src/tests/grouping/grouping_test.cpp index 237c8035b86..94d3afd619b 100644 --- a/searchlib/src/tests/grouping/grouping_test.cpp +++ b/searchlib/src/tests/grouping/grouping_test.cpp @@ -1896,11 +1896,11 @@ Test::testNanSorting() EXPECT_FALSE(0.2 < myNan); EXPECT_FALSE(0.2 > myNan); - fastos::StopWatch timer; + vespalib::Timer timer; std::vector<double> groups; - while (timer.elapsed().ms() < 60000.0) { + while (timer.elapsed() < 60s) { std::vector<double> vec; - srand((unsigned int)timer.elapsed().us()); + srand((unsigned int)count_us(timer.elapsed())); size_t limit = 2345678; size_t mod = rand() % limit; for (size_t i = 0; i < limit; i++) { diff --git a/searchlib/src/tests/groupingengine/groupingengine_test.cpp b/searchlib/src/tests/groupingengine/groupingengine_test.cpp index 11a661a743e..d0e2d749d08 100644 --- a/searchlib/src/tests/groupingengine/groupingengine_test.cpp +++ b/searchlib/src/tests/groupingengine/groupingengine_test.cpp @@ -1894,7 +1894,7 @@ Test::testNanSorting() EXPECT_FALSE(0.2 < myNan); EXPECT_FALSE(0.2 > myNan); - fastos::StopWatch timer; + vespalib::Timer timer; std::vector<double> groups; while (timer.elapsed().ms()() < 60000.0) { std::vector<double> vec; diff --git a/searchlib/src/tests/postinglistbm/stress_runner.cpp b/searchlib/src/tests/postinglistbm/stress_runner.cpp index 100a4fcd70d..9c78515a03f 100644 --- a/searchlib/src/tests/postinglistbm/stress_runner.cpp +++ b/searchlib/src/tests/postinglistbm/stress_runner.cpp @@ -232,7 +232,7 @@ StressMaster::makePostingsHelper(FPFactory *postingFactory, const std::string &postingFormat, bool validate, bool verbose) { - fastos::StopWatch tv; + vespalib::Timer tv; postingFactory->setup(_wordSet); for (size_t i = 0; i < _wordSet.words().size(); ++i) @@ -244,7 +244,7 @@ StressMaster::makePostingsHelper(FPFactory *postingFactory, LOG(info, "StressMaster::makePostingsHelper() elapsed %10.6f s for %s format", - tv.elapsed().sec(), + vespalib::to_s(tv.elapsed()), postingFormat.c_str()); } @@ -314,7 +314,7 @@ StressMaster::run() double StressMaster::runWorkers(const std::string &postingFormat) { - fastos::StopWatch tv; + vespalib::Timer tv; uint32_t numWorkers = 8; for (uint32_t i = 0; i < numWorkers; ++i) { @@ -340,11 +340,11 @@ StressMaster::runWorkers(const std::string &postingFormat) LOG(info, "StressMaster::run() elapsed %10.6f s for workers %s format", - tv.elapsed().sec(), + vespalib::to_s(tv.elapsed()), postingFormat.c_str()); _workers.clear(); _workersDone = 0; - return tv.elapsed().sec(); + return vespalib::to_s(tv.elapsed()); } StressWorker::StressWorker(StressMaster& master, uint32_t id) diff --git a/searchlib/src/tests/transactionlogstress/translogstress.cpp b/searchlib/src/tests/transactionlogstress/translogstress.cpp index 2ec193cfe45..a0e4b4884a9 100644 --- a/searchlib/src/tests/transactionlogstress/translogstress.cpp +++ b/searchlib/src/tests/transactionlogstress/translogstress.cpp @@ -7,7 +7,6 @@ #include <vespa/searchlib/util/runnable.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/fastos/app.h> -#include <vespa/fastos/timestamp.h> #include <iostream> #include <stdexcept> #include <sstream> @@ -202,7 +201,7 @@ private: Packet _packet; SerialNum _current; SerialNum _lastCommited; - fastos::StopWatch _timer; + vespalib::Timer _timer; void commitPacket(); bool addEntry(const Packet::Entry & e); @@ -254,7 +253,7 @@ FeederThread::doRun() while (!_done) { if (_feedRate != 0) { - _timer.restart(); + _timer = vespalib::Timer(); for (uint32_t i = 0; i < _feedRate; ++i) { Packet::Entry entry = _generator.getRandomEntry(_current++); if (!addEntry(entry)) { @@ -267,10 +266,9 @@ FeederThread::doRun() } commitPacket(); - int64_t milliSecsUsed = _timer.elapsed().ms(); - if (milliSecsUsed < 1000) { + if (_timer.elapsed() < 1s) { //LOG(info, "FeederThread: sleep %u ms", 1000 - milliSecsUsed); - std::this_thread::sleep_for(std::chrono::milliseconds(1000 - milliSecsUsed)); + std::this_thread::sleep_for(1s - _timer.elapsed()); } else { LOG(info, "FeederThread: max throughput"); } @@ -460,9 +458,9 @@ private: EntryGenerator _generator; std::vector<std::shared_ptr<VisitorAgent> > _visitors; std::vector<std::shared_ptr<VisitorAgent> > _rndVisitors; - vespalib::duration _visitorInterval; // in milliseconds - int64_t _pruneInterval; // in milliseconds - fastos::StopWatch _pruneTimer; + vespalib::duration _visitorInterval; + vespalib::duration _pruneInterval; + vespalib::Timer _pruneTimer; SerialNum _begin; SerialNum _end; size_t _count; @@ -472,7 +470,7 @@ private: public: ControllerThread(const std::string & tlsSpec, const std::string & domain, const EntryGenerator & generator, - uint32_t numVisitors, uint64_t visitorInterval, uint64_t pruneInterval); + uint32_t numVisitors, vespalib::duration visitorInterval, vespalib::duration pruneInterval); ~ControllerThread(); uint32_t runningVisitors(); std::vector<std::shared_ptr<VisitorAgent> > & getVisitors() { return _visitors; } @@ -482,9 +480,9 @@ public: ControllerThread::ControllerThread(const std::string & tlsSpec, const std::string & domain, const EntryGenerator & generator, uint32_t numVisitors, - uint64_t visitorInterval, uint64_t pruneInterval) + vespalib::duration visitorInterval, vespalib::duration pruneInterval) : _tlsSpec(tlsSpec), _domain(domain), _client(tlsSpec.c_str()), _session(), - _generator(generator), _visitors(), _rndVisitors(), _visitorInterval(std::chrono::milliseconds(visitorInterval)), + _generator(generator), _visitors(), _rndVisitors(), _visitorInterval(visitorInterval), _pruneInterval(pruneInterval), _pruneTimer(), _begin(0), _end(0), _count(0) { for (uint32_t i = 0; i < numVisitors; ++i) { @@ -521,7 +519,7 @@ ControllerThread::doRun() throw std::runtime_error(vespalib::make_string("ControllerThread: Could not open session to %s", _tlsSpec.c_str())); } - _pruneTimer.restart(); + _pruneTimer = vespalib::Timer(); while (!_done) { // set finished visitors as idle for (size_t i = 0; i < _visitors.size(); ++i) { @@ -541,7 +539,7 @@ ControllerThread::doRun() } } // prune transaction log server - if (_pruneTimer.elapsed().ms() > _pruneInterval) { + if (_pruneTimer.elapsed() > _pruneInterval) { getStatus(); SerialNum safePrune = _end; for (size_t i = 0; i < _visitors.size(); ++i) { @@ -554,7 +552,7 @@ ControllerThread::doRun() if (!_session->erase(safePrune)) { throw std::runtime_error(vespalib::make_string("ControllerThread: Could not erase up to %" PRIu64, safePrune)); } - _pruneTimer.restart(); + _pruneTimer = vespalib::Timer(); } std::this_thread::sleep_for(_visitorInterval); } @@ -575,8 +573,8 @@ private: std::chrono::milliseconds stressTime; uint32_t feedRate; uint32_t numVisitors; - uint64_t visitorInterval; - uint64_t pruneInterval; + vespalib::duration visitorInterval; + vespalib::duration pruneInterval; uint32_t numPreGeneratedBuffers; uint32_t minStrLen; @@ -604,8 +602,8 @@ TransLogStress::printConfig() std::cout << "stressTime: " << vespalib::to_s(_cfg.stressTime) << " s" << std::endl; std::cout << "feedRate: " << _cfg.feedRate << " per/sec" << std::endl; std::cout << "numVisitors: " << _cfg.numVisitors << std::endl; - std::cout << "visitorInterval: " << _cfg.visitorInterval << " ms" << std::endl; - std::cout << "pruneInterval: " << _cfg.pruneInterval / 1000 << " s" << std::endl; + std::cout << "visitorInterval: " << vespalib::count_ms(_cfg.visitorInterval) << " ms" << std::endl; + std::cout << "pruneInterval: " << vespalib::to_s(_cfg.pruneInterval) << " s" << std::endl; std::cout << "numPreGeneratedBuffers: " << _cfg.numPreGeneratedBuffers << std::endl; std::cout << "minStrLen: " << _cfg.minStrLen << std::endl; std::cout << "maxStrLen: " << _cfg.maxStrLen << std::endl; @@ -631,11 +629,11 @@ TransLogStress::Main() _cfg.domainPartSize = 8000000; // ~8MB _cfg.packetSize = 0x10000; - _cfg.stressTime = std::chrono::milliseconds(1000 * 60); + _cfg.stressTime = 60s; _cfg.feedRate = 10000; _cfg.numVisitors = 1; - _cfg.visitorInterval = 1000 * 1; - _cfg.pruneInterval = 1000 * 12; + _cfg.visitorInterval = 1s; + _cfg.pruneInterval = 12s; _cfg.numPreGeneratedBuffers = 0; _cfg.minStrLen = 40; @@ -666,10 +664,10 @@ TransLogStress::Main() _cfg.numVisitors = atoi(arg); break; case 'c': - _cfg.visitorInterval = atol(arg); + _cfg.visitorInterval = std::chrono::milliseconds(atol(arg)); break; case 'e': - _cfg.pruneInterval = 1000 * atol(arg); + _cfg.pruneInterval = vespalib::from_s(atol(arg)); break; case 'g': _cfg.numPreGeneratedBuffers = atoi(arg); diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.h b/searchlib/src/vespa/searchlib/docstore/filechunk.h index 5e3723c9522..0f139f507c6 100644 --- a/searchlib/src/vespa/searchlib/docstore/filechunk.h +++ b/searchlib/src/vespa/searchlib/docstore/filechunk.h @@ -13,7 +13,6 @@ #include <vespa/vespalib/stllike/hash_map.h> #include <vespa/vespalib/util/generationhandler.h> #include <vespa/vespalib/util/time.h> -#include <vespa/fastos/timestamp.h> class FastOS_FileInterface; diff --git a/searchlib/src/vespa/searchlib/docstore/idatastore.h b/searchlib/src/vespa/searchlib/docstore/idatastore.h index 2ca693dde95..75e1bd2a5e1 100644 --- a/searchlib/src/vespa/searchlib/docstore/idatastore.h +++ b/searchlib/src/vespa/searchlib/docstore/idatastore.h @@ -3,7 +3,6 @@ #pragma once #include "data_store_file_chunk_stats.h" -#include <vespa/fastos/timestamp.h> #include <vespa/searchlib/common/i_compactable_lid_space.h> #include <vespa/vespalib/stllike/string.h> #include <vespa/vespalib/util/memoryusage.h> diff --git a/searchlib/src/vespa/searchlib/engine/trace.cpp b/searchlib/src/vespa/searchlib/engine/trace.cpp index 95d6c967369..2264685ca13 100644 --- a/searchlib/src/vespa/searchlib/engine/trace.cpp +++ b/searchlib/src/vespa/searchlib/engine/trace.cpp @@ -2,7 +2,6 @@ #include "trace.h" #include <vespa/vespalib/data/slime/slime.h> -#include <vespa/fastos/timestamp.h> namespace search::engine { @@ -39,10 +38,11 @@ Trace::Trace(const RelativeTime & relativeTime, uint32_t level) void Trace::start(int level, bool useUTC) { if (shouldTrace(level) && !hasTrace()) { - vespalib::duration since_epoch = useUTC - ? vespalib::to_utc(_relativeTime.timeOfDawn()).time_since_epoch() - : _relativeTime.timeOfDawn().time_since_epoch(); - root().setString("start_time", fastos::TimeStamp::asString(vespalib::to_s(since_epoch))); + if (useUTC) { + root().setString("start_time", vespalib::to_string(vespalib::to_utc(_relativeTime.timeOfDawn()))); + } else { + root().setString("start_time", vespalib::to_string(vespalib::system_time(_relativeTime.timeOfDawn().time_since_epoch()))); + } } } diff --git a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp index c51cd444b54..aa1fdd249a7 100644 --- a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp +++ b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp @@ -1,6 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "debugwaitfunctionnode.h" -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> namespace search::expression { @@ -30,7 +30,7 @@ using std::chrono::microseconds; bool DebugWaitFunctionNode::onExecute() const { - fastos::StopWatch::waitAtLeast(microseconds(long(_waitTime * 1000000)), _busyWait); + vespalib::Timer::waitAtLeast(vespalib::from_s(_waitTime), _busyWait); getArg().execute(); updateResult().assign(getArg().getResult()); diff --git a/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp b/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp index ff4ca91beb9..4776437a14b 100644 --- a/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp @@ -30,7 +30,7 @@ bool hasAttribute(const IQueryEnvironment &env, const ITermData &term_data) for (FRA iter(term_data); iter.valid(); iter.next()) { const FieldInfo *info = env.getIndexEnvironment().getField(iter.get().getFieldId()); - if (info != 0 && info->type() == FieldType::ATTRIBUTE) { + if (info != nullptr && info->type() == FieldType::ATTRIBUTE) { return true; } } @@ -38,8 +38,7 @@ bool hasAttribute(const IQueryEnvironment &env, const ITermData &term_data) } } // namespace -namespace search { -namespace features { +namespace search::features { template <typename T> AttributeMatchExecutor<T>::Computer::Computer(const IQueryEnvironment & env, AttributeMatchParams params) : @@ -70,7 +69,7 @@ AttributeMatchExecutor<T>::Computer::Computer(const IQueryEnvironment & env, Att _numAttrTerms++; _totalAttrTermWeight += qt.termData()->getWeight().percent(); const ITermFieldData *field = qt.termData()->lookupField(_params.attrInfo->id()); - if (field != 0) { + if (field != nullptr) { qt.fieldHandle(field->getHandle()); _queryTerms.push_back(qt); } @@ -338,7 +337,7 @@ FeatureExecutor & AttributeMatchBlueprint::createExecutor(const IQueryEnvironment & env, vespalib::Stash &stash) const { const IAttributeVector * attribute = env.getAttributeContext().getAttribute(_params.attrInfo->name()); - if (attribute == NULL) { + if (attribute == nullptr) { LOG(error, "The attribute vector '%s' was not found in the attribute manager.", _params.attrInfo->name().c_str()); std::vector<feature_t> values; values.push_back(0.0); // completeness @@ -368,6 +367,4 @@ AttributeMatchBlueprint::createExecutor(const IQueryEnvironment & env, vespalib: } } - -} // namespace features -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/features/attributematchfeature.h b/searchlib/src/vespa/searchlib/features/attributematchfeature.h index 2946521c9f0..4566a417e47 100644 --- a/searchlib/src/vespa/searchlib/features/attributematchfeature.h +++ b/searchlib/src/vespa/searchlib/features/attributematchfeature.h @@ -9,7 +9,7 @@ namespace search::features { struct AttributeMatchParams { AttributeMatchParams() : - attrInfo(NULL), attribute(NULL), weightedSet(false), maxWeight(256), fieldCompletenessImportance(0.05f) {} + attrInfo(nullptr), attribute(nullptr), weightedSet(false), maxWeight(256), fieldCompletenessImportance(0.05f) {} const fef::FieldInfo * attrInfo; const attribute::IAttributeVector * attribute; bool weightedSet; diff --git a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp index 975f510cd22..86a71184f43 100644 --- a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp +++ b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp @@ -1,11 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "debug_attribute_wait.h" -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> using search::attribute::IAttributeVector; using namespace search::fef; -using namespace std::chrono; namespace search::features { @@ -42,9 +41,9 @@ DebugAttributeWaitExecutor::execute(uint32_t docId) _buf.fill(*_attribute, docId); waitTime = _buf[0]; } - fastos::StopWatch timer; - fastos::StopWatch::waitAtLeast(microseconds(long(waitTime * 1000000)), _params.busyWait); - outputs().set_number(0, timer.elapsed().sec()); + vespalib::Timer timer; + vespalib::Timer::waitAtLeast(vespalib::from_s(waitTime), _params.busyWait); + outputs().set_number(0, vespalib::to_s(timer.elapsed())); } //----------------------------------------------------------------------------- diff --git a/searchlib/src/vespa/searchlib/features/debug_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_wait.cpp index 79ba1678b2b..fb002564572 100644 --- a/searchlib/src/vespa/searchlib/features/debug_wait.cpp +++ b/searchlib/src/vespa/searchlib/features/debug_wait.cpp @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "debug_wait.h" -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> using namespace search::fef; @@ -29,9 +29,9 @@ using namespace std::chrono; void DebugWaitExecutor::execute(uint32_t) { - fastos::StopWatch timer; - fastos::StopWatch::waitAtLeast(microseconds(long(_params.waitTime * 1000000)), _params.busyWait); - outputs().set_number(0, timer.elapsed().sec()); + vespalib::Timer timer; + vespalib::Timer::waitAtLeast(vespalib::from_s(_params.waitTime), _params.busyWait); + outputs().set_number(0, vespalib::to_s(timer.elapsed())); } //----------------------------------------------------------------------------- diff --git a/searchlib/src/vespa/searchlib/features/queryterm.cpp b/searchlib/src/vespa/searchlib/features/queryterm.cpp index 84423493eb5..a6b1a6a8f2a 100644 --- a/searchlib/src/vespa/searchlib/features/queryterm.cpp +++ b/searchlib/src/vespa/searchlib/features/queryterm.cpp @@ -9,7 +9,7 @@ using search::feature_t; namespace search::features { QueryTerm::QueryTerm() : - _termData(NULL), + _termData(nullptr), _handle(IllegalHandle), _significance(0), _connectedness(0) diff --git a/searchlib/src/vespa/searchlib/test/fakedata/fake_match_loop.cpp b/searchlib/src/vespa/searchlib/test/fakedata/fake_match_loop.cpp index 1b7f794826d..bd55acbed9e 100644 --- a/searchlib/src/vespa/searchlib/test/fakedata/fake_match_loop.cpp +++ b/searchlib/src/vespa/searchlib/test/fakedata/fake_match_loop.cpp @@ -2,7 +2,6 @@ #include "fake_match_loop.h" #include "fakeposting.h" -#include <vespa/fastos/timestamp.h> #include <vespa/searchlib/fef/termfieldmatchdataarray.h> #include <vespa/searchlib/queryeval/andsearch.h> #include <vespa/searchlib/queryeval/orsearch.h> diff --git a/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp b/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp index 1eec8261bf8..ba691e507fa 100644 --- a/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp +++ b/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp @@ -2,7 +2,7 @@ #include "fakewordset.h" #include "fakeword.h" -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> #include <vespa/searchlib/bitcompression/posocc_fields_params.h> #include <sstream> @@ -99,7 +99,7 @@ FakeWordSet::setupWords(search::Rand48 &rnd, _numDocs = numDocs; LOG(info, "enter setupWords"); - fastos::StopWatch tv; + vespalib::Timer tv; uint32_t packedIndex = _fieldsParams.size() - 1; for (uint32_t i = 0; i < numWordsPerWordClass; ++i) { @@ -122,7 +122,7 @@ FakeWordSet::setupWords(search::Rand48 &rnd, packedIndex)); } - LOG(info, "leave setupWords, elapsed %10.6f s", tv.elapsed().sec()); + LOG(info, "leave setupWords, elapsed %10.6f s", vespalib::to_s(tv.elapsed())); } int diff --git a/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp b/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp index 2cb546395d3..e6133496398 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp @@ -2,8 +2,8 @@ #include "trans_log_server_explorer.h" #include <vespa/vespalib/data/slime/slime.h> +#include <vespa/vespalib/util/time.h> #include <vespa/fastos/file.h> -#include <vespa/fastos/timestamp.h> using vespalib::slime::Inserter; @@ -16,7 +16,7 @@ namespace { struct DomainExplorer : vespalib::StateExplorer { Domain::SP domain; DomainExplorer(Domain::SP domain_in) : domain(std::move(domain_in)) {} - virtual void get_state(const Inserter &inserter, bool full) const override { + void get_state(const Inserter &inserter, bool full) const override { Cursor &state = inserter.insertObject(); DomainInfo info = domain->getDomainInfo(); state.setLong("from", info.range.from()); @@ -35,7 +35,7 @@ struct DomainExplorer : vespalib::StateExplorer { { FastOS_StatInfo stat_info; FastOS_File::Stat(part_in.file.c_str(), &stat_info); - part.setString("lastModified", fastos::TimeStamp::asString(stat_info._modifiedTime)); + part.setString("lastModified", vespalib::to_string(vespalib::system_time(std::chrono::nanoseconds(stat_info._modifiedTimeNS)))); } } } diff --git a/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp b/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp index 5d1025c6de2..9b2510ac3df 100644 --- a/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp +++ b/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp @@ -3,7 +3,7 @@ #include "extractkeywordstest.h" #include <vespa/searchsummary/docsummary/keywordextractor.h> #include <vespa/searchlib/parsequery/simplequerystack.h> -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> #define NUMTESTS 5 @@ -97,7 +97,7 @@ ExtractKeywordsTest::Main() _extractor = new search::docsummary::KeywordExtractor(nullptr); _extractor->AddLegalIndexSpec("*"); - fastos::StopWatch timer; + vespalib::Timer timer; // Actually run the tests that we wanted. for (int j = 0; j < multiplier; j++) @@ -109,7 +109,7 @@ ExtractKeywordsTest::Main() } // Print time taken - double timeTaken = timer.elapsed().ms(); + double timeTaken = vespalib::to_s(timer.elapsed())*1000.0; printf("Time taken : %f ms\n", timeTaken); printf("Number of tests run: %d\n", testCnt); diff --git a/staging_vespalib/src/tests/benchmark/testbase.cpp b/staging_vespalib/src/tests/benchmark/testbase.cpp index eb714039ef5..ff83d1ee9d8 100644 --- a/staging_vespalib/src/tests/benchmark/testbase.cpp +++ b/staging_vespalib/src/tests/benchmark/testbase.cpp @@ -1,12 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "testbase.h" -#include <vespa/fastos/timestamp.h> #include <vespa/vespalib/util/time.h> #include <cassert> #include <vespa/log/log.h> LOG_SETUP(".testbase"); +using namespace std::chrono; + namespace vespalib { IMPLEMENT_IDENTIFIABLE_ABSTRACT_NS(vespalib, Benchmark, Identifiable); @@ -180,13 +181,13 @@ size_t ClockREALTIME::onRun() int foo = clock_gettime(CLOCK_REALTIME, &ts); assert(foo == 0); (void) foo; - fastos::TimeStamp start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); - fastos::TimeStamp end(start); + nanoseconds start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); + nanoseconds end(start); for (size_t i=0; i < 1000; i++) { clock_gettime(CLOCK_REALTIME, &ts); - end = ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec; + end = nanoseconds(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); } - return (start - end).ns(); + return count_ns(start - end); } size_t ClockMONOTONIC::onRun() @@ -195,13 +196,13 @@ size_t ClockMONOTONIC::onRun() int foo = clock_gettime(CLOCK_MONOTONIC, &ts); assert(foo == 0); (void) foo; - fastos::TimeStamp start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); - fastos::TimeStamp end(start); + nanoseconds start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); + nanoseconds end(start); for (size_t i=0; i < 1000; i++) { clock_gettime(CLOCK_MONOTONIC, &ts); - end = ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec; + end = nanoseconds(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); } - return (start - end).ns(); + return count_ns(start - end);; } ClockMONOTONIC_RAW::ClockMONOTONIC_RAW() @@ -221,13 +222,13 @@ size_t ClockMONOTONIC_RAW::onRun() int foo = clock_gettime(CLOCK_MONOTONIC_RAW, &ts); assert(foo == 0); (void) foo; - fastos::TimeStamp start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); - fastos::TimeStamp end(start); + nanoseconds start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); + nanoseconds end(start); for (size_t i=0; i < 1000; i++) { clock_gettime(CLOCK_MONOTONIC_RAW, &ts); - end = ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec; + end = nanoseconds(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); } - return (start - end).ns(); + return count_ns(start - end); } size_t ClockPROCESS_CPUTIME_ID::onRun() @@ -236,13 +237,13 @@ size_t ClockPROCESS_CPUTIME_ID::onRun() int foo = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts); assert(foo == 0); (void) foo; - fastos::TimeStamp start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); - fastos::TimeStamp end(start); + nanoseconds start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); + nanoseconds end(start); for (size_t i=0; i < 1000; i++) { clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts); - end = ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec; + end =nanoseconds(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); } - return (start - end).ns(); + return count_ns(start - end); } size_t ClockTHREAD_CPUTIME_ID::onRun() @@ -251,13 +252,13 @@ size_t ClockTHREAD_CPUTIME_ID::onRun() int foo = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); assert(foo == 0); (void) foo; - fastos::TimeStamp start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); - fastos::TimeStamp end(start); + nanoseconds start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); + nanoseconds end(start); for (size_t i=0; i < 1000; i++) { clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); - end = ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec; + end = nanoseconds(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); } - return (start - end).ns(); + return count_ns(start - end); } size_t CreateVespalibString::onRun() diff --git a/staging_vespalib/src/tests/timer/timer_test.cpp b/staging_vespalib/src/tests/timer/timer_test.cpp index 5472ad6e23f..04b541e75e9 100644 --- a/staging_vespalib/src/tests/timer/timer_test.cpp +++ b/staging_vespalib/src/tests/timer/timer_test.cpp @@ -37,8 +37,8 @@ void Test::testScheduling() vespalib::CountDownLatch latch1(3); vespalib::CountDownLatch latch2(2); ScheduledExecutor timer; - timer.scheduleAtFixedRate(Task::UP(new TestTask(latch1)), 0.1, 0.2); - timer.scheduleAtFixedRate(Task::UP(new TestTask(latch2)), 0.5, 0.5); + timer.scheduleAtFixedRate(Task::UP(new TestTask(latch1)), 100ms, 200ms); + timer.scheduleAtFixedRate(Task::UP(new TestTask(latch2)), 500ms, 500ms); EXPECT_TRUE(latch1.await(60000)); EXPECT_TRUE(latch2.await(60000)); } @@ -47,10 +47,10 @@ void Test::testReset() { vespalib::CountDownLatch latch1(2); ScheduledExecutor timer; - timer.scheduleAtFixedRate(Task::UP(new TestTask(latch1)), 2.0, 3.0); + timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch1), 2s, 3s); timer.reset(); EXPECT_TRUE(!latch1.await(3000)); - timer.scheduleAtFixedRate(Task::UP(new TestTask(latch1)), 0.2, 0.3); + timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch1), 200ms, 300ms); EXPECT_TRUE(latch1.await(60000)); } diff --git a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp index 61f9666114c..d9b4feda293 100644 --- a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp @@ -16,9 +16,9 @@ private: FNET_Scheduler *_scheduler; Task::UP _task; - double _interval; + duration _interval; public: - TimerTask(FNET_Scheduler *scheduler, Task::UP task, double interval) + TimerTask(FNET_Scheduler *scheduler, Task::UP task, duration interval) : FNET_Task(scheduler), _task(std::move(task)), _interval(interval) @@ -30,7 +30,7 @@ public: void PerformTask() override { _task->run(); - Schedule(_interval); + Schedule(to_s(_interval)); } }; @@ -53,12 +53,12 @@ ScheduledExecutor::~ScheduledExecutor() void -ScheduledExecutor::scheduleAtFixedRate(vespalib::Executor::Task::UP task, double delay, double interval) +ScheduledExecutor::scheduleAtFixedRate(vespalib::Executor::Task::UP task, duration delay, duration interval) { vespalib::LockGuard guard(_lock); TimerTaskPtr tTask(new TimerTask(_transport->GetScheduler(), std::move(task), interval)); _taskList.push_back(std::move(tTask)); - _taskList.back()->Schedule(delay); + _taskList.back()->Schedule(to_s(delay)); } void diff --git a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h index d7e56494828..0f052c762a7 100644 --- a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h +++ b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h @@ -3,6 +3,7 @@ #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/util/sync.h> +#include <vespa/vespalib/util/time.h> #include <vespa/fastos/thread.h> #include <vector> @@ -46,7 +47,7 @@ public: * @param delay The delay to wait before first execution. * @param interval The interval in seconds. */ - void scheduleAtFixedRate(vespalib::Executor::Task::UP task, double delay, double interval); + void scheduleAtFixedRate(vespalib::Executor::Task::UP task, duration delay, duration interval); /** * Reset timer, clearing the list of task to execute. diff --git a/storage/src/tests/distributor/garbagecollectiontest.cpp b/storage/src/tests/distributor/garbagecollectiontest.cpp index 88281f3ca20..65c1ac726b5 100644 --- a/storage/src/tests/distributor/garbagecollectiontest.cpp +++ b/storage/src/tests/distributor/garbagecollectiontest.cpp @@ -18,7 +18,7 @@ struct GarbageCollectionOperationTest : Test, DistributorTestUtil { createLinks(); enableDistributorClusterState("distributor:1 storage:2"); addNodesToBucketDB(document::BucketId(16, 1), "0=250/50/300,1=250/50/300"); - getConfig().setGarbageCollection("music.date < 34", 3600); + getConfig().setGarbageCollection("music.date < 34", 3600s); getClock().setAbsoluteTimeInSeconds(34); }; diff --git a/storage/src/tests/distributor/statecheckerstest.cpp b/storage/src/tests/distributor/statecheckerstest.cpp index 0c1ec1e77de..01c4ad1cf6a 100644 --- a/storage/src/tests/distributor/statecheckerstest.cpp +++ b/storage/src/tests/distributor/statecheckerstest.cpp @@ -1242,8 +1242,8 @@ std::string StateCheckersTest::testGarbageCollection( getBucketDatabase().update(e); GarbageCollectionStateChecker checker; - getConfig().setGarbageCollection("music", checkInterval); - getConfig().setLastGarbageCollectionChangeTime(lastChangeTime); + getConfig().setGarbageCollection("music", std::chrono::seconds(checkInterval)); + getConfig().setLastGarbageCollectionChangeTime(vespalib::steady_time(std::chrono::seconds(lastChangeTime))); NodeMaintenanceStatsTracker statsTracker; StateChecker::Context c(getExternalOperationHandler(), getDistributorBucketSpace(), statsTracker, makeDocumentBucket(e.getBucketId())); @@ -1315,8 +1315,8 @@ TEST_F(StateCheckersTest, gc_inhibited_when_ideal_node_in_maintenance) { getBucketDatabase().update(e); GarbageCollectionStateChecker checker; - getConfig().setGarbageCollection("music", 3600); - getConfig().setLastGarbageCollectionChangeTime(0); + getConfig().setGarbageCollection("music", 3600s); + getConfig().setLastGarbageCollectionChangeTime(vespalib::steady_time(vespalib::duration::zero())); NodeMaintenanceStatsTracker statsTracker; StateChecker::Context c(getExternalOperationHandler(), getDistributorBucketSpace(), statsTracker, makeDocumentBucket(bucket)); diff --git a/storage/src/vespa/storage/bucketdb/bucketinfo.h b/storage/src/vespa/storage/bucketdb/bucketinfo.h index f0be700d204..9616a1fae6e 100644 --- a/storage/src/vespa/storage/bucketdb/bucketinfo.h +++ b/storage/src/vespa/storage/bucketdb/bucketinfo.h @@ -3,12 +3,11 @@ #include "bucketcopy.h" #include <vespa/vespalib/util/arrayref.h> +#include <vespa/vespalib/util/time.h> namespace storage { -namespace distributor { - class DistributorTestUtil; -} +namespace distributor { class DistributorTestUtil; } enum class TrustedUpdate { UPDATE, @@ -190,10 +189,6 @@ public: */ bool removeNode(uint16_t node, TrustedUpdate update = TrustedUpdate::UPDATE); - void clearTrusted(uint16_t nodeIdx) { - getNodeInternal(nodeIdx)->clearTrusted(); - } - /** Clears all nodes from the bucket information. */ @@ -207,10 +202,6 @@ private: */ BucketCopy* getNodeInternal(uint16_t node); - const BucketCopy& getNodeRefInternal(uint16_t idx) const { - return _nodes[idx]; - } - void addNodeManual(const BucketCopy& newCopy) { _nodes.push_back(newCopy); } }; diff --git a/storage/src/vespa/storage/config/distributorconfiguration.cpp b/storage/src/vespa/storage/config/distributorconfiguration.cpp index e89b9e6b1aa..0b8564e561a 100644 --- a/storage/src/vespa/storage/config/distributorconfiguration.cpp +++ b/storage/src/vespa/storage/config/distributorconfiguration.cpp @@ -3,7 +3,6 @@ #include <vespa/document/select/parser.h> #include <vespa/document/select/traversingvisitor.h> #include <vespa/vespalib/util/exceptions.h> -#include <vespa/fastos/timestamp.h> #include <sstream> #include <vespa/log/log.h> @@ -23,14 +22,14 @@ DistributorConfiguration::DistributorConfiguration(StorageComponent& component) _maxIdealStateOperations(100), _idealStateChunkSize(1000), _maxNodesPerMerge(16), - _lastGarbageCollectionChange(0), + _lastGarbageCollectionChange(vespalib::duration::zero()), _garbageCollectionInterval(0), _minPendingMaintenanceOps(100), _maxPendingMaintenanceOps(1000), _maxVisitorsPerNodePerClientVisitor(4), _minBucketsPerVisitor(5), _maxClusterClockSkew(0), - _inhibitMergeSendingOnBusyNodeDuration(std::chrono::seconds(60)), + _inhibitMergeSendingOnBusyNodeDuration(60s), _simulated_db_pruning_latency(0), _simulated_db_merging_latency(0), _doInlineSplit(true), @@ -122,20 +121,20 @@ DistributorConfiguration::configure(const vespa::config::content::core::StorDist _minimalBucketSplit = config.minsplitcount; _maxNodesPerMerge = config.maximumNodesPerMerge; - _garbageCollectionInterval = config.garbagecollection.interval; + _garbageCollectionInterval = std::chrono::seconds(config.garbagecollection.interval); if (containsTimeStatement(config.garbagecollection.selectiontoremove)) { // Always changes. - _lastGarbageCollectionChange = 1; + _lastGarbageCollectionChange = vespalib::steady_time::min(); } else if (_garbageCollectionSelection != config.garbagecollection.selectiontoremove) { - _lastGarbageCollectionChange = fastos::time(); + _lastGarbageCollectionChange = vespalib::steady_clock::now(); } _garbageCollectionSelection = config.garbagecollection.selectiontoremove; // Don't garbage collect with empty selection. if (_garbageCollectionSelection.empty()) { - _garbageCollectionInterval = 0; + _garbageCollectionInterval = vespalib::duration::zero(); } _blockedStateCheckers.clear(); @@ -177,7 +176,7 @@ DistributorConfiguration::configure(const vespa::config::content::core::StorDist (int)_byteCountJoinLimit, (int)_minimalBucketSplit, _garbageCollectionSelection.c_str(), - (int)_garbageCollectionInterval, + (int)vespalib::to_s(_garbageCollectionInterval), (int)_maxIdealStateOperations); } diff --git a/storage/src/vespa/storage/config/distributorconfiguration.h b/storage/src/vespa/storage/config/distributorconfiguration.h index 3cb84943508..51ac7f8dae0 100644 --- a/storage/src/vespa/storage/config/distributorconfiguration.h +++ b/storage/src/vespa/storage/config/distributorconfiguration.h @@ -1,17 +1,15 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <vespa/storage/config/config-stor-distributormanager.h> -#include <vespa/storage/config/config-stor-visitordispatcher.h> +#include "config-stor-distributormanager.h" +#include "config-stor-visitordispatcher.h" #include <vespa/vespalib/stllike/hash_set.h> #include <vespa/storage/common/storagecomponent.h> -#include <chrono> +#include <vespa/vespalib/util/time.h> namespace storage { -namespace distributor { -struct DistributorTest; -} +namespace distributor { struct DistributorTest; } class DistributorConfiguration { public: @@ -40,33 +38,22 @@ public: void configure(const DistrConfig& config); void configure(const vespa::config::content::core::StorVisitordispatcherConfig& config); - - void setIdealStateChunkSize(uint32_t chunkSize) { - _idealStateChunkSize = chunkSize; - } - - uint32_t getIdealStateChunkSize() { - return _idealStateChunkSize; - } - uint32_t lastGarbageCollectionChangeTime() const { - return _lastGarbageCollectionChange; - } const std::string& getGarbageCollectionSelection() const { return _garbageCollectionSelection; } - uint32_t getGarbageCollectionInterval() const { + vespalib::duration getGarbageCollectionInterval() const { return _garbageCollectionInterval; } - void setGarbageCollection(const std::string& selection, uint32_t interval) { + void setGarbageCollection(const std::string& selection, vespalib::duration interval) { _garbageCollectionSelection = selection; _garbageCollectionInterval = interval; } - void setLastGarbageCollectionChangeTime(uint32_t lastChangeTime) { + void setLastGarbageCollectionChangeTime(vespalib::steady_time lastChangeTime) { _lastGarbageCollectionChange = lastChangeTime; } @@ -124,20 +111,6 @@ public: */ void setMinimalBucketSplit(int splitBits) { _minimalBucketSplit = splitBits; }; - /** - Sets the maximum number of ideal state operations a distributor should - schedule to each storage node. - - @param numOps The number of operations to schedule. - */ - void setMaxIdealStateOperations(uint32_t numOps) { - _maxIdealStateOperations = numOps; - }; - - uint32_t getMaxIdealStateOperations() { - return _maxIdealStateOperations; - } - void setMaintenancePriorities(const MaintenancePriorities& mp) { _maintenancePriorities = mp; } @@ -191,13 +164,6 @@ public: return _minBucketsPerVisitor; } - void setMaxVisitorsPerNodePerClientVisitor(uint32_t n) { - _maxVisitorsPerNodePerClientVisitor = n; - } - void setMinBucketsPerVisitor(uint32_t n) { - _minBucketsPerVisitor = n; - } - uint32_t getMaxNodesPerMerge() const { return _maxNodesPerMerge; } @@ -213,9 +179,7 @@ public: } using ReplicaCountingMode = DistrConfig::MinimumReplicaCountingMode; - void setMinimumReplicaCountingMode(ReplicaCountingMode mode) noexcept { - _minimumReplicaCountingMode = mode; - } + ReplicaCountingMode getMinimumReplicaCountingMode() const noexcept { return _minimumReplicaCountingMode; } @@ -276,8 +240,8 @@ private: std::string _garbageCollectionSelection; - uint32_t _lastGarbageCollectionChange; - uint32_t _garbageCollectionInterval; + vespalib::steady_time _lastGarbageCollectionChange; + vespalib::duration _garbageCollectionInterval; uint32_t _minPendingMaintenanceOps; uint32_t _maxPendingMaintenanceOps; diff --git a/storage/src/vespa/storage/distributor/statechecker.cpp b/storage/src/vespa/storage/distributor/statechecker.cpp index f7ef1122692..2740d275732 100644 --- a/storage/src/vespa/storage/distributor/statechecker.cpp +++ b/storage/src/vespa/storage/distributor/statechecker.cpp @@ -70,8 +70,7 @@ StateChecker::Context::Context(const DistributorComponent& c, distributorConfig(c.getDistributor().getConfig()), distribution(distributorBucketSpace.getDistribution()), gcTimeCalculator(c.getDistributor().getBucketIdHasher(), - std::chrono::seconds(distributorConfig - .getGarbageCollectionInterval())), + std::chrono::duration_cast<std::chrono::seconds>(distributorConfig.getGarbageCollectionInterval())), component(c), db(distributorBucketSpace.getBucketDatabase()), stats(statsTracker) diff --git a/storage/src/vespa/storage/distributor/statecheckers.cpp b/storage/src/vespa/storage/distributor/statecheckers.cpp index dab2025bfbb..b1fa3056cb1 100644 --- a/storage/src/vespa/storage/distributor/statecheckers.cpp +++ b/storage/src/vespa/storage/distributor/statecheckers.cpp @@ -1119,7 +1119,7 @@ BucketStateStateChecker::check(StateChecker::Context& c) bool GarbageCollectionStateChecker::needsGarbageCollection(const Context& c) const { - if (c.entry->getNodeCount() == 0 || c.distributorConfig.getGarbageCollectionInterval() == 0) { + if (c.entry->getNodeCount() == 0 || c.distributorConfig.getGarbageCollectionInterval() == vespalib::duration::zero()) { return false; } if (containsMaintenanceNode(c.idealState, c)) { @@ -1147,7 +1147,7 @@ GarbageCollectionStateChecker::check(Context& c) << ", current time " << c.component.getClock().getTimeInSeconds().getTime() << ", configured interval " - << c.distributorConfig.getGarbageCollectionInterval() << "]"; + << vespalib::to_s(c.distributorConfig.getGarbageCollectionInterval()) << "]"; op->setPriority(c.distributorConfig.getMaintenancePriorities().garbageCollection); op->setDetailedReason(reason.c_str()); diff --git a/storage/src/vespa/storage/visiting/commandqueue.h b/storage/src/vespa/storage/visiting/commandqueue.h index aae13705dd3..6d9bfc1ca4f 100644 --- a/storage/src/vespa/storage/visiting/commandqueue.h +++ b/storage/src/vespa/storage/visiting/commandqueue.h @@ -17,7 +17,6 @@ #include <boost/multi_index/sequenced_index.hpp> #include <vespa/vespalib/util/printable.h> #include <vespa/vespalib/util/time.h> -#include <vespa/fastos/timestamp.h> #include <vespa/storageframework/generic/clock/clock.h> #include <list> #include <ostream> diff --git a/storageapi/src/vespa/storageapi/buckets/bucketinfo.h b/storageapi/src/vespa/storageapi/buckets/bucketinfo.h index c3aefd95ff3..a80595527e2 100644 --- a/storageapi/src/vespa/storageapi/buckets/bucketinfo.h +++ b/storageapi/src/vespa/storageapi/buckets/bucketinfo.h @@ -17,8 +17,7 @@ #include <vespa/vespalib/util/printable.h> #include <vespa/vespalib/util/xmlserializable.h> -namespace storage { -namespace api { +namespace storage::api { class BucketInfo : public vespalib::AsciiPrintable { @@ -87,5 +86,4 @@ public: void printXml(vespalib::XmlOutputStream&) const; }; -} // api -} // storage +} diff --git a/vespalib/src/tests/btree/iteratespeed.cpp b/vespalib/src/tests/btree/iteratespeed.cpp index 82aa9bb5f54..e20e9537f7f 100644 --- a/vespalib/src/tests/btree/iteratespeed.cpp +++ b/vespalib/src/tests/btree/iteratespeed.cpp @@ -14,9 +14,9 @@ #include <vespa/vespalib/btree/btree.hpp> #include <vespa/vespalib/btree/btreestore.hpp> #include <vespa/vespalib/util/rand48.h> +#include <vespa/vespalib/util/time.h> #include <vespa/fastos/app.h> -#include <vespa/fastos/timestamp.h> #include <vespa/log/log.h> LOG_SETUP("iteratespeed"); @@ -83,7 +83,7 @@ IterateSpeed::workLoop(int loops, bool enableForward, bool enableBackwards, assert(numEntries == tree.size()); assert(tree.isValid()); for (int l = 0; l < loops; ++l) { - fastos::StopWatch stopWatch; + vespalib::Timer timer; uint64_t sum = 0; for (size_t innerl = 0; innerl < numInnerLoops; ++innerl) { if (iterateMethod == IterateMethod::FORWARD) { @@ -106,7 +106,7 @@ IterateSpeed::workLoop(int loops, bool enableForward, bool enableBackwards, [&](int key) { sum += key; } ); } } - double used = stopWatch.elapsed().sec(); + double used = vespalib::to_s(timer.elapsed()); printf("Elapsed time for iterating %ld steps is %8.5f, " "direction=%s, fanout=%u,%u, sum=%" PRIu64 "\n", numEntries * numInnerLoops, diff --git a/vespalib/src/tests/closure/closure_test.cpp b/vespalib/src/tests/closure/closure_test.cpp index 5ba6ecf2a56..9faabb56fc5 100644 --- a/vespalib/src/tests/closure/closure_test.cpp +++ b/vespalib/src/tests/closure/closure_test.cpp @@ -6,7 +6,6 @@ using std::shared_ptr; using std::unique_ptr; -using std::string; using namespace vespalib; namespace { diff --git a/vespalib/src/tests/executor/stress_test.cpp b/vespalib/src/tests/executor/stress_test.cpp index bbe754be2bd..615e7addfd5 100644 --- a/vespalib/src/tests/executor/stress_test.cpp +++ b/vespalib/src/tests/executor/stress_test.cpp @@ -4,7 +4,6 @@ #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/vespalib/locale/c.h> -#include <vespa/fastos/timestamp.h> using namespace vespalib; using namespace std::literals; @@ -60,28 +59,28 @@ uint32_t Test::calibrate(double wanted_ms) { uint32_t n = 0; - fastos::StopWatch t0; - fastos::StopWatch t1; + vespalib::Timer t0; + vespalib::Timer t1; { // calibration of calibration loop uint32_t result = 0; - double ms; + vespalib::duration dur; do { result += doStuff(++n); - t1.restart(); - ms = (t1.elapsed().ms() - t0.elapsed().ms()); - } while (ms < 1000.0); + t1 = vespalib::Timer(); + dur = (t1.elapsed() - t0.elapsed()); + } while (dur < 1s); _result += result; } { // calibrate loop - t0.restart(); + t0 = vespalib::Timer(); uint32_t result = 0; for (uint32_t i = 0; i < n; ++i) { result += doStuff(i); } _result += result; - t1.restart(); + t1 = vespalib::Timer(); } - double ms = (t1.elapsed().ms() - t0.elapsed().ms()); + double ms = vespalib::count_ms(t1.elapsed() - t0.elapsed()); double size = (((double)n) / ms) * wanted_ms; return (uint32_t) std::round(size); } @@ -121,7 +120,7 @@ Test::Main() fprintf(stderr, "all threads have been accounted for...\n"); } { - fastos::StopWatch t0; + vespalib::Timer t0; fprintf(stderr, "starting task submission...\n"); uint32_t result = 0; for (uint32_t i = 0; i < tasks; ++i) { @@ -133,7 +132,7 @@ Test::Main() } } executor.sync(); - double ms = t0.elapsed().ms(); + double ms = vespalib::count_ms(t0.elapsed()); fprintf(stderr, "total execution wall time: %g ms\n", ms); _result += result; } diff --git a/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp b/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp index 7567e8426ae..6c643696615 100644 --- a/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp +++ b/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp @@ -3,7 +3,6 @@ #include <vespa/vespalib/util/left_right_heap.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/inline.h> -#include <vespa/fastos/timestamp.h> using vespalib::RightArrayHeap; using vespalib::RightHeap; @@ -41,11 +40,11 @@ struct MyInvCmp { struct Timer { double minTime; - fastos::StopWatch timer; + vespalib::Timer timer; Timer() : minTime(1.0e10), timer() {} - void start() { timer.restart(); } + void start() { timer = vespalib::Timer(); } void stop() { - double ms = timer.elapsed().ms(); + double ms = vespalib::count_ms(timer.elapsed()); minTime = std::min(minTime, ms); } }; diff --git a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp index d67c417b71a..71bae66ed2f 100644 --- a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp +++ b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp @@ -2,7 +2,6 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/simple_thread_bundle.h> #include <vespa/vespalib/util/box.h> -#include <vespa/fastos/timestamp.h> using namespace vespalib; @@ -57,11 +56,11 @@ TEST("estimate cost of thread bundle fork/join") { } double minTime = 1000000.0; for (size_t samples = 0; samples < 32; ++samples) { - fastos::StopWatch timer; + vespalib::Timer timer; for (size_t n = 0; n < fork; ++n) { threadBundle.run(targets); } - double time = timer.elapsed().ms(); + double time = vespalib::count_ms(timer.elapsed()); if (time < minTime) { minTime = time; } diff --git a/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp b/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp index 61ba2593eb3..dc31f4b8b42 100644 --- a/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp +++ b/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp @@ -2,7 +2,6 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/data/slime/slime.h> -#include <vespa/fastos/timestamp.h> using namespace vespalib; using namespace vespalib::slime::convenience; @@ -47,12 +46,12 @@ TEST_F("slime -> json speed", FeatureFixture()) { double minTime = 1000000.0; MyBuffer buffer; for (size_t i = 0; i < 16; ++i) { - fastos::StopWatch timer; + vespalib::Timer timer; for (size_t j = 0; j < 256; ++j) { buffer.used = 0; slime::JsonFormat::encode(f1.slime, buffer, true); } - minTime = std::min(minTime, timer.elapsed().ms() / 256.0); + minTime = std::min(minTime, vespalib::count_ms(timer.elapsed()) / 256.0); size = buffer.used; } fprintf(stderr, "time: %g ms (size: %zu bytes)\n", minTime, size); @@ -63,12 +62,12 @@ TEST_F("slime -> binary speed", FeatureFixture()) { double minTime = 1000000.0; MyBuffer buffer; for (size_t i = 0; i < 16; ++i) { - fastos::StopWatch timer; + vespalib::Timer timer; for (size_t j = 0; j < 256; ++j) { buffer.used = 0; slime::BinaryFormat::encode(f1.slime, buffer); } - minTime = std::min(minTime, timer.elapsed().ms() / 256.0); + minTime = std::min(minTime, vespalib::count_ms(timer.elapsed()) / 256.0); size = buffer.used; } fprintf(stderr, "time: %g ms (size: %zu bytes)\n", minTime, size); diff --git a/vespalib/src/tests/time/time_test.cpp b/vespalib/src/tests/time/time_test.cpp index 40542b6ca62..ed291adea58 100644 --- a/vespalib/src/tests/time/time_test.cpp +++ b/vespalib/src/tests/time/time_test.cpp @@ -40,10 +40,16 @@ TEST(TimeTest, timeval_conversion_works_as_expected) { } TEST(TimeTest, unit_counting_works_as_expected) { - auto d = 3ms + 5us + 7ns; - EXPECT_EQ(count_ns(d), 3005007); - EXPECT_EQ(count_us(d), 3005); - EXPECT_EQ(count_ms(d), 3); + auto d = 7s + 3ms + 5us + 7ns; + EXPECT_EQ(count_ns(d), 7003005007); + EXPECT_EQ(count_us(d), 7003005); + EXPECT_EQ(count_ms(d), 7003); + EXPECT_EQ(count_s(d), 7); +} + +TEST(TimeTest, to_string_print_iso_time) { + EXPECT_EQ("1970-01-01 00:00:00.000 UTC", to_string(system_time())); + EXPECT_EQ("2019-12-20 02:47:35.768 UTC", to_string(system_time(1576810055768543us))); } GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp index fdd13849287..15dc8b4c781 100644 --- a/vespalib/src/vespa/vespalib/util/time.cpp +++ b/vespalib/src/vespa/vespalib/util/time.cpp @@ -1,6 +1,8 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "time.h" +#include <thread> +#include <immintrin.h> namespace vespalib { @@ -11,6 +13,42 @@ to_utc(steady_time ts) { return system_time(nowUtc.time_since_epoch() - nowSteady.time_since_epoch() + ts.time_since_epoch()); } +namespace { + +string +to_string(duration dur) { + time_t timeStamp = std::chrono::duration_cast<std::chrono::seconds>(dur).count(); + struct tm timeStruct; + gmtime_r(&timeStamp, &timeStruct); + char timeString[128]; + strftime(timeString, sizeof(timeString), "%F %T", &timeStruct); + char retval[160]; + uint32_t milliSeconds = count_ms(dur) % 1000; + snprintf(retval, sizeof(retval), "%s.%03u UTC", timeString, milliSeconds); + return std::string(retval); +} + +} + +string +to_string(system_time time) { + return to_string(time.time_since_epoch()); +} + Timer::~Timer() = default; +void +Timer::waitAtLeast(duration dur, bool busyWait) { + if (busyWait) { + steady_clock::time_point deadline = steady_clock::now() + dur; + while (steady_clock::now() < deadline) { + for (int i = 0; i < 1000; i++) { + _mm_pause(); + } + } + } else { + std::this_thread::sleep_for(dur); + } +} + } diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h index f3348d643e1..719bb112c15 100644 --- a/vespalib/src/vespa/vespalib/util/time.h +++ b/vespalib/src/vespa/vespalib/util/time.h @@ -3,6 +3,7 @@ #pragma once #include <chrono> +#include <vespa/vespalib/stllike/string.h> #include <sys/time.h> // Guidelines: @@ -46,6 +47,10 @@ constexpr duration from_s(double seconds) { return std::chrono::duration_cast<duration>(std::chrono::duration<double>(seconds)); } +constexpr int64_t count_s(duration d) { + return std::chrono::duration_cast<std::chrono::seconds>(d).count(); +} + constexpr int64_t count_ms(duration d) { return std::chrono::duration_cast<std::chrono::milliseconds>(d).count(); } @@ -62,6 +67,8 @@ constexpr duration from_timeval(const timeval & tv) { return duration(tv.tv_sec*1000000000L + tv.tv_usec*1000L); } +vespalib::string to_string(system_time time); + /** * Simple utility class used to measure how much time has elapsed * since it was constructed. @@ -74,6 +81,7 @@ public: Timer() : _start(steady_clock::now()) {} ~Timer(); duration elapsed() const { return (steady_clock::now() - _start); } + static void waitAtLeast(duration dur, bool busyWait); }; } diff --git a/vespalog/src/test/threads/testthreads.cpp b/vespalog/src/test/threads/testthreads.cpp index d23e00930fd..ab7ddad3da7 100644 --- a/vespalog/src/test/threads/testthreads.cpp +++ b/vespalog/src/test/threads/testthreads.cpp @@ -1,6 +1,5 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/app.h> -#include <vespa/fastos/timestamp.h> #include <vespa/fastos/thread.h> #include <vespa/log/bufferedlogger.h> #include <array> @@ -13,6 +12,7 @@ using std::string; using namespace std::chrono_literals; +using namespace std::chrono; LOG_SETUP(".threadtest"); @@ -104,10 +104,10 @@ ThreadTester::Main() pool.NewThread(loggers[i].get()); } - fastos::StopWatch timer; + steady_clock::time_point start = steady_clock::now(); // Reduced runtime to half as the test now repeats itself to test with // buffering. (To avoid test taking a minute) - while (timer.elapsed().ms() < 15 * 1000) { + while ((steady_clock::now() - start) < 15s) { unlink(_argv[1]); std::this_thread::sleep_for(1ms); } @@ -115,8 +115,8 @@ ThreadTester::Main() for (int i = 0; i < numLoggers; i++) { loggers[i]->_useLogBuffer = true; } - timer.restart(); - while (timer.elapsed().ms() < 15 * 1000) { + start = steady_clock::now(); + while ((steady_clock::now() - start) < 15s) { unlink(_argv[1]); std::this_thread::sleep_for(1ms); } |