diff options
Diffstat (limited to 'searchlib')
9 files changed, 54 insertions, 37 deletions
diff --git a/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp b/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp index 1306a0aaaac..e5af6931977 100644 --- a/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp +++ b/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp @@ -7,6 +7,7 @@ #include <vespa/searchlib/attribute/attributecontext.h> #include <vespa/searchlib/attribute/attributeguard.h> #include <vespa/searchlib/attribute/attributevector.h> +#include <vespa/searchlib/attribute/attribute_read_guard.h> #include <vespa/searchlib/attribute/extendableattributes.h> #include <vespa/searchlib/attribute/iattributemanager.h> #include <vespa/searchlib/attribute/predicate_attribute.h> @@ -27,7 +28,6 @@ #include <vespa/searchlib/queryeval/wand/parallel_weak_and_search.h> #include <memory> -using search::AttributeEnumGuard; using search::AttributeFactory; using search::AttributeGuard; using search::AttributeVector; @@ -100,13 +100,13 @@ public: } } - AttributeGuard::UP getAttributeStableEnum(const string &name) const override { - if (name == field) { - return AttributeGuard::UP(new AttributeEnumGuard(_attribute_vector)); - } else if (name == other) { - return AttributeGuard::UP(new AttributeEnumGuard(_other)); + std::unique_ptr<attribute::AttributeReadGuard> getAttributeReadGuard(const string &name, bool stableEnumGuard) const override { + if (name == field && _attribute_vector) { + return _attribute_vector->makeReadGuard(stableEnumGuard); + } else if (name == other && _other) { + return _other->makeReadGuard(stableEnumGuard); } else { - return AttributeGuard::UP(nullptr); + return std::unique_ptr<attribute::AttributeReadGuard>(); } } diff --git a/searchlib/src/tests/attribute/searchable/attribute_weighted_set_blueprint_test.cpp b/searchlib/src/tests/attribute/searchable/attribute_weighted_set_blueprint_test.cpp index c22807f8bf5..39bbb8fb5ad 100644 --- a/searchlib/src/tests/attribute/searchable/attribute_weighted_set_blueprint_test.cpp +++ b/searchlib/src/tests/attribute/searchable/attribute_weighted_set_blueprint_test.cpp @@ -5,6 +5,7 @@ #include <vespa/searchlib/attribute/attribute_weighted_set_blueprint.h> #include <vespa/searchlib/attribute/attributecontext.h> #include <vespa/searchlib/attribute/attributevector.h> +#include <vespa/searchlib/attribute/attribute_read_guard.h> #include <vespa/searchlib/attribute/extendableattributes.h> #include <vespa/searchlib/attribute/singlestringattribute.h> #include <vespa/searchlib/attribute/attributefactory.h> @@ -50,8 +51,13 @@ public: return AttributeGuard::UP(new AttributeGuard(lookup(name))); } - virtual AttributeGuard::UP getAttributeStableEnum(const vespalib::string &name) const override { - return AttributeGuard::UP(new AttributeEnumGuard(lookup(name))); + virtual std::unique_ptr<attribute::AttributeReadGuard> getAttributeReadGuard(const string &name, bool stableEnumGuard) const override { + auto vector = lookup(name); + if (vector) { + return vector->makeReadGuard(stableEnumGuard); + } else { + return std::unique_ptr<attribute::AttributeReadGuard>(); + } } virtual void getAttributeList(std::vector<AttributeGuard> &list) const override { diff --git a/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp b/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp index 6753153c224..dc7cf53d188 100644 --- a/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp +++ b/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp @@ -4,6 +4,7 @@ #include <vespa/searchlib/attribute/attribute_blueprint_factory.h> #include <vespa/searchlib/attribute/attributecontext.h> #include <vespa/searchlib/attribute/attributevector.h> +#include <vespa/searchlib/attribute/attribute_read_guard.h> #include <vespa/searchlib/attribute/extendableattributes.h> #include <vespa/searchlib/attribute/singlenumericattribute.h> #include <vespa/searchlib/attribute/singlenumericattribute.hpp> @@ -17,7 +18,6 @@ #include <vespa/log/log.h> LOG_SETUP("attributeblueprint_test"); -using search::AttributeEnumGuard; using search::AttributeGuard; using search::AttributeVector; using search::IAttributeManager; @@ -64,10 +64,13 @@ public: return AttributeGuard::UP(new AttributeGuard(_attribute_vector)); } - AttributeGuard::UP getAttributeStableEnum(const string &) const override { - return AttributeGuard::UP(new AttributeEnumGuard(_attribute_vector)); + virtual std::unique_ptr<attribute::AttributeReadGuard> getAttributeReadGuard(const string &, bool stableEnumGuard) const override { + if (_attribute_vector) { + return _attribute_vector->makeReadGuard(stableEnumGuard); + } else { + return std::unique_ptr<attribute::AttributeReadGuard>(); + } } - void getAttributeList(vector<AttributeGuard> &) const override { assert(!"Not implemented"); } diff --git a/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp b/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp index 0a3fe963aae..df8e7858f5f 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp @@ -2,6 +2,7 @@ #include "attributecontext.h" #include "attributevector.h" +#include "attribute_read_guard.h" #include <vespa/vespalib/stllike/hash_map.hpp> using namespace search; @@ -14,20 +15,19 @@ AttributeContext::getAttribute(AttributeMap & map, const string & name, bool sta { AttributeMap::const_iterator itr = map.find(name); if (itr != map.end()) { - return itr->second->get(); - } else { - AttributeGuard::UP ret; - if (stableEnum) { - ret = _manager.getAttributeStableEnum(name); + if (itr->second) { + return itr->second->attribute(); } else { - ret = _manager.getAttribute(name); + return nullptr; } - if (ret) { - const AttributeGuard & guard = *ret; - map[name] = std::move(ret); - return guard.get(); + } else { + auto readGuard = _manager.getAttributeReadGuard(name, stableEnum); + const IAttributeVector *attribute = nullptr; + if (readGuard) { + attribute = readGuard->attribute(); } - return nullptr; + map[name] = std::move(readGuard); + return attribute; } } diff --git a/searchlib/src/vespa/searchlib/attribute/attributecontext.h b/searchlib/src/vespa/searchlib/attribute/attributecontext.h index 80abe84f8ef..6a158a26229 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributecontext.h +++ b/searchlib/src/vespa/searchlib/attribute/attributecontext.h @@ -16,7 +16,7 @@ namespace search { class AttributeContext : public attribute::IAttributeContext { private: - typedef vespalib::hash_map<string, AttributeGuard::UP> AttributeMap; + typedef vespalib::hash_map<string, std::unique_ptr<attribute::AttributeReadGuard>> AttributeMap; const search::IAttributeManager & _manager; mutable AttributeMap _attributes; diff --git a/searchlib/src/vespa/searchlib/attribute/attributemanager.cpp b/searchlib/src/vespa/searchlib/attribute/attributemanager.cpp index f10f3491ac0..402824327ff 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributemanager.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attributemanager.cpp @@ -3,6 +3,7 @@ #include "attributemanager.h" #include "attributecontext.h" #include "attributefactory.h" +#include "attribute_read_guard.h" #include "attrvector.h" #include "attributefile.h" #include "interlock.h" @@ -177,15 +178,15 @@ AttributeManager::getAttribute(const string & name) const return attrGuard; } -AttributeGuard::UP -AttributeManager::getAttributeStableEnum(const string & name) const +std::unique_ptr<attribute::AttributeReadGuard> +AttributeManager::getAttributeReadGuard(const string &name, bool stableEnumGuard) const { - AttributeGuard::UP attrGuard(new AttributeEnumGuard(VectorHolder())); const VectorHolder * vh = findAndLoadAttribute(name); - if ( vh != NULL ) { - attrGuard.reset(new AttributeEnumGuard(*vh)); + if (vh != nullptr) { + return (*vh)->makeReadGuard(stableEnumGuard); + } else { + return std::unique_ptr<attribute::AttributeReadGuard>(); } - return attrGuard; } bool diff --git a/searchlib/src/vespa/searchlib/attribute/attributemanager.h b/searchlib/src/vespa/searchlib/attribute/attributemanager.h index 3b23881e3bc..7f3937a7721 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributemanager.h +++ b/searchlib/src/vespa/searchlib/attribute/attributemanager.h @@ -37,7 +37,7 @@ public: const VectorHolder * getAttributeRef(const string & name) const; AttributeGuard::UP getAttribute(const string & name) const override; - AttributeGuard::UP getAttributeStableEnum(const string & name) const override; + std::unique_ptr<attribute::AttributeReadGuard> getAttributeReadGuard(const string &name, bool stableEnumGuard) const override; /** * This will load attributes in the most memory economical way by loading largest first. */ diff --git a/searchlib/src/vespa/searchlib/attribute/iattributemanager.h b/searchlib/src/vespa/searchlib/attribute/iattributemanager.h index 5dc692d56a8..ae95c360c42 100644 --- a/searchlib/src/vespa/searchlib/attribute/iattributemanager.h +++ b/searchlib/src/vespa/searchlib/attribute/iattributemanager.h @@ -8,6 +8,8 @@ namespace search { +namespace attribute { class AttributeReadGuard; } + /** * This is an interface used to access all registered attribute vectors. **/ @@ -28,12 +30,12 @@ public: /** * Returns a view of the attribute vector with the given name. - * Makes sure that the underlying enum values are stable during the use of this attribute vector. * * @param name name of the attribute vector. - * @return view of the attribute vector or empty view if the attribute vector does not exists. + * @param stableEnumGuard flag to block enumeration changes during use of the attribute vector via the view. + * @return view of the attribute vector if the attribute vector exists **/ - virtual AttributeGuard::UP getAttributeStableEnum(const string & name) const = 0; + virtual std::unique_ptr<attribute::AttributeReadGuard> getAttributeReadGuard(const string &name, bool stableEnumGuard) const = 0; /** * Fill the given list with all attribute vectors registered in this manager. diff --git a/searchlib/src/vespa/searchlib/test/mock_attribute_manager.h b/searchlib/src/vespa/searchlib/test/mock_attribute_manager.h index 33bd11e8d6f..fa12089b3cf 100644 --- a/searchlib/src/vespa/searchlib/test/mock_attribute_manager.h +++ b/searchlib/src/vespa/searchlib/test/mock_attribute_manager.h @@ -4,6 +4,7 @@ #include <vespa/searchlib/attribute/attributecontext.h> #include <vespa/searchlib/attribute/attributeguard.h> #include <vespa/searchlib/attribute/attributevector.h> +#include <vespa/searchlib/attribute/attribute_read_guard.h> #include <vespa/searchlib/attribute/iattributemanager.h> namespace search { @@ -33,9 +34,13 @@ public: return AttributeGuard::UP(new AttributeGuard(attr)); } - virtual AttributeGuard::UP getAttributeStableEnum(const vespalib::string &name) const override { + virtual std::unique_ptr<AttributeReadGuard> getAttributeReadGuard(const vespalib::string &name, bool stableEnumGuard) const override { AttributeVector::SP attr = findAttribute(name); - return AttributeGuard::UP(new AttributeEnumGuard(attr)); + if (attr) { + return attr->makeReadGuard(stableEnumGuard); + } else { + return std::unique_ptr<AttributeReadGuard>(); + } } virtual void getAttributeList(std::vector<AttributeGuard> &list) const override { |