diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-06-04 11:04:55 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-06-04 11:04:55 +0000 |
commit | 934a08b254e99acb3fce4282170b612ee2cf286e (patch) | |
tree | c1d56fb2e4eadf139bebf8ffa1699ea1d72f65c4 /searchcore | |
parent | 24a3487c20c02b450b9934f6d48431ec407678d5 (diff) |
Creating the document metastore read guard is expensive and is not necessary to do for every imported attribute.
We do it once per metastore and cache it in the ImportedAttributeContext.
It would be even better if we could drop support for the default makeReadGuard(bool).
Then we would also avoid copying the shared_ptr.
Diffstat (limited to 'searchcore')
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp | 11 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h | 4 |
2 files changed, 14 insertions, 1 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp index 0aaa88db859..376c84c12d6 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp @@ -23,7 +23,15 @@ ImportedAttributesContext::getOrCacheAttribute(const vespalib::string &name, Att } const ImportedAttributeVector::SP & result = _repo.get(name); if (result) { - auto insRes = attributes.emplace(name, result->makeReadGuard(stableEnumGuard)); + auto metaItr = _metaStores.find(result->getTargetDocumentMetaStore().get()); + std::shared_ptr<MetaStoreReadGuard> metaGuard; + if (metaItr == _metaStores.end()) { + metaGuard = result->getTargetDocumentMetaStore()->getReadGuard(); + _metaStores.emplace(result->getTargetDocumentMetaStore().get(), metaGuard); + } else { + metaGuard = metaItr->second; + } + auto insRes = attributes.emplace(name, result->makeReadGuard(std::move(metaGuard), stableEnumGuard)); return insRes.first->second->attribute(); } else { return nullptr; @@ -34,6 +42,7 @@ ImportedAttributesContext::ImportedAttributesContext(const ImportedAttributesRep : _repo(repo), _guardedAttributes(), _enumGuardedAttributes(), + _metaStores(), _cacheMutex() { } diff --git a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h index 4b7058fdb83..39fde4f5fb7 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h @@ -2,6 +2,7 @@ #pragma once #include <vespa/searchcommon/attribute/iattributecontext.h> +#include <vespa/searchlib/common/i_document_meta_store_context.h> #include <vespa/vespalib/stllike/hash_fun.h> #include <vespa/vespalib/stllike/hash_map.h> #include <mutex> @@ -30,13 +31,16 @@ private: using IAttributeVector = search::attribute::IAttributeVector; using ImportedAttributeVector = search::attribute::ImportedAttributeVector; using IAttributeFunctor = search::attribute::IAttributeFunctor; + using MetaStoreReadGuard = search::IDocumentMetaStoreContext::IReadGuard; using AttributeCache = std::unordered_map<vespalib::string, std::unique_ptr<AttributeReadGuard>, vespalib::hash<vespalib::string>>; + using MetaStoreCache = std::unordered_map<const void *, std::shared_ptr<MetaStoreReadGuard>>; using LockGuard = std::lock_guard<std::mutex>; const ImportedAttributesRepo &_repo; mutable AttributeCache _guardedAttributes; mutable AttributeCache _enumGuardedAttributes; + mutable MetaStoreCache _metaStores; mutable std::mutex _cacheMutex; const IAttributeVector *getOrCacheAttribute(const vespalib::string &name, AttributeCache &attributes, |