diff options
author | Haavard <havardpe@yahoo-inc.com> | 2017-03-20 13:04:33 +0000 |
---|---|---|
committer | Haavard <havardpe@yahoo-inc.com> | 2017-03-27 09:53:26 +0000 |
commit | 23abed1a0bc4f4c5ea47b43fc7ea0645e63a26e6 (patch) | |
tree | 6d943bbe31738f7e9b84979e4fd63dfd76eef580 /searchcore | |
parent | 8844ccb7297e8a5120dd903c85e923f2f93aa693 (diff) |
remove most usage of LinkedPtr from vespa
Diffstat (limited to 'searchcore')
29 files changed, 103 insertions, 119 deletions
diff --git a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp index 7df80778cb7..a33a5f147f2 100644 --- a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp +++ b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp @@ -569,7 +569,7 @@ TEST_F("require that outdated put is ignored", FeedHandlerFixture) void addLidToRemove(RemoveDocumentsOperation &op) { - LidVectorContext::LP lids(new LidVectorContext(42)); + LidVectorContext::SP lids(new LidVectorContext(42)); lids->addLid(4); op.setLidsToRemove(0, lids); } diff --git a/searchcore/src/tests/proton/documentdb/storeonlyfeedview/storeonlyfeedview_test.cpp b/searchcore/src/tests/proton/documentdb/storeonlyfeedview/storeonlyfeedview_test.cpp index 2c54188af3a..7a28dd02bca 100644 --- a/searchcore/src/tests/proton/documentdb/storeonlyfeedview/storeonlyfeedview_test.cpp +++ b/searchcore/src/tests/proton/documentdb/storeonlyfeedview/storeonlyfeedview_test.cpp @@ -249,7 +249,7 @@ TEST_F("require that prune removed documents removes documents", { f.addDocsToMetaStore(3); - LidVectorContext::LP lids(new LidVectorContext(4)); + LidVectorContext::SP lids(new LidVectorContext(4)); lids->addLid(1); lids->addLid(3); PruneRemovedDocumentsOperation op(lids->getDocIdLimit(), subdb_id); diff --git a/searchcore/src/tests/proton/metrics/metrics_engine/metrics_engine_test.cpp b/searchcore/src/tests/proton/metrics/metrics_engine/metrics_engine_test.cpp index 36cdd7ff89f..78b53910023 100644 --- a/searchcore/src/tests/proton/metrics/metrics_engine/metrics_engine_test.cpp +++ b/searchcore/src/tests/proton/metrics/metrics_engine/metrics_engine_test.cpp @@ -44,14 +44,14 @@ struct AttributeMetricsFixture { EXPECT_EQUAL(expNumMetrics, totalLegacyMetrics.list.getRegisteredMetrics().size()); } void assertMetricsExists(const vespalib::string &attrName) { - EXPECT_TRUE(metrics.get(attrName).get() != nullptr); - EXPECT_TRUE(legacyMetrics.list.get(attrName).get() != nullptr); - EXPECT_TRUE(totalLegacyMetrics.list.get(attrName).get() != nullptr); + EXPECT_TRUE(metrics.get(attrName) != nullptr); + EXPECT_TRUE(legacyMetrics.list.get(attrName) != nullptr); + EXPECT_TRUE(totalLegacyMetrics.list.get(attrName) != nullptr); } void assertMetricsNotExists(const vespalib::string &attrName) { - EXPECT_TRUE(metrics.get(attrName).get() == nullptr); - EXPECT_TRUE(legacyMetrics.list.get(attrName).get() == nullptr); - EXPECT_TRUE(totalLegacyMetrics.list.get(attrName).get() == nullptr); + EXPECT_TRUE(metrics.get(attrName) == nullptr); + EXPECT_TRUE(legacyMetrics.list.get(attrName) == nullptr); + EXPECT_TRUE(totalLegacyMetrics.list.get(attrName) == nullptr); } }; diff --git a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp index 89159a6b92f..0afbfaedb73 100644 --- a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp +++ b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp @@ -16,7 +16,6 @@ #include <vespa/searchcore/proton/server/i_proton_configurer.h> #include <vespa/searchsummary/config/config-juniperrc.h> #include <vespa/vespalib/testkit/testapp.h> -#include <vespa/vespalib/util/linkedptr.h> #include <vespa/vespalib/util/varholder.h> #include <mutex> @@ -33,7 +32,6 @@ using document::DocumenttypesConfig; using document::DocumenttypesConfigBuilder; using search::TuneFileDocumentDB; using std::map; -using vespalib::LinkedPtr; using vespalib::VarHolder; struct DoctypeFixture { diff --git a/searchcore/src/tests/proton/server/legacy_attribute_metrics_test.cpp b/searchcore/src/tests/proton/server/legacy_attribute_metrics_test.cpp index cd129d79693..513ad5a03dd 100644 --- a/searchcore/src/tests/proton/server/legacy_attribute_metrics_test.cpp +++ b/searchcore/src/tests/proton/server/legacy_attribute_metrics_test.cpp @@ -22,31 +22,31 @@ Test::Main() LegacyAttributeMetrics attrMetrics(0); EXPECT_EQUAL(0u, attrMetrics.list.release().size()); { - LegacyAttributeMetrics::List::Entry::LP e1 = attrMetrics.list.add("foo"); - LegacyAttributeMetrics::List::Entry::LP e2 = attrMetrics.list.add("bar"); - LegacyAttributeMetrics::List::Entry::LP e3 = attrMetrics.list.add("foo"); - EXPECT_TRUE(e1.get() != 0); - EXPECT_TRUE(e2.get() != 0); - EXPECT_TRUE(e3.get() == 0); + LegacyAttributeMetrics::List::Entry *e1 = attrMetrics.list.add("foo"); + LegacyAttributeMetrics::List::Entry *e2 = attrMetrics.list.add("bar"); + LegacyAttributeMetrics::List::Entry *e3 = attrMetrics.list.add("foo"); + EXPECT_TRUE(e1 != nullptr); + EXPECT_TRUE(e2 != nullptr); + EXPECT_TRUE(e3 == nullptr); } { const LegacyAttributeMetrics &constMetrics = attrMetrics; - LegacyAttributeMetrics::List::Entry::LP e1 = constMetrics.list.get("foo"); - LegacyAttributeMetrics::List::Entry::LP e2 = constMetrics.list.get("bar"); - LegacyAttributeMetrics::List::Entry::LP e3 = constMetrics.list.get("baz"); - EXPECT_TRUE(e1.get() != 0); - EXPECT_TRUE(e2.get() != 0); - EXPECT_TRUE(e3.get() == 0); + LegacyAttributeMetrics::List::Entry *e1 = constMetrics.list.get("foo"); + LegacyAttributeMetrics::List::Entry *e2 = constMetrics.list.get("bar"); + LegacyAttributeMetrics::List::Entry *e3 = constMetrics.list.get("baz"); + EXPECT_TRUE(e1 != nullptr); + EXPECT_TRUE(e2 != nullptr); + EXPECT_TRUE(e3 == nullptr); } EXPECT_EQUAL(2u, attrMetrics.list.release().size()); { const LegacyAttributeMetrics &constMetrics = attrMetrics; - LegacyAttributeMetrics::List::Entry::LP e1 = constMetrics.list.get("foo"); - LegacyAttributeMetrics::List::Entry::LP e2 = constMetrics.list.get("bar"); - LegacyAttributeMetrics::List::Entry::LP e3 = constMetrics.list.get("baz"); - EXPECT_TRUE(e1.get() == 0); - EXPECT_TRUE(e2.get() == 0); - EXPECT_TRUE(e3.get() == 0); + LegacyAttributeMetrics::List::Entry *e1 = constMetrics.list.get("foo"); + LegacyAttributeMetrics::List::Entry *e2 = constMetrics.list.get("bar"); + LegacyAttributeMetrics::List::Entry *e3 = constMetrics.list.get("baz"); + EXPECT_TRUE(e1 == nullptr); + EXPECT_TRUE(e2 == nullptr); + EXPECT_TRUE(e3 == nullptr); } EXPECT_EQUAL(0u, attrMetrics.list.release().size()); } diff --git a/searchcore/src/vespa/searchcore/grouping/groupingsession.h b/searchcore/src/vespa/searchcore/grouping/groupingsession.h index f355f5de418..110e0a51f93 100644 --- a/searchcore/src/vespa/searchcore/grouping/groupingsession.h +++ b/searchcore/src/vespa/searchcore/grouping/groupingsession.h @@ -34,7 +34,6 @@ private: fastos::TimeStamp _timeOfDoom; public: - typedef vespalib::LinkedPtr<GroupingSession> LP; typedef std::unique_ptr<GroupingSession> UP; /** diff --git a/searchcore/src/vespa/searchcore/proton/feedoperation/lidvectorcontext.h b/searchcore/src/vespa/searchcore/proton/feedoperation/lidvectorcontext.h index 6e2f9256b84..b4ae56306f0 100644 --- a/searchcore/src/vespa/searchcore/proton/feedoperation/lidvectorcontext.h +++ b/searchcore/src/vespa/searchcore/proton/feedoperation/lidvectorcontext.h @@ -3,7 +3,6 @@ #include <vespa/searchlib/query/base.h> #include <vespa/vespalib/objects/nbostream.h> -#include <vespa/vespalib/util/linkedptr.h> #include <vector> namespace proton { @@ -17,7 +16,7 @@ private: size_t _docIdLimit; enum { ARRAY = 0, BITVECTOR = 1 }; public: - typedef vespalib::LinkedPtr<LidVectorContext> LP; + using SP = std::shared_ptr<LidVectorContext>; LidVectorContext(); LidVectorContext(size_t docIdLimit); LidVectorContext(size_t docIdLimit, const LidVector &lids); diff --git a/searchcore/src/vespa/searchcore/proton/feedoperation/pruneremoveddocumentsoperation.cpp b/searchcore/src/vespa/searchcore/proton/feedoperation/pruneremoveddocumentsoperation.cpp index 9da621b5c84..b257fb14d57 100644 --- a/searchcore/src/vespa/searchcore/proton/feedoperation/pruneremoveddocumentsoperation.cpp +++ b/searchcore/src/vespa/searchcore/proton/feedoperation/pruneremoveddocumentsoperation.cpp @@ -26,7 +26,7 @@ PruneRemovedDocumentsOperation(DocumentIdT docIdLimit, : RemoveDocumentsOperation(FeedOperation::PRUNE_REMOVED_DOCUMENTS), _subDbId(subDbId) { - LidVectorContext::LP lidsToRemove(new LidVectorContext(docIdLimit)); + LidVectorContext::SP lidsToRemove(new LidVectorContext(docIdLimit)); setLidsToRemove(lidsToRemove); } @@ -51,7 +51,7 @@ PruneRemovedDocumentsOperation::deserialize(vespalib::nbostream &is, } vespalib::string PruneRemovedDocumentsOperation::toString() const { - LidVectorContext::LP lids = getLidsToRemove(); + LidVectorContext::SP lids = getLidsToRemove(); return make_string("PruneRemovedDocuments(limitLid=%zu, subDbId=%d, " "serialNum=%" PRIu64 ")", lids.get() ? lids->getDocIdLimit() : 0, diff --git a/searchcore/src/vespa/searchcore/proton/feedoperation/pruneremoveddocumentsoperation.h b/searchcore/src/vespa/searchcore/proton/feedoperation/pruneremoveddocumentsoperation.h index 35c413b2491..3f30c40f881 100644 --- a/searchcore/src/vespa/searchcore/proton/feedoperation/pruneremoveddocumentsoperation.h +++ b/searchcore/src/vespa/searchcore/proton/feedoperation/pruneremoveddocumentsoperation.h @@ -26,12 +26,12 @@ public: uint32_t getSubDbId() const { return _subDbId; } - void setLidsToRemove(const LidVectorContext::LP &lidsToRemove) + void setLidsToRemove(const LidVectorContext::SP &lidsToRemove) { RemoveDocumentsOperation::setLidsToRemove(_subDbId, lidsToRemove); } - const LidVectorContext::LP + const LidVectorContext::SP getLidsToRemove() const { return RemoveDocumentsOperation::getLidsToRemove(_subDbId); diff --git a/searchcore/src/vespa/searchcore/proton/feedoperation/removedocumentsoperation.cpp b/searchcore/src/vespa/searchcore/proton/feedoperation/removedocumentsoperation.cpp index a61819d861a..247a8dfc803 100644 --- a/searchcore/src/vespa/searchcore/proton/feedoperation/removedocumentsoperation.cpp +++ b/searchcore/src/vespa/searchcore/proton/feedoperation/removedocumentsoperation.cpp @@ -37,7 +37,7 @@ RemoveDocumentsOperation::deserializeLidsToRemove(vespalib::nbostream &is) for (i = 0; i < mapSize; ++i) { uint32_t subDbId; is >> subDbId; - LidVectorContext::LP lidsToRemove(new LidVectorContext()); + LidVectorContext::SP lidsToRemove(new LidVectorContext()); lidsToRemove->deserialize(is); setLidsToRemove(subDbId, lidsToRemove); } diff --git a/searchcore/src/vespa/searchcore/proton/feedoperation/removedocumentsoperation.h b/searchcore/src/vespa/searchcore/proton/feedoperation/removedocumentsoperation.h index 49a0f44a175..8ce182591f5 100644 --- a/searchcore/src/vespa/searchcore/proton/feedoperation/removedocumentsoperation.h +++ b/searchcore/src/vespa/searchcore/proton/feedoperation/removedocumentsoperation.h @@ -10,7 +10,7 @@ namespace proton { class RemoveDocumentsOperation : public FeedOperation { protected: - typedef std::map<uint32_t, LidVectorContext::LP> LidsToRemoveMap; + typedef std::map<uint32_t, LidVectorContext::SP> LidsToRemoveMap; LidsToRemoveMap _lidsToRemoveMap; RemoveDocumentsOperation(Type type); @@ -20,17 +20,17 @@ protected: public: virtual ~RemoveDocumentsOperation() { } - void setLidsToRemove(uint32_t subDbId, const LidVectorContext::LP &lidsToRemove) { + void setLidsToRemove(uint32_t subDbId, const LidVectorContext::SP &lidsToRemove) { _lidsToRemoveMap[subDbId] = lidsToRemove; } - const LidVectorContext::LP + const LidVectorContext::SP getLidsToRemove(uint32_t subDbId) const { LidsToRemoveMap::const_iterator found(_lidsToRemoveMap.find(subDbId)); if (found != _lidsToRemoveMap.end()) return found->second; else - return LidVectorContext::LP(); + return LidVectorContext::SP(); } }; diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_master.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_master.cpp index 5398d5d6a3a..f971e2633de 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_master.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/match_master.cpp @@ -81,7 +81,7 @@ MatchMaster::match(const MatchParams ¶ms, } resultProcessor.prepareThreadContextCreation(threadBundle.size()); threadBundle.run(targets); - ResultProcessor::Result::UP reply = resultProcessor.makeReply(); + ResultProcessor::Result::UP reply = resultProcessor.makeReply(threadState[0]->extract_result()); query_latency_time.stop(); double query_time_s = query_latency_time.elapsed().sec(); double rerank_time_s = timedCommunicator.rerank_time.elapsed().sec(); diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_thread.h b/searchcore/src/vespa/searchcore/proton/matching/match_thread.h index d38c2121034..d20e71e370a 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_thread.h +++ b/searchcore/src/vespa/searchcore/proton/matching/match_thread.h @@ -108,6 +108,7 @@ public: virtual void run(); const MatchingStats::Partition &get_thread_stats() const { return thread_stats; } double get_match_time() const { return match_time_s; } + PartialResult::UP extract_result() { return std::move(resultContext->result); } }; } // namespace proton::matching diff --git a/searchcore/src/vespa/searchcore/proton/matching/partial_result.h b/searchcore/src/vespa/searchcore/proton/matching/partial_result.h index f998a8aa92e..e39b0ed92f1 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/partial_result.h +++ b/searchcore/src/vespa/searchcore/proton/matching/partial_result.h @@ -2,7 +2,6 @@ #pragma once -#include <vespa/vespalib/util/linkedptr.h> #include <vespa/vespalib/util/dual_merge_director.h> #include <vespa/searchlib/common/rankedhit.h> #include <vector> @@ -17,8 +16,8 @@ namespace matching { class PartialResult : public vespalib::DualMergeDirector::Source { public: - typedef vespalib::LinkedPtr<PartialResult> LP; - typedef std::pair<const char *, size_t> SortRef; + using UP = std::unique_ptr<PartialResult>; + using SortRef = std::pair<const char *, size_t>; private: std::vector<search::RankedHit> _hits; diff --git a/searchcore/src/vespa/searchcore/proton/matching/result_processor.cpp b/searchcore/src/vespa/searchcore/proton/matching/result_processor.cpp index a6bf98b2ccf..09929774550 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/result_processor.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/result_processor.cpp @@ -36,9 +36,9 @@ ResultProcessor::Sort::Sort(uint32_t partitionId, const vespalib::Doom & doom, I } } -ResultProcessor::Context::Context(Sort::UP s, PartialResult::LP r, GroupingContext::UP g) +ResultProcessor::Context::Context(Sort::UP s, PartialResult::UP r, GroupingContext::UP g) : sort(std::move(s)), - result(r), + result(std::move(r)), grouping(std::move(g)), groupingSource(grouping.get()) { } @@ -70,7 +70,6 @@ ResultProcessor::ResultProcessor(IAttributeContext &attrContext, _sortSpec(sortSpec), _offset(offset), _hits(hits), - _result(), _wasMerged(false) { if (!_groupingContext.empty()) { @@ -95,24 +94,21 @@ ResultProcessor::Context::UP ResultProcessor::createThreadContext(const vespalib::Doom & hardDoom, size_t thread_id, uint32_t distributionKey) { Sort::UP sort(new Sort(distributionKey, hardDoom, _attrContext, _sortSpec)); - PartialResult::LP result(new PartialResult((_offset + _hits), sort->hasSortData())); - if (thread_id == 0) { - _result = result; - } + PartialResult::UP result(new PartialResult((_offset + _hits), sort->hasSortData())); search::grouping::GroupingContext::UP groupingContext; if (_groupingSession.get() != 0) { groupingContext = _groupingSession->createThreadContext(thread_id, _attrContext); } - return Context::UP(new Context(std::move(sort), result, std::move(groupingContext))); + return Context::UP(new Context(std::move(sort), std::move(result), std::move(groupingContext))); } ResultProcessor::Result::UP -ResultProcessor::makeReply() +ResultProcessor::makeReply(PartialResultUP full_result) { search::engine::SearchReply::UP reply(new search::engine::SearchReply()); const search::IDocumentMetaStore &metaStore = _metaStore; search::engine::SearchReply &r = *reply; - PartialResult &result = *_result; + PartialResult &result = *full_result; size_t numFs4Hits(0); if (_groupingSession) { if (_wasMerged) { diff --git a/searchcore/src/vespa/searchcore/proton/matching/result_processor.h b/searchcore/src/vespa/searchcore/proton/matching/result_processor.h index 0ce87ceb7c6..8abc8bbc1a5 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/result_processor.h +++ b/searchcore/src/vespa/searchcore/proton/matching/result_processor.h @@ -27,7 +27,7 @@ class ResultProcessor using GroupingContext = search::grouping::GroupingContext; using GroupingSession = search::grouping::GroupingSession; using IAttributeContext = search::attribute::IAttributeContext; - using PartialResultLP = vespalib::LinkedPtr<PartialResult>; + using PartialResultUP = std::unique_ptr<PartialResult>; public: /** * Sorter selection and owner of additional data needed for @@ -63,11 +63,11 @@ public: using GroupingContextUP = std::unique_ptr<GroupingContext>; Sort::UP sort; - PartialResultLP result; + PartialResultUP result; GroupingContextUP grouping; GroupingSource groupingSource; - Context(Sort::UP s, PartialResultLP r, GroupingContextUP g); + Context(Sort::UP s, PartialResultUP r, GroupingContextUP g); ~Context(); }; @@ -89,7 +89,6 @@ private: const vespalib::string &_sortSpec; size_t _offset; size_t _hits; - PartialResultLP _result; bool _wasMerged; public: @@ -105,7 +104,7 @@ public: size_t countFS4Hits(); void prepareThreadContextCreation(size_t num_threads); Context::UP createThreadContext(const vespalib::Doom & hardDoom, size_t thread_id, uint32_t distributionKey); - std::unique_ptr<Result> makeReply(); + std::unique_ptr<Result> makeReply(PartialResultUP full_result); }; } // namespace proton::matching diff --git a/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.cpp b/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.cpp index db4d12de677..772ee7bd6e4 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.cpp @@ -26,9 +26,8 @@ namespace matching { template <typename T> struct SessionCache : SessionCacheBase { - typedef typename T::LP EntryLP; typedef typename T::UP EntryUP; - vespalib::lrucache_map<vespalib::LruParam<SessionId, EntryLP> > _cache; + vespalib::lrucache_map<vespalib::LruParam<SessionId, EntryUP> > _cache; SessionCache(uint32_t max_size) : _cache(max_size) {} @@ -38,7 +37,7 @@ namespace matching { if (_cache.size() >= _cache.capacity()) { entryDropped(id); } - _cache.insert(id, EntryLP(session.release())); + _cache.insert(id, std::move(session)); _stats.numInsert++; } EntryUP pick(const SessionId & id) { @@ -46,24 +45,23 @@ namespace matching { EntryUP ret; if (_cache.hasKey(id)) { _stats.numPick++; - EntryLP session(_cache.get(id)); + ret = std::move(_cache[id]); _cache.erase(id); - ret.reset(session.release()); } return ret; } void pruneTimedOutSessions(fastos::TimeStamp currentTime) { - std::vector<EntryLP> toDestruct = stealTimedOutSessions(currentTime); + std::vector<EntryUP> toDestruct = stealTimedOutSessions(currentTime); toDestruct.clear(); } - std::vector<EntryLP> stealTimedOutSessions(fastos::TimeStamp currentTime) { - std::vector<EntryLP> toDestruct; + std::vector<EntryUP> stealTimedOutSessions(fastos::TimeStamp currentTime) { + std::vector<EntryUP> toDestruct; vespalib::LockGuard guard(_lock); toDestruct.reserve(_cache.size()); for (auto it(_cache.begin()), mt(_cache.end()); it != mt;) { - EntryLP session = *it; + auto &session = *it; if (session->getTimeOfDoom() < currentTime) { - toDestruct.push_back(session); + toDestruct.push_back(std::move(session)); it = _cache.erase(it); _stats.numTimedout++; } else { diff --git a/searchcore/src/vespa/searchcore/proton/metrics/legacy_attribute_metrics.cpp b/searchcore/src/vespa/searchcore/proton/metrics/legacy_attribute_metrics.cpp index c56cc3f3223..10083daa769 100644 --- a/searchcore/src/vespa/searchcore/proton/metrics/legacy_attribute_metrics.cpp +++ b/searchcore/src/vespa/searchcore/proton/metrics/legacy_attribute_metrics.cpp @@ -12,46 +12,45 @@ LegacyAttributeMetrics::List::Entry::Entry(const std::string &name) { } -LegacyAttributeMetrics::List::Entry::LP +LegacyAttributeMetrics::List::Entry * LegacyAttributeMetrics::List::add(const std::string &name) { if (metrics.find(name) != metrics.end()) { - return Entry::LP(0); + return nullptr; } - Entry::LP entry(new Entry(name)); - metrics[name] = entry; - return entry; + auto &pos = metrics[name]; + pos = std::make_unique<Entry>(name); + return pos.get(); } -LegacyAttributeMetrics::List::Entry::LP +LegacyAttributeMetrics::List::Entry * LegacyAttributeMetrics::List::get(const std::string &name) const { - std::map<std::string, Entry::LP>::const_iterator pos = metrics.find(name); + const auto pos = metrics.find(name); if (pos == metrics.end()) { - return Entry::LP(0); + return nullptr; } - return pos->second; + return pos->second.get(); } -LegacyAttributeMetrics::List::Entry::LP +LegacyAttributeMetrics::List::Entry::UP LegacyAttributeMetrics::List::remove(const std::string &name) { - std::map<std::string, Entry::LP>::const_iterator pos = metrics.find(name); + auto pos = metrics.find(name); if (pos == metrics.end()) { - return Entry::LP(0); + return Entry::UP(); } - Entry::LP retval = pos->second; + Entry::UP retval = std::move(pos->second); metrics.erase(name); return retval; } -std::vector<LegacyAttributeMetrics::List::Entry::LP> +std::vector<LegacyAttributeMetrics::List::Entry::UP> LegacyAttributeMetrics::List::release() { - std::vector<Entry::LP> entries; - std::map<std::string, Entry::LP>::const_iterator pos = metrics.begin(); - for (; pos != metrics.end(); ++pos) { - entries.push_back(pos->second); + std::vector<Entry::UP> entries; + for (auto &pos: metrics) { + entries.push_back(std::move(pos.second)); } metrics.clear(); return entries; diff --git a/searchcore/src/vespa/searchcore/proton/metrics/legacy_attribute_metrics.h b/searchcore/src/vespa/searchcore/proton/metrics/legacy_attribute_metrics.h index 116d0c2b2ea..128bb75662d 100644 --- a/searchcore/src/vespa/searchcore/proton/metrics/legacy_attribute_metrics.h +++ b/searchcore/src/vespa/searchcore/proton/metrics/legacy_attribute_metrics.h @@ -3,7 +3,6 @@ #pragma once #include <vespa/metrics/metrics.h> -#include <vespa/vespalib/util/linkedptr.h> namespace proton { @@ -16,22 +15,22 @@ struct LegacyAttributeMetrics : metrics::MetricSet { struct List : metrics::MetricSet { struct Entry : metrics::MetricSet { - typedef vespalib::LinkedPtr<Entry> LP; + using UP = std::unique_ptr<Entry>; metrics::LongValueMetric memoryUsage; metrics::LongValueMetric bitVectors; Entry(const std::string &name); }; - Entry::LP add(const std::string &name); - Entry::LP get(const std::string &name) const; - Entry::LP remove(const std::string &name); - std::vector<Entry::LP> release(); + Entry *add(const std::string &name); + Entry *get(const std::string &name) const; + Entry::UP remove(const std::string &name); + std::vector<Entry::UP> release(); // per attribute metrics will be wired in here (by the metrics engine) List(metrics::MetricSet *parent); ~List(); private: - std::map<std::string, Entry::LP> metrics; + std::map<std::string, Entry::UP> metrics; }; List list; diff --git a/searchcore/src/vespa/searchcore/proton/metrics/legacy_documentdb_metrics.cpp b/searchcore/src/vespa/searchcore/proton/metrics/legacy_documentdb_metrics.cpp index f1a65b18084..8d15559b4a6 100644 --- a/searchcore/src/vespa/searchcore/proton/metrics/legacy_documentdb_metrics.cpp +++ b/searchcore/src/vespa/searchcore/proton/metrics/legacy_documentdb_metrics.cpp @@ -69,7 +69,7 @@ LegacyDocumentDBMetrics::MatchingMetrics::RankProfileMetrics::RankProfileMetrics { for (size_t i=0; i < numDocIdPartitions; i++) { vespalib::string s(make_string("docid_part%02ld", i)); - partitions.push_back(DocIdPartition::LP(new DocIdPartition(s, this))); + partitions.push_back(DocIdPartition::UP(new DocIdPartition(s, this))); } } diff --git a/searchcore/src/vespa/searchcore/proton/metrics/legacy_documentdb_metrics.h b/searchcore/src/vespa/searchcore/proton/metrics/legacy_documentdb_metrics.h index dd246443ae4..b7b22d256f1 100644 --- a/searchcore/src/vespa/searchcore/proton/metrics/legacy_documentdb_metrics.h +++ b/searchcore/src/vespa/searchcore/proton/metrics/legacy_documentdb_metrics.h @@ -59,14 +59,13 @@ struct LegacyDocumentDBMetrics : metrics::MetricSet metrics::DoubleAverageMetric active_time; metrics::DoubleAverageMetric wait_time; - typedef vespalib::LinkedPtr<DocIdPartition> LP; + using UP = std::unique_ptr<DocIdPartition>; DocIdPartition(const std::string &name, metrics::MetricSet *parent); ~DocIdPartition(); void update(const matching::MatchingStats::Partition &stats); }; - typedef std::vector<DocIdPartition::LP> DocIdPartitions; - - typedef vespalib::LinkedPtr<RankProfileMetrics> LP; + using DocIdPartitions = std::vector<DocIdPartition::UP>; + using UP = std::unique_ptr<RankProfileMetrics>; metrics::LongCountMetric queries; metrics::LongCountMetric limited_queries; @@ -82,7 +81,7 @@ struct LegacyDocumentDBMetrics : metrics::MetricSet void update(const matching::MatchingStats &stats); }; - typedef std::map<std::string, RankProfileMetrics::LP> RankProfileMap; + using RankProfileMap = std::map<std::string, RankProfileMetrics::UP>; RankProfileMap rank_profiles; void update(const matching::MatchingStats &stats); diff --git a/searchcore/src/vespa/searchcore/proton/metrics/metrics_engine.cpp b/searchcore/src/vespa/searchcore/proton/metrics/metrics_engine.cpp index 23daf44d98a..125ffde7530 100644 --- a/searchcore/src/vespa/searchcore/proton/metrics/metrics_engine.cpp +++ b/searchcore/src/vespa/searchcore/proton/metrics/metrics_engine.cpp @@ -132,8 +132,8 @@ void doAddAttribute(LegacyAttributeMetrics &attributes, const std::string &name) { - LegacyAttributeMetrics::List::Entry::LP entry = attributes.list.add(name); - if (entry.get() != 0) { + LegacyAttributeMetrics::List::Entry *entry = attributes.list.add(name); + if (entry != nullptr) { LOG(debug, "doAddAttribute(): name='%s', attributes=%p", name.c_str(), (void*)&attributes); attributes.list.registerMetric(*entry); @@ -146,7 +146,7 @@ void doRemoveAttribute(LegacyAttributeMetrics &attributes, const std::string &name) { - LegacyAttributeMetrics::List::Entry::LP entry = attributes.list.remove(name); + LegacyAttributeMetrics::List::Entry::UP entry = attributes.list.remove(name); if (entry.get() != 0) { LOG(debug, "doRemoveAttribute(): name='%s', attributes=%p", name.c_str(), (void*)&attributes); @@ -159,7 +159,7 @@ doRemoveAttribute(LegacyAttributeMetrics &attributes, void doCleanAttributes(LegacyAttributeMetrics &attributes) { - std::vector<LegacyAttributeMetrics::List::Entry::LP> entries = attributes.list.release(); + std::vector<LegacyAttributeMetrics::List::Entry::UP> entries = attributes.list.release(); for (size_t i = 0; i < entries.size(); ++i) { attributes.list.unregisterMetric(*entries[i]); } @@ -240,8 +240,7 @@ void MetricsEngine::addRankProfile(LegacyDocumentDBMetrics &owner, const std::string &name, size_t numDocIdPartitions) { metrics::MetricLockGuard guard(_manager->getMetricLock()); - LegacyDocumentDBMetrics::MatchingMetrics::RankProfileMetrics::LP &entry = - owner.matching.rank_profiles[name]; + auto &entry = owner.matching.rank_profiles[name]; if (entry.get()) { LOG(warning, "Two rank profiles have the same name: %s", name.c_str()); } else { diff --git a/searchcore/src/vespa/searchcore/proton/persistenceengine/document_iterator.cpp b/searchcore/src/vespa/searchcore/proton/persistenceengine/document_iterator.cpp index 18effa74af0..818bb13c21a 100644 --- a/searchcore/src/vespa/searchcore/proton/persistenceengine/document_iterator.cpp +++ b/searchcore/src/vespa/searchcore/proton/persistenceengine/document_iterator.cpp @@ -110,12 +110,11 @@ DocumentIterator::iterate(size_t maxBytes) } else { IterateResult::List results; for (size_t sz(0); (_nextItem < _list.size()) && ((sz < maxBytes) || results.empty()); _nextItem++) { - DocEntry::LP & item = _list[_nextItem]; + DocEntry::UP item = std::move(_list[_nextItem]); sz += item->getSize(); - results.push_back(item); - item.reset(); + results.push_back(std::move(item)); } - return IterateResult(results, _nextItem >= _list.size()); + return IterateResult(std::move(results), _nextItem >= _list.size()); } } diff --git a/searchcore/src/vespa/searchcore/proton/server/docstorevalidator.cpp b/searchcore/src/vespa/searchcore/proton/server/docstorevalidator.cpp index 14e29a2650c..fc6b7b9eeee 100644 --- a/searchcore/src/vespa/searchcore/proton/server/docstorevalidator.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/docstorevalidator.cpp @@ -92,10 +92,10 @@ DocStoreValidator::killOrphans(search::IDocumentStore &store, } -LidVectorContext::LP +LidVectorContext::SP DocStoreValidator::getInvalidLids(void) const { - LidVectorContext::LP res(new LidVectorContext(_docIdLimit)); + LidVectorContext::SP res(new LidVectorContext(_docIdLimit)); assert(_invalid->size() == _docIdLimit); for (search::DocumentIdT lid(_invalid->getFirstTrueBit(1)); lid < _docIdLimit; diff --git a/searchcore/src/vespa/searchcore/proton/server/docstorevalidator.h b/searchcore/src/vespa/searchcore/proton/server/docstorevalidator.h index fcca1fd9178..6057a801460 100644 --- a/searchcore/src/vespa/searchcore/proton/server/docstorevalidator.h +++ b/searchcore/src/vespa/searchcore/proton/server/docstorevalidator.h @@ -30,7 +30,7 @@ public: uint32_t getOrphanCount() const; uint32_t getVisitCount() const { return _visitCount; } uint32_t getVisitEmptyCount() const { return _visitEmptyCount; } - LidVectorContext::LP getInvalidLids() const; + LidVectorContext::SP getInvalidLids() const; }; diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp index 98ca479e8c8..d64a57f78e3 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp @@ -1392,8 +1392,8 @@ updateLegacyAttributeMetrics(LegacyAttributeMetrics &metrics, const TempAttributeMetrics &tmpMetrics) { for (const auto &attr : tmpMetrics._attrs) { - LegacyAttributeMetrics::List::Entry::LP entry = metrics.list.get(attr.first); - if (entry.get()) { + LegacyAttributeMetrics::List::Entry *entry = metrics.list.get(attr.first); + if (entry) { entry->memoryUsage.set(attr.second._memoryUsage.allocatedBytes()); entry->bitVectors.set(attr.second._bitVectors); } else { diff --git a/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp b/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp index 4a96c25d948..6cdf87eaaaf 100644 --- a/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp @@ -823,7 +823,7 @@ void FeedHandler:: performPruneRemovedDocuments(PruneRemovedDocumentsOperation &pruneOp) { - const LidVectorContext::LP lids_to_remove = pruneOp.getLidsToRemove(); + const LidVectorContext::SP lids_to_remove = pruneOp.getLidsToRemove(); if (lids_to_remove.get() && lids_to_remove->getNumLids() != 0) { storeOperation(pruneOp); _activeFeedView->handlePruneRemovedDocuments(pruneOp); diff --git a/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp b/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp index 5510a7a67bc..f7f0a5ae272 100644 --- a/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/pruneremoveddocumentsjob.cpp @@ -44,7 +44,7 @@ PruneRemovedDocumentsJob::flush(DocId lowLid, DocId nextLowLid, return; DocId docIdLimit = _metaStore.getCommittedDocIdLimit(); PruneRemovedDocumentsOperation pruneOp(docIdLimit, _subDbId); - LidVectorContext::LP lvCtx(pruneOp.getLidsToRemove()); + LidVectorContext::SP lvCtx(pruneOp.getLidsToRemove()); for (std::vector<DocId>::const_iterator it = _pruneLids.begin(), ite = _pruneLids.end(); it != ite; ++it) { diff --git a/searchcore/src/vespa/searchcore/proton/server/storeonlyfeedview.cpp b/searchcore/src/vespa/searchcore/proton/server/storeonlyfeedview.cpp index c0bfcaf0024..2541900b036 100644 --- a/searchcore/src/vespa/searchcore/proton/server/storeonlyfeedview.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/storeonlyfeedview.cpp @@ -695,7 +695,7 @@ StoreOnlyFeedView::removeDocuments(const RemoveDocumentsOperation &op, bool immediateCommit) { const SerialNum serialNum = op.getSerialNum(); - const LidVectorContext::LP &ctx = op.getLidsToRemove(_params._subDbId); + const LidVectorContext::SP &ctx = op.getLidsToRemove(_params._subDbId); if (!ctx.get()) { if (useDocumentMetaStore(serialNum)) { _metaStore.commit(serialNum, serialNum); @@ -748,7 +748,7 @@ StoreOnlyFeedView::prepareDeleteBucket(DeleteBucketOperation &delOp) bucket.toString().c_str(), lidsToRemove.size()); if (!lidsToRemove.empty()) { - LidVectorContext::LP ctx + LidVectorContext::SP ctx (new LidVectorContext(_metaStore.getCommittedDocIdLimit(), lidsToRemove)); delOp.setLidsToRemove(_params._subDbId, ctx); |