diff options
18 files changed, 81 insertions, 56 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp b/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp index 6da1ff890c9..59393ac0a26 100644 --- a/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp +++ b/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp @@ -23,12 +23,12 @@ LOG_SETUP("attribute_manager_test"); #include <vespa/searchcore/proton/test/attribute_vectors.h> #include <vespa/searchlib/attribute/attributefactory.h> #include <vespa/searchlib/attribute/attributevector.hpp> +#include <vespa/searchlib/attribute/attribute_read_guard.h> #include <vespa/searchlib/attribute/imported_attribute_vector.h> #include <vespa/searchlib/attribute/imported_attribute_vector_factory.h> #include <vespa/searchlib/attribute/integerbase.h> #include <vespa/searchlib/attribute/predicate_attribute.h> #include <vespa/searchlib/attribute/reference_attribute.h> -#include <vespa/searchlib/attribute/reference_attribute.h> #include <vespa/searchlib/attribute/singlenumericattribute.hpp> #include <vespa/searchlib/common/foregroundtaskexecutor.h> #include <vespa/searchlib/common/indexmetainfo.h> @@ -268,9 +268,9 @@ TEST_F("require that attributes are added", Fixture) EXPECT_TRUE(f.addAttribute("a1").get() != NULL); EXPECT_TRUE(f.addAttribute("a2").get() != NULL); EXPECT_EQUAL("a1", (*f._m.getAttribute("a1"))->getName()); - EXPECT_EQUAL("a1", (*f._m.getAttributeStableEnum("a1"))->getName()); + EXPECT_EQUAL("a1", (*f._m.getAttributeReadGuard("a1", true))->getName()); EXPECT_EQUAL("a2", (*f._m.getAttribute("a2"))->getName()); - EXPECT_EQUAL("a2", (*f._m.getAttributeStableEnum("a2"))->getName()); + EXPECT_EQUAL("a2", (*f._m.getAttributeReadGuard("a2", true))->getName()); EXPECT_TRUE(!f._m.getAttribute("not")->valid()); } @@ -279,7 +279,7 @@ TEST_F("require that predicate attributes are added", Fixture) EXPECT_TRUE(f._m.addAttribute({"p1", AttributeUtils::getPredicateConfig()}, createSerialNum).get() != NULL); EXPECT_EQUAL("p1", (*f._m.getAttribute("p1"))->getName()); - EXPECT_EQUAL("p1", (*f._m.getAttributeStableEnum("p1"))->getName()); + EXPECT_EQUAL("p1", (*f._m.getAttributeReadGuard("p1", true))->getName()); } TEST_F("require that attributes are flushed and loaded", BaseFixture) diff --git a/searchcore/src/tests/proton/common/cachedselect_test.cpp b/searchcore/src/tests/proton/common/cachedselect_test.cpp index 7c295486110..a955bd60cf8 100644 --- a/searchcore/src/tests/proton/common/cachedselect_test.cpp +++ b/searchcore/src/tests/proton/common/cachedselect_test.cpp @@ -48,7 +48,6 @@ using document::select::ResultSet; using proton::CachedSelect; using proton::SelectContext; using search::AttributeContext; -using search::AttributeEnumGuard; using search::AttributeFactory; using search::AttributeGuard; using search::AttributePosting; diff --git a/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp b/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp index 57bddd6aede..a7512b41f30 100644 --- a/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp +++ b/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp @@ -27,7 +27,6 @@ using document::Field; using document::IntFieldValue; using document::StringFieldValue; using search::AttributeContext; -using search::AttributeEnumGuard; using search::AttributeGuard; using search::AttributeVector; using search::DocumentIdT; diff --git a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp index 0f17577e789..9c8e2d63385 100644 --- a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp +++ b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp @@ -339,7 +339,7 @@ struct MyAttributeManager : public proton::IAttributeManager virtual AttributeGuard::UP getAttribute(const string &) const override { abort(); } - virtual AttributeGuard::UP getAttributeStableEnum(const string &) const override { + virtual std::unique_ptr<search::attribute::AttributeReadGuard> getAttributeReadGuard(const string &, bool) const override { abort(); } virtual void getAttributeList(std::vector<AttributeGuard> &) const override { diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp index f1c078bb598..b4f087c65c0 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp @@ -11,6 +11,7 @@ #include "flushableattribute.h" #include <vespa/searchcore/proton/flushengine/shrink_lid_space_flush_target.h> #include <vespa/searchlib/attribute/attributecontext.h> +#include <vespa/searchlib/attribute/attribute_read_guard.h> #include <vespa/searchlib/attribute/interlock.h> #include <vespa/searchlib/common/isequencedtaskexecutor.h> #include <vespa/searchlib/common/threaded_compactable_lid_space.h> @@ -23,7 +24,6 @@ LOG_SETUP(".proton.attribute.attributemanager"); using search::AttributeContext; -using search::AttributeEnumGuard; using search::AttributeGuard; using search::AttributeVector; using search::common::ThreadedCompactableLidSpace; @@ -402,10 +402,15 @@ AttributeManager::getAttribute(const vespalib::string &name) const return AttributeGuard::UP(new AttributeGuard(findAttribute(name))); } -AttributeGuard::UP -AttributeManager::getAttributeStableEnum(const vespalib::string &name) const +std::unique_ptr<search::attribute::AttributeReadGuard> +AttributeManager::getAttributeReadGuard(const string &name, bool stableEnumGuard) const { - return AttributeGuard::UP(new AttributeEnumGuard(findAttribute(name))); + auto attribute = findAttribute(name); + if (attribute) { + return attribute->makeReadGuard(stableEnumGuard); + } else { + return std::unique_ptr<search::attribute::AttributeReadGuard>(); + } } void diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h index 7148815ca9e..b8f245d9c68 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h @@ -158,8 +158,7 @@ public: // Implements search::IAttributeManager virtual search::AttributeGuard::UP getAttribute(const vespalib::string &name) const override; - - virtual search::AttributeGuard::UP getAttributeStableEnum(const vespalib::string &name) const override; + virtual std::unique_ptr<search::attribute::AttributeReadGuard> getAttributeReadGuard(const string &name, bool stableEnumGuard) const override; /** * Fills all regular registered attributes (not extra attributes) diff --git a/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.cpp b/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.cpp index af64f47fc0a..d3a74bb9a98 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.cpp @@ -5,6 +5,7 @@ #include <vespa/searchlib/common/isequencedtaskexecutor.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/searchlib/attribute/attributevector.h> +#include <vespa/searchlib/attribute/attribute_read_guard.h> using search::AttributeGuard; using searchcorespi::IFlushTarget; @@ -70,10 +71,6 @@ FilterAttributeManager::FilterAttributeManager(const AttributeSet &acceptedAttri FilterAttributeManager::~FilterAttributeManager() { } -search::AttributeGuard::UP -FilterAttributeManager::getAttributeStableEnum(const vespalib::string &) const { - throw vespalib::IllegalArgumentException("Not implemented"); -} search::attribute::IAttributeContext::UP FilterAttributeManager::createContext() const { throw vespalib::IllegalArgumentException("Not implemented"); @@ -133,6 +130,15 @@ FilterAttributeManager::getAttribute(const vespalib::string &name) const return AttributeGuard::UP(); } +std::unique_ptr<search::attribute::AttributeReadGuard> +FilterAttributeManager::getAttributeReadGuard(const vespalib::string &name, bool stableEnumGuard) const +{ + if (acceptAttribute(name)) { + return _mgr->getAttributeReadGuard(name, stableEnumGuard); + } + return std::unique_ptr<search::attribute::AttributeReadGuard>(); +} + void FilterAttributeManager::getAttributeList(std::vector<AttributeGuard> &list) const { diff --git a/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.h b/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.h index 81fafa477ee..82f8107f92f 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.h @@ -35,8 +35,8 @@ public: virtual search::AttributeGuard::UP getAttribute(const vespalib::string &name) const override; virtual void getAttributeList(std::vector<search::AttributeGuard> &list) const override; virtual search::SerialNum getFlushedSerialNum(const vespalib::string &name) const override; - virtual search::AttributeGuard::UP getAttributeStableEnum(const vespalib::string &) const override; virtual search::attribute::IAttributeContext::UP createContext() const override; + virtual std::unique_ptr<search::attribute::AttributeReadGuard> getAttributeReadGuard(const vespalib::string &name, bool stableEnumGuard) const override; // Implements proton::IAttributeManager virtual IAttributeManager::SP create(const AttributeCollectionSpec &) const override; 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 { diff --git a/searchsummary/src/tests/docsummary/positionsdfw_test.cpp b/searchsummary/src/tests/docsummary/positionsdfw_test.cpp index 9af75846b85..7e1da35bd75 100644 --- a/searchsummary/src/tests/docsummary/positionsdfw_test.cpp +++ b/searchsummary/src/tests/docsummary/positionsdfw_test.cpp @@ -76,7 +76,7 @@ public: virtual AttributeGuard::UP getAttribute(const string &) const override { abort(); } - virtual AttributeGuard::UP getAttributeStableEnum(const string &) const override { + virtual std::unique_ptr<attribute::AttributeReadGuard> getAttributeReadGuard(const string &, bool) const override { abort(); } virtual void getAttributeList(vector<AttributeGuard> &) const override { |