diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2024-02-29 15:32:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-29 15:32:43 +0100 |
commit | 4e03205f6f094b063d6ab14b3366fb370bb62820 (patch) | |
tree | a98a5d6f01d674150d17c4425b741549abdf7b98 | |
parent | cd0c793b26d0787429d4ae55c71b9e5a99bcd195 (diff) | |
parent | e34cb01cc56158c97036f54c34467bd14470b4c4 (diff) |
Merge pull request #30437 from vespa-engine/balder/cache-and-use-stackdump-for-summary-processing
Balder/cache and use stackdump for summary processing
13 files changed, 46 insertions, 31 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/docsummary/docsumcontext.cpp b/searchcore/src/vespa/searchcore/proton/docsummary/docsumcontext.cpp index d6cccf47b18..6c7232c5491 100644 --- a/searchcore/src/vespa/searchcore/proton/docsummary/docsumcontext.cpp +++ b/searchcore/src/vespa/searchcore/proton/docsummary/docsumcontext.cpp @@ -7,7 +7,6 @@ #include <vespa/searchlib/common/location.h> #include <vespa/searchlib/common/matching_elements.h> #include <vespa/vespalib/data/slime/slime.h> -#include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/log/log.h> @@ -50,6 +49,11 @@ DocsumContext::initState() { const DocsumRequest & req = _request; _docsumState._args.initFromDocsumRequest(req); + auto [session, expectSession] = Matcher::lookupSearchSession(_sessionMgr, req); + if (session) { + vespalib::stringref queryStack = session->getStackDump(); + _docsumState._args.setStackDump(queryStack.size(), queryStack.data()); + } _docsumState._docsumbuf.clear(); _docsumState._docsumbuf.reserve(req.hits.size()); for (const auto & hit : req.hits) { diff --git a/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp b/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp index 05a517a76b6..8d646597729 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp @@ -4,8 +4,6 @@ #include "match_tools.h" #include "search_session.h" #include "extract_features.h" -#include <vespa/eval/eval/value_codec.h> -#include <vespa/vespalib/objects/nbostream.h> #include <vespa/searchcommon/attribute/i_search_context.h> #include <vespa/searchlib/queryeval/blueprint.h> #include <vespa/searchlib/queryeval/intermediate_blueprints.h> @@ -63,10 +61,10 @@ void find_matching_elements(const std::vector<uint32_t> &docs, const SameElement auto search = same_element.create_same_element_search(dummy_tfmd, false); search->initRange(docs.front(), docs.back()+1); std::vector<uint32_t> matches; - for (uint32_t i = 0; i < docs.size(); ++i) { - search->find_matching_elements(docs[i], matches); + for (uint32_t doc : docs) { + search->find_matching_elements(doc, matches); if (!matches.empty()) { - result.add_matching_elements(docs[i], same_element.field_name(), matches); + result.add_matching_elements(doc, same_element.field_name(), matches); matches.clear(); } } @@ -74,20 +72,20 @@ void find_matching_elements(const std::vector<uint32_t> &docs, const SameElement void find_matching_elements(const std::vector<uint32_t> &docs, MatchingElementsSearch &search, MatchingElements &result) { search.initRange(docs.front(), docs.back() + 1); - for (uint32_t i = 0; i < docs.size(); ++i) { - search.find_matching_elements(docs[i], result); + for (uint32_t doc : docs) { + search.find_matching_elements(doc, result); } } void find_matching_elements(const std::vector<uint32_t> &docs, const vespalib::string &field_name, const AttrSearchCtx &attr_ctx, MatchingElements &result) { int32_t weight = 0; std::vector<uint32_t> matches; - for (uint32_t i = 0; i < docs.size(); ++i) { - for (int32_t id = attr_ctx.find(docs[i], 0, weight); id >= 0; id = attr_ctx.find(docs[i], id+1, weight)) { + for (uint32_t doc : docs) { + for (int32_t id = attr_ctx.find(doc, 0, weight); id >= 0; id = attr_ctx.find(doc, id+1, weight)) { matches.push_back(id); } if (!matches.empty()) { - result.add_matching_elements(docs[i], field_name, matches); + result.add_matching_elements(doc, field_name, matches); matches.clear(); } } diff --git a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp index c4a0593a865..4a9156770f0 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp @@ -269,6 +269,8 @@ Matcher::match(const SearchRequest &request, vespalib::ThreadBundle &threadBundl // These should have been moved instead. owned_objects.feature_overrides = std::make_unique<Properties>(*feature_overrides); feature_overrides = owned_objects.feature_overrides.get(); + vespalib::stringref queryStack = request.getStackRef(); + owned_objects.stackDump.assign(queryStack.begin(), queryStack.end()); } MatchToolsFactory::UP mtf = create_match_tools_factory(request, searchContext, attrContext, metaStore, @@ -385,6 +387,18 @@ Matcher::get_matching_elements(const DocsumRequest &req, ISearchContext &search_ return docsum_matcher->get_matching_elements(fields); } +std::pair<std::shared_ptr<SearchSession>, bool> +Matcher::lookupSearchSession(SessionManager &session_manager, const Request & req) { + SessionId sessionId(req.sessionId.data(), req.sessionId.size()); + if (!sessionId.empty()) { + const Properties &cache_props = req.propertiesMap.cacheProperties(); + if (cache_props.lookup("query").found()) { + return {session_manager.pickSearch(sessionId), true}; + } + } + return {{}, false}; +} + DocsumMatcher::UP Matcher::create_docsum_matcher(const DocsumRequest &req, ISearchContext &search_ctx, IAttributeContext &attr_ctx, SessionManager &session_manager) const @@ -397,17 +411,9 @@ Matcher::create_docsum_matcher(const DocsumRequest &req, ISearchContext &search_ } } std::sort(docs.begin(), docs.end()); - SessionId sessionId(req.sessionId.data(), req.sessionId.size()); - bool expectedSessionCached(false); - if (!sessionId.empty()) { - const Properties &cache_props = req.propertiesMap.cacheProperties(); - expectedSessionCached = cache_props.lookup("query").found(); - if (expectedSessionCached) { - SearchSession::SP session(session_manager.pickSearch(sessionId)); - if (session) { - return std::make_unique<DocsumMatcher>(std::move(session), std::move(docs)); - } - } + auto [session, expectedSessionCached] = lookupSearchSession(session_manager, req); + if (session) { + return std::make_unique<DocsumMatcher>(std::move(session), std::move(docs)); } StupidMetaStore meta; MatchToolsFactory::UP mtf = create_match_tools_factory(req, search_ctx, attr_ctx, meta, diff --git a/searchcore/src/vespa/searchcore/proton/matching/matcher.h b/searchcore/src/vespa/searchcore/proton/matching/matcher.h index bf75dd9da89..24a7d67496f 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/matcher.h +++ b/searchcore/src/vespa/searchcore/proton/matching/matcher.h @@ -183,6 +183,11 @@ public: * @return true if this rankprofile has summary-features enabled **/ bool canProduceSummaryFeatures() const; + /** + * Return a session if it exist, and a bool saying if it should exist. + */ + static std::pair<std::shared_ptr<SearchSession>, bool> + lookupSearchSession(SessionManager &session_manager, const Request & request); }; } diff --git a/searchcore/src/vespa/searchcore/proton/matching/search_session.cpp b/searchcore/src/vespa/searchcore/proton/matching/search_session.cpp index 21bfbd25af0..76ddf80aa54 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/search_session.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/search_session.cpp @@ -28,7 +28,8 @@ SearchSession::OwnershipBundle::OwnershipBundle(MatchContext && match_context, : search_handler(std::move(searchHandler)), context(std::move(match_context)), feature_overrides(), - readGuard() + readGuard(), + stackDump() {} SearchSession::OwnershipBundle::OwnershipBundle() noexcept = default; diff --git a/searchcore/src/vespa/searchcore/proton/matching/search_session.h b/searchcore/src/vespa/searchcore/proton/matching/search_session.h index d044ce456be..7cdb79f003c 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/search_session.h +++ b/searchcore/src/vespa/searchcore/proton/matching/search_session.h @@ -33,6 +33,7 @@ public: MatchContext context; std::unique_ptr<search::fef::Properties> feature_overrides; IDocumentMetaStoreContext::IReadGuard::SP readGuard; + std::vector<char> stackDump; }; private: using SessionId = vespalib::string; @@ -64,6 +65,9 @@ public: vespalib::steady_time getTimeOfDoom() const { return _time_of_doom; } MatchToolsFactory &getMatchToolsFactory() { return *_match_tools_factory; } + vespalib::stringref getStackDump() const noexcept { + return {_owned_objects.stackDump.data(), _owned_objects.stackDump.size()}; + } }; } diff --git a/searchlib/src/vespa/searchlib/engine/docsumrequest.cpp b/searchlib/src/vespa/searchlib/engine/docsumrequest.cpp index 00c190220ab..4a716557d87 100644 --- a/searchlib/src/vespa/searchlib/engine/docsumrequest.cpp +++ b/searchlib/src/vespa/searchlib/engine/docsumrequest.cpp @@ -13,7 +13,6 @@ DocsumRequest::DocsumRequest(RelativeTime relativeTime) : Request(std::move(relativeTime)), resultClassName(), hits(), - sessionId(), _fields() { } diff --git a/searchlib/src/vespa/searchlib/engine/docsumrequest.h b/searchlib/src/vespa/searchlib/engine/docsumrequest.h index 403b8e047f4..447bb390816 100644 --- a/searchlib/src/vespa/searchlib/engine/docsumrequest.h +++ b/searchlib/src/vespa/searchlib/engine/docsumrequest.h @@ -28,7 +28,6 @@ public: vespalib::string resultClassName; std::vector<Hit> hits; - std::vector<char> sessionId; DocsumRequest(); explicit DocsumRequest(RelativeTime relativeTime); diff --git a/searchlib/src/vespa/searchlib/engine/request.cpp b/searchlib/src/vespa/searchlib/engine/request.cpp index 89860a0e87c..b58b2110bdc 100644 --- a/searchlib/src/vespa/searchlib/engine/request.cpp +++ b/searchlib/src/vespa/searchlib/engine/request.cpp @@ -16,6 +16,7 @@ Request::Request(RelativeTime relativeTime, uint32_t reservePropMaps) location(), propertiesMap(reservePropMaps), stackDump(), + sessionId(), _trace(_relativeTime, 0) { } diff --git a/searchlib/src/vespa/searchlib/engine/request.h b/searchlib/src/vespa/searchlib/engine/request.h index eb428246d00..31eb5c8683f 100644 --- a/searchlib/src/vespa/searchlib/engine/request.h +++ b/searchlib/src/vespa/searchlib/engine/request.h @@ -23,7 +23,7 @@ public: vespalib::duration getTimeLeft() const; bool expired() const { return getTimeLeft() <= vespalib::duration::zero(); } - const vespalib::stringref getStackRef() const { + vespalib::stringref getStackRef() const { return vespalib::stringref(stackDump.data(), stackDump.size()); } @@ -43,6 +43,7 @@ public: vespalib::string location; PropertiesMap propertiesMap; std::vector<char> stackDump; + std::vector<char> sessionId; private: mutable Trace _trace; }; diff --git a/searchlib/src/vespa/searchlib/engine/searchrequest.cpp b/searchlib/src/vespa/searchlib/engine/searchrequest.cpp index ad1a6e8cde5..c7a3ffc9380 100644 --- a/searchlib/src/vespa/searchlib/engine/searchrequest.cpp +++ b/searchlib/src/vespa/searchlib/engine/searchrequest.cpp @@ -12,8 +12,7 @@ SearchRequest::SearchRequest(RelativeTime relativeTime) offset(0), maxhits(10), sortSpec(), - groupSpec(), - sessionId() + groupSpec() { } diff --git a/searchlib/src/vespa/searchlib/engine/searchrequest.h b/searchlib/src/vespa/searchlib/engine/searchrequest.h index 158df4a3dd4..d6807806cd5 100644 --- a/searchlib/src/vespa/searchlib/engine/searchrequest.h +++ b/searchlib/src/vespa/searchlib/engine/searchrequest.h @@ -19,7 +19,6 @@ public: uint32_t maxhits; vespalib::string sortSpec; std::vector<char> groupSpec; - std::vector<char> sessionId; SearchRequest(); explicit SearchRequest(RelativeTime relativeTime); diff --git a/searchsummary/src/vespa/searchsummary/docsummary/getdocsumargs.cpp b/searchsummary/src/vespa/searchsummary/docsummary/getdocsumargs.cpp index 22ee6711556..d78f463f91d 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/getdocsumargs.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/getdocsumargs.cpp @@ -34,8 +34,7 @@ GetDocsumArgs::initFromDocsumRequest(const engine::DocsumRequest &req) void GetDocsumArgs::setStackDump(uint32_t stackDumpLen, const char *stackDump) { - _stackDump.resize(stackDumpLen); - memcpy(&_stackDump[0], stackDump, _stackDump.size()); + _stackDump.assign(stackDump, stackDump + stackDumpLen); } bool |