From c4a01e6c3b85eb18ece1c4b5d9f337b08ba3b76d Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 17 Feb 2020 14:48:49 +0000 Subject: Use enable_shared_from_this to simplify interface and keep the details local. --- .../src/tests/proton/matchengine/matchengine.cpp | 54 ++++++++++----------- .../src/tests/proton/matching/matching_test.cpp | 2 +- .../tests/proton/summaryengine/summaryengine.cpp | 56 ++++++++++------------ .../vespa/searchcore/proton/common/doctypename.cpp | 12 ++--- .../vespa/searchcore/proton/common/handlermap.hpp | 1 - .../searchcore/proton/matchengine/matchengine.cpp | 7 ++- .../vespa/searchcore/proton/server/documentdb.cpp | 4 +- .../vespa/searchcore/proton/server/documentdb.h | 3 +- .../searchcore/proton/server/emptysearchview.cpp | 19 +++----- .../searchcore/proton/server/emptysearchview.h | 13 ++--- .../src/vespa/searchcore/proton/server/proton.cpp | 3 +- .../proton/server/searchhandlerproxy.cpp | 10 ++-- .../searchcore/proton/server/searchhandlerproxy.h | 6 +-- .../vespa/searchcore/proton/server/searchview.cpp | 5 +- .../vespa/searchcore/proton/server/searchview.h | 6 +-- .../proton/summaryengine/isearchhandler.h | 2 +- .../proton/summaryengine/summaryengine.cpp | 4 +- 17 files changed, 90 insertions(+), 117 deletions(-) (limited to 'searchcore') diff --git a/searchcore/src/tests/proton/matchengine/matchengine.cpp b/searchcore/src/tests/proton/matchengine/matchengine.cpp index 9ae938981a4..fd48fffcb5c 100644 --- a/searchcore/src/tests/proton/matchengine/matchengine.cpp +++ b/searchcore/src/tests/proton/matchengine/matchengine.cpp @@ -18,18 +18,17 @@ class MySearchHandler : public ISearchHandler { std::string _reply; public: MySearchHandler(size_t numHits = 0) : - _numHits(numHits), _name("my"), _reply("myreply") {} - virtual DocsumReply::UP getDocsums(const DocsumRequest &) override { - return DocsumReply::UP(new DocsumReply); + _numHits(numHits), _name("my"), _reply("myreply") + {} + DocsumReply::UP getDocsums(const DocsumRequest &) override { + return std::make_unique(); } - virtual search::engine::SearchReply::UP match( - const ISearchHandler::SP &, - const search::engine::SearchRequest &, - vespalib::ThreadBundle &) const override { - SearchReply::UP retval(new SearchReply); + SearchReply::UP match(const SearchRequest &, vespalib::ThreadBundle &) const override + { + auto retval = std::make_unique(); for (size_t i = 0; i < _numHits; ++i) { - retval->hits.push_back(SearchReply::Hit()); + retval->hits.emplace_back(); } return retval; } @@ -43,7 +42,7 @@ private: public: LocalSearchClient(); - ~LocalSearchClient(); + ~LocalSearchClient() override; void searchDone(SearchReply::UP reply) override { std::lock_guard guard(_lock); _reply = std::move(reply); @@ -62,8 +61,8 @@ public: } }; -LocalSearchClient::LocalSearchClient() {} -LocalSearchClient::~LocalSearchClient() {} +LocalSearchClient::LocalSearchClient() = default; +LocalSearchClient::~LocalSearchClient() = default; TEST("requireThatSearchesExecute") { @@ -71,23 +70,23 @@ TEST("requireThatSearchesExecute") MatchEngine engine(numMatcherThreads, 1, 7); engine.setNodeUp(true); - MySearchHandler::SP handler(new MySearchHandler); + auto handler = std::make_shared(); DocTypeName dtnvfoo("foo"); engine.putSearchHandler(dtnvfoo, handler); LocalSearchClient client; SearchRequest::Source request(new SearchRequest()); SearchReply::UP reply = engine.search(std::move(request), client); - EXPECT_TRUE(reply.get() == NULL); + EXPECT_FALSE(reply); reply = client.getReply(10000); - EXPECT_TRUE(reply.get() != NULL); + EXPECT_TRUE(reply); } bool assertSearchReply(MatchEngine & engine, const std::string & searchDocType, size_t expHits) { - SearchRequest *request = new SearchRequest(); + auto *request = new SearchRequest(); request->propertiesMap.lookupCreate(search::MapNames::MATCH).add("documentdb.searchdoctype", searchDocType); LocalSearchClient client; engine.search(SearchRequest::Source(request), client); @@ -99,9 +98,9 @@ TEST("requireThatCorrectHandlerIsUsed") { MatchEngine engine(1, 1, 7); engine.setNodeUp(true); - ISearchHandler::SP h1(new MySearchHandler(2)); - ISearchHandler::SP h2(new MySearchHandler(4)); - ISearchHandler::SP h3(new MySearchHandler(6)); + auto h1 = std::make_shared(2); + auto h2 = std::make_shared(4); + auto h3 = std::make_shared(6); DocTypeName dtnvfoo("foo"); DocTypeName dtnvbar("bar"); DocTypeName dtnvbaz("baz"); @@ -120,13 +119,12 @@ struct ObserveBundleMatchHandler : MySearchHandler { mutable size_t bundleSize; ObserveBundleMatchHandler() : bundleSize(0) {} - virtual search::engine::SearchReply::UP match( - const ISearchHandler::SP &, + search::engine::SearchReply::UP match( const search::engine::SearchRequest &, vespalib::ThreadBundle &threadBundle) const override { bundleSize = threadBundle.size(); - return SearchReply::UP(new SearchReply); + return std::make_unique(); } }; @@ -135,7 +133,7 @@ TEST("requireThatBundlesAreUsed") MatchEngine engine(15, 5, 7); engine.setNodeUp(true); - ObserveBundleMatchHandler::SP handler(new ObserveBundleMatchHandler()); + auto handler = std::make_shared(); DocTypeName dtnvfoo("foo"); engine.putSearchHandler(dtnvfoo, handler); @@ -151,20 +149,20 @@ TEST("requireThatHandlersCanBeRemoved") { MatchEngine engine(1, 1, 7); engine.setNodeUp(true); - ISearchHandler::SP h(new MySearchHandler(1)); + auto h = std::make_shared(1); DocTypeName docType("foo"); engine.putSearchHandler(docType, h); ISearchHandler::SP r = engine.getSearchHandler(docType); - EXPECT_TRUE(r.get() != NULL); + EXPECT_TRUE(r); EXPECT_TRUE(h.get() == r.get()); r = engine.removeSearchHandler(docType); - EXPECT_TRUE(r.get() != NULL); + EXPECT_TRUE(r); EXPECT_TRUE(h.get() == r.get()); r = engine.getSearchHandler(docType); - EXPECT_TRUE(r.get() == NULL); + EXPECT_FALSE(r); } TEST("requireThatEmptySearchReplyIsReturnedWhenEngineIsClosed") @@ -175,7 +173,7 @@ TEST("requireThatEmptySearchReplyIsReturnedWhenEngineIsClosed") LocalSearchClient client; SearchRequest::Source request(new SearchRequest()); SearchReply::UP reply = engine.search(std::move(request), client); - EXPECT_TRUE(reply.get() != NULL); + EXPECT_TRUE(reply ); EXPECT_EQUAL(0u, reply->hits.size()); EXPECT_EQUAL(7u, reply->getDistributionKey()); } diff --git a/searchcore/src/tests/proton/matching/matching_test.cpp b/searchcore/src/tests/proton/matching/matching_test.cpp index 95ab43dbcba..00a319db394 100644 --- a/searchcore/src/tests/proton/matching/matching_test.cpp +++ b/searchcore/src/tests/proton/matching/matching_test.cpp @@ -289,7 +289,7 @@ struct MyWorld { DocsumReply::UP getDocsums(const DocsumRequest &) override { return DocsumReply::UP(); } - SearchReply::UP match(const ISearchHandler::SP &, const SearchRequest &, vespalib::ThreadBundle &) const override { + SearchReply::UP match(const SearchRequest &, vespalib::ThreadBundle &) const override { return SearchReply::UP(); } }; diff --git a/searchcore/src/tests/proton/summaryengine/summaryengine.cpp b/searchcore/src/tests/proton/summaryengine/summaryengine.cpp index a9cae7d8ab7..7cdd8d767c6 100644 --- a/searchcore/src/tests/proton/summaryengine/summaryengine.cpp +++ b/searchcore/src/tests/proton/summaryengine/summaryengine.cpp @@ -42,7 +42,7 @@ public: : _name(name), _reply(reply) {} - virtual DocsumReply::UP getDocsums(const DocsumRequest &request) override { + DocsumReply::UP getDocsums(const DocsumRequest &request) override { return (request.useRootSlime()) ? std::make_unique(createSlimeReply(request.hits.size())) : createOldDocSum(request); @@ -62,7 +62,7 @@ public: } DocsumReply::UP createOldDocSum(const DocsumRequest &request) { - DocsumReply::UP retval(new DocsumReply()); + auto retval = std::make_unique(); for (size_t i = 0; i < request.hits.size(); i++) { const DocsumRequest::Hit &h = request.hits[i]; DocsumReply::Docsum docsum; @@ -74,11 +74,8 @@ public: return retval; } - virtual search::engine::SearchReply::UP match( - const ISearchHandler::SP &, - const search::engine::SearchRequest &, - vespalib::ThreadBundle &) const override { - return SearchReply::UP(new SearchReply); + SearchReply::UP match(const SearchRequest &, vespalib::ThreadBundle &) const override { + return std::make_unique(); } }; @@ -90,8 +87,7 @@ private: public: MyDocsumClient(); - - ~MyDocsumClient(); + ~MyDocsumClient() override; void getDocsumsDone(DocsumReply::UP reply) override { std::lock_guard guard(_lock); @@ -111,19 +107,19 @@ public: } }; -MyDocsumClient::MyDocsumClient() {} +MyDocsumClient::MyDocsumClient() = default; -MyDocsumClient::~MyDocsumClient() {} +MyDocsumClient::~MyDocsumClient() = default; DocsumRequest::UP createRequest(size_t num = 1) { - DocsumRequest::UP r(new DocsumRequest()); + auto r = std::make_unique(); if (num == 1) { r->hits.emplace_back(GlobalId("aaaaaaaaaaaa")); } else { for (size_t i = 0; i < num; i++) { vespalib::string s = vespalib::make_string("aaaaaaaaaaa%c", char('a' + i % 26)); - r->hits.push_back(GlobalId(s.c_str())); + r->hits.emplace_back(GlobalId(s.c_str())); } } return r; @@ -132,7 +128,7 @@ createRequest(size_t num = 1) { TEST("requireThatGetDocsumsExecute") { int numSummaryThreads = 2; SummaryEngine engine(numSummaryThreads); - ISearchHandler::SP handler(new MySearchHandler); + auto handler = std::make_shared(); DocTypeName dtnvfoo("foo"); engine.putSearchHandler(dtnvfoo, handler); @@ -140,9 +136,9 @@ TEST("requireThatGetDocsumsExecute") { { // async call when engine running DocsumRequest::Source request(createRequest()); DocsumReply::UP reply = engine.getDocsums(std::move(request), client); - EXPECT_TRUE(reply.get() == NULL); + EXPECT_FALSE(reply); reply = client.getReply(10000); - EXPECT_TRUE(reply.get() != NULL); + EXPECT_TRUE(reply); EXPECT_EQUAL(1u, reply->docsums.size()); EXPECT_EQUAL(10u, reply->docsums[0].docid); EXPECT_EQUAL(GlobalId("aaaaaaaaaaaa"), reply->docsums[0].gid); @@ -152,7 +148,7 @@ TEST("requireThatGetDocsumsExecute") { { // sync call when engine closed DocsumRequest::Source request(createRequest()); DocsumReply::UP reply = engine.getDocsums(std::move(request), client); - EXPECT_TRUE(reply.get() != NULL); + EXPECT_TRUE(reply); } } @@ -161,23 +157,23 @@ TEST("requireThatHandlersAreStored") { DocTypeName dtnvbar("bar"); int numSummaryThreads = 2; SummaryEngine engine(numSummaryThreads); - ISearchHandler::SP h1(new MySearchHandler("foo")); - ISearchHandler::SP h2(new MySearchHandler("bar")); - ISearchHandler::SP h3(new MySearchHandler("baz")); + auto h1 = std::make_shared("foo"); + auto h2 = std::make_shared("bar"); + auto h3 = std::make_shared("baz"); // not found - EXPECT_TRUE(engine.getSearchHandler(dtnvfoo).get() == NULL); - EXPECT_TRUE(engine.removeSearchHandler(dtnvfoo).get() == NULL); + EXPECT_FALSE(engine.getSearchHandler(dtnvfoo)); + EXPECT_FALSE(engine.removeSearchHandler(dtnvfoo)); // put & get - EXPECT_TRUE(engine.putSearchHandler(dtnvfoo, h1).get() == NULL); + EXPECT_FALSE(engine.putSearchHandler(dtnvfoo, h1)); EXPECT_EQUAL(engine.getSearchHandler(dtnvfoo).get(), h1.get()); - EXPECT_TRUE(engine.putSearchHandler(dtnvbar, h2).get() == NULL); + EXPECT_FALSE(engine.putSearchHandler(dtnvbar, h2)); EXPECT_EQUAL(engine.getSearchHandler(dtnvbar).get(), h2.get()); // replace EXPECT_TRUE(engine.putSearchHandler(dtnvfoo, h3).get() == h1.get()); EXPECT_EQUAL(engine.getSearchHandler(dtnvfoo).get(), h3.get()); // remove EXPECT_EQUAL(engine.removeSearchHandler(dtnvfoo).get(), h3.get()); - EXPECT_TRUE(engine.getSearchHandler(dtnvfoo).get() == NULL); + EXPECT_FALSE(engine.getSearchHandler(dtnvfoo)); } bool @@ -196,9 +192,9 @@ TEST("requireThatCorrectHandlerIsUsed") { DocTypeName dtnvbar("bar"); DocTypeName dtnvbaz("baz"); SummaryEngine engine(1); - ISearchHandler::SP h1(new MySearchHandler("foo", "foo reply")); - ISearchHandler::SP h2(new MySearchHandler("bar", "bar reply")); - ISearchHandler::SP h3(new MySearchHandler("baz", "baz reply")); + auto h1 = std::make_shared("foo", "foo reply"); + auto h2 = std::make_shared("bar", "bar reply"); + auto h3 = std::make_shared("baz", "baz reply"); engine.putSearchHandler(dtnvfoo, h1); engine.putSearchHandler(dtnvbar, h2); engine.putSearchHandler(dtnvbaz, h3); @@ -369,7 +365,7 @@ public: Server::Server() : BaseServer(), engine(2), - handler(new MySearchHandler("slime", stringref(buf.GetDrainPos(), buf.GetUsedLen()))), + handler(std::make_shared("slime", stringref(buf.GetDrainPos(), buf.GetUsedLen()))), docsumBySlime(engine), docsumByRPC(docsumBySlime) { @@ -377,7 +373,7 @@ Server::Server() engine.putSearchHandler(dtnvfoo, handler); } -Server::~Server() {} +Server::~Server() = default; vespalib::string getAnswer(size_t num) { diff --git a/searchcore/src/vespa/searchcore/proton/common/doctypename.cpp b/searchcore/src/vespa/searchcore/proton/common/doctypename.cpp index 70daeeebeca..21b27ef6ffd 100644 --- a/searchcore/src/vespa/searchcore/proton/common/doctypename.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/doctypename.cpp @@ -4,20 +4,16 @@ #include #include -namespace proton -{ +namespace proton { DocTypeName::DocTypeName(const search::engine::Request &request) : _name(request.propertiesMap.matchProperties().lookup("documentdb", "searchdoctype").get("")) -{ -} +{} DocTypeName::DocTypeName(const document::DocumentType &docType) : _name(docType.getName()) -{ -} +{} - -} // namespace proton +} diff --git a/searchcore/src/vespa/searchcore/proton/common/handlermap.hpp b/searchcore/src/vespa/searchcore/proton/common/handlermap.hpp index 3fb32a9d1e0..e762ac527f0 100644 --- a/searchcore/src/vespa/searchcore/proton/common/handlermap.hpp +++ b/searchcore/src/vespa/searchcore/proton/common/handlermap.hpp @@ -53,7 +53,6 @@ public: bool valid() const override { return (_offset < _handlers.size()); } T *get() const override { return _handlers[_offset].get(); } - HandlerSP getSP() const { return _handlers[_offset]; } void next() override { ++_offset; } }; diff --git a/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp b/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp index b170f60d71f..ad47fb98232 100644 --- a/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp +++ b/searchcore/src/vespa/searchcore/proton/matchengine/matchengine.cpp @@ -121,12 +121,12 @@ MatchEngine::performSearch(search::engine::SearchRequest::Source req, ISearchHandler::SP searchHandler; vespalib::SimpleThreadBundle::UP threadBundle = _threadBundlePool.obtain(); { // try to find the match handler corresponding to the specified search doc type - std::lock_guard guard(_lock); DocTypeName docTypeName(*searchRequest); + std::lock_guard guard(_lock); searchHandler = _handlers.getHandler(docTypeName); } if (searchHandler) { - ret = searchHandler->match(searchHandler, *searchRequest, *threadBundle); + ret = searchHandler->match(*searchRequest, *threadBundle); } else { HandlerMap::Snapshot snapshot; { @@ -134,8 +134,7 @@ MatchEngine::performSearch(search::engine::SearchRequest::Source req, snapshot = _handlers.snapshot(); } if (snapshot.valid()) { - ISearchHandler::SP handler = snapshot.getSP(); - ret = handler->match(handler, *searchRequest, *threadBundle); // use the first handler + ret = snapshot.get()->match(*searchRequest, *threadBundle); // use the first handler } } _threadBundlePool.release(std::move(threadBundle)); diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp index 1b182c3e618..302ffc93f6a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp @@ -756,11 +756,11 @@ DocumentDB::getNewestFlushedSerial() } std::unique_ptr -DocumentDB::match(const ISearchHandler::SP &, const SearchRequest &req, vespalib::ThreadBundle &threadBundle) const +DocumentDB::match(const SearchRequest &req, vespalib::ThreadBundle &threadBundle) const { // Ignore input searchhandler. Use readysubdb's searchhandler instead. ISearchHandler::SP view(_subDBs.getReadySubDB()->getSearchView()); - return view->match(view, req, threadBundle); + return view->match(req, threadBundle); } std::unique_ptr diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.h b/searchcore/src/vespa/searchcore/proton/server/documentdb.h index 02ad144af68..f296e264903 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.h +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.h @@ -368,8 +368,7 @@ public: virtual SerialNum getNewestFlushedSerial(); std::unique_ptr - match(const ISearchHandler::SP &searchHandler, - const search::engine::SearchRequest &req, + match(const search::engine::SearchRequest &req, vespalib::ThreadBundle &threadBundle) const; std::unique_ptr diff --git a/searchcore/src/vespa/searchcore/proton/server/emptysearchview.cpp b/searchcore/src/vespa/searchcore/proton/server/emptysearchview.cpp index 90cf0011685..9f2ec26ad4b 100644 --- a/searchcore/src/vespa/searchcore/proton/server/emptysearchview.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/emptysearchview.cpp @@ -14,10 +14,7 @@ using search::engine::SearchRequest; namespace proton { -EmptySearchView::EmptySearchView() - : ISearchHandler() -{ -} +EmptySearchView::EmptySearchView() = default; DocsumReply::UP @@ -25,20 +22,16 @@ EmptySearchView::getDocsums(const DocsumRequest &req) { LOG(debug, "getDocsums(): resultClass(%s), numHits(%zu)", req.resultClassName.c_str(), req.hits.size()); - DocsumReply::UP reply(new DocsumReply()); - for (size_t i = 0; i < req.hits.size(); ++i) { - reply->docsums.push_back(DocsumReply::Docsum()); - reply->docsums.back().gid = req.hits[i].gid; + auto reply = std::make_unique(); + for (const auto & hit : req.hits) { + reply->docsums.emplace_back(hit.gid); } return reply; } SearchReply::UP -EmptySearchView::match(const ISearchHandler::SP &, - const SearchRequest &, - vespalib::ThreadBundle &) const { - SearchReply::UP reply(new SearchReply); - return reply; +EmptySearchView::match(const SearchRequest &, vespalib::ThreadBundle &) const { + return std::make_unique(); } diff --git a/searchcore/src/vespa/searchcore/proton/server/emptysearchview.h b/searchcore/src/vespa/searchcore/proton/server/emptysearchview.h index a3e2a2b176c..92fb97f6177 100644 --- a/searchcore/src/vespa/searchcore/proton/server/emptysearchview.h +++ b/searchcore/src/vespa/searchcore/proton/server/emptysearchview.h @@ -13,15 +13,10 @@ public: EmptySearchView(); - /** - * Implements ISearchHandler - */ - virtual std::unique_ptr getDocsums(const DocsumRequest & req) override; - - virtual std::unique_ptr - match(const ISearchHandler::SP &searchHandler, - const SearchRequest &req, - vespalib::ThreadBundle &threadBundle) const override; + std::unique_ptr getDocsums(const DocsumRequest & req) override; + + std::unique_ptr + match(const SearchRequest &req, vespalib::ThreadBundle &threadBundle) const override; }; } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp index 28de4dff917..20de5bb07c1 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp @@ -628,8 +628,7 @@ Proton::removeDocumentDB(const DocTypeName &docTypeName) { // Not allowed to get to service layer to call pause(). std::unique_lock persistenceWguard(_persistenceEngine->getWLock()); - IPersistenceHandler::SP oldHandler; - oldHandler = _persistenceEngine->removeHandler(persistenceWguard, old->getBucketSpace(), docTypeName); + IPersistenceHandler::SP oldHandler = _persistenceEngine->removeHandler(persistenceWguard, old->getBucketSpace(), docTypeName); if (_initComplete && oldHandler) { // TODO: Fix race with bucket db modifying ops. _persistenceEngine->grabExtraModifiedBuckets(old->getBucketSpace(), *oldHandler); diff --git a/searchcore/src/vespa/searchcore/proton/server/searchhandlerproxy.cpp b/searchcore/src/vespa/searchcore/proton/server/searchhandlerproxy.cpp index f611b4e1f4c..6da6c09cdba 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchhandlerproxy.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchhandlerproxy.cpp @@ -7,8 +7,8 @@ namespace proton { -SearchHandlerProxy::SearchHandlerProxy(const DocumentDB::SP &documentDB) - : _documentDB(documentDB) +SearchHandlerProxy::SearchHandlerProxy(DocumentDB::SP documentDB) + : _documentDB(std::move(documentDB)) { _documentDB->retain(); } @@ -25,11 +25,9 @@ SearchHandlerProxy::getDocsums(const DocsumRequest & request) } std::unique_ptr -SearchHandlerProxy::match(const ISearchHandler::SP &searchHandler, - const SearchRequest &req, - vespalib::ThreadBundle &threadBundle) const +SearchHandlerProxy::match(const SearchRequest &req, vespalib::ThreadBundle &threadBundle) const { - return _documentDB->match(searchHandler, req, threadBundle); + return _documentDB->match(req, threadBundle); } } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/searchhandlerproxy.h b/searchcore/src/vespa/searchcore/proton/server/searchhandlerproxy.h index 4e9f5bdab8a..fc4f517fb36 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchhandlerproxy.h +++ b/searchcore/src/vespa/searchcore/proton/server/searchhandlerproxy.h @@ -13,11 +13,11 @@ class SearchHandlerProxy : public ISearchHandler private: std::shared_ptr _documentDB; public: - SearchHandlerProxy(const std::shared_ptr &documentDB); + SearchHandlerProxy(std::shared_ptr documentDB); - virtual~SearchHandlerProxy(); + ~SearchHandlerProxy() override; std::unique_ptr getDocsums(const DocsumRequest & request) override; - std::unique_ptr match(const ISearchHandler::SP &searchHandler, const SearchRequest &req, ThreadBundle &threadBundle) const override; + std::unique_ptr match(const SearchRequest &req, ThreadBundle &threadBundle) const override; }; } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/searchview.cpp b/searchcore/src/vespa/searchcore/proton/server/searchview.cpp index 9830048cdd8..3ca0e4b0a82 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchview.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchview.cpp @@ -161,8 +161,9 @@ SearchView::getDocsumsInternal(const DocsumRequest & req) } std::unique_ptr -SearchView::match(const ISearchHandler::SP &self, const SearchRequest &req, ThreadBundle &threadBundle) const { - return _matchView->match(self, req, threadBundle); +SearchView::match(const SearchRequest &req, ThreadBundle &threadBundle) const { + ISearchHandler::SP self = const_cast(this)->shared_from_this(); + return _matchView->match(std::move(self), req, threadBundle); } } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/searchview.h b/searchcore/src/vespa/searchcore/proton/server/searchview.h index 28c7ffd2b36..8148f10feeb 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchview.h +++ b/searchcore/src/vespa/searchcore/proton/server/searchview.h @@ -8,7 +8,7 @@ namespace proton { -class SearchView : public ISearchHandler +class SearchView : public ISearchHandler, public std::enable_shared_from_this { public: using SessionManagerSP = std::shared_ptr; @@ -21,7 +21,7 @@ public: SearchView(SearchView &&) = delete; SearchView &operator=(const SearchView &) = delete; SearchView &operator=(SearchView &&) = delete; - ~SearchView(); + ~SearchView() override; const ISummaryManager::ISummarySetup::SP & getSummarySetup() const { return _summarySetup; } const MatchView::SP & getMatchView() const { return _matchView; } @@ -34,7 +34,7 @@ public: matching::MatchingStats getMatcherStats(const vespalib::string &rankProfile) const { return _matchView->getMatcherStats(rankProfile); } std::unique_ptr getDocsums(const DocsumRequest & req) override; - std::unique_ptr match(const ISearchHandler::SP &self, const SearchRequest &req, vespalib::ThreadBundle &threadBundle) const override; + std::unique_ptr match(const SearchRequest &req, vespalib::ThreadBundle &threadBundle) const override; private: InternalDocsumReply getDocsumsInternal(const DocsumRequest & req); ISummaryManager::ISummarySetup::SP _summarySetup; diff --git a/searchcore/src/vespa/searchcore/proton/summaryengine/isearchhandler.h b/searchcore/src/vespa/searchcore/proton/summaryengine/isearchhandler.h index ffcdfbaf365..dc14ac08aef 100644 --- a/searchcore/src/vespa/searchcore/proton/summaryengine/isearchhandler.h +++ b/searchcore/src/vespa/searchcore/proton/summaryengine/isearchhandler.h @@ -39,7 +39,7 @@ public: virtual std::unique_ptr getDocsums(const DocsumRequest & request) = 0; virtual std::unique_ptr - match(const ISearchHandler::SP &self, const SearchRequest &req, ThreadBundle &threadBundle) const = 0; + match(const SearchRequest &req, ThreadBundle &threadBundle) const = 0; }; } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/summaryengine/summaryengine.cpp b/searchcore/src/vespa/searchcore/proton/summaryengine/summaryengine.cpp index 692b05899f4..1189e8a550c 100644 --- a/searchcore/src/vespa/searchcore/proton/summaryengine/summaryengine.cpp +++ b/searchcore/src/vespa/searchcore/proton/summaryengine/summaryengine.cpp @@ -107,13 +107,13 @@ SummaryEngine::getDocsums(DocsumRequest::Source request, DocsumClient & client) { if (_closed) { LOG(warning, "Receiving docsumrequest after engine has been shutdown"); - DocsumReply::UP ret(new DocsumReply()); + auto ret = std::make_unique(); // TODO: Notify closed. return ret; } - vespalib::Executor::Task::UP task(new DocsumTask(*this, std::move(request), client)); + auto task =std::make_unique(*this, std::move(request), client); _executor.execute(std::move(task)); return DocsumReply::UP(); } -- cgit v1.2.3