diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-12-15 17:23:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-15 17:23:56 +0100 |
commit | c6fa4683a9fb3b356e944078f114de555618b5d1 (patch) | |
tree | 10ad6d5d3d4d49b89f32f2ef974e1aad2e64a5e6 | |
parent | 28f8cf3e298d51ca703ceee36a992297d38637cc (diff) | |
parent | 3a1502c2e21eec47d34d73bb5ba641dfec51a5c2 (diff) |
Merge pull request #29677 from vespa-engine/balder/remove-most-of-clock-indirection
Remove most of the now void clock indirection.
40 files changed, 117 insertions, 147 deletions
diff --git a/searchcore/src/tests/grouping/grouping_test.cpp b/searchcore/src/tests/grouping/grouping_test.cpp index 951b0bf2857..905384416e6 100644 --- a/searchcore/src/tests/grouping/grouping_test.cpp +++ b/searchcore/src/tests/grouping/grouping_test.cpp @@ -178,7 +178,7 @@ TEST_F("testGroupingContextInitialization", DoomFixture()) { baseRequest.serialize(nos); AllocatedBitVector bv(1); - GroupingContext context(bv, f1.clock.clock(), f1.timeOfDoom, os.data(), os.size()); + GroupingContext context(bv, f1.clock.nowRef(), f1.timeOfDoom, os.data(), os.size()); ASSERT_TRUE(!context.empty()); GroupingContext::GroupingList list = context.getGroupingList(); ASSERT_TRUE(list.size() == 1); @@ -209,7 +209,7 @@ TEST_F("testGroupingContextUsage", DoomFixture()) { auto r1 = std::make_shared<Grouping>(request1); auto r2 = std::make_shared<Grouping>(request2); AllocatedBitVector bv(1); - GroupingContext context(bv, f1.clock.clock(), f1.timeOfDoom); + GroupingContext context(bv, f1.clock.nowRef(), f1.timeOfDoom); ASSERT_TRUE(context.empty()); context.addGrouping(r1); ASSERT_TRUE(context.getGroupingList().size() == 1); @@ -232,7 +232,7 @@ TEST_F("testGroupingContextSerializing", DoomFixture()) { baseRequest.serialize(nos); AllocatedBitVector bv(1); - GroupingContext context(bv, f1.clock.clock(), f1.timeOfDoom); + GroupingContext context(bv, f1.clock.nowRef(), f1.timeOfDoom); auto bp = std::make_shared<Grouping>(baseRequest); context.addGrouping(bp); context.serialize(); @@ -251,7 +251,7 @@ TEST_F("testGroupingManager", DoomFixture()) { .addLevel(createGL(MU<AttributeNode>("attr2"), MU<AttributeNode>("attr3"))); AllocatedBitVector bv(1); - GroupingContext context(bv, f1.clock.clock(), f1.timeOfDoom); + GroupingContext context(bv, f1.clock.nowRef(), f1.timeOfDoom); auto bp = std::make_shared<Grouping>(request1); context.addGrouping(bp); GroupingManager manager(context); @@ -285,7 +285,7 @@ TEST_F("testGroupingSession", DoomFixture()) { auto r1 = std::make_shared<Grouping>(request1); auto r2 = std::make_shared<Grouping>(request2); - GroupingContext initContext(world.bv, f1.clock.clock(), f1.timeOfDoom); + GroupingContext initContext(world.bv, f1.clock.nowRef(), f1.timeOfDoom); initContext.addGrouping(r1); initContext.addGrouping(r2); SessionId id("foo"); @@ -317,7 +317,7 @@ TEST_F("testGroupingSession", DoomFixture()) { } // Test second pass { - GroupingContext context(world.bv, f1.clock.clock(), f1.timeOfDoom); + GroupingContext context(world.bv, f1.clock.nowRef(), f1.timeOfDoom); auto r = std::make_shared<Grouping>(request1); r->setFirstLevel(1); r->setLastLevel(1); @@ -328,7 +328,7 @@ TEST_F("testGroupingSession", DoomFixture()) { } // Test last pass. Session should be marked as finished { - GroupingContext context(world.bv, f1.clock.clock(), f1.timeOfDoom); + GroupingContext context(world.bv, f1.clock.nowRef(), f1.timeOfDoom); auto r = std::make_shared<Grouping>(request1); r->setFirstLevel(2); r->setLastLevel(2); @@ -351,7 +351,7 @@ TEST_F("testEmptySessionId", DoomFixture()) { .addLevel(createGL(MU<AttributeNode>("attr2"), MU<AttributeNode>("attr3"))); auto r1 = std::make_shared<Grouping>(request1); - GroupingContext initContext(world.bv, f1.clock.clock(), f1.timeOfDoom); + GroupingContext initContext(world.bv, f1.clock.nowRef(), f1.timeOfDoom); initContext.addGrouping(r1); SessionId id; @@ -383,7 +383,7 @@ TEST_F("testSessionManager", DoomFixture()) { .setResult(Int64ResultNode(0)))); auto r1 = std::make_shared<Grouping>(request1); - GroupingContext initContext(world.bv, f1.clock.clock(), f1.timeOfDoom); + GroupingContext initContext(world.bv, f1.clock.nowRef(), f1.timeOfDoom); initContext.addGrouping(r1); SessionManager mgr(2); @@ -440,7 +440,7 @@ TEST_F("test grouping fork/join", DoomFixture()) { .setLastLevel(1); auto g1 = std::make_shared<Grouping>(request); - GroupingContext context(world.bv, f1.clock.clock(), f1.timeOfDoom); + GroupingContext context(world.bv, f1.clock.nowRef(), f1.timeOfDoom); context.addGrouping(g1); GroupingSession session(SessionId(), context, world.attributeContext); session.prepareThreadContextCreation(4); @@ -481,8 +481,8 @@ TEST_F("test session timeout", DoomFixture()) { SessionId id1("foo"); SessionId id2("bar"); - GroupingContext initContext1(world.bv, f1.clock.clock(), steady_time(duration(10))); - GroupingContext initContext2(world.bv, f1.clock.clock(), steady_time(duration(20))); + GroupingContext initContext1(world.bv, f1.clock.nowRef(), steady_time(duration(10))); + GroupingContext initContext2(world.bv, f1.clock.nowRef(), steady_time(duration(20))); auto s1 = std::make_unique<GroupingSession>(id1, initContext1, world.attributeContext); auto s2 = std::make_unique<GroupingSession>(id2, initContext2, world.attributeContext); mgr.insert(std::move(s1)); diff --git a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp index 90c08d2eb19..2504bca17e4 100644 --- a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp +++ b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp @@ -202,7 +202,7 @@ Fixture::Fixture() std::filesystem::create_directory(std::filesystem::path(BASE_DIR)); initViewSet(_views); _configurer = std::make_unique<Configurer>(_views._summaryMgr, _views.searchView, _views.feedView, _queryLimiter, - _constantValueFactory, _clock.clock(), "test", 0); + _constantValueFactory, _clock.nowRef(), "test", 0); } Fixture::~Fixture() = default; @@ -212,7 +212,7 @@ Fixture::initViewSet(ViewSet &views) using IndexManager = proton::index::IndexManager; using IndexConfig = proton::index::IndexConfig; RankingAssetsRepo ranking_assets_repo_source(_constantValueFactory, {}, {}, {}); - auto matchers = std::make_shared<Matchers>(_clock.clock(), _queryLimiter, ranking_assets_repo_source); + auto matchers = std::make_shared<Matchers>(_clock.nowRef(), _queryLimiter, ranking_assets_repo_source); auto indexMgr = make_shared<IndexManager>(BASE_DIR, IndexConfig(searchcorespi::index::WarmupConfig(), 2, 0), Schema(), 1, views._reconfigurer, views._service.write(), _summaryExecutor, TuneFileIndexManager(), TuneFileAttributes(), views._fileHeaderContext); diff --git a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp index 596ebb933a4..da8e842b9e4 100644 --- a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp +++ b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp @@ -256,7 +256,7 @@ MySearchableContext::MySearchableContext(IThreadingService &writeService, IBucketDBHandlerInitializer & bucketDBHandlerInitializer) : _fastUpdCtx(writeService, bucketDB, bucketDBHandlerInitializer), _queryLimiter(), _clock(), - _ctx(_fastUpdCtx._ctx, _queryLimiter, _clock.clock(), writeService.shared()) + _ctx(_fastUpdCtx._ctx, _queryLimiter, _clock.nowRef(), writeService.shared()) {} MySearchableContext::~MySearchableContext() = default; diff --git a/searchcore/src/tests/proton/documentdb/executor_threading_service/executor_threading_service_test.cpp b/searchcore/src/tests/proton/documentdb/executor_threading_service/executor_threading_service_test.cpp index 322f3c389ad..8a354ded706 100644 --- a/searchcore/src/tests/proton/documentdb/executor_threading_service/executor_threading_service_test.cpp +++ b/searchcore/src/tests/proton/documentdb/executor_threading_service/executor_threading_service_test.cpp @@ -28,7 +28,6 @@ public: field_writer_executor(SequencedTaskExecutor::create(my_field_writer_executor, 3, 200)), service(std::make_unique<ExecutorThreadingService>(_transport.shared(), _transport.transport(), - _transport.clock(), *field_writer_executor, nullptr, ThreadingServiceConfig::make())) diff --git a/searchcore/src/tests/proton/index/indexcollection_test.cpp b/searchcore/src/tests/proton/index/indexcollection_test.cpp index 24460000596..0e699fd1443 100644 --- a/searchcore/src/tests/proton/index/indexcollection_test.cpp +++ b/searchcore/src/tests/proton/index/indexcollection_test.cpp @@ -47,7 +47,6 @@ public: std::shared_ptr<IndexSearchable> _source2; std::shared_ptr<IndexSearchable> _fusion_source; vespalib::ThreadStackExecutor _executor; - vespalib::TestClock _clock; std::shared_ptr<IndexSearchable> _warmup; void expect_searchable_can_be_appended(ISearchableIndexCollection & collection) { @@ -84,7 +83,7 @@ public: std::shared_ptr<WarmupIndexCollection> create_warmup(const IndexCollection::SP& prev, const IndexCollection::SP& next) { - return std::make_shared<WarmupIndexCollection>(WarmupConfig(1s, false), prev, next, *_warmup, _executor, _clock.clock(), *this); + return std::make_shared<WarmupIndexCollection>(WarmupConfig(1s, false), prev, next, *_warmup, _executor, *this); } void warmupDone(std::shared_ptr<WarmupIndexCollection> current) override { diff --git a/searchcore/src/tests/proton/matching/matching_test.cpp b/searchcore/src/tests/proton/matching/matching_test.cpp index 5f4f26c6c6b..02506afa709 100644 --- a/searchcore/src/tests/proton/matching/matching_test.cpp +++ b/searchcore/src/tests/proton/matching/matching_test.cpp @@ -356,7 +356,7 @@ struct MyWorld { } Matcher::SP createMatcher() { - return std::make_shared<Matcher>(schema, config, clock.clock(), queryLimiter, constantValueRepo, 0); + return std::make_shared<Matcher>(schema, config, clock.nowRef(), queryLimiter, constantValueRepo, 0); } struct MySearchHandler : ISearchHandler { diff --git a/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp b/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp index 8b223c3ef3a..36636d58429 100644 --- a/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp +++ b/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp @@ -53,7 +53,7 @@ private: public: RequestContextTest() : _clock(), - _doom(_clock.clock(), vespalib::steady_time(), vespalib::steady_time(), false), + _doom(_clock.nowRef(), vespalib::steady_time(), vespalib::steady_time(), false), _thread_bundle(1), _attr_ctx(), _index_env(), diff --git a/searchcore/src/vespa/searchcore/grouping/groupingcontext.cpp b/searchcore/src/vespa/searchcore/grouping/groupingcontext.cpp index 882a4d1509d..e21cb4c1282 100644 --- a/searchcore/src/vespa/searchcore/grouping/groupingcontext.cpp +++ b/searchcore/src/vespa/searchcore/grouping/groupingcontext.cpp @@ -51,10 +51,10 @@ GroupingContext::setDistributionKey(uint32_t distributionKey) } } -GroupingContext::GroupingContext(const BitVector & validLids, const vespalib::Clock & clock, vespalib::steady_time timeOfDoom, +GroupingContext::GroupingContext(const BitVector & validLids, const std::atomic<steady_time> & now_ref, vespalib::steady_time timeOfDoom, const char *groupSpec, uint32_t groupSpecLen) : _validLids(validLids), - _clock(clock), + _now_ref(now_ref), _timeOfDoom(timeOfDoom), _os(), _groupingList() @@ -62,9 +62,9 @@ GroupingContext::GroupingContext(const BitVector & validLids, const vespalib::Cl deserialize(groupSpec, groupSpecLen); } -GroupingContext::GroupingContext(const BitVector & validLids, const vespalib::Clock & clock, vespalib::steady_time timeOfDoom) +GroupingContext::GroupingContext(const BitVector & validLids, const std::atomic<steady_time> & now_ref, vespalib::steady_time timeOfDoom) : _validLids(validLids), - _clock(clock), + _now_ref(now_ref), _timeOfDoom(timeOfDoom), _os(), _groupingList() @@ -72,7 +72,7 @@ GroupingContext::GroupingContext(const BitVector & validLids, const vespalib::Cl GroupingContext::GroupingContext(const GroupingContext & rhs) : _validLids(rhs._validLids), - _clock(rhs._clock), + _now_ref(rhs._now_ref), _timeOfDoom(rhs._timeOfDoom), _os(), _groupingList() diff --git a/searchcore/src/vespa/searchcore/grouping/groupingcontext.h b/searchcore/src/vespa/searchcore/grouping/groupingcontext.h index e1b296df99b..34e96847d63 100644 --- a/searchcore/src/vespa/searchcore/grouping/groupingcontext.h +++ b/searchcore/src/vespa/searchcore/grouping/groupingcontext.h @@ -3,8 +3,9 @@ #include <vespa/searchlib/aggregation/grouping.h> #include <vespa/vespalib/objects/nbostream.h> -#include <vespa/vespalib/util/clock.h> +#include <vespa/vespalib/util/time.h> #include <vector> +#include <atomic> namespace search::grouping { @@ -19,6 +20,7 @@ public: using UP = std::unique_ptr<GroupingContext>; using Grouping = search::aggregation::Grouping; using GroupingList = std::vector<std::shared_ptr<Grouping>>; + using steady_time = vespalib::steady_time; /** * Deserialize a grouping spec into this context. @@ -33,7 +35,7 @@ public: * @param groupSpec The grouping specification to use for initialization. * @param groupSpecLen The length of the grouping specification, in bytes. **/ - GroupingContext(const BitVector & validLids, const vespalib::Clock & clock, vespalib::steady_time timeOfDoom, + GroupingContext(const BitVector & validLids, const std::atomic<steady_time> & now_ref, steady_time timeOfDoom, const char *groupSpec, uint32_t groupSpecLen); /** @@ -41,7 +43,7 @@ public: * @param groupSpec The grouping specification to use for initialization. * @param groupSpecLen The length of the grouping specification, in bytes. **/ - GroupingContext(const BitVector & validLids, const vespalib::Clock & clock, vespalib::steady_time timeOfDoom); + GroupingContext(const BitVector & validLids, const std::atomic<steady_time> & now_ref, steady_time timeOfDoom); /** * Shallow copy of references @@ -99,8 +101,8 @@ public: /** * Obtain the time of doom. */ - vespalib::steady_time getTimeOfDoom() const noexcept { return _timeOfDoom; } - bool hasExpired() const noexcept { return _clock.getTimeNS() > _timeOfDoom; } + steady_time getTimeOfDoom() const noexcept { return _timeOfDoom; } + bool hasExpired() const noexcept { return _now_ref.load(std::memory_order_relaxed) > _timeOfDoom; } /** * Figure out if ranking is necessary for any of the grouping requests here. * @return true if ranking is required. @@ -116,11 +118,11 @@ private: unsigned int aggregateRanked(Grouping & grouping, const RankedHit * rankedHit, unsigned int len) const; void aggregate(Grouping & grouping, const BitVector * bv, unsigned int lidLimit) const; void aggregate(Grouping & grouping, const BitVector * bv, unsigned int , unsigned int topN) const; - const BitVector & _validLids; - const vespalib::Clock & _clock; - vespalib::steady_time _timeOfDoom; - vespalib::nbostream _os; - GroupingList _groupingList; + const BitVector & _validLids; + const std::atomic<steady_time> & _now_ref; + steady_time _timeOfDoom; + vespalib::nbostream _os; + GroupingList _groupingList; }; } diff --git a/searchcore/src/vespa/searchcore/proton/matching/fakesearchcontext.cpp b/searchcore/src/vespa/searchcore/proton/matching/fakesearchcontext.cpp index e442bb5fdfa..8bf92ec1709 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/fakesearchcontext.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/fakesearchcontext.cpp @@ -8,7 +8,7 @@ namespace proton::matching { FakeSearchContext::FakeSearchContext(size_t initialNumDocs) : _clock(std::make_unique<vespalib::TestClock>()), - _doom(_clock->clock(), vespalib::steady_time()), + _doom(_clock->nowRef(), vespalib::steady_time()), _selector(std::make_shared<search::FixedSourceSelector>(0, "fs", initialNumDocs)), _indexes(std::make_shared<IndexCollection>(_selector)), _attrSearchable(), diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_tools.h b/searchcore/src/vespa/searchcore/proton/matching/match_tools.h index ce1a9ff0b0a..5dcd874f82b 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_tools.h +++ b/searchcore/src/vespa/searchcore/proton/matching/match_tools.h @@ -16,7 +16,6 @@ #include <vespa/searchlib/common/stringmap.h> #include <vespa/searchlib/queryeval/idiversifier.h> #include <vespa/vespalib/util/doom.h> -#include <vespa/vespalib/util/clock.h> namespace vespalib { class ExecutionProfiler; } namespace vespalib { struct ThreadBundle; } diff --git a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp index 3e8909aa593..c4a0593a865 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp @@ -116,7 +116,7 @@ handleGroupingSession(SessionManager &sessionMgr, GroupingContext & groupingCont } // namespace proton::matching::<unnamed> -Matcher::Matcher(const search::index::Schema &schema, Properties props, const vespalib::Clock &clock, +Matcher::Matcher(const search::index::Schema &schema, Properties props, const std::atomic<steady_time> & now_ref, QueryLimiter &queryLimiter, const search::fef::IRankingAssetsRepo &rankingAssetsRepo, uint32_t distributionKey) : _indexEnv(distributionKey, schema, std::move(props), rankingAssetsRepo), _blueprintFactory(), @@ -125,7 +125,7 @@ Matcher::Matcher(const search::index::Schema &schema, Properties props, const ve _statsLock(), _stats(softtimeout::Factor::lookup(_indexEnv.getProperties())), _startTime(my_clock::now()), - _clock(clock), + _now_ref(now_ref), _queryLimiter(queryLimiter), _distributionKey(distributionKey) { @@ -166,12 +166,12 @@ Matcher::create_match_tools_factory(const search::engine::Request &request, ISea : _stats.softDoomFactor()) : 0.95; vespalib::duration safeLeft = std::chrono::duration_cast<vespalib::duration>(request.getTimeLeft() * factor); - vespalib::steady_time safeDoom(_clock.getTimeNS() + safeLeft); + vespalib::steady_time safeDoom(_now_ref.load(std::memory_order_relaxed) + safeLeft); if (softTimeoutEnabled) { LOG(debug, "Soft-timeout computed factor=%1.3f, used factor=%1.3f, userSupplied=%d, softTimeout=%" PRId64, _stats.softDoomFactor(), factor, hasFactorOverride, vespalib::count_ns(safeLeft)); } - vespalib::Doom doom(_clock, safeDoom, request.getTimeOfDoom(), hasFactorOverride); + vespalib::Doom doom(_now_ref, safeDoom, request.getTimeOfDoom(), hasFactorOverride); return std::make_unique<MatchToolsFactory>(_queryLimiter, doom, searchContext, attrContext, request.trace(), request.getStackRef(), request.location, _viewResolver, metaStore, _indexEnv, *_rankSetup, @@ -248,7 +248,7 @@ Matcher::match(const SearchRequest &request, vespalib::ThreadBundle &threadBundl bool isDoomExplicit = false; { // we want to measure full set-up and tear-down time as part of // collateral time - GroupingContext groupingContext(metaStore.getValidLids(), _clock, request.getTimeOfDoom(), + GroupingContext groupingContext(metaStore.getValidLids(), _now_ref, request.getTimeOfDoom(), request.groupSpec.data(), request.groupSpec.size()); SessionId sessionId(request.sessionId.data(), request.sessionId.size()); bool shouldCacheSearchSession = false; diff --git a/searchcore/src/vespa/searchcore/proton/matching/matcher.h b/searchcore/src/vespa/searchcore/proton/matching/matcher.h index ab9b8ed88f3..bf75dd9da89 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/matcher.h +++ b/searchcore/src/vespa/searchcore/proton/matching/matcher.h @@ -16,7 +16,6 @@ #include <vespa/searchlib/fef/i_ranking_assets_repo.h> #include <vespa/searchlib/queryeval/blueprint.h> #include <vespa/searchlib/query/base.h> -#include <vespa/vespalib/util/clock.h> #include <vespa/vespalib/util/featureset.h> #include <vespa/vespalib/util/thread_bundle.h> #include <mutex> @@ -59,16 +58,17 @@ private: using my_clock = std::chrono::steady_clock; using MatchingElements = search::MatchingElements; using MatchingElementsFields = search::MatchingElementsFields; - IndexEnvironment _indexEnv; - search::fef::BlueprintFactory _blueprintFactory; - std::shared_ptr<RankSetup> _rankSetup; - ViewResolver _viewResolver; - std::mutex _statsLock; - MatchingStats _stats; - my_clock::time_point _startTime; - const vespalib::Clock &_clock; - QueryLimiter &_queryLimiter; - uint32_t _distributionKey; + using steady_time = vespalib::steady_time; + IndexEnvironment _indexEnv; + search::fef::BlueprintFactory _blueprintFactory; + std::shared_ptr<RankSetup> _rankSetup; + ViewResolver _viewResolver; + std::mutex _statsLock; + MatchingStats _stats; + my_clock::time_point _startTime; + const std::atomic<steady_time> &_now_ref; + QueryLimiter &_queryLimiter; + uint32_t _distributionKey; size_t computeNumThreadsPerSearch(search::queryeval::Blueprint::HitEstimate hits, const Properties & rankProperties) const; @@ -91,7 +91,7 @@ public: * @param clock used for timeout handling **/ Matcher(const search::index::Schema &schema, Properties props, - const vespalib::Clock &clock, QueryLimiter &queryLimiter, + const std::atomic<steady_time> & now_ref, QueryLimiter &queryLimiter, const search::fef::IRankingAssetsRepo &rankingAssetsRepo, uint32_t distributionKey); const search::fef::IIndexEnvironment &get_index_env() const { return _indexEnv; } diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp index eb7a664ae24..6682214927b 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp @@ -37,6 +37,7 @@ #include <vespa/searchlib/engine/searchreply.h> #include <vespa/vespalib/util/destructor_callbacks.h> #include <vespa/vespalib/util/exceptions.h> +#include <vespa/vespalib/util/clock.h> #include <vespa/log/log.h> #include <vespa/searchcorespi/index/warmupconfig.h> @@ -188,7 +189,7 @@ DocumentDB::DocumentDB(const vespalib::string &baseDir, _baseDir(baseDir + "/" + _docTypeName.toString()), // Only one thread per executor, or performDropFeedView() will fail. _writeServiceConfig(configSnapshot->get_threading_service_config()), - _writeService(shared_service.shared(), shared_service.transport(), shared_service.clock(), shared_service.field_writer(), + _writeService(shared_service.shared(), shared_service.transport(), shared_service.field_writer(), &shared_service.invokeService(), _writeServiceConfig), _initializeThreads(std::move(initializeThreads)), _initConfigSnapshot(), @@ -218,7 +219,7 @@ DocumentDB::DocumentDB(const vespalib::string &baseDir, _feedHandler(std::make_unique<FeedHandler>(_writeService, tlsSpec, docTypeName, *this, _writeFilter, *this, tlsWriterFactory)), _subDBs(*this, *this, *_feedHandler, _docTypeName, _writeService, shared_service.shared(), fileHeaderContext, std::move(attribute_interlock), - metricsWireService, getMetrics(), queryLimiter, shared_service.clock(), + metricsWireService, getMetrics(), queryLimiter, shared_service.clock().nowRef(), _configMutex, _baseDir, hwInfo), _maintenanceController(shared_service.transport(), _writeService.master(), _refCount, _docTypeName), _jobTrackers(), diff --git a/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.cpp b/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.cpp index 5989e9c1433..4bf21b814fe 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.cpp @@ -34,7 +34,7 @@ DocumentSubDBCollection::DocumentSubDBCollection( MetricsWireService &metricsWireService, DocumentDBTaggedMetrics &metrics, matching::QueryLimiter &queryLimiter, - const vespalib::Clock &clock, + const std::atomic<vespalib::steady_time> & now_ref, std::mutex &configMutex, const vespalib::string &baseDir, const vespalib::HwInfo &hwInfo) @@ -64,7 +64,7 @@ DocumentSubDBCollection::DocumentSubDBCollection( metrics.ready.attributes, metricsWireService, attribute_interlock), - queryLimiter, clock, warmupExecutor))); + queryLimiter, now_ref, warmupExecutor))); _subDBs.push_back (new StoreOnlyDocSubDB(StoreOnlyDocSubDB::Config(docTypeName, "1.removed", baseDir, _remSubDbId, SubDbType::REMOVED), diff --git a/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.h b/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.h index 7c823d72bac..60a99a7d98a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.h +++ b/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.h @@ -91,7 +91,7 @@ public: MetricsWireService &metricsWireService, DocumentDBTaggedMetrics &metrics, matching::QueryLimiter & queryLimiter, - const vespalib::Clock &clock, + const std::atomic<vespalib::steady_time> & now_ref, std::mutex &configMutex, const vespalib::string &baseDir, const vespalib::HwInfo &hwInfo); diff --git a/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.cpp b/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.cpp index dd475484b6f..a169aed4af4 100644 --- a/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.cpp @@ -44,21 +44,18 @@ VESPA_THREAD_STACK_TAG(summary_executor) ExecutorThreadingService::ExecutorThreadingService(vespalib::Executor& sharedExecutor, FNET_Transport& transport, - const vespalib::Clock& clock, vespalib::ISequencedTaskExecutor& field_writer) - : ExecutorThreadingService(sharedExecutor, transport, clock, field_writer, nullptr, ThreadingServiceConfig::make()) + : ExecutorThreadingService(sharedExecutor, transport, field_writer, nullptr, ThreadingServiceConfig::make()) {} ExecutorThreadingService::ExecutorThreadingService(vespalib::Executor & sharedExecutor, FNET_Transport & transport, - const vespalib::Clock & clock, vespalib::ISequencedTaskExecutor& field_writer, vespalib::InvokeService * invokerService, const ThreadingServiceConfig & cfg) : _sharedExecutor(sharedExecutor), _transport(transport), - _clock(clock), _masterExecutor(1, CpuUsage::wrap(master_executor, CpuUsage::Category::WRITE)), _master_task_limit(cfg.master_task_limit()), _indexExecutor(createExecutorWithOneThread(cfg, CpuUsage::wrap(index_executor, CpuUsage::Category::WRITE))), diff --git a/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.h b/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.h index f09083c9682..28ab4b8977a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.h +++ b/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.h @@ -22,7 +22,6 @@ private: using Registration = std::unique_ptr<vespalib::IDestructorCallback>; vespalib::Executor & _sharedExecutor; FNET_Transport & _transport; - const vespalib::Clock & _clock; vespalib::ThreadStackExecutor _masterExecutor; std::atomic<uint32_t> _master_task_limit; std::unique_ptr<vespalib::SyncableThreadExecutor> _indexExecutor; @@ -39,12 +38,10 @@ public: */ ExecutorThreadingService(vespalib::Executor& sharedExecutor, FNET_Transport& transport, - const vespalib::Clock& clock, vespalib::ISequencedTaskExecutor& field_writer); ExecutorThreadingService(vespalib::Executor& sharedExecutor, FNET_Transport & transport, - const vespalib::Clock & clock, vespalib::ISequencedTaskExecutor& field_writer, vespalib::InvokeService * invokeService, const ThreadingServiceConfig& cfg); @@ -77,7 +74,6 @@ public: vespalib::ISequencedTaskExecutor &field_writer() override; FNET_Transport &transport() override { return _transport; } - const vespalib::Clock &clock() const override { return _clock; } ExecutorThreadingServiceStats getStats(); }; diff --git a/searchcore/src/vespa/searchcore/proton/server/matchers.cpp b/searchcore/src/vespa/searchcore/proton/server/matchers.cpp index c2e471c088e..587fbad8d77 100644 --- a/searchcore/src/vespa/searchcore/proton/server/matchers.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/matchers.cpp @@ -16,12 +16,12 @@ using matching::Matcher; using matching::MatchingStats; using namespace vespalib::make_string_short; -Matchers::Matchers(const vespalib::Clock &clock, +Matchers::Matchers(const std::atomic<vespalib::steady_time> & now_ref, matching::QueryLimiter &queryLimiter, const search::fef::RankingAssetsRepo &rankingAssetsRepo) : _rpmap(), _ranking_assets_repo(rankingAssetsRepo), - _fallback(std::make_shared<Matcher>(search::index::Schema(), search::fef::Properties(), clock, queryLimiter, + _fallback(std::make_shared<Matcher>(search::index::Schema(), search::fef::Properties(), now_ref, queryLimiter, _ranking_assets_repo, -1)), _default() { } diff --git a/searchcore/src/vespa/searchcore/proton/server/matchers.h b/searchcore/src/vespa/searchcore/proton/server/matchers.h index 66d494556d9..08f3031ce7a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/matchers.h +++ b/searchcore/src/vespa/searchcore/proton/server/matchers.h @@ -6,8 +6,6 @@ #include <vespa/searchlib/fef/ranking_assets_repo.h> #include <vespa/vespalib/stllike/hash_map.h> -namespace vespalib { class Clock; } - namespace proton { namespace matching { @@ -24,7 +22,7 @@ private: std::shared_ptr<matching::Matcher> _default; public: using SP = std::shared_ptr<Matchers>; - Matchers(const vespalib::Clock &clock, + Matchers(const std::atomic<vespalib::steady_time> & now_ref, matching::QueryLimiter &queryLimiter, const search::fef::RankingAssetsRepo &rankingAssetsRepo); Matchers(const Matchers &) = delete; diff --git a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp index 61f6db12a4b..0ffe69f2278 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp @@ -95,7 +95,7 @@ SearchableDocSubDBConfigurer(const std::shared_ptr<ISummaryManager>& summaryMgr, FeedViewHolder &feedView, matching::QueryLimiter &queryLimiter, const vespalib::eval::ConstantValueFactory& constant_value_factory, - const vespalib::Clock &clock, + const std::atomic<steady_time> & now_ref, const vespalib::string &subDbName, uint32_t distributionKey) : _summaryMgr(summaryMgr), @@ -103,7 +103,7 @@ SearchableDocSubDBConfigurer(const std::shared_ptr<ISummaryManager>& summaryMgr, _feedView(feedView), _queryLimiter(queryLimiter), _constant_value_factory(constant_value_factory), - _clock(clock), + _now_ref(now_ref), _subDbName(subDbName), _distributionKey(distributionKey) { } @@ -119,7 +119,7 @@ SearchableDocSubDBConfigurer::createMatchers(const DocumentDBConfig& new_config_ new_config_snapshot.getRankingConstantsSP(), new_config_snapshot.getRankingExpressionsSP(), new_config_snapshot.getOnnxModelsSP()); - auto newMatchers = std::make_shared<Matchers>(_clock, _queryLimiter, ranking_assets_repo_source); + auto newMatchers = std::make_shared<Matchers>(_now_ref, _queryLimiter, ranking_assets_repo_source); auto& ranking_assets_repo = newMatchers->get_ranking_assets_repo(); for (const auto &profile : cfg.rankprofile) { vespalib::string name = profile.name; @@ -128,7 +128,7 @@ SearchableDocSubDBConfigurer::createMatchers(const DocumentDBConfig& new_config_ properties.add(property.name, property.value); } // schema instance only used during call. - auto profptr = std::make_shared<Matcher>(*schema, std::move(properties), _clock, _queryLimiter, + auto profptr = std::make_shared<Matcher>(*schema, std::move(properties), _now_ref, _queryLimiter, ranking_assets_repo, _distributionKey); newMatchers->add(name, std::move(profptr)); } diff --git a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h index 8dff36a304a..740f312bfb5 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h +++ b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h @@ -41,12 +41,13 @@ class SearchableDocSubDBConfigurer private: using SearchViewHolder = vespalib::VarHolder<std::shared_ptr<SearchView>>; using FeedViewHolder = vespalib::VarHolder<std::shared_ptr<SearchableFeedView>>; + using steady_time = vespalib::steady_time; const std::shared_ptr<ISummaryManager>& _summaryMgr; SearchViewHolder &_searchView; FeedViewHolder &_feedView; matching::QueryLimiter &_queryLimiter; const vespalib::eval::ConstantValueFactory& _constant_value_factory; - const vespalib::Clock &_clock; + const std::atomic<steady_time> & _now_ref; vespalib::string _subDbName; uint32_t _distributionKey; @@ -72,7 +73,7 @@ public: FeedViewHolder &feedView, matching::QueryLimiter &queryLimiter, const vespalib::eval::ConstantValueFactory& constant_value_factory, - const vespalib::Clock &clock, + const std::atomic<steady_time> & now_ref, const vespalib::string &subDbName, uint32_t distributionKey); ~SearchableDocSubDBConfigurer(); diff --git a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp index ed9dfbfe578..5e9d9585ca9 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp @@ -39,7 +39,7 @@ SearchableDocSubDB::SearchableDocSubDB(const Config &cfg, const Context &ctx) _rFeedView(), _tensorLoader(FastValueBuilderFactory::get()), _constantValueCache(_tensorLoader), - _configurer(_iSummaryMgr, _rSearchView, _rFeedView, ctx._queryLimiter, _constantValueCache, ctx._clock, + _configurer(_iSummaryMgr, _rSearchView, _rFeedView, ctx._queryLimiter, _constantValueCache, ctx._now_ref, getSubDbName(), ctx._fastUpdCtx._storeOnlyCtx._owner.getDistributionKey()), _warmupExecutor(ctx._warmupExecutor), _realGidToLidChangeHandler(std::make_shared<GidToLidChangeHandler>()), diff --git a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.h b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.h index c8dd064fcea..eb27406e228 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.h +++ b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.h @@ -41,18 +41,19 @@ SearchableDocSubDB : public FastAccessDocSubDB, public: struct Context { + using steady_time = vespalib::steady_time; const FastAccessDocSubDB::Context _fastUpdCtx; matching::QueryLimiter &_queryLimiter; - const vespalib::Clock &_clock; + const std::atomic<steady_time> &_now_ref; vespalib::Executor &_warmupExecutor; Context(const FastAccessDocSubDB::Context &fastUpdCtx, matching::QueryLimiter &queryLimiter, - const vespalib::Clock &clock, + const std::atomic<steady_time> & now_ref, vespalib:: Executor &warmupExecutor) : _fastUpdCtx(fastUpdCtx), _queryLimiter(queryLimiter), - _clock(clock), + _now_ref(now_ref), _warmupExecutor(warmupExecutor) { } }; diff --git a/searchcore/src/vespa/searchcore/proton/test/threading_service_observer.h b/searchcore/src/vespa/searchcore/proton/test/threading_service_observer.h index 8f31ea66d3a..f209b9a7709 100644 --- a/searchcore/src/vespa/searchcore/proton/test/threading_service_observer.h +++ b/searchcore/src/vespa/searchcore/proton/test/threading_service_observer.h @@ -48,7 +48,6 @@ public: return _shared; } FNET_Transport & transport() override { return _service.transport(); } - const vespalib::Clock & clock() const override { return _service.clock(); } vespalib::ISequencedTaskExecutor &field_writer() override { return _field_writer; } diff --git a/searchcore/src/vespa/searchcore/proton/test/transport_helper.cpp b/searchcore/src/vespa/searchcore/proton/test/transport_helper.cpp index 3e5ce6e7a53..ffcc964bf56 100644 --- a/searchcore/src/vespa/searchcore/proton/test/transport_helper.cpp +++ b/searchcore/src/vespa/searchcore/proton/test/transport_helper.cpp @@ -4,15 +4,12 @@ #include <vespa/fnet/transport.h> #include <vespa/searchcore/proton/server/executorthreadingservice.h> #include <vespa/vespalib/util/sequencedtaskexecutor.h> -#include <vespa/vespalib/util/size_literals.h> -#include <vespa/vespalib/util/testclock.h> #include <vespa/vespalib/util/threadstackexecutor.h> namespace proton { Transport::Transport() - : _transport(std::make_unique<FNET_Transport>()), - _clock(std::make_unique<vespalib::TestClock>()) + : _transport(std::make_unique<FNET_Transport>()) { _transport->Start(); } @@ -21,10 +18,6 @@ Transport::~Transport() { shutdown(); } -const vespalib::Clock & -Transport::clock() const { - return _clock->clock(); -} void Transport::shutdown() { _transport->ShutDown(true); @@ -47,7 +40,7 @@ TransportAndExecutor::shutdown() { TransportAndExecutorService::TransportAndExecutorService(size_t num_threads) : TransportAndExecutor(num_threads), - _writeService(std::make_unique<ExecutorThreadingService>(shared(), transport(), clock(), field_writer())) + _writeService(std::make_unique<ExecutorThreadingService>(shared(), transport(), field_writer())) {} TransportAndExecutorService::~TransportAndExecutorService() = default; diff --git a/searchcore/src/vespa/searchcore/proton/test/transport_helper.h b/searchcore/src/vespa/searchcore/proton/test/transport_helper.h index 66fbcdbabfb..6a5fd3aeb85 100644 --- a/searchcore/src/vespa/searchcore/proton/test/transport_helper.h +++ b/searchcore/src/vespa/searchcore/proton/test/transport_helper.h @@ -3,8 +3,6 @@ #include <vespa/searchcorespi/index/ithreadingservice.h> -namespace vespalib { class TestClock; } - namespace proton { class ExecutorThreadingService; @@ -17,16 +15,14 @@ public: Transport(); virtual ~Transport(); FNET_Transport & transport() { return *_transport; } - const vespalib::Clock & clock() const; virtual void shutdown(); private: std::unique_ptr<FNET_Transport> _transport; - std::unique_ptr<vespalib::TestClock> _clock; }; class TransportAndExecutor : public Transport { public: - TransportAndExecutor(size_t num_threads); + explicit TransportAndExecutor(size_t num_threads); ~TransportAndExecutor() override; vespalib::Executor & shared() { return *_sharedExecutor; } vespalib::ISequencedTaskExecutor& field_writer() { return *_field_writer; } @@ -39,7 +35,7 @@ private: class TransportAndExecutorService : public TransportAndExecutor { public: - TransportAndExecutorService(size_t num_threads); + explicit TransportAndExecutorService(size_t num_threads); ~TransportAndExecutorService() override; searchcorespi::index::IThreadingService & write(); void shutdown() override; diff --git a/searchcore/src/vespa/searchcorespi/index/indexmaintainer.cpp b/searchcore/src/vespa/searchcorespi/index/indexmaintainer.cpp index bbd17be9b5a..6028a543320 100644 --- a/searchcore/src/vespa/searchcorespi/index/indexmaintainer.cpp +++ b/searchcore/src/vespa/searchcorespi/index/indexmaintainer.cpp @@ -437,8 +437,7 @@ IndexMaintainer::swapInNewIndex(LockGuard & guard, LOG(debug, "Warming up a disk index."); indexes = std::make_shared<WarmupIndexCollection> (_warmupConfig, getLeaf(guard, _source_list, true), indexes, - static_cast<IDiskIndex &>(source), _ctx.getWarmupExecutor(), - _ctx.getThreadingService().clock(), *this); + static_cast<IDiskIndex &>(source), _ctx.getWarmupExecutor(), *this); } else { LOG(debug, "No warmup needed as it is a memory index that is mapped in."); } diff --git a/searchcore/src/vespa/searchcorespi/index/ithreadingservice.h b/searchcore/src/vespa/searchcorespi/index/ithreadingservice.h index 3f3a76b5506..52c586a6bb9 100644 --- a/searchcore/src/vespa/searchcorespi/index/ithreadingservice.h +++ b/searchcore/src/vespa/searchcorespi/index/ithreadingservice.h @@ -66,7 +66,6 @@ struct IThreadingService virtual vespalib::ThreadExecutor &summary() = 0; virtual vespalib::Executor &shared() = 0; virtual FNET_Transport &transport() = 0; - virtual const vespalib::Clock &clock() const = 0; virtual vespalib::ISequencedTaskExecutor &field_writer() = 0; }; diff --git a/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp b/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp index 5d5348de52a..49dcb5a1f54 100644 --- a/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp +++ b/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp @@ -35,9 +35,9 @@ class WarmupRequestContext : public IRequestContext { using IAttributeVector = search::attribute::IAttributeVector; using AttributeBlueprintParams = search::attribute::AttributeBlueprintParams; public: - explicit WarmupRequestContext(const vespalib::Clock & clock); + explicit WarmupRequestContext(); ~WarmupRequestContext() override; - const vespalib::Doom & getDoom() const override { return _doom; } + const vespalib::Doom & getDoom() const override { return vespalib::Doom::never(); } vespalib::ThreadBundle & thread_bundle() const override { return vespalib::ThreadBundle::trivial(); } const IAttributeVector *getAttribute(const vespalib::string &) const override { return nullptr; } const IAttributeVector *getAttributeStableEnum(const vespalib::string &) const override { return nullptr; } @@ -45,7 +45,6 @@ public: const AttributeBlueprintParams& get_attribute_blueprint_params() const override { return _params; } const MetaStoreReadGuardSP * getMetaStoreReadGuard() const override { return nullptr; } private: - const vespalib::Doom _doom; const AttributeBlueprintParams _params; }; class WarmupTask : public vespalib::Executor::Task { @@ -80,14 +79,12 @@ WarmupIndexCollection::WarmupIndexCollection(const WarmupConfig & warmupConfig, ISearchableIndexCollection::SP next, IndexSearchable & warmup, vespalib::Executor & executor, - const vespalib::Clock & clock, IWarmupDone & warmupDone) : _warmupConfig(warmupConfig), _prev(std::move(prev)), _next(std::move(next)), _warmup(warmup), _executor(executor), - _clock(clock), _warmupDone(warmupDone), _warmupEndTime(vespalib::steady_clock::now() + warmupConfig.getDuration()), _handledTerms(std::make_unique<FieldTermMap>()), @@ -278,9 +275,7 @@ WarmupIndexCollection::drainPending() { _pendingTasks.waitForZeroRefCount(); } -WarmupRequestContext::WarmupRequestContext(const vespalib::Clock & clock) - : _doom(clock, vespalib::steady_time::max(), vespalib::steady_time::max(), false) -{} +WarmupRequestContext::WarmupRequestContext() = default; WarmupRequestContext::~WarmupRequestContext() = default; const vespalib::eval::Value* @@ -292,7 +287,7 @@ WarmupTask::WarmupTask(std::unique_ptr<MatchData> md, std::shared_ptr<WarmupInde _retainGuard(_warmup->pendingTasks()), _matchData(std::move(md)), _bluePrint(), - _requestContext(_warmup->clock()) + _requestContext() { } diff --git a/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.h b/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.h index 27651b8999a..14358774347 100644 --- a/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.h +++ b/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.h @@ -17,7 +17,7 @@ class WarmupIndexCollection; class IWarmupDone { public: - virtual ~IWarmupDone() { } + virtual ~IWarmupDone() = default; virtual void warmupDone(std::shared_ptr<WarmupIndexCollection> current) = 0; }; /** @@ -35,7 +35,6 @@ public: ISearchableIndexCollection::SP next, IndexSearchable & warmup, vespalib::Executor & executor, - const vespalib::Clock & clock, IWarmupDone & warmupDone); ~WarmupIndexCollection() override; // Implements IIndexCollection @@ -66,7 +65,6 @@ public: vespalib::string toString() const override; bool doUnpack() const { return _warmupConfig.getUnpack(); } void drainPending(); - const vespalib::Clock & clock() const { return _clock; } vespalib::steady_time warmupEndTime() const { return _warmupEndTime; } vespalib::MonitoredRefCount & pendingTasks() { return _pendingTasks; } private: @@ -80,7 +78,6 @@ private: ISearchableIndexCollection::SP _next; IndexSearchable & _warmup; vespalib::Executor & _executor; - const vespalib::Clock & _clock; IWarmupDone & _warmupDone; vespalib::steady_time _warmupEndTime; std::mutex _lock; diff --git a/searchlib/src/tests/sortspec/multilevelsort_test.cpp b/searchlib/src/tests/sortspec/multilevelsort_test.cpp index 2d0456e13fc..f3bf363645e 100644 --- a/searchlib/src/tests/sortspec/multilevelsort_test.cpp +++ b/searchlib/src/tests/sortspec/multilevelsort_test.cpp @@ -8,7 +8,6 @@ #include <vespa/searchlib/attribute/attributemanager.h> #include <vespa/searchlib/uca/ucaconverter.h> #include <vespa/searchcommon/attribute/config.h> -#include <vespa/vespalib/util/testclock.h> #include <vespa/vespalib/testkit/testapp.h> #include <type_traits> #include <cinttypes> @@ -242,10 +241,8 @@ MultilevelSortTest::sortAndCheck(const std::vector<Spec> &specs, uint32_t num, hits.emplace_back(i, getRandomValue<uint32_t>()); } - vespalib::TestClock clock; - vespalib::Doom doom(clock.clock(), vespalib::steady_time::max()); search::uca::UcaConverterFactory ucaFactory; - FastS_SortSpec sorter("no-metastore", 7, doom, ucaFactory); + FastS_SortSpec sorter("no-metastore", 7, vespalib::Doom::never(), ucaFactory); // init sorter with sort data for (const auto & spec : specs) { AttributeGuard ag; @@ -384,10 +381,8 @@ TEST("require that all sort methods behave the same") } TEST("test that [docid] translates to [lid][paritionid]") { - vespalib::TestClock clock; - vespalib::Doom doom(clock.clock(), vespalib::steady_time::max()); search::uca::UcaConverterFactory ucaFactory; - FastS_SortSpec asc("no-metastore", 7, doom, ucaFactory); + FastS_SortSpec asc("no-metastore", 7, vespalib::Doom::never(), ucaFactory); RankedHit hits[2] = {RankedHit(91, 0.0), RankedHit(3, 2.0)}; search::AttributeManager mgr; search::AttributeContext ac(mgr); @@ -404,7 +399,7 @@ TEST("test that [docid] translates to [lid][paritionid]") { EXPECT_EQUAL(6u, sr2.second); EXPECT_EQUAL(0, memcmp(SECOND_ASC, sr2.first, 6)); - FastS_SortSpec desc("no-metastore", 7, doom, ucaFactory); + FastS_SortSpec desc("no-metastore", 7, vespalib::Doom::never(), ucaFactory); desc.Init("-[docid]", ac); desc.initWithoutSorting(hits, 2); sr1 = desc.getSortRef(0); @@ -416,10 +411,8 @@ TEST("test that [docid] translates to [lid][paritionid]") { } TEST("test that [docid] uses attribute when one exists") { - vespalib::TestClock clock; - vespalib::Doom doom(clock.clock(), vespalib::steady_time::max()); search::uca::UcaConverterFactory ucaFactory; - FastS_SortSpec asc("metastore", 7, doom, ucaFactory); + FastS_SortSpec asc("metastore", 7, vespalib::Doom::never(), ucaFactory); RankedHit hits[2] = {RankedHit(91, 0.0), RankedHit(3, 2.0)}; Config cfg(BasicType::INT64, CollectionType::SINGLE); auto metastore = AttributeFactory::createAttribute("metastore", cfg); @@ -445,7 +438,7 @@ TEST("test that [docid] uses attribute when one exists") { EXPECT_EQUAL(8u, sr2.second); EXPECT_EQUAL(0, memcmp(SECOND_ASC, sr2.first, 8)); - FastS_SortSpec desc("metastore", 7, doom, ucaFactory); + FastS_SortSpec desc("metastore", 7, vespalib::Doom::never(), ucaFactory); desc.Init("-[docid]", ac); desc.initWithoutSorting(hits, 2); sr1 = desc.getSortRef(0); diff --git a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.cpp b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.cpp index ae5a7583c8c..f15f3d0e84c 100644 --- a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.cpp @@ -3,7 +3,6 @@ #include "fake_requestcontext.h" #include <vespa/vespalib/util/testclock.h> - namespace search::queryeval { FakeRequestContext::FakeRequestContext() @@ -13,7 +12,7 @@ FakeRequestContext::FakeRequestContext() FakeRequestContext::FakeRequestContext(attribute::IAttributeContext * context, vespalib::steady_time softDoom, vespalib::steady_time hardDoom) : _clock(std::make_unique<vespalib::TestClock>()), - _doom(_clock->clock(), softDoom, hardDoom, false), + _doom(_clock->nowRef(), softDoom, hardDoom, false), _attributeContext(context), _query_tensor_name(), _query_tensor(), diff --git a/vespalib/src/vespa/vespalib/util/clock.h b/vespalib/src/vespa/vespalib/util/clock.h index 1e37e3fff8d..ab4671f7bfb 100644 --- a/vespalib/src/vespa/vespalib/util/clock.h +++ b/vespalib/src/vespa/vespalib/util/clock.h @@ -28,6 +28,7 @@ public: vespalib::steady_time getTimeNS() const noexcept { return vespalib::steady_time(_timeNS.load(std::memory_order_relaxed)); } + const std::atomic<steady_time> & nowRef() const { return _timeNS; } }; } diff --git a/vespalib/src/vespa/vespalib/util/doom.cpp b/vespalib/src/vespa/vespalib/util/doom.cpp index 8fc82031e79..66df17e8897 100644 --- a/vespalib/src/vespa/vespalib/util/doom.cpp +++ b/vespalib/src/vespa/vespalib/util/doom.cpp @@ -5,9 +5,9 @@ namespace vespalib { -Doom::Doom(const Clock &clock, steady_time softDoom, +Doom::Doom(const std::atomic<steady_time> & now_ref, steady_time softDoom, steady_time hardDoom, bool explicitSoftDoom) noexcept - : _clock(clock), + : _now(now_ref), _softDoom(softDoom), _hardDoom(hardDoom), _isExplicitSoftDoom(explicitSoftDoom) diff --git a/vespalib/src/vespa/vespalib/util/doom.h b/vespalib/src/vespa/vespalib/util/doom.h index 1d7070cedd0..c9b66725b0f 100644 --- a/vespalib/src/vespa/vespalib/util/doom.h +++ b/vespalib/src/vespa/vespalib/util/doom.h @@ -2,26 +2,30 @@ #pragma once -#include "clock.h" +#include "time.h" +#include <atomic> namespace vespalib { class Doom { public: - Doom(const Clock &clock, steady_time doom) noexcept - : Doom(clock, doom, doom, false) + Doom(const std::atomic<steady_time> & now_ref, steady_time doom) noexcept + : Doom(now_ref, doom, doom, false) {} - Doom(const Clock &clock, steady_time softDoom, + Doom(const std::atomic<steady_time> & now_ref, steady_time softDoom, steady_time hardDoom, bool explicitSoftDoom) noexcept; - bool soft_doom() const noexcept { return (_clock.getTimeNS() > _softDoom); } - bool hard_doom() const noexcept { return (_clock.getTimeNS() > _hardDoom); } - duration soft_left() const noexcept { return _softDoom - _clock.getTimeNS(); } - duration hard_left() const noexcept { return _hardDoom - _clock.getTimeNS(); } + bool soft_doom() const noexcept { return (getTimeNS() > _softDoom); } + bool hard_doom() const noexcept { return (getTimeNS() > _hardDoom); } + duration soft_left() const noexcept { return _softDoom - getTimeNS(); } + duration hard_left() const noexcept { return _hardDoom - getTimeNS(); } bool isExplicitSoftDoom() const noexcept { return _isExplicitSoftDoom; } static const Doom & never() noexcept; private: - const Clock &_clock; + vespalib::steady_time getTimeNS() const noexcept { + return vespalib::steady_time(_now.load(std::memory_order_relaxed)); + } + const std::atomic<steady_time> & _now; steady_time _softDoom; steady_time _hardDoom; bool _isExplicitSoftDoom; diff --git a/vespalib/src/vespa/vespalib/util/fake_doom.cpp b/vespalib/src/vespa/vespalib/util/fake_doom.cpp index d9cbce0b152..eeedc555d21 100644 --- a/vespalib/src/vespa/vespalib/util/fake_doom.cpp +++ b/vespalib/src/vespa/vespalib/util/fake_doom.cpp @@ -6,8 +6,7 @@ namespace vespalib { FakeDoom::FakeDoom(steady_time::duration time_to_doom) noexcept : _time(steady_clock::now()), - _clock(_time), - _doom(_clock, _clock.getTimeNS() + time_to_doom) + _doom(_time, _time.load(std::memory_order_relaxed) + time_to_doom) { } diff --git a/vespalib/src/vespa/vespalib/util/fake_doom.h b/vespalib/src/vespa/vespalib/util/fake_doom.h index 1e6cfcb0c4d..a5c25ac4d9d 100644 --- a/vespalib/src/vespa/vespalib/util/fake_doom.h +++ b/vespalib/src/vespa/vespalib/util/fake_doom.h @@ -12,7 +12,6 @@ namespace vespalib { */ class FakeDoom { std::atomic<steady_time> _time; - Clock _clock; Doom _doom; public: FakeDoom() noexcept : FakeDoom(1s) { } diff --git a/vespalib/src/vespa/vespalib/util/testclock.cpp b/vespalib/src/vespa/vespalib/util/testclock.cpp index 9f63ce6c217..fe2da504150 100644 --- a/vespalib/src/vespa/vespalib/util/testclock.cpp +++ b/vespalib/src/vespa/vespalib/util/testclock.cpp @@ -6,11 +6,15 @@ namespace vespalib { TestClock::TestClock() - : _ticker(std::make_unique<InvokeServiceImpl>(10ms)), - _clock(_ticker->nowRef()) + : _ticker(std::make_unique<InvokeServiceImpl>(10ms)) { } TestClock::~TestClock() = default; +const std::atomic<steady_time> & +TestClock::nowRef() const { + return _ticker->nowRef(); +} + } diff --git a/vespalib/src/vespa/vespalib/util/testclock.h b/vespalib/src/vespa/vespalib/util/testclock.h index 748c239b309..117e19bedb8 100644 --- a/vespalib/src/vespa/vespalib/util/testclock.h +++ b/vespalib/src/vespa/vespalib/util/testclock.h @@ -1,7 +1,8 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include "clock.h" +#include "time.h" +#include <atomic> namespace vespalib { @@ -15,7 +16,6 @@ class TestClock { private: std::unique_ptr<InvokeServiceImpl> _ticker; - Clock _clock; public: TestClock(); TestClock(const TestClock &) = delete; @@ -23,7 +23,7 @@ public: TestClock(TestClock &&) = delete; TestClock & operator =(TestClock &&) = delete; ~TestClock(); - const Clock & clock() { return _clock; } + const std::atomic<steady_time> & nowRef() const; }; } |