diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-12-14 22:58:54 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-12-15 13:12:36 +0100 |
commit | 2a85dc3fd5af5c33601cf04ead06c7545fa46d75 (patch) | |
tree | f46f355235fd7684a9f8a6bb562797fd985d1180 /searchcore | |
parent | d9b45214d28207564329991afe70afc358fe6d12 (diff) |
Split in hash_xxx, array, lru, cache ++ in hpp files. To reduce clinon build
Diffstat (limited to 'searchcore')
19 files changed, 274 insertions, 242 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp index ecc68558f50..3c6cb26e5e9 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp @@ -1,22 +1,18 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".proton.attribute.attributemanager"); +#include "attributemanager.h" #include "attribute_factory.h" -#include "attribute_initializer.h" #include "attributedisklayout.h" -#include "attributemanager.h" -#include "flushableattribute.h" #include "sequential_attributes_initializer.h" +#include "i_attribute_functor.h" #include <vespa/searchlib/attribute/attributecontext.h> #include <vespa/vespalib/io/fileutil.h> -#include <vespa/vespalib/data/fileheader.h> -#include <vespa/searchcore/proton/common/hw_info.h> #include <vespa/searchlib/attribute/interlock.h> #include <vespa/searchlib/common/isequencedtaskexecutor.h> -#include <memory> -#include "i_attribute_functor.h" +#include <vespa/vespalib/stllike/hash_map.hpp> + +#include <vespa/log/log.h> +LOG_SETUP(".proton.attribute.attributemanager"); using search::AttributeContext; using search::AttributeEnumGuard; @@ -245,6 +241,8 @@ AttributeManager::AttributeManager(const AttributeManager &currMgr, transferExtraAttributes(currMgr); } +AttributeManager::~AttributeManager() { } + AttributeVector::SP AttributeManager::addAttribute(const vespalib::string &name, const Config &cfg, diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h index cbefeff8e7e..878e6b3558f 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h @@ -116,6 +116,7 @@ public: AttributeManager(const AttributeManager &currMgr, const Spec &newSpec, IAttributeInitializerRegistry &initializerRegistry); + ~AttributeManager(); search::AttributeVector::SP addAttribute(const vespalib::string &name, const Config &cfg, diff --git a/searchcore/src/vespa/searchcore/proton/common/attrupdate.cpp b/searchcore/src/vespa/searchcore/proton/common/attrupdate.cpp index 71991317d2d..bcc24101019 100644 --- a/searchcore/src/vespa/searchcore/proton/common/attrupdate.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/attrupdate.cpp @@ -1,6 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> + +#include "attrupdate.h" #include <vespa/document/fieldvalue/arrayfieldvalue.h> #include <vespa/document/fieldvalue/predicatefieldvalue.h> #include <vespa/document/fieldvalue/weightedsetfieldvalue.h> @@ -13,13 +13,13 @@ #include <vespa/document/update/arithmeticvalueupdate.h> #include <vespa/document/update/clearvalueupdate.h> #include <vespa/document/base/forcelink.h> -#include <vespa/vespalib/util/stringfmt.h> #include <vespa/searchlib/common/base.h> -#include <vespa/searchlib/attribute/attribute.h> #include <vespa/searchlib/tensor/tensor_attribute.h> -#include "attrupdate.h" #include <vespa/searchlib/attribute/attributevector.hpp> +#include <vespa/searchlib/attribute/changevector.hpp> + +#include <vespa/log/log.h> LOG_SETUP(".attrupdate"); using namespace document; diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp index 11ff8474e88..e097966b029 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp @@ -2,7 +2,7 @@ #include "documentmetastore.h" #include "search_context.h" - +#include "documentmetastoresaver.h" #include <vespa/searchlib/attribute/attributevector.hpp> #include <vespa/searchlib/btree/btree.hpp> #include <vespa/searchlib/btree/btreenode.hpp> @@ -17,7 +17,8 @@ #include <vespa/searchcore/proton/bucketdb/joinbucketssession.h> #include <vespa/searchcore/proton/bucketdb/splitbucketsession.h> #include <vespa/searchlib/util/bufferwriter.h> -#include "documentmetastoresaver.h" +#include <vespa/searchlib/common/rcuvector.hpp> + using document::GlobalId; using document::BucketId; diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/flushengine/CMakeLists.txt index 6ef5d80106c..dddcfbd9327 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/CMakeLists.txt +++ b/searchcore/src/vespa/searchcore/proton/flushengine/CMakeLists.txt @@ -12,5 +12,6 @@ vespa_add_library(searchcore_flushengine STATIC prepare_restart_flush_strategy.cpp threadedflushtarget.cpp tls_stats_factory.cpp + tls_stats_map.cpp DEPENDS ) diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/tls_stats.h b/searchcore/src/vespa/searchcore/proton/flushengine/tls_stats.h index bfa31086c42..07e726d2032 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/tls_stats.h +++ b/searchcore/src/vespa/searchcore/proton/flushengine/tls_stats.h @@ -19,13 +19,17 @@ public: : _numBytes(0), _firstSerial(0), _lastSerial(0) - { - } + { } TlsStats(uint64_t numBytes, uint64_t firstSerial, uint64_t lastSerial) : _numBytes(numBytes), _firstSerial(firstSerial), _lastSerial(lastSerial) - { + { } + + bool operator == (const TlsStats & b) const { + return (_numBytes == b._numBytes) && + (_firstSerial == b._firstSerial) && + (_lastSerial == b._lastSerial); } uint64_t getNumBytes() const { return _numBytes; } diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/tls_stats_map.cpp b/searchcore/src/vespa/searchcore/proton/flushengine/tls_stats_map.cpp new file mode 100644 index 00000000000..b7b12822b82 --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/flushengine/tls_stats_map.cpp @@ -0,0 +1,27 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "tls_stats_map.h" +#include <vespa/vespalib/stllike/hash_map.hpp> + +namespace proton { +namespace flushengine { + +TlsStatsMap::TlsStatsMap(Map &&map) + : _map(std::move(map)) +{ } + +TlsStatsMap::~TlsStatsMap() { } + +const TlsStats & +TlsStatsMap::getTlsStats(const vespalib::string &domain) const { + auto itr = _map.find(domain); + if (itr != _map.end()) { + return itr->second; + } + abort(); +} + +} +} + +VESPALIB_HASH_MAP_INSTANTIATE(vespalib::string, proton::flushengine::TlsStats); diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/tls_stats_map.h b/searchcore/src/vespa/searchcore/proton/flushengine/tls_stats_map.h index b03da7407a4..7e46ac13ecf 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/tls_stats_map.h +++ b/searchcore/src/vespa/searchcore/proton/flushengine/tls_stats_map.h @@ -19,18 +19,10 @@ private: Map _map; public: - TlsStatsMap(Map &&map) - : _map(std::move(map)) - { - } + TlsStatsMap(Map &&map); + ~TlsStatsMap(); - const TlsStats &getTlsStats(const vespalib::string &domain) const { - auto itr = _map.find(domain); - if (itr != _map.end()) { - return itr->second; - } - abort(); - } + const TlsStats &getTlsStats(const vespalib::string &domain) const; }; } // namespace proton::flushengine diff --git a/searchcore/src/vespa/searchcore/proton/initializer/initializer_task.h b/searchcore/src/vespa/searchcore/proton/initializer/initializer_task.h index 2958b4a182a..f08e7a5f97b 100644 --- a/searchcore/src/vespa/searchcore/proton/initializer/initializer_task.h +++ b/searchcore/src/vespa/searchcore/proton/initializer/initializer_task.h @@ -1,6 +1,9 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once +#include <memory> +#include <vector> + namespace proton { namespace initializer { @@ -23,19 +26,12 @@ private: List _dependencies; public: InitializerTask(); - virtual ~InitializerTask(); - State getState() const { return _state; } - const List &getDependencies() const { return _dependencies; } - void setRunning() { _state = State::RUNNING; } - void setDone() { _state = State::DONE; } - void addDependency(SP dependency); - virtual void run() = 0; }; diff --git a/searchcore/src/vespa/searchcore/proton/initializer/task_runner.cpp b/searchcore/src/vespa/searchcore/proton/initializer/task_runner.cpp index c653dd30b9e..16fcf94b1d3 100644 --- a/searchcore/src/vespa/searchcore/proton/initializer/task_runner.cpp +++ b/searchcore/src/vespa/searchcore/proton/initializer/task_runner.cpp @@ -1,6 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> #include "task_runner.h" #include <vespa/searchlib/common/lambdatask.h> #include <vespa/vespalib/util/threadstackexecutor.h> @@ -24,8 +23,7 @@ TaskRunner::~TaskRunner() } void -TaskRunner::getReadyTasks(const InitializerTask::SP task, TaskList &readyTasks, - TaskSet &checked) +TaskRunner::getReadyTasks(const InitializerTask::SP task, TaskList &readyTasks, TaskSet &checked) { if (task->getState() != State::BLOCKED) { return; // task running or done, all dependencies done diff --git a/searchcore/src/vespa/searchcore/proton/initializer/task_runner.h b/searchcore/src/vespa/searchcore/proton/initializer/task_runner.h index 6fc52a6c289..2f68f0a24f7 100644 --- a/searchcore/src/vespa/searchcore/proton/initializer/task_runner.h +++ b/searchcore/src/vespa/searchcore/proton/initializer/task_runner.h @@ -18,7 +18,7 @@ class TaskRunner { uint32_t _runningTasks; // used by context executor using State = InitializerTask::State; using TaskList = InitializerTask::List; - using TaskSet = vespalib::hash_set<void *>; + using TaskSet = vespalib::hash_set<const void *>; class Context { InitializerTask::SP _rootTask; @@ -44,8 +44,7 @@ class TaskRunner { const InitializerTask::SP &rootTask() { return _rootTask; } void schedulePoll(); }; - void getReadyTasks(const InitializerTask::SP task, TaskList &readyTasks, - TaskSet &checked); + void getReadyTasks(const InitializerTask::SP task, TaskList &readyTasks, TaskSet &checked); void setTaskRunning(InitializerTask &task); diff --git a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp index e1ad0bd0400..e82d4101178 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp @@ -1,9 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".proton.matching.queryenvironment"); - #include "queryenvironment.h" using search::attribute::IAttributeContext; diff --git a/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.cpp b/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.cpp index 15d68ecfb08..a676b89c65d 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.cpp @@ -1,46 +1,201 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> +#include "sessionmanager.h" +#include <vespa/vespalib/stllike/lrucache_map.hpp> +#include <vespa/vespalib/stllike/hash_map.hpp> + #include <vespa/log/log.h> LOG_SETUP(".sessionmanager"); -#include "sessionmanager.h" using search::grouping::GroupingSession; namespace proton { namespace matching { -void SessionManager::SessionCacheBase::entryDropped(const SessionId &id) { - LOG(debug, "Session cache is full, dropping entry to fit " - "session '%s'", id.c_str()); - _stats.numDropped++; -} + namespace { + using Stats = SessionManager::Stats; + struct SessionCacheBase { + protected: + Stats _stats; + vespalib::Lock _lock; + + void entryDropped(const SessionId &id); + ~SessionCacheBase() {} + }; + + template <typename T> + struct SessionCache : SessionCacheBase { + typedef typename T::LP EntryLP; + typedef typename T::UP EntryUP; + vespalib::lrucache_map<vespalib::LruParam<SessionId, EntryLP> > _cache; + + SessionCache(uint32_t max_size) : _cache(max_size) {} + + void insert(EntryUP session) { + vespalib::LockGuard guard(_lock); + const SessionId &id(session->getSessionId()); + if (_cache.size() >= _cache.capacity()) { + entryDropped(id); + } + _cache.insert(id, EntryLP(session.release())); + _stats.numInsert++; + } + EntryUP pick(const SessionId & id) { + vespalib::LockGuard guard(_lock); + EntryUP ret; + if (_cache.hasKey(id)) { + _stats.numPick++; + EntryLP session(_cache.get(id)); + _cache.erase(id); + ret.reset(session.release()); + } + return ret; + } + void pruneTimedOutSessions(fastos::TimeStamp currentTime) { + std::vector<EntryLP> toDestruct = stealTimedOutSessions(currentTime); + toDestruct.clear(); + } + std::vector<EntryLP> stealTimedOutSessions(fastos::TimeStamp currentTime) { + std::vector<EntryLP> toDestruct; + vespalib::LockGuard guard(_lock); + toDestruct.reserve(_cache.size()); + for (auto it(_cache.begin()), mt(_cache.end()); it != mt;) { + EntryLP session = *it; + if (session->getTimeOfDoom() < currentTime) { + toDestruct.push_back(session); + it = _cache.erase(it); + _stats.numTimedout++; + } else { + it++; + } + } + return toDestruct; + } + Stats getStats() { + vespalib::LockGuard guard(_lock); + Stats stats = _stats; + stats.numCached = _cache.size(); + _stats = Stats(); + return stats; + } + bool empty() const { + vespalib::LockGuard guard(_lock); + return _cache.empty(); + } + }; + + template <typename T> + struct SessionMap : SessionCacheBase { + typedef typename T::SP EntrySP; + vespalib::hash_map<SessionId, EntrySP> _map; + + void insert(EntrySP session) { + vespalib::LockGuard guard(_lock); + const SessionId &id(session->getSessionId()); + _map.insert(std::make_pair(id, session)); + _stats.numInsert++; + } + EntrySP pick(const SessionId & id) { + vespalib::LockGuard guard(_lock); + auto it = _map.find(id); + if (it != _map.end()) { + _stats.numPick++; + return it->second; + } + return EntrySP(); + } + void pruneTimedOutSessions(fastos::TimeStamp currentTime) { + std::vector<EntrySP> toDestruct = stealTimedOutSessions(currentTime); + toDestruct.clear(); + } + std::vector<EntrySP> stealTimedOutSessions(fastos::TimeStamp currentTime) { + std::vector<EntrySP> toDestruct; + std::vector<SessionId> keys; + vespalib::LockGuard guard(_lock); + keys.reserve(_map.size()); + toDestruct.reserve(_map.size()); + for (auto & it : _map) { + EntrySP &session = it.second; + if (session->getTimeOfDoom() < currentTime) { + keys.push_back(it.first); + toDestruct.push_back(EntrySP()); + toDestruct.back().swap(session); + } + } + for (auto key : keys) { + _map.erase(key); + _stats.numTimedout++; + } + return toDestruct; + } + Stats getStats() { + vespalib::LockGuard guard(_lock); + Stats stats = _stats; + stats.numCached = _map.size(); + _stats = Stats(); + return stats; + } + size_t size() const { + vespalib::LockGuard guard(_lock); + return _map.size(); + } + bool empty() const { + vespalib::LockGuard guard(_lock); + return _map.empty(); + } + template <typename F> + void each(F f) const { + vespalib::LockGuard guard(_lock); + for (const auto &entry: _map) { + f(*entry.second); + } + } + }; + + void SessionCacheBase::entryDropped(const SessionId &id) { + LOG(debug, "Session cache is full, dropping entry to fit session '%s'", id.c_str()); + _stats.numDropped++; + } + + } + + struct GroupingSessionCache : public SessionCache<search::grouping::GroupingSession> { + using Parent = SessionCache<search::grouping::GroupingSession>; + using Parent::Parent; + }; + + struct SearchSessionCache : public SessionMap<SearchSession> { + + }; + SessionManager::SessionManager(uint32_t maxSize) - : _grouping_cache(maxSize), - _search_map() { + : _grouping_cache(std::make_unique<GroupingSessionCache>(maxSize)), + _search_map(std::make_unique<SearchSessionCache>()) { } +SessionManager::~SessionManager() { } + void SessionManager::insert(search::grouping::GroupingSession::UP session) { - _grouping_cache.insert(std::move(session)); + _grouping_cache->insert(std::move(session)); } void SessionManager::insert(SearchSession::SP session) { - _search_map.insert(std::move(session)); + _search_map->insert(std::move(session)); } GroupingSession::UP SessionManager::pickGrouping(const SessionId &id) { - return _grouping_cache.pick(id); + return _grouping_cache->pick(id); } SearchSession::SP SessionManager::pickSearch(const SessionId &id) { - return _search_map.pick(id); + return _search_map->pick(id); } std::vector<SessionManager::SearchSessionInfo> SessionManager::getSortedSearchSessionInfo() const { std::vector<SearchSessionInfo> sessions; - _search_map.each([&sessions](const SearchSession &session) + _search_map->each([&sessions](const SearchSession &session) { sessions.emplace_back(session.getSessionId(), session.getCreateTime(), @@ -56,14 +211,24 @@ SessionManager::getSortedSearchSessionInfo() const } void SessionManager::pruneTimedOutSessions(fastos::TimeStamp currentTime) { - _grouping_cache.pruneTimedOutSessions(currentTime); - _search_map.pruneTimedOutSessions(currentTime); + _grouping_cache->pruneTimedOutSessions(currentTime); + _search_map->pruneTimedOutSessions(currentTime); } void SessionManager::close() { pruneTimedOutSessions(fastos::TimeStamp::FUTURE); - assert(_grouping_cache.empty()); - assert(_search_map.empty()); + assert(_grouping_cache->empty()); + assert(_search_map->empty()); +} + +SessionManager::Stats SessionManager::getGroupingStats() { + return _grouping_cache->getStats(); +} +SessionManager::Stats SessionManager::getSearchStats() { + return _search_map->getStats(); +} +size_t SessionManager::getNumSearchSessions() const { + return _search_map->size(); } } // namespace proton::matching diff --git a/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.h b/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.h index 56b48047611..ddb3fd253d3 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.h +++ b/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.h @@ -12,6 +12,9 @@ namespace matching { typedef vespalib::string SessionId; +class GroupingSessionCache; +class SearchSessionCache; + class SessionManager : public ISessionCachePruner { public: struct Stats { @@ -40,161 +43,24 @@ public: }; private: - struct SessionCacheBase { - protected: - Stats _stats; - vespalib::Lock _lock; - - void entryDropped(const SessionId &id); - ~SessionCacheBase() {} - }; - - template <typename T> - struct SessionCache : SessionCacheBase { - typedef typename T::LP EntryLP; - typedef typename T::UP EntryUP; - vespalib::lrucache_map<vespalib::LruParam<SessionId, EntryLP> > _cache; - - SessionCache(uint32_t max_size) : _cache(max_size) {} - - void insert(EntryUP session) { - vespalib::LockGuard guard(_lock); - const SessionId &id(session->getSessionId()); - if (_cache.size() >= _cache.capacity()) { - entryDropped(id); - } - _cache.insert(id, EntryLP(session.release())); - _stats.numInsert++; - } - EntryUP pick(const SessionId & id) { - vespalib::LockGuard guard(_lock); - EntryUP ret; - if (_cache.hasKey(id)) { - _stats.numPick++; - EntryLP session(_cache.get(id)); - _cache.erase(id); - ret.reset(session.release()); - } - return ret; - } - void pruneTimedOutSessions(fastos::TimeStamp currentTime) { - std::vector<EntryLP> toDestruct = stealTimedOutSessions(currentTime); - toDestruct.clear(); - } - std::vector<EntryLP> stealTimedOutSessions(fastos::TimeStamp currentTime) { - std::vector<EntryLP> toDestruct; - vespalib::LockGuard guard(_lock); - toDestruct.reserve(_cache.size()); - for (auto it(_cache.begin()), mt(_cache.end()); it != mt;) { - EntryLP session = *it; - if (session->getTimeOfDoom() < currentTime) { - toDestruct.push_back(session); - it = _cache.erase(it); - _stats.numTimedout++; - } else { - it++; - } - } - return toDestruct; - } - Stats getStats() { - vespalib::LockGuard guard(_lock); - Stats stats = _stats; - stats.numCached = _cache.size(); - _stats = Stats(); - return stats; - } - bool empty() const { - vespalib::LockGuard guard(_lock); - return _cache.empty(); - } - }; - - template <typename T> - struct SessionMap : SessionCacheBase { - typedef typename T::SP EntrySP; - vespalib::hash_map<SessionId, EntrySP> _map; - - void insert(EntrySP session) { - vespalib::LockGuard guard(_lock); - const SessionId &id(session->getSessionId()); - _map.insert(std::make_pair(id, session)); - _stats.numInsert++; - } - EntrySP pick(const SessionId & id) { - vespalib::LockGuard guard(_lock); - auto it = _map.find(id); - if (it != _map.end()) { - _stats.numPick++; - return it->second; - } - return EntrySP(); - } - void pruneTimedOutSessions(fastos::TimeStamp currentTime) { - std::vector<EntrySP> toDestruct = stealTimedOutSessions(currentTime); - toDestruct.clear(); - } - std::vector<EntrySP> stealTimedOutSessions(fastos::TimeStamp currentTime) { - std::vector<EntrySP> toDestruct; - std::vector<SessionId> keys; - vespalib::LockGuard guard(_lock); - keys.reserve(_map.size()); - toDestruct.reserve(_map.size()); - for (auto & it : _map) { - EntrySP &session = it.second; - if (session->getTimeOfDoom() < currentTime) { - keys.push_back(it.first); - toDestruct.push_back(EntrySP()); - toDestruct.back().swap(session); - } - } - for (auto key : keys) { - _map.erase(key); - _stats.numTimedout++; - } - return toDestruct; - } - Stats getStats() { - vespalib::LockGuard guard(_lock); - Stats stats = _stats; - stats.numCached = _map.size(); - _stats = Stats(); - return stats; - } - size_t size() const { - vespalib::LockGuard guard(_lock); - return _map.size(); - } - bool empty() const { - vespalib::LockGuard guard(_lock); - return _map.empty(); - } - template <typename F> - void each(F f) const { - vespalib::LockGuard guard(_lock); - for (const auto &entry: _map) { - f(*entry.second); - } - } - }; - - SessionCache<search::grouping::GroupingSession> _grouping_cache; - SessionMap<SearchSession> _search_map; + std::unique_ptr<GroupingSessionCache> _grouping_cache; + std::unique_ptr<SearchSessionCache> _search_map; public: typedef std::unique_ptr<SessionManager> UP; typedef std::shared_ptr<SessionManager> SP; SessionManager(uint32_t maxSizeGrouping); + ~SessionManager(); void insert(search::grouping::GroupingSession::UP session); search::grouping::GroupingSession::UP pickGrouping(const SessionId &id); - Stats getGroupingStats() { return _grouping_cache.getStats(); } + Stats getGroupingStats(); void insert(SearchSession::SP session); SearchSession::SP pickSearch(const SessionId &id); - Stats getSearchStats() { return _search_map.getStats(); } - size_t getNumSearchSessions() const { return _search_map.size(); } + Stats getSearchStats(); + size_t getNumSearchSessions() const; std::vector<SearchSessionInfo> getSortedSearchSessionInfo() const; void pruneTimedOutSessions(fastos::TimeStamp currentTime); diff --git a/searchcore/src/vespa/searchcore/proton/persistenceengine/persistenceengine.cpp b/searchcore/src/vespa/searchcore/proton/persistenceengine/persistenceengine.cpp index 1f4a32bc4b5..40106e5b332 100644 --- a/searchcore/src/vespa/searchcore/proton/persistenceengine/persistenceengine.cpp +++ b/searchcore/src/vespa/searchcore/proton/persistenceengine/persistenceengine.cpp @@ -1,16 +1,14 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> +#include "persistenceengine.h" +#include "ipersistenceengineowner.h" +#include "transport_latch.h" +#include <vespa/documentapi/messagebus/documentprotocol.h> #include <vespa/documentapi/messagebus/messages/feedreply.h> #include <vespa/documentapi/messagebus/messages/removedocumentreply.h> #include <vespa/documentapi/messagebus/messages/updatedocumentreply.h> -#include <vespa/searchcore/proton/common/feedtoken.h> -#include <vespa/searchcore/proton/persistenceengine/persistenceengine.h> -#include "ipersistenceengineowner.h" -#include "transport_latch.h" -#include <vespa/vespalib/util/exception.h> -#include <vespa/vespalib/util/sequence.h> #include <vespa/vespalib/stllike/hash_set.h> + #include <vespa/log/log.h> LOG_SETUP(".proton.persistenceengine.persistenceengine"); @@ -55,8 +53,7 @@ public: GenericResultHandler(uint32_t waitCnt) : ResultHandlerBase(waitCnt), _result() - { - } + { } virtual void handle(const Result &result) { if (result.hasError()) { vespalib::LockGuard guard(_lock); @@ -80,8 +77,7 @@ private: public: BucketIdListResultHandler() : _bucketSet() - { - } + { } virtual void handle(const BucketIdListResult &result) { const BucketIdListResult::List &buckets = result.getList(); for (size_t i = 0; i < buckets.size(); ++i) { @@ -106,8 +102,7 @@ public: SynchronizedBucketIdListResultHandler(uint32_t waitCnt) : ResultHandlerBase(waitCnt), BucketIdListResultHandler() - { - } + { } virtual void handle(const BucketIdListResult &result) { { vespalib::LockGuard guard(_lock); diff --git a/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.cpp b/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.cpp index 2aadee9b320..5c77d573788 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.cpp @@ -1,30 +1,21 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".documentretrieverbase"); - #include "documentretrieverbase.h" -#include <vespa/document/base/documentid.h> #include <vespa/document/repo/documenttyperepo.h> -#include <vespa/searchlib/common/idocumentmetastore.h> -#include <vespa/searchcore/proton/common/cachedselect.h> -#include <vespa/searchcore/proton/documentmetastore/i_document_meta_store_context.h> +#include <vespa/vespalib/stllike/lrucache_map.hpp> using document::DocumentId; using document::GlobalId; using search::index::Schema; -namespace -{ +namespace { const DocumentId docId("doc:test:1"); const Schema emptySchema; } -namespace proton -{ +namespace proton { DocumentRetrieverBase::DocumentRetrieverBase( const DocTypeName &docTypeName, @@ -46,6 +37,8 @@ DocumentRetrieverBase::DocumentRetrieverBase( _emptyDoc->setRepo(_repo); } +DocumentRetrieverBase::~DocumentRetrieverBase() { } + const document::DocumentTypeRepo & DocumentRetrieverBase::getDocumentTypeRepo() const { return _repo; diff --git a/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.h b/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.h index 4894baf46e0..22d31c26895 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.h +++ b/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.h @@ -9,8 +9,7 @@ #include <vespa/searchcommon/common/schema.h> #include <vespa/searchlib/attribute/iattributemanager.h> -namespace proton -{ +namespace proton { class DocumentRetrieverBase : public IDocumentRetriever { @@ -18,7 +17,7 @@ class DocumentRetrieverBase : public IDocumentRetriever const document::DocumentTypeRepo &_repo; const IDocumentMetaStoreContext &_meta_store; - typedef vespalib::lrucache_map<vespalib::LruParam<vespalib::string, CachedSelect::SP>> SelectCache; + using SelectCache = vespalib::lrucache_map<vespalib::LruParam<vespalib::string, CachedSelect::SP>>; mutable SelectCache _selectCache; vespalib::Lock _lock; @@ -33,6 +32,7 @@ public: const document::DocumentTypeRepo &repo, const IDocumentMetaStoreContext &meta_store, bool hasFields); + ~DocumentRetrieverBase(); const document::DocumentTypeRepo &getDocumentTypeRepo() const override; void getBucketMetaData(const storage::spi::Bucket &bucket, diff --git a/searchcore/src/vespa/searchcore/proton/server/matchers.cpp b/searchcore/src/vespa/searchcore/proton/server/matchers.cpp index 9d2322e1286..c577b31ff0f 100644 --- a/searchcore/src/vespa/searchcore/proton/server/matchers.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/matchers.cpp @@ -1,9 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".proton.server.matchers"); #include "matchers.h" +#include <vespa/vespalib/stllike/hash_map.hpp> namespace proton { @@ -14,8 +12,9 @@ Matchers::Matchers(const vespalib::Clock &clock, _fallback(new matching::Matcher(search::index::Schema(), search::fef::Properties(), clock, queryLimiter, constantValueRepo, -1)), _default() -{ -} +{ } + +Matchers::~Matchers() { } void Matchers::add(const vespalib::string &name, matching::Matcher::SP matcher) diff --git a/searchcore/src/vespa/searchcore/proton/server/matchers.h b/searchcore/src/vespa/searchcore/proton/server/matchers.h index cb01ab7dbb9..b83603f04c1 100644 --- a/searchcore/src/vespa/searchcore/proton/server/matchers.h +++ b/searchcore/src/vespa/searchcore/proton/server/matchers.h @@ -19,6 +19,7 @@ public: Matchers(const vespalib::Clock &clock, matching::QueryLimiter &queryLimiter, const matching::IConstantValueRepo &constantValueRepo); + ~Matchers(); void add(const vespalib::string &name, matching::Matcher::SP matcher); matching::MatchingStats getStats() const; matching::MatchingStats getStats(const vespalib::string &name) const; |