diff options
17 files changed, 67 insertions, 82 deletions
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 e28e25560d4..3152b737ea7 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 @@ -27,7 +27,7 @@ public: class RequestContextTest : public ::testing::Test { private: vespalib::Clock _clock; - vespalib::CombinedDoom _doom; + vespalib::Doom _doom; MyAttributeContext _attr_ctx; Properties _props; RequestContext _request_ctx; diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp index f9ba34d7830..a0381af29a8 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp @@ -71,15 +71,14 @@ LazyValue get_score_feature(const RankProgram &rankProgram) { //----------------------------------------------------------------------------- -MatchThread::Context::Context(double rankDropLimit, MatchTools &tools, HitCollector &hits, - uint32_t num_threads) +MatchThread::Context::Context(double rankDropLimit, MatchTools &tools, HitCollector &hits, uint32_t num_threads) : matches(0), _matches_limit(tools.match_limiter().sample_hits_per_thread(num_threads)), _score_feature(get_score_feature(tools.rank_program())), _ranking(tools.rank_program()), _rankDropLimit(rankDropLimit), _hits(hits), - _softDoom(tools.getDoom().soft()) + _doom(tools.getDoom()) { } @@ -307,7 +306,7 @@ MatchThread::findMatches(MatchTools &tools) auto kept_hits = communicator.selectBest(sorted_hit_seq); select_best_timer.done(); DocumentScorer scorer(tools.rank_program(), tools.search()); - if (tools.getDoom().hard().doom()) { + if (tools.getDoom().hard_doom()) { kept_hits.clear(); } uint32_t reRanked = hits.reRank(scorer, std::move(kept_hits)); @@ -330,16 +329,16 @@ MatchThread::findMatches(MatchTools &tools) } void -MatchThread::processResult(const Doom & hardDoom, +MatchThread::processResult(const Doom & doom, search::ResultSet::UP result, ResultProcessor::Context &context) { - if (hardDoom.doom()) return; + if (doom.hard_doom()) return; bool hasGrouping = (context.grouping.get() != 0); if (context.sort->hasSortData() || hasGrouping) { result->mergeWithBitOverflow(fallback_rank_value()); } - if (hardDoom.doom()) return; + if (doom.hard_doom()) return; size_t totalHits = result->getNumHits(); const search::RankedHit *hits = result->getArray(); size_t numHits = result->getArrayUsed(); @@ -347,20 +346,20 @@ MatchThread::processResult(const Doom & hardDoom, if (bits != nullptr && hits != nullptr) { bits->andNotWithT(search::RankedHitIterator(hits, numHits)); } - if (hardDoom.doom()) return; + if (doom.hard_doom()) return; if (hasGrouping) { search::grouping::GroupingManager man(*context.grouping); man.groupUnordered(hits, numHits, bits); } - if (hardDoom.doom()) return; + if (doom.hard_doom()) return; size_t sortLimit = hasGrouping ? numHits : context.result->maxSize(); result->sort(*context.sort->sorter, sortLimit); - if (hardDoom.doom()) return; + if (doom.hard_doom()) return; if (hasGrouping) { search::grouping::GroupingManager man(*context.grouping); man.groupInRelevanceOrder(hits, numHits); } - if (hardDoom.doom()) return; + if (doom.hard_doom()) return; PartialResult &pr = *context.result; pr.totalHits(totalHits); size_t maxHits = std::min(numHits, pr.maxSize()); @@ -432,19 +431,19 @@ MatchThread::run() MatchTools::UP matchTools = matchToolsFactory.createMatchTools(); search::ResultSet::UP result = findMatches(*matchTools); match_time_s = match_time.elapsed().sec(); - resultContext = resultProcessor.createThreadContext(matchTools->getDoom().hard(), thread_id, _distributionKey); + resultContext = resultProcessor.createThreadContext(matchTools->getDoom(), thread_id, _distributionKey); { trace->addEvent(5, "Wait for result processing token"); WaitTimer get_token_timer(wait_time_s); QueryLimiter::Token::UP processToken( - matchTools->getQueryLimiter().getToken(matchTools->getDoom().hard(), + matchTools->getQueryLimiter().getToken(matchTools->getDoom(), scheduler.total_size(thread_id), result->getNumHits(), resultContext->sort->hasSortData(), resultContext->grouping.get() != 0)); get_token_timer.done(); trace->addEvent(5, "Start result processing"); - processResult(matchTools->getDoom().hard(), std::move(result), *resultContext); + processResult(matchTools->getDoom(), std::move(result), *resultContext); } total_time_s = total_time.elapsed().sec(); thread_stats.active_time(total_time_s - wait_time_s).wait_time(wait_time_s); diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_thread.h b/searchcore/src/vespa/searchcore/proton/matching/match_thread.h index 95c9b200bb6..7ecbfef634e 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_thread.h +++ b/searchcore/src/vespa/searchcore/proton/matching/match_thread.h @@ -73,8 +73,8 @@ private: void addHit(uint32_t docId) { _hits.addHit(docId, search::zero_rank_value); } bool isBelowLimit() const { return matches < _matches_limit; } bool isAtLimit() const { return matches == _matches_limit; } - bool atSoftDoom() const { return _softDoom.doom(); } - fastos::TimeStamp timeLeft() const { return _softDoom.left(); } + bool atSoftDoom() const { return _doom.soft_doom(); } + fastos::TimeStamp timeLeft() const { return _doom.soft_left(); } uint32_t matches; private: uint32_t _matches_limit; @@ -82,7 +82,7 @@ private: RankProgram &_ranking; double _rankDropLimit; HitCollector &_hits; - const Doom &_softDoom; + const Doom &_doom; }; double estimate_match_frequency(uint32_t matches, uint32_t searchedSoFar) __attribute__((noinline)); @@ -106,7 +106,7 @@ private: search::ResultSet::UP findMatches(MatchTools &tools); - void processResult(const Doom & hardDoom, search::ResultSet::UP result, ResultProcessor::Context &context); + void processResult(const Doom & doom, search::ResultSet::UP result, ResultProcessor::Context &context); bool isFirstThread() const { return thread_id == 0; } diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp index d4c910f7b96..05b70cfb8bf 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp @@ -89,7 +89,7 @@ MatchTools::setup(search::fef::RankProgram::UP rank_program, double termwise_lim } MatchTools::MatchTools(QueryLimiter & queryLimiter, - const vespalib::CombinedDoom & doom, + const vespalib::Doom & doom, const Query &query, MaybeMatchPhaseLimiter & match_limiter_in, const QueryEnvironment & queryEnv, @@ -147,7 +147,7 @@ MatchTools::setup_dump() MatchToolsFactory:: MatchToolsFactory(QueryLimiter & queryLimiter, - const vespalib::CombinedDoom & doom, + const vespalib::Doom & doom, ISearchContext & searchContext, IAttributeContext & attributeContext, vespalib::stringref queryStack, diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_tools.h b/searchcore/src/vespa/searchcore/proton/matching/match_tools.h index 0dd612d404a..5cf2919198a 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_tools.h +++ b/searchcore/src/vespa/searchcore/proton/matching/match_tools.h @@ -28,7 +28,7 @@ class MatchTools private: using IRequestContext = search::queryeval::IRequestContext; QueryLimiter &_queryLimiter; - const vespalib::CombinedDoom &_doom; + const vespalib::Doom &_doom; const Query &_query; MaybeMatchPhaseLimiter &_match_limiter; const QueryEnvironment &_queryEnv; @@ -45,7 +45,7 @@ public: MatchTools(const MatchTools &) = delete; MatchTools & operator = (const MatchTools &) = delete; MatchTools(QueryLimiter & queryLimiter, - const vespalib::CombinedDoom & doom, + const vespalib::Doom & doom, const Query &query, MaybeMatchPhaseLimiter &match_limiter_in, const QueryEnvironment &queryEnv, @@ -53,7 +53,7 @@ public: const search::fef::RankSetup &rankSetup, const search::fef::Properties &featureOverrides); ~MatchTools(); - const vespalib::CombinedDoom &getDoom() const { return _doom; } + const vespalib::Doom &getDoom() const { return _doom; } QueryLimiter & getQueryLimiter() { return _queryLimiter; } MaybeMatchPhaseLimiter &match_limiter() { return _match_limiter; } bool has_second_phase_rank() const; @@ -106,7 +106,7 @@ public: using BasicType = search::attribute::BasicType; MatchToolsFactory(QueryLimiter & queryLimiter, - const vespalib::CombinedDoom & softDoom, + const vespalib::Doom & softDoom, ISearchContext &searchContext, search::attribute::IAttributeContext &attributeContext, vespalib::stringref queryStack, diff --git a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp index 85169e70697..426bb353826 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp @@ -140,7 +140,7 @@ Matcher::create_match_tools_factory(const search::engine::Request &request, ISea LOG(debug, "Soft-timeout computed factor=%1.3f, used factor=%1.3f, userSupplied=%d, softTimeout=%" PRId64, _stats.softDoomFactor(), factor, hasFactorOverride, safeLeft); } - vespalib::CombinedDoom doom(_clock, safeDoom, request.getTimeOfDoom(), hasFactorOverride); + vespalib::Doom doom(_clock, safeDoom, request.getTimeOfDoom(), hasFactorOverride); return std::make_unique<MatchToolsFactory>(_queryLimiter, doom, searchContext, attrContext, request.getStackRef(), request.location, _viewResolver, metaStore, _indexEnv, *_rankSetup, rankProperties, feature_overrides); diff --git a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp index 0d985496d41..5053cc5fdbe 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp @@ -2,8 +2,7 @@ #include "querylimiter.h" #include <chrono> -namespace proton { -namespace matching { +namespace proton:: matching { QueryLimiter::LimitedToken::LimitedToken(const Doom & doom, QueryLimiter & limiter) : _limiter(limiter) @@ -20,8 +19,8 @@ void QueryLimiter::grabToken(const Doom & doom) { std::unique_lock<std::mutex> guard(_lock); - while ((_maxThreads > 0) && (_activeThreads >= _maxThreads) && !doom.doom()) { - int left = doom.left().ms(); + while ((_maxThreads > 0) && (_activeThreads >= _maxThreads) && !doom.hard_doom()) { + int left = doom.hard_left().ms(); if (left > 0) { _cond.wait_for(guard, std::chrono::milliseconds(left)); } @@ -62,13 +61,12 @@ QueryLimiter::getToken(const Doom & doom, uint32_t numDocs, uint32_t numHits, bo if (hasSorting || hasGrouping) { if (numHits > _minHits) { if (numDocs * _coverage < numHits) { - return Token::UP(new LimitedToken(doom, *this)); + return std::make_unique<LimitedToken>(doom, *this); } } } } - return Token::UP(new NoLimitToken()); + return std::make_unique<NoLimitToken>(); } } -} diff --git a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h index fbe8526b051..45783959957 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h +++ b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h @@ -7,8 +7,7 @@ #include <mutex> #include <condition_variable> -namespace proton { -namespace matching { +namespace proton::matching { class QueryLimiter { @@ -46,6 +45,4 @@ private: volatile uint32_t _minHits; }; -} // namespace matching -} // namespace proton - +} diff --git a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp index 28a1d680e85..c30854c051f 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp @@ -14,7 +14,7 @@ namespace proton { using search::attribute::IAttributeVector; -RequestContext::RequestContext(const CombinedDoom & doom, IAttributeContext & attributeContext, +RequestContext::RequestContext(const Doom & doom, IAttributeContext & attributeContext, const search::fef::Properties& rank_properties) : _doom(doom), _attributeContext(attributeContext), diff --git a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h index cfec168405e..31d3d573a20 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h +++ b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h @@ -17,11 +17,11 @@ class RequestContext : public search::queryeval::IRequestContext, public: using IAttributeContext = search::attribute::IAttributeContext; using IAttributeFunctor = search::attribute::IAttributeFunctor; - using CombinedDoom = vespalib::CombinedDoom; - RequestContext(const CombinedDoom & softDoom, IAttributeContext & attributeContext, + using Doom = vespalib::Doom; + RequestContext(const Doom & softDoom, IAttributeContext & attributeContext, const search::fef::Properties& rank_properties); - const CombinedDoom & getDoom() const override { return _doom; } + const Doom & getDoom() const override { return _doom; } const search::attribute::IAttributeVector *getAttribute(const vespalib::string &name) const override; void asyncForAttribute(const vespalib::string &name, std::unique_ptr<IAttributeFunctor> func) const override; @@ -32,7 +32,7 @@ public: private: - const CombinedDoom _doom; + const Doom _doom; IAttributeContext & _attributeContext; const search::fef::Properties & _rank_properties; }; diff --git a/searchlib/src/vespa/searchlib/common/sortresults.cpp b/searchlib/src/vespa/searchlib/common/sortresults.cpp index 757ba9f3f9a..729f31795c9 100644 --- a/searchlib/src/vespa/searchlib/common/sortresults.cpp +++ b/searchlib/src/vespa/searchlib/common/sortresults.cpp @@ -242,7 +242,7 @@ FastS_SortSpec::initSortData(const RankedHit *hits, uint32_t n) _sortDataArray.resize(n); document::GlobalId gid; - for (uint32_t i(0), idx(0); (i < n) && !_doom.doom(); ++i) { + for (uint32_t i(0), idx(0); (i < n) && !_doom.hard_doom(); ++i) { uint32_t len = 0; for (auto iter = _vectors.begin(); iter != _vectors.end(); ++iter) { int written(0); diff --git a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h index 36ab6614cae..184e0f7faf8 100644 --- a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h +++ b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h @@ -20,7 +20,7 @@ public: fastos::SteadyTimeStamp soft=fastos::SteadyTimeStamp::FUTURE, fastos::SteadyTimeStamp hard=fastos::SteadyTimeStamp::FUTURE); ~FakeRequestContext(); - const vespalib::CombinedDoom & getDoom() const override { return _doom; } + const vespalib::Doom & getDoom() const override { return _doom; } const attribute::IAttributeVector *getAttribute(const vespalib::string &name) const override { return _attributeContext ? _attributeContext->getAttribute(name) @@ -44,7 +44,7 @@ public: private: vespalib::Clock _clock; - const vespalib::CombinedDoom _doom; + const vespalib::Doom _doom; attribute::IAttributeContext *_attributeContext; vespalib::string _query_tensor_name; std::unique_ptr<vespalib::eval::TensorSpec> _query_tensor; diff --git a/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h b/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h index f8908a67cf2..75025b5cbf2 100644 --- a/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h +++ b/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h @@ -6,7 +6,7 @@ namespace search::attribute { class IAttributeVector; } namespace vespalib::eval { class Value; } -namespace vespalib { class CombinedDoom; } +namespace vespalib { class Doom; } namespace search::queryeval { @@ -22,7 +22,7 @@ public: * Provides the time of soft doom for the query. Now it is time to start cleaning up and return what you have. * @return time of soft doom. */ - virtual const vespalib::CombinedDoom & getDoom() const = 0; + virtual const vespalib::Doom & getDoom() const = 0; /** * Provide access to attributevectors diff --git a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp index 44f5d3ce619..edb26fdb296 100644 --- a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp @@ -11,7 +11,7 @@ namespace search::queryeval { SimplePhraseBlueprint::SimplePhraseBlueprint(const FieldSpec &field, const IRequestContext & requestContext, bool expensive) : ComplexLeafBlueprint(field), - _doom(requestContext.getDoom().soft()), + _doom(requestContext.getDoom()), _field(field), _estimate(), _layout(), diff --git a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_search.h b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_search.h index 2d9d47fb680..d45e67ed4cb 100644 --- a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_search.h +++ b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_search.h @@ -30,7 +30,7 @@ class SimplePhraseSearch : public AndSearch std::vector<It> _iterators; void phraseSeek(uint32_t doc_id); - bool doom() const { return ((_doom != nullptr) && _doom->doom()); } + bool doom() const { return ((_doom != nullptr) && _doom->soft_doom()); } public: /** diff --git a/staging_vespalib/src/vespa/vespalib/util/doom.cpp b/staging_vespalib/src/vespa/vespalib/util/doom.cpp index df20981c584..87b24799721 100644 --- a/staging_vespalib/src/vespa/vespalib/util/doom.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/doom.cpp @@ -4,10 +4,12 @@ namespace vespalib { -Doom::Doom(const vespalib::Clock &clock, fastos::SteadyTimeStamp timeOfDoom) : - _clock(clock), - _timeOfDoom(timeOfDoom) -{ -} - -} // namespace vespalib
\ No newline at end of file +Doom::Doom(const vespalib::Clock &clock, fastos::SteadyTimeStamp softDoom, + fastos::SteadyTimeStamp hardDoom, bool explicitSoftDoom) + : _clock(clock), + _softDoom(softDoom), + _hardDoom(hardDoom), + _isExplicitSoftDoom(explicitSoftDoom) +{ } + +}
\ No newline at end of file diff --git a/staging_vespalib/src/vespa/vespalib/util/doom.h b/staging_vespalib/src/vespa/vespalib/util/doom.h index 89421f69686..d85c3dc9084 100644 --- a/staging_vespalib/src/vespa/vespalib/util/doom.h +++ b/staging_vespalib/src/vespa/vespalib/util/doom.h @@ -6,35 +6,24 @@ namespace vespalib { -class Doom -{ -private: - const vespalib::Clock &_clock; - fastos::SteadyTimeStamp _timeOfDoom; - +class Doom { public: - Doom(const vespalib::Clock &clock, fastos::SteadyTimeStamp timeOfDoom); - bool doom() const { - return (_clock.getTimeNSAssumeRunning() > _timeOfDoom); - } - fastos::TimeStamp left() const { return _timeOfDoom - _clock.getTimeNS(); } -}; + Doom(const vespalib::Clock &clock, fastos::SteadyTimeStamp doom) + : Doom(clock, doom, doom, false) + {} + Doom(const vespalib::Clock &clock, fastos::SteadyTimeStamp softDoom, + fastos::SteadyTimeStamp hardDoom, bool explicitSoftDoom); -class CombinedDoom { -public: - CombinedDoom(const vespalib::Clock &clock, fastos::SteadyTimeStamp softDoom, - fastos::SteadyTimeStamp hardDoom, bool explicitSoftDoom) - : _soft(clock, softDoom), - _hard(clock, hardDoom), - _isExplicitSoftDoom(explicitSoftDoom) - { } - const Doom & soft() const { return _soft; } - const Doom & hard() const { return _hard; } + bool soft_doom() const { return (_clock.getTimeNSAssumeRunning() > _softDoom); } + bool hard_doom() const { return (_clock.getTimeNSAssumeRunning() > _hardDoom); } + fastos::TimeStamp soft_left() const { return _softDoom - _clock.getTimeNS(); } + fastos::TimeStamp hard_left() const { return _hardDoom - _clock.getTimeNS(); } bool isExplicitSoftDoom() const { return _isExplicitSoftDoom; } private: - Doom _soft; - Doom _hard; - bool _isExplicitSoftDoom; + const vespalib::Clock &_clock; + fastos::SteadyTimeStamp _softDoom; + fastos::SteadyTimeStamp _hardDoom; + bool _isExplicitSoftDoom; }; } |