diff options
58 files changed, 337 insertions, 384 deletions
diff --git a/config/src/vespa/config/common/trace.cpp b/config/src/vespa/config/common/trace.cpp index 2d9b3ce8370..e6183a9fec1 100644 --- a/config/src/vespa/config/common/trace.cpp +++ b/config/src/vespa/config/common/trace.cpp @@ -12,8 +12,7 @@ namespace config { struct SystemClock : public Clock { int64_t currentTimeMillis() const override { - fastos::TimeStamp ts(fastos::ClockSystem::now()); - return ts.ms(); + return fastos::ClockSystem::now().timeSinceEpoch().ms(); } }; diff --git a/fastos/src/vespa/fastos/timestamp.cpp b/fastos/src/vespa/fastos/timestamp.cpp index d5c7f623fde..a1da4322f8c 100644 --- a/fastos/src/vespa/fastos/timestamp.cpp +++ b/fastos/src/vespa/fastos/timestamp.cpp @@ -32,7 +32,7 @@ TimeStamp::asString(double timeInSeconds) return std::string(retval); } -int64_t +UTCTimeStamp ClockSystem::now() { struct timeval timeNow; @@ -40,7 +40,7 @@ ClockSystem::now() int64_t ns = timeNow.tv_sec; ns *= TimeStamp::NANO; ns += timeNow.tv_usec*1000; - return ns; + return UTCTimeStamp(ns); } time_t @@ -57,6 +57,16 @@ steady_now() { } +std::ostream & +operator << (std::ostream & os, UTCTimeStamp ts) { + return os << ts.toString(); +} + +std::ostream & +operator << (std::ostream & os, SteadyTimeStamp ts) { + return os << ts.toString(); +} + SteadyTimeStamp ClockSteady::now() { @@ -65,10 +75,12 @@ ClockSteady::now() const SteadyTimeStamp SteadyTimeStamp::ZERO; const SteadyTimeStamp SteadyTimeStamp::FUTURE(TimeStamp::FUTURE); +const UTCTimeStamp UTCTimeStamp::ZERO; +const UTCTimeStamp UTCTimeStamp::FUTURE(TimeStamp::FUTURE); -TimeStamp +UTCTimeStamp SteadyTimeStamp::toUTC() const { - TimeStamp nowUtc = ClockSystem::now(); + UTCTimeStamp nowUtc = ClockSystem::now(); SteadyTimeStamp nowSteady = ClockSteady::now(); return nowUtc - (nowSteady - *this); } diff --git a/fastos/src/vespa/fastos/timestamp.h b/fastos/src/vespa/fastos/timestamp.h index 2eb895c01f9..c670e9f9b49 100644 --- a/fastos/src/vespa/fastos/timestamp.h +++ b/fastos/src/vespa/fastos/timestamp.h @@ -54,6 +54,48 @@ private: 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 UTCTimeStamp { +public: + static const UTCTimeStamp ZERO; + static const UTCTimeStamp FUTURE; + UTCTimeStamp() : _timeStamp() { } + explicit UTCTimeStamp(TimeStamp timeStamp) : _timeStamp(timeStamp) { } + + friend TimeStamp operator -(UTCTimeStamp a, UTCTimeStamp b) { + return a._timeStamp - b._timeStamp; + } + friend UTCTimeStamp operator -(UTCTimeStamp a, TimeStamp b) { + return UTCTimeStamp(a._timeStamp - b); + } + friend UTCTimeStamp operator +(UTCTimeStamp a, TimeStamp b) { + return UTCTimeStamp(a._timeStamp + b); + } + friend bool operator != (UTCTimeStamp a, UTCTimeStamp b) { + return a._timeStamp != b._timeStamp; + } + friend bool operator == (UTCTimeStamp a, UTCTimeStamp b) { + return a._timeStamp == b._timeStamp; + } + friend bool operator < (UTCTimeStamp a, UTCTimeStamp b) { + return a._timeStamp < b._timeStamp; + } + friend bool operator <= (UTCTimeStamp a, UTCTimeStamp b) { + return a._timeStamp <= b._timeStamp; + } + friend bool operator > (UTCTimeStamp a, UTCTimeStamp b) { + return a._timeStamp > b._timeStamp; + } + friend bool operator >= (UTCTimeStamp a, UTCTimeStamp b) { + return a._timeStamp >= b._timeStamp; + } + TimeStamp timeSinceEpoch() const { return _timeStamp - ZERO._timeStamp; } + std::string toString() const { return _timeStamp.toString(); }; +private: + TimeStamp _timeStamp; +}; class SteadyTimeStamp { public: @@ -65,6 +107,9 @@ public: 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); } @@ -80,16 +125,19 @@ public: friend bool operator > (SteadyTimeStamp a, SteadyTimeStamp b) { return a._timeStamp > b._timeStamp; } - TimeStamp toUTC() const; + UTCTimeStamp toUTC() const; std::string toString() const { return _timeStamp.toString(); }; private: TimeStamp _timeStamp; }; +std::ostream & operator << (std::ostream & os, UTCTimeStamp ts); +std::ostream & operator << (std::ostream & os, SteadyTimeStamp ts); + class ClockSystem { public: - static int64_t now(); + static UTCTimeStamp now(); }; class ClockSteady diff --git a/fnet/src/vespa/fnet/iocomponent.h b/fnet/src/vespa/fnet/iocomponent.h index 1a50ccbca73..a6a9e77ec99 100644 --- a/fnet/src/vespa/fnet/iocomponent.h +++ b/fnet/src/vespa/fnet/iocomponent.h @@ -47,7 +47,7 @@ protected: Selector *_ioc_selector; // attached event selector char *_ioc_spec; // connect/listen spec Flags _flags; // Compressed representation of boolean flags; - fastos::TimeStamp _ioc_timestamp; // last I/O activity + fastos::UTCTimeStamp _ioc_timestamp; // last I/O activity std::mutex _ioc_lock; // synchronization std::condition_variable _ioc_cond; // synchronization uint32_t _ioc_refcnt; // reference counter diff --git a/fnet/src/vespa/fnet/transport_thread.cpp b/fnet/src/vespa/fnet/transport_thread.cpp index f350d7c96b4..b850bd6a8c2 100644 --- a/fnet/src/vespa/fnet/transport_thread.cpp +++ b/fnet/src/vespa/fnet/transport_thread.cpp @@ -80,7 +80,7 @@ FNET_TransportThread::RemoveComponent(FNET_IOComponent *comp) void FNET_TransportThread::UpdateTimeOut(FNET_IOComponent *comp) { - comp->_ioc_timestamp = _now; + comp->_ioc_timestamp = fastos::UTCTimeStamp(_now); RemoveComponent(comp); AddComponent(comp); } @@ -520,9 +520,9 @@ FNET_TransportThread::EventLoopIteration() FastOS_Time t = _now; t.SubtractMilliSecs((double)_config._iocTimeOut); - fastos::TimeStamp oldest(t); + fastos::UTCTimeStamp oldest(t); while (_timeOutHead != nullptr && - oldest >= _timeOutHead->_ioc_timestamp) { + oldest > _timeOutHead->_ioc_timestamp) { component = _timeOutHead; RemoveComponent(component); diff --git a/searchcore/src/tests/grouping/grouping.cpp b/searchcore/src/tests/grouping/grouping.cpp index 79dba576bbd..edaa8792d6c 100644 --- a/searchcore/src/tests/grouping/grouping.cpp +++ b/searchcore/src/tests/grouping/grouping.cpp @@ -24,13 +24,6 @@ using search::attribute::test::MockAttributeContext; using proton::matching::SessionManager; using fastos::SteadyTimeStamp; -namespace fastos { - std::ostream & - operator<<(std::ostream &os, SteadyTimeStamp ts) { - return os << ts.toString(); - } -} - //----------------------------------------------------------------------------- const uint32_t NUM_DOCS = 1000; diff --git a/searchcore/src/tests/proton/attribute/attributeflush_test.cpp b/searchcore/src/tests/proton/attribute/attributeflush_test.cpp index 31bf982ad70..c41ac3a3a1c 100644 --- a/searchcore/src/tests/proton/attribute/attributeflush_test.cpp +++ b/searchcore/src/tests/proton/attribute/attributeflush_test.cpp @@ -506,31 +506,31 @@ Test::requireThatLastFlushTimeIsReported() AttributeManagerFixture amf(f); AttributeManager &am = amf._m; AttributeVector::SP av = amf.addAttribute("a9"); - EXPECT_EQUAL(0, am.getFlushable("a9")->getLastFlushTime().time()); + EXPECT_EQUAL(fastos::UTCTimeStamp::ZERO, am.getFlushable("a9")->getLastFlushTime()); } { // no snapshot flushed yet AttributeManagerFixture amf(f); AttributeManager &am = amf._m; AttributeVector::SP av = amf.addAttribute("a9"); IFlushTarget::SP ft = am.getFlushable("a9"); - EXPECT_EQUAL(0, ft->getLastFlushTime().time()); + EXPECT_EQUAL(fastos::UTCTimeStamp::ZERO, ft->getLastFlushTime()); ft->initFlush(200)->run(); EXPECT_TRUE(FastOS_File::Stat("flush/a9/snapshot-200", &stat)); - EXPECT_EQUAL(stat._modifiedTime, ft->getLastFlushTime().time()); + EXPECT_EQUAL(stat._modifiedTime, ft->getLastFlushTime().timeSinceEpoch().time()); } { // snapshot flushed AttributeManagerFixture amf(f); AttributeManager &am = amf._m; amf.addAttribute("a9"); IFlushTarget::SP ft = am.getFlushable("a9"); - EXPECT_EQUAL(stat._modifiedTime, ft->getLastFlushTime().time()); + EXPECT_EQUAL(stat._modifiedTime, ft->getLastFlushTime().timeSinceEpoch().time()); { // updated flush time after nothing to flush std::this_thread::sleep_for(8000ms); - fastos::TimeStamp now = fastos::ClockSystem::now(); + fastos::TimeStamp now = fastos::ClockSystem::now().timeSinceEpoch(); Executor::Task::UP task = ft->initFlush(200); EXPECT_TRUE(task.get() == NULL); - EXPECT_LESS(stat._modifiedTime, ft->getLastFlushTime().time()); - EXPECT_APPROX(now.time(), ft->getLastFlushTime().time(), 8); + EXPECT_LESS(stat._modifiedTime, ft->getLastFlushTime().timeSinceEpoch().time()); + EXPECT_APPROX(now.time(), ft->getLastFlushTime().timeSinceEpoch().time(), 8); } } } diff --git a/searchcore/src/tests/proton/flushengine/flushengine_test.cpp b/searchcore/src/tests/proton/flushengine/flushengine_test.cpp index 96092625979..bfd4450b1f2 100644 --- a/searchcore/src/tests/proton/flushengine/flushengine_test.cpp +++ b/searchcore/src/tests/proton/flushengine/flushengine_test.cpp @@ -55,14 +55,14 @@ public: class SimpleGetSerialNum : public IGetSerialNum { - virtual search::SerialNum getSerialNum() const override { + search::SerialNum getSerialNum() const override { return 0u; } }; class SimpleTlsStatsFactory : public flushengine::ITlsStatsFactory { - virtual flushengine::TlsStatsMap create() override { + flushengine::TlsStatsMap create() override { vespalib::hash_map<vespalib::string, flushengine::TlsStats> map; return flushengine::TlsStatsMap(std::move(map)); } @@ -76,7 +76,7 @@ class WrappedFlushTask : public searchcorespi::FlushTask SimpleHandler &_handler; public: - virtual void run() override; + void run() override; WrappedFlushTask(searchcorespi::FlushTask::UP task, SimpleHandler &handler) : _task(std::move(task)), @@ -84,8 +84,7 @@ public: { } - virtual search::SerialNum getFlushSerial() const override - { + search::SerialNum getFlushSerial() const override { return _task->getFlushSerial(); } }; @@ -101,7 +100,7 @@ public: { } - virtual Task::UP initFlush(SerialNum currentSerial) override + Task::UP initFlush(SerialNum currentSerial) override { Task::UP task(_target->initFlush(currentSerial)); if (task) { @@ -228,11 +227,7 @@ public: _done.countDown(); } - virtual search::SerialNum - getFlushSerial() const override - { - return 0u; - } + search::SerialNum getFlushSerial() const override { return 0u; } }; class SimpleTarget : public test::DummyFlushTarget { @@ -284,22 +279,15 @@ public: : SimpleTarget(name, Type::OTHER, flushedSerial, proceedImmediately) { } - virtual Time - getLastFlushTime() const override { return fastos::ClockSystem::now(); } + Time getLastFlushTime() const override { return fastos::ClockSystem::now(); } - virtual SerialNum - getFlushedSerialNum() const override - { - LOG(info, "SimpleTarget(%s)::getFlushedSerialNum() = %" PRIu64, - getName().c_str(), _flushedSerial); + SerialNum getFlushedSerialNum() const override { + LOG(info, "SimpleTarget(%s)::getFlushedSerialNum() = %" PRIu64, getName().c_str(), _flushedSerial); return _flushedSerial; } - virtual Task::UP - initFlush(SerialNum currentSerial) override - { - LOG(info, "SimpleTarget(%s)::initFlush(%" PRIu64 ")", - getName().c_str(), currentSerial); + Task::UP initFlush(SerialNum currentSerial) override { + LOG(info, "SimpleTarget(%s)::initFlush(%" PRIu64 ")", getName().c_str(), currentSerial); _currentSerial = currentSerial; _initDone.countDown(); return std::move(_task); @@ -329,17 +317,13 @@ public: { } - virtual MemoryGain - getApproxMemoryGain() const override - { + MemoryGain getApproxMemoryGain() const override { LOG_ASSERT(_mgain == false); _mgain = true; return SimpleTarget::getApproxMemoryGain(); } - virtual search::SerialNum - getFlushedSerialNum() const override - { + search::SerialNum getFlushedSerialNum() const override { LOG_ASSERT(_serial == false); _serial = true; return SimpleTarget::getFlushedSerialNum(); @@ -358,8 +342,8 @@ public: const SimpleStrategy &_flush; }; - virtual FlushContext::List getFlushTargets(const FlushContext::List &targetList, - const flushengine::TlsStatsMap &) const override { + FlushContext::List getFlushTargets(const FlushContext::List &targetList, + const flushengine::TlsStatsMap &) const override { FlushContext::List fv(targetList); std::sort(fv.begin(), fv.end(), CompareTarget(*this)); return fv; @@ -403,8 +387,8 @@ public: class NoFlushStrategy : public SimpleStrategy { - virtual FlushContext::List getFlushTargets(const FlushContext::List &, - const flushengine::TlsStatsMap &) const override { + FlushContext::List getFlushTargets(const FlushContext::List &, + const flushengine::TlsStatsMap &) const override { return FlushContext::List(); } }; @@ -427,11 +411,7 @@ public: _list.push_back(_name); _done.countDown(); } - virtual search::SerialNum - getFlushSerial() const override - { - return 0u; - } + search::SerialNum getFlushSerial() const override { return 0u; } std::vector<vespalib::string> & _list; vespalib::Gate & _done; vespalib::string _name; diff --git a/searchcore/src/tests/proton/flushengine/shrink_lid_space_flush_target/shrink_lid_space_flush_target_test.cpp b/searchcore/src/tests/proton/flushengine/shrink_lid_space_flush_target/shrink_lid_space_flush_target_test.cpp index 4f0f3c48278..376f37a512e 100644 --- a/searchcore/src/tests/proton/flushengine/shrink_lid_space_flush_target/shrink_lid_space_flush_target_test.cpp +++ b/searchcore/src/tests/proton/flushengine/shrink_lid_space_flush_target/shrink_lid_space_flush_target_test.cpp @@ -57,7 +57,7 @@ struct Fixture IFlushTarget::Type::GC, IFlushTarget::Component::ATTRIBUTE, 10, - IFlushTarget::Time(), + fastos::UTCTimeStamp::ZERO, _lidSpace)) { } diff --git a/searchcore/src/tests/proton/index/indexmanager_test.cpp b/searchcore/src/tests/proton/index/indexmanager_test.cpp index 80b1f9f0560..2f5d3e353db 100644 --- a/searchcore/src/tests/proton/index/indexmanager_test.cpp +++ b/searchcore/src/tests/proton/index/indexmanager_test.cpp @@ -277,12 +277,12 @@ TEST_F(IndexManagerTest, require_that_memory_index_is_flushed) EXPECT_EQ(1u, sources->getSourceId(0)); IndexFlushTarget target(_index_manager->getMaintainer()); - EXPECT_EQ(0, target.getLastFlushTime().time()); + EXPECT_EQ(fastos::UTCTimeStamp::ZERO, target.getLastFlushTime()); vespalib::Executor::Task::UP flushTask; runAsMaster([&]() { flushTask = target.initFlush(1); }); flushTask->run(); EXPECT_TRUE(FastOS_File::Stat("test_data/index.flush.1", &stat)); - EXPECT_EQ(stat._modifiedTime, target.getLastFlushTime().time()); + EXPECT_EQ(stat._modifiedTime, target.getLastFlushTime().timeSinceEpoch().time()); sources = get_source_collection(); EXPECT_EQ(2u, sources->getSourceCount()); @@ -300,17 +300,17 @@ TEST_F(IndexManagerTest, require_that_memory_index_is_flushed) { // verify last flush time when loading disk index resetIndexManager(); IndexFlushTarget target(_index_manager->getMaintainer()); - EXPECT_EQ(stat._modifiedTime, target.getLastFlushTime().time()); + EXPECT_EQ(stat._modifiedTime, target.getLastFlushTime().timeSinceEpoch().time()); // updated serial number & flush time when nothing to flush FastOS_Thread::Sleep(8000); - fastos::TimeStamp now = fastos::ClockSystem::now(); + fastos::TimeStamp now = fastos::ClockSystem::now().timeSinceEpoch(); vespalib::Executor::Task::UP task; runAsMaster([&]() { task = target.initFlush(2); }); EXPECT_TRUE(task.get() == nullptr); EXPECT_EQ(2u, target.getFlushedSerialNum()); - EXPECT_LT(stat._modifiedTime, target.getLastFlushTime().time()); - EXPECT_NEAR(now.time(), target.getLastFlushTime().time(), 8); + EXPECT_LT(stat._modifiedTime, target.getLastFlushTime().timeSinceEpoch().time()); + EXPECT_NEAR(now.time(), target.getLastFlushTime().timeSinceEpoch().time(), 8); } } diff --git a/searchcore/src/tests/proton/matching/matching_test.cpp b/searchcore/src/tests/proton/matching/matching_test.cpp index 883aa8f5aa5..83d520ea69b 100644 --- a/searchcore/src/tests/proton/matching/matching_test.cpp +++ b/searchcore/src/tests/proton/matching/matching_test.cpp @@ -60,13 +60,6 @@ using vespalib::nbostream; using vespalib::eval::TensorSpec; using vespalib::tensor::DefaultTensorEngine; -namespace fastos { - std::ostream & - operator<<(std::ostream &os, SteadyTimeStamp ts) { - return os << ts.toString(); - } -} - void inject_match_phase_limiting(Properties &setup, const vespalib::string &attribute, size_t max_hits, bool descending) { Properties cfg; diff --git a/searchcore/src/tests/proton/server/memoryflush/memoryflush_test.cpp b/searchcore/src/tests/proton/server/memoryflush/memoryflush_test.cpp index 3222d9b1190..a1693832506 100644 --- a/searchcore/src/tests/proton/server/memoryflush/memoryflush_test.cpp +++ b/searchcore/src/tests/proton/server/memoryflush/memoryflush_test.cpp @@ -7,12 +7,13 @@ #include <vespa/searchcore/proton/server/memoryflush.h> using fastos::TimeStamp; +using fastos::UTCTimeStamp; +using fastos::SteadyTimeStamp; using search::SerialNum; using namespace proton; using namespace searchcorespi; -namespace -{ +namespace{ static constexpr uint64_t gibi = UINT64_C(1024) * UINT64_C(1024) * UINT64_C(1024); @@ -40,15 +41,15 @@ public: class MyFlushTarget : public test::DummyFlushTarget { private: - MemoryGain _memoryGain; - DiskGain _diskGain; - SerialNum _flushedSerial; - TimeStamp _lastFlushTime; - bool _urgentFlush; + MemoryGain _memoryGain; + DiskGain _diskGain; + SerialNum _flushedSerial; + UTCTimeStamp _lastFlushTime; + bool _urgentFlush; public: MyFlushTarget(const vespalib::string &name, MemoryGain memoryGain, DiskGain diskGain, SerialNum flushedSerial, - TimeStamp lastFlushTime, bool urgentFlush) : + UTCTimeStamp lastFlushTime, bool urgentFlush) : test::DummyFlushTarget(name), _memoryGain(memoryGain), _diskGain(diskGain), @@ -61,7 +62,7 @@ public: virtual MemoryGain getApproxMemoryGain() const override { return _memoryGain; } virtual DiskGain getApproxDiskGain() const override { return _diskGain; } virtual SerialNum getFlushedSerialNum() const override { return _flushedSerial; } - virtual TimeStamp getLastFlushTime() const override { return _lastFlushTime; } + virtual UTCTimeStamp getLastFlushTime() const override { return _lastFlushTime; } virtual bool needUrgentFlush() const override { return _urgentFlush; } }; @@ -116,41 +117,36 @@ public: ContextBuilder::ContextBuilder() : _list(), _handler(new MyFlushHandler("myhandler")) {} -ContextBuilder::~ContextBuilder() {} +ContextBuilder::~ContextBuilder() = default; MyFlushTarget::SP createTargetM(const vespalib::string &name, MemoryGain memoryGain) { - return MyFlushTarget::SP(new MyFlushTarget(name, memoryGain, DiskGain(), - SerialNum(), TimeStamp(), false)); + return std::make_shared<MyFlushTarget>(name, memoryGain, DiskGain(),SerialNum(), UTCTimeStamp::ZERO, false); } MyFlushTarget::SP createTargetD(const vespalib::string &name, DiskGain diskGain, SerialNum serial = 0) { - return MyFlushTarget::SP(new MyFlushTarget(name, MemoryGain(), diskGain, - serial, TimeStamp(), false)); + return std::make_shared<MyFlushTarget>(name, MemoryGain(), diskGain, serial, UTCTimeStamp::ZERO, false); } MyFlushTarget::SP -createTargetS(const vespalib::string &name, SerialNum serial, TimeStamp timeStamp = TimeStamp()) +createTargetS(const vespalib::string &name, SerialNum serial, UTCTimeStamp timeStamp = UTCTimeStamp::ZERO) { - return MyFlushTarget::SP(new MyFlushTarget(name, MemoryGain(), DiskGain(), - serial, timeStamp, false)); + return std::make_shared<MyFlushTarget>(name, MemoryGain(), DiskGain(), serial, timeStamp, false); } MyFlushTarget::SP -createTargetT(const vespalib::string &name, TimeStamp lastFlushTime, SerialNum serial = 0) +createTargetT(const vespalib::string &name, UTCTimeStamp lastFlushTime, SerialNum serial = 0) { - return MyFlushTarget::SP(new MyFlushTarget(name, MemoryGain(), DiskGain(), - serial, lastFlushTime, false)); + return std::make_shared<MyFlushTarget>(name, MemoryGain(), DiskGain(), serial, lastFlushTime, false); } MyFlushTarget::SP createTargetF(const vespalib::string &name, bool urgentFlush) { - return MyFlushTarget::SP(new MyFlushTarget(name, MemoryGain(), DiskGain(), - SerialNum(), TimeStamp(), urgentFlush)); + return std::make_shared<MyFlushTarget>(name, MemoryGain(), DiskGain(), SerialNum(), UTCTimeStamp::ZERO, urgentFlush); } bool @@ -236,13 +232,13 @@ requireThatWeCanOrderByDiskGainWithSmallValues() void requireThatWeCanOrderByAge() { - TimeStamp now(fastos::ClockSystem::now()); - TimeStamp start(now.val() - 20 * TimeStamp::SEC); + UTCTimeStamp now(fastos::ClockSystem::now()); + UTCTimeStamp start(now - TimeStamp(20 * TimeStamp::SEC)); ContextBuilder cb; - cb.add(createTargetT("t2", TimeStamp(now.val() - 10 * TimeStamp::SEC))) - .add(createTargetT("t1", TimeStamp(now.val() - 5 * TimeStamp::SEC))) - .add(createTargetT("t4", TimeStamp())) - .add(createTargetT("t3", TimeStamp(now.val() - 15 * TimeStamp::SEC))); + cb.add(createTargetT("t2", now - TimeStamp(10 * TimeStamp::SEC))) + .add(createTargetT("t1", now - TimeStamp(5 * TimeStamp::SEC))) + .add(createTargetT("t4", UTCTimeStamp::ZERO)) + .add(createTargetT("t3", now - TimeStamp(15 * TimeStamp::SEC))); { // all targets have timeDiff >= maxTimeGain MemoryFlush flush({1000, 20 * gibi, 1.0, 1000, 1.0, TimeStamp(2 * TimeStamp::SEC)}, start); @@ -258,33 +254,17 @@ requireThatWeCanOrderByAge() void requireThatWeCanOrderByTlsSize() { - TimeStamp now(fastos::ClockSystem::now()); - TimeStamp start(now.val() - 20 * TimeStamp::SEC); + UTCTimeStamp now(fastos::ClockSystem::now()); + UTCTimeStamp start = now - TimeStamp(20 * TimeStamp::SEC); ContextBuilder cb; IFlushHandler::SP handler1(std::make_shared<MyFlushHandler>("handler1")); IFlushHandler::SP handler2(std::make_shared<MyFlushHandler>("handler2")); cb.addTls("handler1", {20 * gibi, 1001, 2000 }); cb.addTls("handler2", { 5 * gibi, 1001, 2000 }); - cb.add(std::make_shared<FlushContext> - (handler1, - createTargetT("t2", TimeStamp(now.val() - 10 * TimeStamp::SEC), - 1900), - 2000)). - add(std::make_shared<FlushContext> - (handler2, - createTargetT("t1", TimeStamp(now.val() - 5 * TimeStamp::SEC), - 1000), - 2000)). - add(std::make_shared<FlushContext> - (handler1, - createTargetT("t4", TimeStamp(), - 1000), - 2000)). - add(std::make_shared<FlushContext> - (handler2, - createTargetT("t3", TimeStamp(now.val() - 15 * TimeStamp::SEC), - 1900), - 2000)); + cb.add(std::make_shared<FlushContext>(handler1, createTargetT("t2", now - TimeStamp(10 * TimeStamp::SEC), 1900), 2000)). + add(std::make_shared<FlushContext>(handler2, createTargetT("t1", now - TimeStamp(5 * TimeStamp::SEC), 1000), 2000)). + add(std::make_shared<FlushContext>(handler1, createTargetT("t4", UTCTimeStamp::ZERO, 1000), 2000)). + add(std::make_shared<FlushContext>(handler2, createTargetT("t3", now - TimeStamp(15 * TimeStamp::SEC), 1900), 2000)); { // sum of tls sizes above limit, trigger sort order based on tls size MemoryFlush flush({1000, 3 * gibi, 1.0, 1000, 1.0, TimeStamp(2 * TimeStamp::SEC)}, start); EXPECT_TRUE(assertOrder(StringList().add("t4").add("t1").add("t2").add("t3"), @@ -304,22 +284,18 @@ requireThatWeHandleLargeSerialNumbersWhenOrderingByTlsSize() SerialNum firstSerial = 10; SerialNum lastSerial = uint32_max + 10; builder.addTls("myhandler", {uint32_max, firstSerial, lastSerial}); - builder.add(createTargetT("t1", TimeStamp(), uint32_max + 5), lastSerial); - builder.add(createTargetT("t2", TimeStamp(), uint32_max - 5), lastSerial); + builder.add(createTargetT("t1", UTCTimeStamp::ZERO, uint32_max + 5), lastSerial); + builder.add(createTargetT("t2", UTCTimeStamp::ZERO, uint32_max - 5), lastSerial); uint64_t maxMemoryGain = 10; - MemoryFlush flush({maxMemoryGain, 1000, 0, maxMemoryGain, 0, TimeStamp()}, TimeStamp()); - EXPECT_TRUE(assertOrder(StringList().add("t2").add("t1"), - flush.getFlushTargets(builder.list(), builder.tlsStats()))); + MemoryFlush flush({maxMemoryGain, 1000, 0, maxMemoryGain, 0, TimeStamp()}, UTCTimeStamp::ZERO); + EXPECT_TRUE(assertOrder(StringList().add("t2").add("t1"), flush.getFlushTargets(builder.list(), builder.tlsStats()))); } void requireThatOrderTypeIsPreserved() { - TimeStamp now(fastos::ClockSystem::now()); - TimeStamp ts1(now.val() - 30 * TimeStamp::SEC); - TimeStamp ts2(now.val() - 20 * TimeStamp::SEC); - TimeStamp ts3(now.val() - 10 * TimeStamp::SEC); - TimeStamp maxTimeGain(15 * TimeStamp::SEC); + UTCTimeStamp now(fastos::ClockSystem::now()); + UTCTimeStamp ts2 = now - TimeStamp(20 * TimeStamp::SEC); { // MAXAGE VS DISKBLOAT ContextBuilder cb; @@ -354,5 +330,3 @@ TEST_MAIN() TEST_DO(requireThatWeHandleLargeSerialNumbersWhenOrderingByTlsSize()); TEST_DO(requireThatOrderTypeIsPreserved()); } - - diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.cpp index 2bbc6c99dc0..56b53a46693 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.cpp @@ -75,14 +75,14 @@ AttributeDirectory::getFlushedSerialNum() const return bestSnap.valid ? bestSnap.syncToken : 0; } -fastos::TimeStamp +fastos::UTCTimeStamp AttributeDirectory::getLastFlushTime() const { return _lastFlushTime; } void -AttributeDirectory::setLastFlushTime(fastos::TimeStamp lastFlushTime) +AttributeDirectory::setLastFlushTime(fastos::UTCTimeStamp lastFlushTime) { _lastFlushTime = lastFlushTime; } diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h b/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h index 603727dbb75..19f89466e39 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h @@ -27,7 +27,7 @@ public: private: std::weak_ptr<AttributeDiskLayout> _diskLayout; const vespalib::string _name; - fastos::TimeStamp _lastFlushTime; + fastos::UTCTimeStamp _lastFlushTime; Writer *_writer; // current writer mutable std::mutex _mutex; std::condition_variable _cv; @@ -35,7 +35,7 @@ private: void saveSnapInfo(); vespalib::string getSnapshotDir(SerialNum serialNum); - void setLastFlushTime(fastos::TimeStamp lastFlushTime); + void setLastFlushTime(fastos::UTCTimeStamp lastFlushTime); void createInvalidSnapshot(SerialNum serialNum); void markValidSnapshot(SerialNum serialNum); void invalidateOldSnapshots(SerialNum serialNum); @@ -65,7 +65,7 @@ public: ~Writer(); // methods called when saving an attribute. - void setLastFlushTime(fastos::TimeStamp lastFlushTime) { _dir.setLastFlushTime(lastFlushTime); } + void setLastFlushTime(fastos::UTCTimeStamp lastFlushTime) { _dir.setLastFlushTime(lastFlushTime); } void createInvalidSnapshot(SerialNum serialNum) { _dir.createInvalidSnapshot(serialNum); } void markValidSnapshot(SerialNum serialNum) { _dir.markValidSnapshot(serialNum); } vespalib::string getSnapshotDir(SerialNum serialNum) { return _dir.getSnapshotDir(serialNum); } @@ -81,7 +81,7 @@ public: std::unique_ptr<Writer> getWriter(); std::unique_ptr<Writer> tryGetWriter(); SerialNum getFlushedSerialNum() const; - fastos::TimeStamp getLastFlushTime() const; + fastos::UTCTimeStamp getLastFlushTime() const; bool empty() const; vespalib::string getAttributeFileName(SerialNum serialNum); }; diff --git a/searchcore/src/vespa/searchcore/proton/attribute/flushableattribute.cpp b/searchcore/src/vespa/searchcore/proton/attribute/flushableattribute.cpp index 378b7106610..66d1c27a5b5 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/flushableattribute.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/flushableattribute.cpp @@ -203,21 +203,18 @@ FlushableAttribute::internalInitFlush(SerialNum currentSerial) { // Called by attribute field writer thread while document db executor waits _attr->removeAllOldGenerations(); - SerialNum syncToken = std::max(currentSerial, - _attr->getStatus().getLastSyncToken()); + SerialNum syncToken = std::max(currentSerial, _attr->getStatus().getLastSyncToken()); auto writer = _attrDir->tryGetWriter(); if (!writer) { return Task::UP(); } if (syncToken <= getFlushedSerialNum()) { writer->setLastFlushTime(fastos::ClockSystem::now()); - LOG(debug, - "No attribute vector to flush." - " Update flush time to current: lastFlushTime(%f)", - getLastFlushTime().sec()); + LOG(debug,"No attribute vector to flush. Update flush time to current: lastFlushTime(%f)", + getLastFlushTime().timeSinceEpoch().sec()); return Task::UP(); } - return Task::UP(new Flusher(*this, syncToken, *writer)); + return std::make_unique<Flusher>(*this, syncToken, *writer); } diff --git a/searchcore/src/vespa/searchcore/proton/common/commit_time_tracker.cpp b/searchcore/src/vespa/searchcore/proton/common/commit_time_tracker.cpp index 0075497ff9d..c9db3d23979 100644 --- a/searchcore/src/vespa/searchcore/proton/common/commit_time_tracker.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/commit_time_tracker.cpp @@ -6,10 +6,10 @@ namespace proton { CommitTimeTracker::CommitTimeTracker(fastos::TimeStamp visibilityDelay) : _visibilityDelay(visibilityDelay), - _nextCommit(fastos::ClockSystem::now()), + _nextCommit(fastos::ClockSteady::now()), _replayDone(false) { - _nextCommit += visibilityDelay; + _nextCommit = _nextCommit + visibilityDelay; } bool @@ -19,8 +19,8 @@ CommitTimeTracker::needCommit() const if (_replayDone) { return false; // maintenance job will do forced commits now } - fastos::TimeStamp now(fastos::ClockSystem::now()); - if (now >= _nextCommit) { + fastos::SteadyTimeStamp now(fastos::ClockSteady::now()); + if (now > _nextCommit) { _nextCommit = now + _visibilityDelay; return true; } @@ -32,13 +32,11 @@ CommitTimeTracker::needCommit() const void CommitTimeTracker::setVisibilityDelay(fastos::TimeStamp visibilityDelay) { - fastos::TimeStamp now(fastos::ClockSystem::now()); - fastos::TimeStamp nextCommit = now + visibilityDelay; - if (nextCommit.val() < _nextCommit.val()) { + fastos::SteadyTimeStamp nextCommit = fastos::ClockSteady::now() + visibilityDelay; + if (nextCommit < _nextCommit) { _nextCommit = nextCommit; } _visibilityDelay = visibilityDelay; } - } // namespace proton 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 5cc082c0b19..d00152cf372 100644 --- a/searchcore/src/vespa/searchcore/proton/common/commit_time_tracker.h +++ b/searchcore/src/vespa/searchcore/proton/common/commit_time_tracker.h @@ -11,9 +11,9 @@ namespace proton { class CommitTimeTracker { private: - fastos::TimeStamp _visibilityDelay; - mutable fastos::TimeStamp _nextCommit; - bool _replayDone; + fastos::TimeStamp _visibilityDelay; + mutable fastos::SteadyTimeStamp _nextCommit; + bool _replayDone; public: CommitTimeTracker(fastos::TimeStamp visibilityDelay); diff --git a/searchcore/src/vespa/searchcore/proton/docsummary/summaryflushtarget.cpp b/searchcore/src/vespa/searchcore/proton/docsummary/summaryflushtarget.cpp index 2f7681c5909..a101ad4d83c 100644 --- a/searchcore/src/vespa/searchcore/proton/docsummary/summaryflushtarget.cpp +++ b/searchcore/src/vespa/searchcore/proton/docsummary/summaryflushtarget.cpp @@ -82,7 +82,7 @@ SummaryFlushTarget::getFlushedSerialNum() const IFlushTarget::Task::UP SummaryFlushTarget::internalInitFlush(SerialNum currentSerial) { - return Task::UP(new Flusher(_docStore, _lastStats, currentSerial)); + return std::make_unique<Flusher>(_docStore, _lastStats, currentSerial); } IFlushTarget::Task::UP SummaryFlushTarget::initFlush(SerialNum currentSerial) diff --git a/searchcore/src/vespa/searchcore/proton/docsummary/summarymanager.cpp b/searchcore/src/vespa/searchcore/proton/docsummary/summarymanager.cpp index 113855d7e2b..74d107814fd 100644 --- a/searchcore/src/vespa/searchcore/proton/docsummary/summarymanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/docsummary/summarymanager.cpp @@ -50,7 +50,7 @@ class ShrinkSummaryLidSpaceFlushTarget : public ShrinkLidSpaceFlushTarget public: ShrinkSummaryLidSpaceFlushTarget(const vespalib::string &name, Type type, Component component, - SerialNum flushedSerialNum, Time lastFlushTime, + SerialNum flushedSerialNum, fastos::UTCTimeStamp lastFlushTime, searchcorespi::index::IThreadService & summaryService, std::shared_ptr<ICompactableLidSpace> target); ~ShrinkSummaryLidSpaceFlushTarget() override; @@ -59,7 +59,7 @@ public: ShrinkSummaryLidSpaceFlushTarget:: ShrinkSummaryLidSpaceFlushTarget(const vespalib::string &name, Type type, Component component, - SerialNum flushedSerialNum, Time lastFlushTime, + SerialNum flushedSerialNum, fastos::UTCTimeStamp lastFlushTime, searchcorespi::index::IThreadService & summaryService, std::shared_ptr<ICompactableLidSpace> target) : ShrinkLidSpaceFlushTarget(name, type, component, flushedSerialNum, lastFlushTime, std::move(target)), @@ -194,7 +194,7 @@ createShrinkLidSpaceFlushTarget(searchcorespi::index::IThreadService & summarySe IFlushTarget::Type::GC, IFlushTarget::Component::DOCUMENT_STORE, docStore->lastSyncToken(), - docStore->getLastFlushTime(), + fastos::UTCTimeStamp(docStore->getLastFlushTime()), summaryService, docStore); } diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreflushtarget.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreflushtarget.cpp index 56ecdaa0cb0..2cadedd0f59 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreflushtarget.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreflushtarget.cpp @@ -223,7 +223,7 @@ DocumentMetaStoreFlushTarget::initFlush(SerialNum currentSerial) if (syncToken <= getFlushedSerialNum()) { writer->setLastFlushTime(fastos::ClockSystem::now()); LOG(debug, "No document meta store to flush. Update flush time to current: lastFlushTime(%f)", - getLastFlushTime().sec()); + getLastFlushTime().timeSinceEpoch().sec()); return Task::UP(); } return std::make_unique<Flusher>(*this, syncToken, *writer); diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/i_bucket_handler.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/i_bucket_handler.h index 1a0b3c61c47..f96972c4562 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/i_bucket_handler.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/i_bucket_handler.h @@ -8,18 +8,12 @@ #include <vespa/searchcore/proton/bucketdb/bucketdeltapair.h> #include <vector> -namespace proton { - -namespace bucketdb -{ - -class SplitBucketSession; -class JoinBucketsSession; - +namespace proton::bucketdb { + class SplitBucketSession; + class JoinBucketsSession; } - -namespace documentmetastore { +namespace proton::documentmetastore { /** * Interface for handling bucket changes relevant to the document meta store. @@ -63,6 +57,4 @@ struct IBucketHandler }; -} // namespace documentmetastore -} // namespace proton - +} diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/i_store.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/i_store.h index 64071eef526..9e3988c76f0 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/i_store.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/i_store.h @@ -7,8 +7,7 @@ #include <vespa/document/bucket/bucketid.h> #include <persistence/spi/types.h> -namespace proton { -namespace documentmetastore { +namespace proton::documentmetastore { /** @@ -117,8 +116,7 @@ struct IStore * Removes a list of lids. * The caller must call removeBatchComplete() after documents removal is done. */ - virtual void removeBatch(const std::vector<DocId> &lidsToRemove, - const DocId docIdLimit) = 0; + virtual void removeBatch(const std::vector<DocId> &lidsToRemove, const DocId docIdLimit) = 0; /** * Signal that the removal of the documents associated with these lids is complete. @@ -138,6 +136,5 @@ struct IStore virtual bool getFreeListActive() const = 0; }; -} // namespace documentmetastore -} // 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 d538c80b429..5ba6a805a8e 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 @@ -13,8 +13,7 @@ LidReuseDelayerConfig::LidReuseDelayerConfig() LidReuseDelayerConfig::LidReuseDelayerConfig(const DocumentDBConfig & configSnapshot) - : _visibilityDelay(configSnapshot.getMaintenanceConfigSP()-> - getVisibilityDelay()), + : _visibilityDelay(configSnapshot.getMaintenanceConfigSP()->getVisibilityDelay()), _hasIndexedOrAttributeFields(configSnapshot.getSchemaSP()->getNumIndexFields() > 0 || configSnapshot.getSchemaSP()->getNumAttributeFields() > 0) { 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 bbc712339cd..a11f5ff1f24 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 @@ -3,11 +3,10 @@ #pragma once #include <vespa/fastos/timestamp.h> -namespace proton { -class DocumentDBConfig; +namespace proton { class DocumentDBConfig; } -namespace documentmetastore { +namespace proton::documentmetastore { /* * Class representing configuration for lid reuse delayer. @@ -24,6 +23,4 @@ public: bool hasIndexedOrAttributeFields() const { return _hasIndexedOrAttributeFields; } }; -} // namespace proton::documentmetastore - -} // 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 61f332bd5fc..ebb7ad5ecd2 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/flush_engine_explorer.cpp +++ b/searchcore/src/vespa/searchcore/proton/flushengine/flush_engine_explorer.cpp @@ -15,15 +15,13 @@ namespace proton { namespace { void -convertToSlime(const FlushEngine::FlushMetaSet &flushingTargets, - const fastos::TimeStamp &now, - Cursor &array) +convertToSlime(const FlushEngine::FlushMetaSet &flushingTargets, Cursor &array) { for (const auto &target : flushingTargets) { Cursor &object = array.addObject(); object.setString("name", target.getName()); object.setString("startTime", target.getStart().toString()); - fastos::TimeStamp elapsedTime = now - target.getStart(); + fastos::TimeStamp elapsedTime = target.elapsed(); object.setDouble("elapsedTime", elapsedTime.sec()); } } @@ -40,7 +38,7 @@ sortTargetList(FlushContext::List &allTargets) void convertToSlime(const FlushContext::List &allTargets, - const fastos::TimeStamp &now, + const fastos::UTCTimeStamp &now, Cursor &array) { for (const auto &ctx : allTargets) { @@ -69,8 +67,8 @@ FlushEngineExplorer::get_state(const Inserter &inserter, bool full) const { Cursor &object = inserter.insertObject(); if (full) { - fastos::TimeStamp now = fastos::ClockSystem::now(); - convertToSlime(_engine.getCurrentlyFlushingSet(), now, object.setArray("flushingTargets")); + fastos::UTCTimeStamp now = fastos::ClockSystem::now(); + convertToSlime(_engine.getCurrentlyFlushingSet(), object.setArray("flushingTargets")); FlushContext::List allTargets = _engine.getTargetList(true); sortTargetList(allTargets); convertToSlime(allTargets, now, object.setArray("allTargets")); diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp index 44406e2227a..1922b906075 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp +++ b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.cpp @@ -51,15 +51,15 @@ logTarget(const char * text, const FlushContext & ctx) { } -FlushEngine::FlushMeta::FlushMeta(const vespalib::string & name, fastos::TimeStamp start, uint32_t id) +FlushEngine::FlushMeta::FlushMeta(const vespalib::string & name, uint32_t id) : _name(name), - _start(start), + _stopWatch(), _id(id) { } FlushEngine::FlushMeta::~FlushMeta() = default; FlushEngine::FlushInfo::FlushInfo() - : FlushMeta("", fastos::ClockSystem::now(), 0), + : FlushMeta("", 0), _target() { } @@ -68,7 +68,7 @@ FlushEngine::FlushInfo::~FlushInfo() = default; FlushEngine::FlushInfo::FlushInfo(uint32_t taskId, const IFlushTarget::SP &target, const vespalib::string & destination) - : FlushMeta(destination, fastos::ClockSystem::now(), taskId), + : FlushMeta(destination, taskId), _target(target) { } @@ -351,7 +351,7 @@ FlushEngine::flushDone(const FlushContext &ctx, uint32_t taskId) fastos::TimeStamp duration; { std::lock_guard<std::mutex> guard(_lock); - duration = fastos::TimeStamp(fastos::ClockSystem::now()) - _flushing[taskId].getStart(); + duration = _flushing[taskId].elapsed(); } if (LOG_WOULD_LOG(event)) { FlushStats stats = ctx.getTarget()->getLastFlushStats(); diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h index c1be05ba067..38f8eabf828 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h +++ b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h @@ -20,15 +20,16 @@ class FlushEngine final : public FastOS_Runnable public: class FlushMeta { public: - FlushMeta(const vespalib::string & name, fastos::TimeStamp start, uint32_t id); + FlushMeta(const vespalib::string & name, uint32_t id); ~FlushMeta(); const vespalib::string & getName() const { return _name; } - fastos::TimeStamp getStart() const { return _start; } + fastos::UTCTimeStamp getStart() const { return fastos::ClockSystem::now() - elapsed(); } + fastos::TimeStamp elapsed() const { return _stopWatch.stop().elapsed(); } uint32_t getId() const { return _id; } bool operator < (const FlushMeta & rhs) const { return _id < rhs._id; } private: vespalib::string _name; - fastos::TimeStamp _start; + mutable fastos::StopWatch _stopWatch; 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 d24cb77f86b..03a905a18ca 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 @@ -15,8 +15,8 @@ class ShrinkLidSpaceFlushTarget::Flusher : public FlushTask SerialNum _flushSerialNum; public: Flusher(ShrinkLidSpaceFlushTarget &target, SerialNum flushSerialNum); - virtual void run() override; - virtual search::SerialNum getFlushSerial() const override; + void run() override; + search::SerialNum getFlushSerial() const override; }; ShrinkLidSpaceFlushTarget::Flusher::Flusher(ShrinkLidSpaceFlushTarget &target, SerialNum flushSerialNum) diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/shrink_lid_space_flush_target.h b/searchcore/src/vespa/searchcore/proton/flushengine/shrink_lid_space_flush_target.h index f2123bf67b4..c1ecb2c2b4a 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/shrink_lid_space_flush_target.h +++ b/searchcore/src/vespa/searchcore/proton/flushengine/shrink_lid_space_flush_target.h @@ -42,14 +42,14 @@ public: std::shared_ptr<ICompactableLidSpace> target); // Implements IFlushTarget. - virtual MemoryGain getApproxMemoryGain() const override; - virtual DiskGain getApproxDiskGain() const override; - virtual SerialNum getFlushedSerialNum() const override; - virtual Time getLastFlushTime() const override; - virtual bool needUrgentFlush() const override; - virtual Task::UP initFlush(SerialNum currentSerial) override; - virtual searchcorespi::FlushStats getLastFlushStats() const override; - virtual uint64_t getApproxBytesToWriteToDisk() const override; + MemoryGain getApproxMemoryGain() const override; + DiskGain getApproxDiskGain() const override; + SerialNum getFlushedSerialNum() const override; + Time getLastFlushTime() const override; + bool needUrgentFlush() const override; + Task::UP initFlush(SerialNum currentSerial) override; + searchcorespi::FlushStats getLastFlushStats() const override; + uint64_t getApproxBytesToWriteToDisk() const override; }; } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp index 7c581d7b01d..48599b1ecff 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp @@ -287,7 +287,7 @@ Matcher::match(const SearchRequest &request, vespalib::ThreadBundle &threadBundl _stats.add(my_stats); if (my_stats.softDoomed()) { double old = _stats.softDoomFactor(); - fastos::TimeStamp softLimit = uint64_t((1.0 - _rankSetup->getSoftTimeoutTailCost()) * request.getTimeout()); + fastos::TimeStamp softLimit = (1.0 - _rankSetup->getSoftTimeoutTailCost()) * request.getTimeout(); fastos::TimeStamp adjustedDuration = duration - my_stats.doomOvertime(); if (adjustedDuration < 0) { adjustedDuration = 0; diff --git a/searchcore/src/vespa/searchcore/proton/server/memoryflush.cpp b/searchcore/src/vespa/searchcore/proton/server/memoryflush.cpp index d3b65505277..8ea9e095385 100644 --- a/searchcore/src/vespa/searchcore/proton/server/memoryflush.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/memoryflush.cpp @@ -74,7 +74,7 @@ MemoryFlush::Config::Config(uint64_t maxGlobalMemory_in, maxTimeGain(maxTimeGain_in) { } -MemoryFlush::MemoryFlush(const Config &config, fastos::TimeStamp startTime) +MemoryFlush::MemoryFlush(const Config &config, fastos::UTCTimeStamp startTime) : _lock(), _config(config), _startTime(startTime) @@ -85,7 +85,7 @@ MemoryFlush::MemoryFlush() : MemoryFlush(Config(), fastos::ClockSystem::now()) { } -MemoryFlush::~MemoryFlush() { } +MemoryFlush::~MemoryFlush() = default; MemoryFlush::Config MemoryFlush::getConfig() const @@ -133,14 +133,14 @@ MemoryFlush::getFlushTargets(const FlushContext::List &targetList, uint64_t totalTlsSize(0); const Config config(getConfig()); vespalib::hash_set<const void *> visitedHandlers; - fastos::TimeStamp now(fastos::ClockSystem::now()); + fastos::UTCTimeStamp now(fastos::ClockSystem::now()); LOG(debug, "getFlushTargets(): globalMaxMemory(%" PRIu64 "), maxGlobalTlsSize(%" PRIu64 "), globalDiskBloatFactor(%f), " "maxMemoryGain(%" PRIu64 "), diskBloatFactor(%f), maxTimeGain(%f), startTime(%f)", config.maxGlobalMemory, config.maxGlobalTlsSize, config.globalDiskBloatFactor, config.maxMemoryGain, config.diskBloatFactor, config.maxTimeGain.sec(), - _startTime.sec()); + _startTime.timeSinceEpoch().sec()); for (size_t i(0), m(targetList.size()); i < m; i++) { const IFlushTarget & target(*targetList[i]->getTarget()); const IFlushHandler & handler(*targetList[i]->getHandler()); @@ -150,8 +150,8 @@ MemoryFlush::getFlushTargets(const FlushContext::List &targetList, SerialNum localLastSerial = targetList[i]->getLastSerial(); int64_t serialDiff = getSerialDiff(localLastSerial, target); vespalib::string name(getName(handler, target)); - fastos::TimeStamp lastFlushTime = target.getLastFlushTime(); - fastos::TimeStamp timeDiff(now - (lastFlushTime.val() > 0 ? lastFlushTime : _startTime)); + fastos::UTCTimeStamp lastFlushTime = target.getLastFlushTime(); + fastos::TimeStamp timeDiff(now - (lastFlushTime > fastos::UTCTimeStamp::ZERO ? lastFlushTime : _startTime)); totalMemory += mgain; const flushengine::TlsStats &tlsStats = tlsStatsMap.getTlsStats(handler.getName()); if (visitedHandlers.insert(&handler).second) { @@ -183,8 +183,8 @@ MemoryFlush::getFlushTargets(const FlushContext::List &targetList, target.getFlushedSerialNum(), localLastSerial, serialDiff, - lastFlushTime.sec(), - now.sec(), + lastFlushTime.timeSinceEpoch().sec(), + now.timeSinceEpoch().sec(), timeDiff.sec(), getOrderName(order).c_str()); } diff --git a/searchcore/src/vespa/searchcore/proton/server/memoryflush.h b/searchcore/src/vespa/searchcore/proton/server/memoryflush.h index 7e9bba59b25..532abe939cb 100644 --- a/searchcore/src/vespa/searchcore/proton/server/memoryflush.h +++ b/searchcore/src/vespa/searchcore/proton/server/memoryflush.h @@ -42,7 +42,7 @@ private: mutable std::mutex _lock; Config _config; /// The time when the strategy was started. - fastos::TimeStamp _startTime; + fastos::UTCTimeStamp _startTime; class CompareTarget { @@ -63,7 +63,7 @@ public: MemoryFlush(); explicit MemoryFlush(const Config &config) : MemoryFlush(config, fastos::ClockSystem::now()) { } - MemoryFlush(const Config &config, fastos::TimeStamp startTime); + MemoryFlush(const Config &config, fastos::UTCTimeStamp startTime); ~MemoryFlush(); FlushContext::List diff --git a/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp b/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp index 96952cf9f13..b5a430b3bcb 100644 --- a/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp @@ -12,8 +12,7 @@ LOG_SETUP(".proton.server.pruneremoveddocumentsjob"); using document::BucketId; using storage::spi::Timestamp; -namespace proton -{ +namespace proton { PruneRemovedDocumentsJob:: PruneRemovedDocumentsJob(const Config &config, @@ -45,10 +44,8 @@ PruneRemovedDocumentsJob::flush(DocId lowLid, DocId nextLowLid, DocId docIdLimit = _metaStore.getCommittedDocIdLimit(); PruneRemovedDocumentsOperation pruneOp(docIdLimit, _subDbId); LidVectorContext::SP lvCtx(pruneOp.getLidsToRemove()); - for (std::vector<DocId>::const_iterator it = _pruneLids.begin(), - ite = _pruneLids.end(); - it != ite; ++it) { - lvCtx->addLid(*it); + for (DocId docId : _pruneLids) { + lvCtx->addLid(docId); } _pruneLids.clear(); LOG(debug, @@ -68,9 +65,9 @@ bool PruneRemovedDocumentsJob::run() { uint64_t tshz = 1000000; - fastos::TimeStamp now = fastos::ClockSystem::now(); + fastos::UTCTimeStamp now = fastos::ClockSystem::now(); const Timestamp ageLimit(static_cast<Timestamp::Type> - ((now.sec() - _cfgAgeLimit) * tshz)); + ((now.timeSinceEpoch().sec() - _cfgAgeLimit) * tshz)); 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 551cf4615b0..42c5d964aed 100644 --- a/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.h +++ b/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.h @@ -5,8 +5,7 @@ #include "document_db_maintenance_config.h" #include <persistence/spi/types.h> -namespace proton -{ +namespace proton { struct IDocumentMetaStore; class IPruneRemovedDocumentsHandler; @@ -30,8 +29,7 @@ private: std::vector<DocId> _pruneLids; DocId _nextLid; - void - flush(DocId lowLid, DocId nextLowLid, const storage::spi::Timestamp ageLimit); + void flush(DocId lowLid, DocId nextLowLid, const storage::spi::Timestamp ageLimit); public: using Config = DocumentDBPruneRemovedDocumentsConfig; @@ -43,7 +41,7 @@ public: IFrozenBucketHandler &frozenHandler); // Implements IMaintenanceJob - virtual bool run() override; + bool run() override; }; } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/test/dummy_document_store.h b/searchcore/src/vespa/searchcore/proton/test/dummy_document_store.h index a62e5e77bc1..2eee9b5dd8e 100644 --- a/searchcore/src/vespa/searchcore/proton/test/dummy_document_store.h +++ b/searchcore/src/vespa/searchcore/proton/test/dummy_document_store.h @@ -17,49 +17,47 @@ struct DummyDocumentStore : public search::IDocumentStore : _baseDir(baseDir) {} ~DummyDocumentStore() {} - virtual document::Document::UP read(search::DocumentIdT, - const document::DocumentTypeRepo &) const override { + document::Document::UP read(search::DocumentIdT, const document::DocumentTypeRepo &) const override { return document::Document::UP(); } - virtual void write(uint64_t, search::DocumentIdT, const document::Document &) override {} - virtual void write(uint64_t, search::DocumentIdT, const vespalib::nbostream &) override {} - virtual void remove(uint64_t, search::DocumentIdT) override {} - virtual void flush(uint64_t) override {} - virtual uint64_t initFlush(uint64_t) override { return 0; } - virtual void compact(uint64_t) override {} - virtual uint64_t lastSyncToken() const override { return 0; } - virtual uint64_t tentativeLastSyncToken() const override { return 0; } - virtual fastos::TimeStamp getLastFlushTime() const override { return fastos::TimeStamp(); } - virtual uint32_t getDocIdLimit() const override { return 0; } - virtual size_t memoryUsed() const override { return 0; } - virtual size_t memoryMeta() const override { return 0; } - virtual size_t getDiskFootprint() const override { return 0; } - virtual size_t getDiskBloat() const override { return 0; } - virtual size_t getMaxCompactGain() const override { return getDiskBloat(); } - virtual search::CacheStats getCacheStats() const override { return search::CacheStats(); } - virtual const vespalib::string &getBaseDir() const override { return _baseDir; } - virtual void accept(search::IDocumentStoreReadVisitor &, - search::IDocumentStoreVisitorProgress &, - const document::DocumentTypeRepo &) override {} - - virtual void accept(search::IDocumentStoreRewriteVisitor &, - search::IDocumentStoreVisitorProgress &, - const document::DocumentTypeRepo &) override {} - - virtual double getVisitCost() const override { return 1.0; } - virtual search::DataStoreStorageStats getStorageStats() const override { + void write(uint64_t, search::DocumentIdT, const document::Document &) override {} + void write(uint64_t, search::DocumentIdT, const vespalib::nbostream &) override {} + void remove(uint64_t, search::DocumentIdT) override {} + void flush(uint64_t) override {} + uint64_t initFlush(uint64_t) override { return 0; } + void compact(uint64_t) override {} + uint64_t lastSyncToken() const override { return 0; } + uint64_t tentativeLastSyncToken() const override { return 0; } + fastos::UTCTimeStamp getLastFlushTime() const override { return fastos::UTCTimeStamp::ZERO; } + uint32_t getDocIdLimit() const override { return 0; } + size_t memoryUsed() const override { return 0; } + size_t memoryMeta() const override { return 0; } + size_t getDiskFootprint() const override { return 0; } + size_t getDiskBloat() const override { return 0; } + size_t getMaxCompactGain() const override { return getDiskBloat(); } + search::CacheStats getCacheStats() const override { return search::CacheStats(); } + const vespalib::string &getBaseDir() const override { return _baseDir; } + void accept(search::IDocumentStoreReadVisitor &, + search::IDocumentStoreVisitorProgress &, + const document::DocumentTypeRepo &) override {} + void accept(search::IDocumentStoreRewriteVisitor &, + search::IDocumentStoreVisitorProgress &, + const document::DocumentTypeRepo &) override {} + + double getVisitCost() const override { return 1.0; } + search::DataStoreStorageStats getStorageStats() const override { return search::DataStoreStorageStats(0, 0, 0.0, 0, 0, 0); } - virtual vespalib::MemoryUsage getMemoryUsage() const override { return vespalib::MemoryUsage(); } - virtual std::vector<search::DataStoreFileChunkStats> getFileChunkStats() const override { + vespalib::MemoryUsage getMemoryUsage() const override { return vespalib::MemoryUsage(); } + std::vector<search::DataStoreFileChunkStats> getFileChunkStats() const override { std::vector<search::DataStoreFileChunkStats> result; return result; } - virtual void compactLidSpace(uint32_t wantedDocLidLimit) override { (void) wantedDocLidLimit; } - virtual bool canShrinkLidSpace() const override { return false; } - virtual size_t getEstimatedShrinkLidSpaceGain() const override { return 0; } - virtual void shrinkLidSpace() override {} + void compactLidSpace(uint32_t wantedDocLidLimit) override { (void) wantedDocLidLimit; } + bool canShrinkLidSpace() const override { return false; } + size_t getEstimatedShrinkLidSpaceGain() const override { return 0; } + void shrinkLidSpace() override {} }; } diff --git a/searchcorespi/src/vespa/searchcorespi/flush/iflushtarget.h b/searchcorespi/src/vespa/searchcorespi/flush/iflushtarget.h index aab16ab107f..6d3313b4cf2 100644 --- a/searchcorespi/src/vespa/searchcorespi/flush/iflushtarget.h +++ b/searchcorespi/src/vespa/searchcorespi/flush/iflushtarget.h @@ -38,7 +38,7 @@ public: private: vespalib::string _name; - Type _type; + Type _type; Component _component; public: @@ -57,10 +57,10 @@ public: T _before; T _after; }; - typedef Gain<int64_t> MemoryGain; - typedef Gain<int64_t> DiskGain; - typedef search::SerialNum SerialNum; - typedef fastos::TimeStamp Time; + using MemoryGain = Gain<int64_t>; + using DiskGain = Gain<int64_t>; + using SerialNum = search::SerialNum; + using Time = fastos::UTCTimeStamp; /** * Convenience typedefs. diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexflushtarget.cpp b/searchcorespi/src/vespa/searchcorespi/index/indexflushtarget.cpp index 3486f7167c0..e7bc26b8dd1 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/indexflushtarget.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/indexflushtarget.cpp @@ -8,8 +8,7 @@ LOG_SETUP(".searchcorespi.index.indexflushtarget"); using vespalib::makeClosure; -namespace searchcorespi { -namespace index { +namespace searchcorespi::index { IndexFlushTarget::IndexFlushTarget(IndexMaintainer &indexMaintainer) : IFlushTarget("memoryindex.flush", Type::FLUSH, Component::INDEX), @@ -22,7 +21,7 @@ IndexFlushTarget::IndexFlushTarget(IndexMaintainer &indexMaintainer) _lastStats.setPathElementsToLog(7); } -IndexFlushTarget::~IndexFlushTarget() {} +IndexFlushTarget::~IndexFlushTarget() = default; IFlushTarget::MemoryGain IndexFlushTarget::getApproxMemoryGain() const @@ -38,7 +37,7 @@ IndexFlushTarget::getApproxDiskGain() const bool -IndexFlushTarget::needUrgentFlush(void) const +IndexFlushTarget::needUrgentFlush() const { bool urgent = _numFrozenMemoryIndexes > _maxFrozenMemoryIndexes; SerialNum flushedSerial = _indexMaintainer.getFlushedSerialNum(); @@ -80,6 +79,4 @@ IndexFlushTarget::getApproxBytesToWriteToDisk() const } } - -} // namespace index -} // namespace searchcorespi +} diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexfusiontarget.cpp b/searchcorespi/src/vespa/searchcorespi/index/indexfusiontarget.cpp index 4c01bf83779..a9b4531fe93 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/indexfusiontarget.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/indexfusiontarget.cpp @@ -17,16 +17,18 @@ private: SerialNum _serialNum; public: Fusioner(IndexMaintainer &indexMaintainer, FlushStats &stats, SerialNum serialNum) : - _indexMaintainer(indexMaintainer), _stats(stats), _serialNum(serialNum) {} - virtual void run() override { + _indexMaintainer(indexMaintainer), + _stats(stats), + _serialNum(serialNum) + {} + + void run() override { vespalib::string outputFusionDir = _indexMaintainer.doFusion(_serialNum); // the target must live until this task is done (handled by flush engine). _stats.setPath(outputFusionDir); } - virtual SerialNum - getFlushSerial(void) const override - { + SerialNum getFlushSerial() const override { return 0u; // Zero means that no tls syncing is needed } }; @@ -42,7 +44,7 @@ IndexFusionTarget::IndexFusionTarget(IndexMaintainer &indexMaintainer) LOG(debug, "New target, Num flushed: %d, Disk usage: %" PRIu64, _fusionStats.numUnfused, _fusionStats.diskUsage); } -IndexFusionTarget::~IndexFusionTarget() {} +IndexFusionTarget::~IndexFusionTarget() = default; IFlushTarget::MemoryGain IndexFusionTarget::getApproxMemoryGain() const @@ -54,13 +56,7 @@ IFlushTarget::DiskGain IndexFusionTarget::getApproxDiskGain() const { uint64_t diskUsageBefore = _fusionStats.diskUsage; - uint64_t diskUsageGain = - static_cast<uint64_t>((0.1 * - (diskUsageBefore * - std::max(0, - static_cast<int> - (_fusionStats.numUnfused - 1) - )))); + uint64_t diskUsageGain = static_cast<uint64_t>((0.1 * (diskUsageBefore * std::max(0,static_cast<int>(_fusionStats.numUnfused - 1))))); diskUsageGain = std::min(diskUsageGain, diskUsageBefore); if (!_fusionStats._canRunFusion) diskUsageGain = 0; @@ -70,8 +66,7 @@ IndexFusionTarget::getApproxDiskGain() const bool IndexFusionTarget::needUrgentFlush() const { - bool urgent = _fusionStats.numUnfused > _fusionStats.maxFlushed && - _fusionStats._canRunFusion; + bool urgent = (_fusionStats.numUnfused > _fusionStats.maxFlushed) && (_fusionStats._canRunFusion); LOG(debug, "Num flushed: %d Urgent: %d", _fusionStats.numUnfused, urgent); return urgent; } @@ -93,7 +88,7 @@ IndexFusionTarget::getFlushedSerialNum() const IFlushTarget::Task::UP IndexFusionTarget::initFlush(SerialNum serialNum) { - return Task::UP(new Fusioner(_indexMaintainer, _lastStats, serialNum)); + return std::make_unique<Fusioner>(_indexMaintainer, _lastStats, serialNum); } uint64_t @@ -102,5 +97,4 @@ IndexFusionTarget::getApproxBytesToWriteToDisk() const return _fusionStats.diskUsage; } - } diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp index 083fe70969c..45bd2a52349 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp @@ -620,8 +620,8 @@ IndexMaintainer::doneFlush(FlushArgs *args, IDiskIndex::SP *disk_index) { return false; // Must retry operation } _flush_serial_num = std::max(_flush_serial_num, args->flush_serial_num); - fastos::TimeStamp timeStamp = search::FileKit::getModificationTime((*disk_index)->getIndexDir()); - _lastFlushTime = timeStamp.time() > _lastFlushTime.time() ? timeStamp : _lastFlushTime; + fastos::UTCTimeStamp timeStamp = search::FileKit::getModificationTime((*disk_index)->getIndexDir()); + _lastFlushTime = timeStamp > _lastFlushTime ? timeStamp : _lastFlushTime; const uint32_t old_id = args->old_absolute_id - _last_fusion_id; replaceSource(old_id, *disk_index); return true; @@ -947,7 +947,7 @@ IndexMaintainer::initFlush(SerialNum serialNum, searchcorespi::FlushStats * stat _lastFlushTime = fastos::ClockSystem::now(); LOG(debug, "No memory index to flush. Update serial number and flush time to current: " "flushSerialNum(%" PRIu64 "), lastFlushTime(%f)", - _flush_serial_num, _lastFlushTime.sec()); + _flush_serial_num, _lastFlushTime.timeSinceEpoch().sec()); return FlushTask::UP(); } SerialNum realSerialNum = args.flush_serial_num; diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h index e95613017fa..a1bf676e48f 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h +++ b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.h @@ -87,14 +87,14 @@ class IndexMaintainer : public IIndexManager, // _selector is protected by SL + IUL ISourceSelector::SP _selector; ISearchableIndexCollection::SP _source_list; // Protected by SL + NSL, only set by master thread - uint32_t _last_fusion_id; // Protected by SL + IUL - uint32_t _next_id; // Protected by SL + IUL - uint32_t _current_index_id; // Protected by SL + IUL - IMemoryIndex::SP _current_index; // Protected by SL + IUL - bool _flush_empty_current_index; - SerialNum _current_serial_num;// Protected by IUL - SerialNum _flush_serial_num; // Protected by SL - fastos::TimeStamp _lastFlushTime; // Protected by SL + uint32_t _last_fusion_id; // Protected by SL + IUL + uint32_t _next_id; // Protected by SL + IUL + uint32_t _current_index_id; // Protected by SL + IUL + IMemoryIndex::SP _current_index; // Protected by SL + IUL + bool _flush_empty_current_index; + SerialNum _current_serial_num;// Protected by IUL + SerialNum _flush_serial_num; // Protected by SL + fastos::UTCTimeStamp _lastFlushTime; // Protected by SL // Extra frozen memory indexes. This list is empty unless new // memory index has been added by force (due to config change or // data structure limitations). @@ -335,7 +335,7 @@ public: uint32_t getNumFrozenMemoryIndexes() const; uint32_t getMaxFrozenMemoryIndexes() const { return _maxFrozen; } - fastos::TimeStamp getLastFlushTime() const { return _lastFlushTime; } + fastos::UTCTimeStamp getLastFlushTime() const { return _lastFlushTime; } // Implements IIndexManager void putDocument(uint32_t lid, const Document &doc, SerialNum serialNum) override; diff --git a/searchlib/src/tests/docstore/document_store/document_store_test.cpp b/searchlib/src/tests/docstore/document_store/document_store_test.cpp index 3597de0dcc5..6ea5176f4f3 100644 --- a/searchlib/src/tests/docstore/document_store/document_store_test.cpp +++ b/searchlib/src/tests/docstore/document_store/document_store_test.cpp @@ -27,7 +27,7 @@ struct NullDataStore : IDataStore { size_t getDiskBloat() const override { return 0; } uint64_t lastSyncToken() const override { return 0; } uint64_t tentativeLastSyncToken() const override { return 0; } - fastos::TimeStamp getLastFlushTime() const override { return fastos::TimeStamp(); } + fastos::UTCTimeStamp getLastFlushTime() const override { return fastos::UTCTimeStamp::ZERO; } void accept(IDataStoreVisitor &, IDataStoreVisitorProgress &, bool) override { } double getVisitCost() const override { return 1.0; } DataStoreStorageStats getStorageStats() const override { diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index 35e21d133c2..4e2450dccc9 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -757,21 +757,21 @@ TEST("requireThatSyncTokenIsUpdatedAfterFlush") { TEST("requireThatFlushTimeIsAvailableAfterFlush") { TmpDirectory testDir("flushtime"); - fastos::TimeStamp before(fastos::ClockSystem::now()); + fastos::UTCTimeStamp before(fastos::ClockSystem::now()); DummyFileHeaderContext fileHeaderContext; LogDataStore::Config config; vespalib::ThreadStackExecutor executor(1, 128*1024); MyTlSyncer tlSyncer; LogDataStore store(executor, testDir.getDir(), config, GrowStrategy(), TuneFileSummary(), fileHeaderContext, tlSyncer, nullptr); - EXPECT_EQUAL(0, store.getLastFlushTime().time()); + EXPECT_EQUAL(0, store.getLastFlushTime().timeSinceEpoch().time()); uint64_t flushToken = store.initFlush(5); EXPECT_EQUAL(5u, flushToken); store.flush(flushToken); - fastos::TimeStamp after(fastos::ClockSystem::now()); + fastos::UTCTimeStamp after(fastos::ClockSystem::now()); // the file name of the dat file is 'magic', using the clock instead of stating the file - EXPECT_LESS_EQUAL(before.time(), store.getLastFlushTime().time()); - EXPECT_GREATER_EQUAL(after.time(), store.getLastFlushTime().time()); + EXPECT_LESS_EQUAL(before, store.getLastFlushTime()); + EXPECT_GREATER_EQUAL(after, store.getLastFlushTime()); } diff --git a/searchlib/src/tests/util/bufferwriter/bm.cpp b/searchlib/src/tests/util/bufferwriter/bm.cpp index b19a7390e9c..ac3cc3a09b1 100644 --- a/searchlib/src/tests/util/bufferwriter/bm.cpp +++ b/searchlib/src/tests/util/bufferwriter/bm.cpp @@ -11,8 +11,6 @@ LOG_SETUP("bufferwriter_bm"); using search::DrainingBufferWriter; -double getTime() { return fastos::TimeStamp(fastos::ClockSystem::now()).sec(); } - constexpr size_t million = 1000000; enum class WorkFuncDispatch @@ -33,7 +31,7 @@ callWork(size_t size, WorkFuncDispatch dispatch) foo.resize(size); std::cout << "will write " << size << " elements of size " << sizeof(T) << std::endl; - double before = getTime(); + fastos::StopWatch stopWatch; switch (dispatch) { case WorkFuncDispatch::DIRECT: work(foo, writer); @@ -50,8 +48,7 @@ callWork(size_t size, WorkFuncDispatch dispatch) default: LOG_ABORT("should not be reached"); } - double after = getTime(); - double delta = (after - before); + double delta = stopWatch.stop().elapsed(); double writeSpeed = writer.getBytesWritten() / delta; EXPECT_GREATER(writeSpeed, 1000); std::cout << "written is " << writer.getBytesWritten() << std::endl; diff --git a/searchlib/src/vespa/searchlib/common/fileheadercontext.cpp b/searchlib/src/vespa/searchlib/common/fileheadercontext.cpp index 4f29c3b7b87..5c23953b9b3 100644 --- a/searchlib/src/vespa/searchlib/common/fileheadercontext.cpp +++ b/searchlib/src/vespa/searchlib/common/fileheadercontext.cpp @@ -2,26 +2,23 @@ #include "fileheadercontext.h" #include <vespa/vespalib/data/fileheader.h> -#include <vespa/fastos/timestamp.h> +#include <chrono> + +using namespace std::chrono; namespace search::common { using vespalib::GenericHeader; -FileHeaderContext::FileHeaderContext() -{ -} +FileHeaderContext::FileHeaderContext() = default; -FileHeaderContext::~FileHeaderContext() -{ -} +FileHeaderContext::~FileHeaderContext() = default; void FileHeaderContext::addCreateAndFreezeTime(GenericHeader &header) { typedef GenericHeader::Tag Tag; - fastos::TimeStamp ts(fastos::ClockSystem::now()); - header.putTag(Tag("createTime", ts.us())); + header.putTag(Tag("createTime", duration_cast<microseconds>(system_clock::now().time_since_epoch()).count())); header.putTag(Tag("freezeTime", 0)); } @@ -31,8 +28,7 @@ FileHeaderContext::setFreezeTime(GenericHeader &header) typedef GenericHeader::Tag Tag; if (header.hasTag("freezeTime") && header.getTag("freezeTime").getType() == Tag::TYPE_INTEGER) { - fastos::TimeStamp ts(fastos::ClockSystem::now()); - header.putTag(Tag("freezeTime", ts.us())); + header.putTag(Tag("freezeTime", duration_cast<microseconds>(system_clock::now().time_since_epoch()).count())); } } diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp index e7efe3f366b..a180a303780 100644 --- a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp +++ b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp @@ -274,7 +274,7 @@ DocumentStore::tentativeLastSyncToken() const return _backingStore.tentativeLastSyncToken(); } -fastos::TimeStamp +fastos::UTCTimeStamp DocumentStore::getLastFlushTime() const { return _backingStore.getLastFlushTime(); diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.h b/searchlib/src/vespa/searchlib/docstore/documentstore.h index a2b855deaf6..8bdba21f8d5 100644 --- a/searchlib/src/vespa/searchlib/docstore/documentstore.h +++ b/searchlib/src/vespa/searchlib/docstore/documentstore.h @@ -75,7 +75,7 @@ public: void compact(uint64_t syncToken) override; uint64_t lastSyncToken() const override; uint64_t tentativeLastSyncToken() const override; - fastos::TimeStamp getLastFlushTime() const override; + fastos::UTCTimeStamp getLastFlushTime() const override; uint32_t getDocIdLimit() const override { return _backingStore.getDocIdLimit(); } size_t memoryUsed() const override { return _backingStore.memoryUsed(); } size_t getDiskFootprint() const override { return _backingStore.getDiskFootprint(); } diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp index fecee481b77..94214ad7d84 100644 --- a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp +++ b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp @@ -293,7 +293,7 @@ FileChunk::getLastPersistedSerialNum() const return _lastPersistedSerialNum; } -fastos::TimeStamp +fastos::UTCTimeStamp FileChunk::getModificationTime() const { return _modificationTime; diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.h b/searchlib/src/vespa/searchlib/docstore/filechunk.h index 9f09d535880..2e47f010fc3 100644 --- a/searchlib/src/vespa/searchlib/docstore/filechunk.h +++ b/searchlib/src/vespa/searchlib/docstore/filechunk.h @@ -159,7 +159,7 @@ public: size_t getErasedBytes() const { return _erasedBytes; } uint64_t getLastPersistedSerialNum() const; uint32_t getDocIdLimit() const { return _docIdLimit; } - virtual fastos::TimeStamp getModificationTime() const; + virtual fastos::UTCTimeStamp getModificationTime() const; virtual bool frozen() const { return true; } const vespalib::string & getName() const { return _name; } void compact(const IGetLid & iGetLid); @@ -239,17 +239,17 @@ protected: static void writeDocIdLimit(vespalib::GenericHeader &header, uint32_t docIdLimit); typedef vespalib::Array<ChunkInfo> ChunkInfoVector; - const IBucketizer * _bucketizer; - size_t _addedBytes; - TuneFileSummary _tune; - vespalib::string _dataFileName; - vespalib::string _idxFileName; - ChunkInfoVector _chunkInfo; - uint32_t _dataHeaderLen; - uint32_t _idxHeaderLen; - uint64_t _lastPersistedSerialNum; - uint32_t _docIdLimit; // Limit when the file was created. Stored in idx file header. - fastos::TimeStamp _modificationTime; + const IBucketizer * _bucketizer; + size_t _addedBytes; + TuneFileSummary _tune; + vespalib::string _dataFileName; + vespalib::string _idxFileName; + ChunkInfoVector _chunkInfo; + uint32_t _dataHeaderLen; + uint32_t _idxHeaderLen; + uint64_t _lastPersistedSerialNum; + uint32_t _docIdLimit; // Limit when the file was created. Stored in idx file header. + fastos::UTCTimeStamp _modificationTime; }; } // namespace search diff --git a/searchlib/src/vespa/searchlib/docstore/idatastore.h b/searchlib/src/vespa/searchlib/docstore/idatastore.h index e2d89fc160c..f0545ce1d9b 100644 --- a/searchlib/src/vespa/searchlib/docstore/idatastore.h +++ b/searchlib/src/vespa/searchlib/docstore/idatastore.h @@ -145,7 +145,7 @@ public: * or 0 if no flush has been performed yet. * @return Time of last flush. **/ - virtual fastos::TimeStamp getLastFlushTime() const = 0; + virtual fastos::UTCTimeStamp getLastFlushTime() const = 0; /** * Visit all data found in data store. diff --git a/searchlib/src/vespa/searchlib/docstore/idocumentstore.h b/searchlib/src/vespa/searchlib/docstore/idocumentstore.h index cceae5d39ee..fc91d95b5a6 100644 --- a/searchlib/src/vespa/searchlib/docstore/idocumentstore.h +++ b/searchlib/src/vespa/searchlib/docstore/idocumentstore.h @@ -130,7 +130,7 @@ public: * or 0 if no flush has been performed yet. * @return Time of last flush. **/ - virtual fastos::TimeStamp getLastFlushTime() const = 0; + virtual fastos::UTCTimeStamp getLastFlushTime() const = 0; /** * Get the number of entries (including removed IDs diff --git a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp index e96628bdf4f..19b945ddd9c 100644 --- a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp +++ b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp @@ -247,20 +247,21 @@ LogDataStore::tentativeLastSyncToken() const return getActive(guard).getSerialNum(); } -fastos::TimeStamp +fastos::UTCTimeStamp LogDataStore::getLastFlushTime() const { if (lastSyncToken() == 0) { - return fastos::TimeStamp(); + return fastos::UTCTimeStamp::ZERO; } LockGuard guard(_updateLock); - fastos::TimeStamp timeStamp(getActive(guard).getModificationTime()); - if (timeStamp == 0) { + fastos::UTCTimeStamp timeStamp(getActive(guard).getModificationTime()); + if (timeStamp == fastos::UTCTimeStamp::ZERO) { const FileChunk * prev = getPrevActive(guard); if (prev != nullptr) { timeStamp = prev->getModificationTime(); } } + // TODO Needs to change when we decide on Flush time reference return timeStamp; } @@ -655,7 +656,7 @@ LogDataStore::createWritableFile(FileId fileId, SerialNum serialNum, NameId name FileChunk::UP LogDataStore::createWritableFile(FileId fileId, SerialNum serialNum) { - return createWritableFile(fileId, serialNum, NameId(fastos::ClockSystem::now())); + return createWritableFile(fileId, serialNum, NameId(fastos::ClockSystem::now().timeSinceEpoch())); } namespace { diff --git a/searchlib/src/vespa/searchlib/docstore/logdatastore.h b/searchlib/src/vespa/searchlib/docstore/logdatastore.h index 4ab747d115d..9ea1403fbe6 100644 --- a/searchlib/src/vespa/searchlib/docstore/logdatastore.h +++ b/searchlib/src/vespa/searchlib/docstore/logdatastore.h @@ -102,7 +102,7 @@ public: size_t memoryMeta() const override; uint64_t lastSyncToken() const override; uint64_t tentativeLastSyncToken() const override; - fastos::TimeStamp getLastFlushTime() const override; + fastos::UTCTimeStamp getLastFlushTime() const override; size_t getDiskFootprint() const override; size_t getDiskHeaderFootprint() const override; size_t getDiskBloat() const override; diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp index 50517cf09e2..d0fada0f498 100644 --- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp +++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp @@ -524,7 +524,7 @@ WriteableFileChunk::fileWriter(const uint32_t firstChunkId) } } -fastos::TimeStamp +fastos::UTCTimeStamp WriteableFileChunk::getModificationTime() const { LockGuard guard(_lock); @@ -832,7 +832,7 @@ WriteableFileChunk::flushPendingChunks(uint64_t serialNum) { if (frozen()) return; uint64_t datFileLen = _dataFile.getSize(); - fastos::TimeStamp timeStamp(fastos::ClockSystem::now()); + fastos::UTCTimeStamp timeStamp(fastos::ClockSystem::now()); if (needFlushPendingChunks(serialNum, datFileLen)) { timeStamp = unconditionallyFlushPendingChunks(flushGuard, serialNum, datFileLen); } @@ -840,7 +840,7 @@ WriteableFileChunk::flushPendingChunks(uint64_t serialNum) { _modificationTime = std::max(timeStamp, _modificationTime); } -fastos::TimeStamp +fastos::UTCTimeStamp WriteableFileChunk::unconditionallyFlushPendingChunks(const vespalib::LockGuard &flushGuard, uint64_t serialNum, uint64_t datFileLen) { (void) flushGuard; @@ -870,7 +870,7 @@ WriteableFileChunk::unconditionallyFlushPendingChunks(const vespalib::LockGuard os.write(os2.c_str(), os2.size()); } } - fastos::TimeStamp timeStamp(fastos::ClockSystem::now()); + fastos::UTCTimeStamp timeStamp(fastos::ClockSystem::now()); auto idxFile = openIdx(); idxFile->SetPosition(idxFile->GetSize()); ssize_t wlen = idxFile->Write2(os.c_str(), os.size()); diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h index 2c300bc9035..927ce524850 100644 --- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h +++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h @@ -57,7 +57,7 @@ public: uint64_t getSerialNum() const { return _serialNum; } void setSerialNum(uint64_t serialNum) { _serialNum = std::max(_serialNum, serialNum); } - fastos::TimeStamp getModificationTime() const override; + fastos::UTCTimeStamp getModificationTime() const override; void freeze(); size_t getDiskFootprint() const override; size_t getMemoryFootprint() const override; @@ -90,7 +90,7 @@ private: void writeDataHeader(const common::FileHeaderContext &fileHeaderContext); bool needFlushPendingChunks(uint64_t serialNum, uint64_t datFileLen); bool needFlushPendingChunks(const vespalib::MonitorGuard & guard, uint64_t serialNum, uint64_t datFileLen); - fastos::TimeStamp unconditionallyFlushPendingChunks(const vespalib::LockGuard & flushGuard, uint64_t serialNum, uint64_t datFileLen); + fastos::UTCTimeStamp unconditionallyFlushPendingChunks(const vespalib::LockGuard & flushGuard, uint64_t serialNum, uint64_t datFileLen); static void insertChunks(ProcessedChunkMap & orderedChunks, ProcessedChunkQ & newChunks, const uint32_t nextChunkId); static ProcessedChunkQ fetchNextChain(ProcessedChunkMap & orderedChunks, const uint32_t firstChunkId); ChunkMeta computeChunkMeta(const vespalib::LockGuard & guard, diff --git a/searchlib/src/vespa/searchlib/util/filekit.cpp b/searchlib/src/vespa/searchlib/util/filekit.cpp index 7fc4ca8e7bb..9230b66867c 100644 --- a/searchlib/src/vespa/searchlib/util/filekit.cpp +++ b/searchlib/src/vespa/searchlib/util/filekit.cpp @@ -90,14 +90,14 @@ FileKit::removeStamp(const vespalib::string &name) } -fastos::TimeStamp +fastos::UTCTimeStamp FileKit::getModificationTime(const vespalib::string &name) { FastOS_StatInfo statInfo; if (FastOS_File::Stat(name.c_str(), &statInfo)) { - return fastos::TimeStamp(statInfo._modifiedTimeNS); + return fastos::UTCTimeStamp(statInfo._modifiedTimeNS); } - return fastos::TimeStamp(); + return fastos::UTCTimeStamp(); } diff --git a/searchlib/src/vespa/searchlib/util/filekit.h b/searchlib/src/vespa/searchlib/util/filekit.h index 929412ee6d8..fc9d8cc84be 100644 --- a/searchlib/src/vespa/searchlib/util/filekit.h +++ b/searchlib/src/vespa/searchlib/util/filekit.h @@ -20,7 +20,7 @@ public: * Returns the modification time of the given file/directory, * or time stamp 0 if stating of file/directory fails. **/ - static fastos::TimeStamp getModificationTime(const vespalib::string &name); + static fastos::UTCTimeStamp getModificationTime(const vespalib::string &name); }; } diff --git a/staging_vespalib/src/tests/benchmark/testbase.cpp b/staging_vespalib/src/tests/benchmark/testbase.cpp index d8555974e79..bad2bdf0546 100644 --- a/staging_vespalib/src/tests/benchmark/testbase.cpp +++ b/staging_vespalib/src/tests/benchmark/testbase.cpp @@ -165,8 +165,8 @@ size_t ReturnByValueMultiVectorString::onRun() size_t ClockSystem::onRun() { - fastos::TimeStamp start(fastos::ClockSystem::now()); - fastos::TimeStamp end(start); + fastos::UTCTimeStamp start(fastos::ClockSystem::now()); + fastos::UTCTimeStamp end(start); for (size_t i=0; i < 1000; i++) { end = fastos::ClockSystem::now(); } diff --git a/vespalib/src/tests/btree/iteratespeed.cpp b/vespalib/src/tests/btree/iteratespeed.cpp index d1b9b3d7b1d..20aad948f33 100644 --- a/vespalib/src/tests/btree/iteratespeed.cpp +++ b/vespalib/src/tests/btree/iteratespeed.cpp @@ -21,8 +21,7 @@ #include <vespa/log/log.h> LOG_SETUP("iteratespeed"); -namespace search { -namespace btree { +namespace search::btree { enum class IterateMethod { @@ -84,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::TimeStamp before = fastos::ClockSystem::now(); + fastos::StopWatch stopWatch; uint64_t sum = 0; for (size_t innerl = 0; innerl < numInnerLoops; ++innerl) { if (iterateMethod == IterateMethod::FORWARD) { @@ -107,8 +106,7 @@ IterateSpeed::workLoop(int loops, bool enableForward, bool enableBackwards, [&](int key) { sum += key; } ); } } - fastos::TimeStamp after = fastos::ClockSystem::now(); - double used = after.sec() - before.sec(); + double used = stopWatch.stop().elapsed().sec(); printf("Elapsed time for iterating %ld steps is %8.5f, " "direction=%s, fanout=%u,%u, sum=%" PRIu64 "\n", numEntries * numInnerLoops, @@ -205,7 +203,6 @@ IterateSpeed::Main() } } -} FASTOS_MAIN(search::btree::IterateSpeed); |