diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-07 12:21:21 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-07 12:24:36 +0000 |
commit | 5e4a93cf7049b5ae25ed8cda192afd3d7126d5a1 (patch) | |
tree | 1874792ca0f145a2081a0ffb0d649f6aae762320 /storage | |
parent | 21a4d3c623ef93dc4ed37758fde1d7e0b493e998 (diff) |
Unify on using steady_time for visiting too.
Diffstat (limited to 'storage')
6 files changed, 31 insertions, 46 deletions
diff --git a/storage/src/tests/visiting/visitormanagertest.cpp b/storage/src/tests/visiting/visitormanagertest.cpp index be4e7270c69..a82514acb03 100644 --- a/storage/src/tests/visiting/visitormanagertest.cpp +++ b/storage/src/tests/visiting/visitormanagertest.cpp @@ -217,7 +217,7 @@ VisitorManagerTest::getSession(uint32_t n) // Wait until we have started the visitor const std::vector<TestVisitorMessageSession*>& sessions(_messageSessionFactory->_visitorSessions); framework::defaultimplementation::RealClock clock; - framework::MilliSecTime endTime(clock.getTimeInMillis() + framework::MilliSecTime(30 * 1000)); + vespalib::steady_time endTime = clock.getMonotonicTime() + 30s; while (true) { { std::lock_guard lock(_messageSessionFactory->_accessLock); @@ -225,9 +225,8 @@ VisitorManagerTest::getSession(uint32_t n) return *sessions[n]; } } - if (clock.getTimeInMillis() > endTime) { - throw vespalib::IllegalStateException( - "Timed out waiting for visitor session", VESPA_STRLOC); + if (clock.getMonotonicTime() > endTime) { + throw vespalib::IllegalStateException("Timed out waiting for visitor session", VESPA_STRLOC); } std::this_thread::sleep_for(10ms); } @@ -255,12 +254,10 @@ VisitorManagerTest::getMessagesAndReply( switch (session.sentMessages[i]->getType()) { case documentapi::DocumentProtocol::MESSAGE_PUTDOCUMENT: - docs.push_back(static_cast<documentapi::PutDocumentMessage&>( - *session.sentMessages[i]).getDocumentSP()); + docs.push_back(static_cast<documentapi::PutDocumentMessage&>(*session.sentMessages[i]).getDocumentSP()); break; case documentapi::DocumentProtocol::MESSAGE_REMOVEDOCUMENT: - docIds.push_back(static_cast<documentapi::RemoveDocumentMessage&>( - *session.sentMessages[i]).getDocumentId()); + docIds.push_back(static_cast<documentapi::RemoveDocumentMessage&>(*session.sentMessages[i]).getDocumentId()); break; default: break; @@ -355,10 +352,7 @@ TEST_F(VisitorManagerTest, normal_usage) { getMessagesAndReply(1, getSession(0), docs, docIds); // All data has been replied to, expecting to get a create visitor reply - ASSERT_NO_FATAL_FAILURE( - verifyCreateVisitorReply(api::ReturnCode::OK, - int(docs.size()), - getTotalSerializedSize(docs))); + ASSERT_NO_FATAL_FAILURE(verifyCreateVisitorReply(api::ReturnCode::OK, int(docs.size()), getTotalSerializedSize(docs))); EXPECT_EQ(1u, getMatchingDocuments(docs)); EXPECT_FALSE(_manager->hasPendingMessageState()); diff --git a/storage/src/tests/visiting/visitortest.cpp b/storage/src/tests/visiting/visitortest.cpp index f3a538b7832..565131b3b99 100644 --- a/storage/src/tests/visiting/visitortest.cpp +++ b/storage/src/tests/visiting/visitortest.cpp @@ -256,11 +256,9 @@ TestVisitorMessageSession& VisitorTest::getSession(uint32_t n) { // Wait until we have started the visitor - const std::vector<TestVisitorMessageSession*>& sessions( - _messageSessionFactory->_visitorSessions); + const std::vector<TestVisitorMessageSession*>& sessions(_messageSessionFactory->_visitorSessions); framework::defaultimplementation::RealClock clock; - framework::MilliSecTime endTime( - clock.getTimeInMillis() + framework::MilliSecTime(30 * 1000)); + vespalib::steady_time endTime = clock.getMonotonicTime() + 30s; while (true) { { std::lock_guard lock(_messageSessionFactory->_accessLock); @@ -268,7 +266,7 @@ VisitorTest::getSession(uint32_t n) return *sessions[n]; } } - if (clock.getTimeInMillis() > endTime) { + if (clock.getMonotonicTime() > endTime) { throw vespalib::IllegalStateException( "Timed out waiting for visitor session", VESPA_STRLOC); } diff --git a/storage/src/vespa/storage/visiting/visitormanager.cpp b/storage/src/vespa/storage/visiting/visitormanager.cpp index a03b9a9a8a3..07938002746 100644 --- a/storage/src/vespa/storage/visiting/visitormanager.cpp +++ b/storage/src/vespa/storage/visiting/visitormanager.cpp @@ -187,9 +187,8 @@ VisitorManager::configure(std::unique_ptr<vespa::config::content::core::StorVisi for (int32_t i=0; i<config->visitorthreads; ++i) { _visitorThread.emplace_back( // Naked new due to a lot of private inheritance in VisitorThread and VisitorManager - std::shared_ptr<VisitorThread>( - new VisitorThread(i, _componentRegister, _messageSessionFactory, - _visitorFactories, *_metrics->threads[i], *this)), + std::shared_ptr<VisitorThread>(new VisitorThread(i, _componentRegister, _messageSessionFactory, + _visitorFactories, *_metrics->threads[i], *this)), std::map<api::VisitorId, std::string>()); } } @@ -450,8 +449,7 @@ VisitorManager::processReply(const std::shared_ptr<api::StorageReply>& reply) } void -VisitorManager::send(const std::shared_ptr<api::StorageCommand>& cmd, - Visitor& visitor) +VisitorManager::send(const std::shared_ptr<api::StorageCommand>& cmd, Visitor& visitor) { assert(cmd->getType() == api::MessageType::INTERNAL); // Only add to internal state if not destroy iterator command, as @@ -460,7 +458,7 @@ VisitorManager::send(const std::shared_ptr<api::StorageCommand>& cmd, if (static_cast<const api::InternalCommand&>(*cmd).getType() != DestroyIteratorCommand::ID) { MessageInfo inf; inf.id = visitor.getVisitorId(); - inf.timestamp = _component.getClock().getTimeInSeconds().getTime(); + inf.timestamp = _component.getClock().getSystemTime(); inf.timeout = cmd->getTimeout(); if (cmd->getAddress()) { @@ -623,7 +621,7 @@ VisitorManager::reportHtmlStatus(std::ostream& out, out << "<tr>" << "<td>" << entry.first << "</td>" << "<td>" << entry.second.id << "</td>" - << "<td>" << entry.second.timestamp << "</td>" + << "<td>" << vespalib::to_string(entry.second.timestamp) << "</td>" << "<td>" << vespalib::count_ms(entry.second.timeout) << "</td>" << "<td>" << xml_content_escaped(entry.second.destination) << "</td>" << "</tr>\n"; diff --git a/storage/src/vespa/storage/visiting/visitormanager.h b/storage/src/vespa/storage/visiting/visitormanager.h index 33703b392bc..3e331e1c9a2 100644 --- a/storage/src/vespa/storage/visiting/visitormanager.h +++ b/storage/src/vespa/storage/visiting/visitormanager.h @@ -57,7 +57,7 @@ private: struct MessageInfo { api::VisitorId id; - time_t timestamp; + vespalib::system_time timestamp; vespalib::duration timeout; std::string destination; }; @@ -168,9 +168,7 @@ private: * by the formula: fixed + variable * ((255 - priority) / 255) */ uint32_t maximumConcurrent(const api::CreateVisitorCommand& cmd) const { - return _maxFixedConcurrentVisitors + static_cast<uint32_t>( - _maxVariableConcurrentVisitors - * ((255.0 - cmd.getPriority()) / 255.0)); + return _maxFixedConcurrentVisitors + static_cast<uint32_t>(_maxVariableConcurrentVisitors * ((255.0 - cmd.getPriority()) / 255.0)); } void updateMetrics(const MetricLockGuard &) override; diff --git a/storage/src/vespa/storage/visiting/visitorthread.cpp b/storage/src/vespa/storage/visiting/visitorthread.cpp index 55ef83ba658..e3ebef3a3ef 100644 --- a/storage/src/vespa/storage/visiting/visitorthread.cpp +++ b/storage/src/vespa/storage/visiting/visitorthread.cpp @@ -126,10 +126,10 @@ VisitorThread::shutdown() if (event._message.get()) { if (!event._message->getType().isReply() && (event._message->getType() != api::MessageType::INTERNAL - || static_cast<const api::InternalCommand&>(*event._message).getType() != PropagateVisitorConfig::ID)) + || dynamic_cast<const api::InternalCommand&>(*event._message).getType() != PropagateVisitorConfig::ID)) { std::shared_ptr<api::StorageReply> reply( - static_cast<api::StorageCommand&>(*event._message).makeReply()); + dynamic_cast<api::StorageCommand&>(*event._message).makeReply()); reply->setResult(api::ReturnCode(api::ReturnCode::ABORTED, "Shutting down storage node.")); _messageSender.send(reply); } @@ -197,7 +197,7 @@ VisitorThread::run(framework::ThreadHandle& thread) // disappear when no visiting is done) if (entry._message.get() && (entry._message->getType() != api::MessageType::INTERNAL - || static_cast<api::InternalCommand&>(*entry._message).getType() != PropagateVisitorConfig::ID)) + || dynamic_cast<api::InternalCommand&>(*entry._message).getType() != PropagateVisitorConfig::ID)) { entry._timer.stop(_metrics.averageQueueWaitingTime); } @@ -290,7 +290,7 @@ VisitorThread::close() } else { _metrics.completedVisitors.inc(1); } - framework::SecondTime currentTime(_component.getClock().getTimeInSeconds()); + vespalib::steady_time currentTime(_component.getClock().getMonotonicTime()); trimRecentlyCompletedList(currentTime); _recentlyCompleted.emplace_back(_currentlyRunningVisitor->first, currentTime); _visitors.erase(_currentlyRunningVisitor); @@ -298,9 +298,9 @@ VisitorThread::close() } void -VisitorThread::trimRecentlyCompletedList(framework::SecondTime currentTime) +VisitorThread::trimRecentlyCompletedList(vespalib::steady_time currentTime) { - framework::SecondTime recentLimit(currentTime - framework::SecondTime(30)); + vespalib::steady_time recentLimit(currentTime - 30s); // Dump all elements that aren't recent anymore while (!_recentlyCompleted.empty() && _recentlyCompleted.front().second < recentLimit) @@ -313,8 +313,7 @@ void VisitorThread::handleNonExistingVisitorCall(const Event& entry, ReturnCode& code) { // Get current time. Set the time that is the oldest still recent. - framework::SecondTime currentTime(_component.getClock().getTimeInSeconds()); - trimRecentlyCompletedList(currentTime); + trimRecentlyCompletedList(_component.getClock().getMonotonicTime()); // Go through all recent visitors. Ignore request if recent for (const auto& e : _recentlyCompleted) { @@ -344,7 +343,7 @@ VisitorThread::createVisitor(vespalib::stringref libName, auto it = _visitorFactories.find(str); if (it == _visitorFactories.end()) { error << "Visitor library " << str << " not found."; - return std::shared_ptr<Visitor>(); + return {}; } auto libIter = _libs.find(str); @@ -363,7 +362,7 @@ VisitorThread::createVisitor(vespalib::stringref libName, } catch (std::exception& e) { error << "Failed to create visitor instance of type " << libName << ": " << e.what(); - return std::shared_ptr<Visitor>(); + return {}; } } @@ -690,7 +689,7 @@ VisitorThread::getStatus(vespalib::asciistream& out, } for (const auto& cv : _recentlyCompleted) { out << "<li> Visitor " << cv.first << " done at " - << cv.second.getTime() << "\n"; + << vespalib::to_string(vespalib::to_utc(cv.second)) << "\n"; } out << "</ul>\n"; out << "<h3>Current queue size: " << _queue.size() << "</h3>\n"; @@ -736,12 +735,10 @@ VisitorThread::getStatus(vespalib::asciistream& out, if (_visitors.empty()) { out << "None\n"; } - for (VisitorMap::const_iterator it = _visitors.begin(); - it != _visitors.end(); ++it) - { - out << "<a href=\"?visitor=" << it->first + for (const auto & v : _visitors) { + out << "<a href=\"?visitor=" << v.first << (verbose ? "&verbose" : "") << "\">Visitor " - << it->first << "</a><br>\n"; + << v.first << "</a><br>\n"; } } } diff --git a/storage/src/vespa/storage/visiting/visitorthread.h b/storage/src/vespa/storage/visiting/visitorthread.h index 226e7c0631b..56e40328fda 100644 --- a/storage/src/vespa/storage/visiting/visitorthread.h +++ b/storage/src/vespa/storage/visiting/visitorthread.h @@ -38,7 +38,7 @@ class VisitorThread : public framework::Runnable, using VisitorMap = std::map<api::VisitorId, std::shared_ptr<Visitor>>; VisitorMap _visitors; - std::deque<std::pair<api::VisitorId, framework::SecondTime>> _recentlyCompleted; + std::deque<std::pair<api::VisitorId, vespalib::steady_time>> _recentlyCompleted; struct Event { enum class Type { @@ -118,7 +118,7 @@ private: */ Event popNextQueuedEventIfAvailable(); void tick(); - void trimRecentlyCompletedList(framework::SecondTime currentTime); + void trimRecentlyCompletedList(vespalib::steady_time currentTime); void handleNonExistingVisitorCall(const Event& entry, api::ReturnCode& code); std::shared_ptr<Visitor> createVisitor(vespalib::stringref libName, |