diff options
author | Geir Storli <geirstorli@yahoo.no> | 2017-04-19 10:51:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-19 10:51:04 +0200 |
commit | 6adab6f821248cf7c7e6b3105c6e26145b8abaea (patch) | |
tree | e34095fc4dff471c24ebd4ad4d6939f798c44895 /searchcore | |
parent | 92d2c47b4904e4fb811e4a91849809ca5307a265 (diff) | |
parent | 5188254e1a5969d3504bcbe422c213b61a2ca00b (diff) |
Merge pull request #2177 from yahoo/toregge/add-index-aspect-inspector
Toregge/add index aspect inspector
Diffstat (limited to 'searchcore')
32 files changed, 297 insertions, 202 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_specs_builder/attribute_specs_builder_test.cpp b/searchcore/src/tests/proton/attribute/attribute_specs_builder/attribute_specs_builder_test.cpp index 379c9282b67..59756d377da 100644 --- a/searchcore/src/tests/proton/attribute/attribute_specs_builder/attribute_specs_builder_test.cpp +++ b/searchcore/src/tests/proton/attribute/attribute_specs_builder/attribute_specs_builder_test.cpp @@ -8,6 +8,7 @@ LOG_SETUP("attribute_specs_builder_test"); #include <vespa/searchcore/proton/attribute/attribute_specs_builder.h> #include <vespa/searchcore/proton/attribute/attribute_specs.h> #include <vespa/searchcore/proton/common/i_document_type_inspector.h> +#include <vespa/searchcore/proton/common/indexschema_inspector.h> #include <vespa/vespalib/test/insertion_operators.h> #include <vespa/config-indexschema.h> #include <vespa/config-attributes.h> @@ -170,7 +171,8 @@ public: _builder.setup(newConfig); } void setup(const AttributesConfig &oldConfig, const AttributesConfig &newConfig) { - _builder.setup(oldConfig, newConfig, _oldIndexSchema, _inspector); + IndexschemaInspector indexschemaInspector(_oldIndexSchema); + _builder.setup(oldConfig, newConfig, indexschemaInspector, _inspector); } void assertSpecs(const std::vector<AttributeSpec> &expSpecs) { diff --git a/searchcore/src/tests/proton/attribute/document_field_populator/document_field_populator_test.cpp b/searchcore/src/tests/proton/attribute/document_field_populator/document_field_populator_test.cpp index d0be50bfd2f..8e6d9050d88 100644 --- a/searchcore/src/tests/proton/attribute/document_field_populator/document_field_populator_test.cpp +++ b/searchcore/src/tests/proton/attribute/document_field_populator/document_field_populator_test.cpp @@ -58,7 +58,7 @@ struct Fixture Fixture() : _attr(search::AttributeFactory::createAttribute("a1", AVConfig(AVBasicType::INT32))), _intAttr(dynamic_cast<IntegerAttribute &>(*_attr)), - _pop(createAttributeField(), _attr, "test"), + _pop("a1", _attr, "test"), _ctx() { _intAttr.addDocs(2); diff --git a/searchcore/src/tests/proton/common/cachedselect_test.cpp b/searchcore/src/tests/proton/common/cachedselect_test.cpp index 6030c9c6fad..6d1f7735479 100644 --- a/searchcore/src/tests/proton/common/cachedselect_test.cpp +++ b/searchcore/src/tests/proton/common/cachedselect_test.cpp @@ -15,6 +15,7 @@ #include <vespa/searchlib/attribute/singlenumericenumattribute.hpp> #include <vespa/searchlib/attribute/singlenumericpostattribute.hpp> #include <vespa/searchlib/attribute/attributevector.hpp> +#include <vespa/searchlib/attribute/attributefactory.h> #include <vespa/searchlib/test/mock_attribute_manager.h> #include <vespa/document/select/parser.h> #include <vespa/document/select/cloningvisitor.h> @@ -22,7 +23,6 @@ #include <vespa/document/fieldvalue/stringfieldvalue.h> #include <vespa/document/fieldvalue/intfieldvalue.h> #include <vespa/document/fieldvalue/document.h> -#include <vespa/searchcommon/common/schema.h> #include <vespa/log/log.h> LOG_SETUP("cachedselect_test"); @@ -48,6 +48,7 @@ using proton::CachedSelect; using proton::SelectContext; using search::AttributeContext; using search::AttributeEnumGuard; +using search::AttributeFactory; using search::AttributeGuard; using search::AttributePosting; using search::AttributeVector; @@ -55,10 +56,10 @@ using search::EnumAttribute; using search::IntegerAttribute; using search::IntegerAttributeTemplate; using search::SingleValueNumericPostingAttribute; +using search::attribute::BasicType; +using search::attribute::CollectionType; using search::attribute::IAttributeContext; using search::attribute::test::MockAttributeManager; -using search::index::Schema; -using search::index::schema::CollectionType; using vespalib::string; using namespace search::index; @@ -75,15 +76,6 @@ typedef SingleValueNumericPostingAttribute<IntEnumAttribute> SvIntAttr; namespace { -void -makeSchema(Schema &s) -{ - s.addIndexField(Schema::IndexField("ia", schema::DataType::STRING)); - s.addAttributeField(Schema::AttributeField("aa", schema::DataType::INT32)); - s.addAttributeField(Schema::AttributeField("aaa", schema::DataType::INT32, CollectionType::ARRAY)); - s.addAttributeField(Schema::AttributeField("aaw", schema::DataType::INT32, CollectionType::WEIGHTEDSET)); -} - const int32_t doc_type_id = 787121340; const string type_name = "test"; const string header_name = type_name + ".header"; @@ -212,6 +204,7 @@ public: class MyAttributeManager : public MockAttributeManager { public: + using MockAttributeManager::addAttribute; void addAttribute(const vespalib::string &name) { if (findAttribute(name).get() != NULL) { return; @@ -230,7 +223,6 @@ class MyDB public: typedef std::unique_ptr<MyDB> UP; - const Schema &_schema; const DocumentTypeRepo &_repo; MyAttributeManager &_amgr; typedef std::map<string, uint32_t> DocIdToLid; @@ -238,11 +230,9 @@ public: DocIdToLid _docIdToLid; LidToDocSP _lidToDocSP; - MyDB(const Schema &schema, - const DocumentTypeRepo &repo, + MyDB(const DocumentTypeRepo &repo, MyAttributeManager &amgr) - : _schema(schema), - _repo(repo), + : _repo(repo), _amgr(amgr) { } @@ -298,7 +288,6 @@ MyDB::getDoc(uint32_t lid) const class TestFixture { public: - Schema _s; DocumentTypeRepo::UP _repoUP; bool _hasFields; MyAttributeManager _amgr; @@ -316,18 +305,18 @@ public: TestFixture::TestFixture(void) - : _s(), - _repoUP(), + : _repoUP(), _hasFields(true), _amgr(), _db() { - makeSchema(_s); _repoUP = makeDocTypeRepo(); _amgr.addAttribute("aa"); + _amgr.addAttribute("aaa", AttributeFactory::createAttribute("aaa", {BasicType::INT32, CollectionType::ARRAY})); + _amgr.addAttribute("aaw", AttributeFactory::createAttribute("aaw", {BasicType::INT32, CollectionType::WSET})); - _db.reset(new MyDB(_s, *_repoUP, _amgr)); + _db.reset(new MyDB(*_repoUP, _amgr)); } @@ -341,7 +330,6 @@ TestFixture::testParse(const string &selection, const string &docTypeName) { const DocumentTypeRepo &repo(*_repoUP); - const Schema &schema(_s); CachedSelect::SP res(new CachedSelect); @@ -353,7 +341,6 @@ TestFixture::testParse(const string &selection, docTypeName, *emptyDoc, repo, - schema, &_amgr, _hasFields); diff --git a/searchcore/src/tests/proton/common/selectpruner_test.cpp b/searchcore/src/tests/proton/common/selectpruner_test.cpp index 7199cda27d6..e167979d065 100644 --- a/searchcore/src/tests/proton/common/selectpruner_test.cpp +++ b/searchcore/src/tests/proton/common/selectpruner_test.cpp @@ -7,11 +7,12 @@ #include <vespa/searchcore/proton/common/selectpruner.h> #include <vespa/document/select/parser.h> #include <vespa/document/select/cloningvisitor.h> +#include <vespa/searchlib/attribute/attributefactory.h> +#include <vespa/searchlib/test/mock_attribute_manager.h> #include <vespa/log/log.h> LOG_SETUP("selectpruner_test"); -using namespace search::index; using document::DataType; using document::Document; using document::DocumentType; @@ -26,25 +27,17 @@ using document::select::Node; using document::select::Result; using document::select::ResultSet; using proton::SelectPruner; -using search::index::schema::CollectionType; using vespalib::string; +using search::attribute::BasicType; +using search::attribute::CollectionType; +using search::attribute::test::MockAttributeManager; +using search::AttributeFactory; typedef Node::UP NodeUP; namespace { -void -makeSchema(Schema &s) -{ - s.addIndexField(Schema::IndexField("ia", schema::DataType::STRING)); - s.addAttributeField(Schema::AttributeField("aa", schema::DataType::INT32)); - s.addAttributeField(Schema::AttributeField("aaa", schema::DataType::INT32, - CollectionType::ARRAY)); - s.addAttributeField(Schema::AttributeField("aaw", schema::DataType::INT32, - CollectionType::WEIGHTEDSET)); -} - const int32_t doc_type_id = 787121340; const string type_name = "test"; const string header_name = type_name + ".header"; @@ -134,7 +127,7 @@ csString(const SelectPruner &pruner) class TestFixture { public: - Schema _s; + MockAttributeManager _amgr; DocumentTypeRepo::UP _repoUP; bool _hasFields; @@ -160,11 +153,13 @@ public: TestFixture::TestFixture(void) - : _s(), + : _amgr(), _repoUP(), _hasFields(true) { - makeSchema(_s); + _amgr.addAttribute("aa", AttributeFactory::createAttribute("aa", { BasicType::INT32 })); + _amgr.addAttribute("aaa", AttributeFactory::createAttribute("aaa", { BasicType::INT32 , CollectionType::ARRAY})); + _amgr.addAttribute("aaw", AttributeFactory::createAttribute("aaw", { BasicType::INT32 , CollectionType::WSET})); _repoUP = makeDocTypeRepo(); } @@ -227,7 +222,6 @@ TestFixture::testPrune(const string &selection, const string &docTypeName) { const DocumentTypeRepo &repo(*_repoUP); - const Schema &schema(_s); document::select::Parser parser(repo, document::BucketIdFactory()); @@ -252,7 +246,7 @@ TestFixture::testPrune(const string &selection, ASSERT_TRUE(docType != NULL); Document::UP emptyDoc(new Document(*docType, docId)); emptyDoc->setRepo(repo); - SelectPruner pruner(docTypeName, schema, *emptyDoc, repo, _hasFields); + SelectPruner pruner(docTypeName, &_amgr, *emptyDoc, repo, _hasFields); pruner.process(*select); std::ostringstream pos; pruner.getNode()->print(pos, true, ""); 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 66035647d86..0ccd5b8d6ee 100644 --- a/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp +++ b/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp @@ -5,7 +5,6 @@ #include <vespa/persistence/spi/bucket.h> #include <vespa/persistence/spi/docentry.h> #include <vespa/persistence/spi/result.h> -#include <vespa/searchcommon/common/schema.h> #include <vespa/searchcore/proton/common/attrupdate.h> #include <vespa/searchcore/proton/persistenceengine/document_iterator.h> #include <vespa/searchcore/proton/server/commit_and_wait_document_retriever.h> @@ -185,41 +184,39 @@ struct VisitRecordingUnitDR : UnitDR { struct AttrUnitDR : public UnitDR { MockAttributeManager _amgr; - Schema _schema; AttributeVector::SP _aa; AttributeVector::SP _dd; AttributeVector::SP _ss; AttrUnitDR(document::Document::UP d, Timestamp t, Bucket b, bool r) : UnitDR(d->getType(), document::Document::UP(d->clone()), t, b, r), - _amgr(), _schema(), _aa(), _dd(), _ss() + _amgr(), _aa(), _dd(), _ss() { - createAttribute(_aa, BasicType::INT32, schema::DataType::INT32, "aa"); - createAttribute(_dd, BasicType::DOUBLE, schema::DataType::DOUBLE, "dd"); - createAttribute(_ss, BasicType::STRING, schema::DataType::STRING, "ss"); + createAttribute(_aa, BasicType::INT32, "aa"); + createAttribute(_dd, BasicType::DOUBLE, "dd"); + createAttribute(_ss, BasicType::STRING, "ss"); } AttrUnitDR(document::Document::UP d, Timestamp t, Bucket b, bool r, int32_t aa, double dd, const vespalib::string &ss) : UnitDR(d->getType(), document::Document::UP(d->clone()), t, b, r), - _amgr(), _schema(), _aa(), _dd(), _ss() + _amgr(), _aa(), _dd(), _ss() { - createAttribute(_aa, BasicType::INT32, schema::DataType::INT32, "aa"); + createAttribute(_aa, BasicType::INT32, "aa"); addAttribute<IntFieldValue, int32_t>(*_aa, aa); - createAttribute(_dd, BasicType::DOUBLE, schema::DataType::DOUBLE, "dd"); + createAttribute(_dd, BasicType::DOUBLE, "dd"); addAttribute<DoubleFieldValue, double>(*_dd, dd); - createAttribute(_ss, BasicType::STRING, schema::DataType::STRING, "ss"); + createAttribute(_ss, BasicType::STRING, "ss"); addAttribute<StringFieldValue, vespalib::string>(*_ss, ss); } void createAttribute(AttributeVector::SP &av, BasicType basicType, - Schema::DataType dataType, const vespalib::string &fieldName) + const vespalib::string &fieldName) { Config cfg(basicType, CollectionType::SINGLE); cfg.setFastSearch(true); av = search::AttributeFactory::createAttribute(fieldName, cfg); _amgr.addAttribute(fieldName, av); - _schema.addAttributeField(Schema::AttributeField(fieldName, dataType)); while (docid >= av->getNumDocs()) { AttributeVector::DocId checkDocId(0u); ASSERT_TRUE(av->addDoc(checkDocId)); @@ -236,7 +233,7 @@ struct AttrUnitDR : public UnitDR CachedSelect::SP parseSelect(const vespalib::string &selection) const override { CachedSelect::SP res(new CachedSelect); - res->set(selection, "foo", Document(document->getType(), DocumentId()), repo, _schema, &_amgr, true); + res->set(selection, "foo", Document(document->getType(), DocumentId()), repo, &_amgr, true); return res; } }; diff --git a/searchcore/src/tests/proton/reprocessing/attribute_reprocessing_initializer/attribute_reprocessing_initializer_test.cpp b/searchcore/src/tests/proton/reprocessing/attribute_reprocessing_initializer/attribute_reprocessing_initializer_test.cpp index aeb6d9a3587..73dfae75d7b 100644 --- a/searchcore/src/tests/proton/reprocessing/attribute_reprocessing_initializer/attribute_reprocessing_initializer_test.cpp +++ b/searchcore/src/tests/proton/reprocessing/attribute_reprocessing_initializer/attribute_reprocessing_initializer_test.cpp @@ -8,6 +8,7 @@ LOG_SETUP("attribute_reprocessing_initializer_test"); #include <vespa/searchcore/proton/attribute/attributedisklayout.h> #include <vespa/searchcore/proton/attribute/attribute_directory.h> #include <vespa/searchcore/proton/attribute/document_field_populator.h> +#include <vespa/searchcore/proton/common/i_indexschema_inspector.h> #include <vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.h> #include <vespa/searchcore/proton/reprocessing/i_reprocessing_handler.h> #include <vespa/searchcore/proton/test/attribute_utils.h> @@ -105,6 +106,23 @@ struct MyDocTypeInspector : public IDocumentTypeInspector } }; +struct MyIndexschemaInspector : public IIndexschemaInspector +{ + const search::index::Schema &_schema; + MyIndexschemaInspector(const search::index::Schema &schema) + : _schema(schema) + { + } + virtual bool isStringIndex(const vespalib::string &name) const override { + uint32_t fieldId = _schema.getIndexFieldId(name); + if (fieldId == Schema::UNKNOWN_FIELD_ID) { + return false; + } + const auto &field = _schema.getIndexField(fieldId); + return (field.getDataType() == DataType::STRING); + } +}; + struct Fixture { test::DirectoryHandler _dirHandler; @@ -134,10 +152,12 @@ struct Fixture } ~Fixture() { } void init() { + MyIndexschemaInspector oldIndexschemaInspector(_oldCfg._schema); _initializer.reset(new AttributeReprocessingInitializer (ARIConfig(_newCfg._mgr, _newCfg._schema), ARIConfig(_oldCfg._mgr, _oldCfg._schema), - _inspector, "test", INIT_SERIAL_NUM)); + _inspector, oldIndexschemaInspector, + "test", INIT_SERIAL_NUM)); _initializer->initialize(_handler); } Fixture &addOldConfig(const StringVector &fields, diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_specs_builder.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attribute_specs_builder.cpp index 504dfa9f102..6ee6d0e7873 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_specs_builder.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_specs_builder.cpp @@ -3,42 +3,21 @@ #include "attribute_specs_builder.h" #include <vespa/searchlib/attribute/configconverter.h> #include <vespa/searchcore/proton/common/i_document_type_inspector.h> -#include <vespa/vespalib/stllike/hash_map.hpp> -#include <vespa/config-indexschema.h> +#include <vespa/searchcore/proton/common/i_indexschema_inspector.h> +#include <vespa/searchcore/proton/common/config_hash.hpp> #include <vespa/config-attributes.h> #include "attribute_specs.h" using search::attribute::ConfigConverter; using vespa::config::search::AttributesConfig; using vespa::config::search::AttributesConfigBuilder; -using vespa::config::search::IndexschemaConfig; using search::attribute::BasicType; namespace proton { namespace { -template <class Elem> -class ConfigHash { - vespalib::hash_map<vespalib::string, const Elem *> _hash; -public: - ConfigHash(const std::vector<Elem> &config) - : _hash() - { - for (const auto &elem : config) { - auto insres = _hash.insert(std::make_pair(elem.name, &elem)); - assert(insres.second); - } - } - ~ConfigHash() { } - const Elem *lookup(const vespalib::string &name) const { - auto itr = _hash.find(name); - return ((itr == _hash.end()) ? nullptr : itr->second); - } -}; - using AttributesConfigHash = ConfigHash<AttributesConfig::Attribute>; -using IndexConfigHash = ConfigHash<IndexschemaConfig::Indexfield>; bool fastPartialUpdateAttribute(const search::attribute::Config &cfg) { auto basicType = cfg.basicType().type(); @@ -47,22 +26,11 @@ bool fastPartialUpdateAttribute(const search::attribute::Config &cfg) { (basicType != BasicType::Type::REFERENCE)); } -bool isStringIndex(const IndexConfigHash &indexConfig, const vespalib::string &name) -{ - auto index = indexConfig.lookup(name); - if (index != nullptr) { - if (index->datatype == IndexschemaConfig::Indexfield::Datatype::STRING) { - return true; - } - } - return false; -} - bool willTriggerReprocessOnAttributeAspectRemoval(const search::attribute::Config &cfg, - const IndexConfigHash &indexConfig, + const IIndexschemaInspector &indexschemaInspector, const vespalib::string &name) { - return fastPartialUpdateAttribute(cfg) && !isStringIndex(indexConfig, name); + return fastPartialUpdateAttribute(cfg) && !indexschemaInspector.isStringIndex(name); } @@ -105,7 +73,7 @@ namespace { void handleNewAttributes(const AttributesConfig &oldAttributesConfig, const AttributesConfig &newAttributesConfig, - IndexConfigHash &oldIndexes, + const IIndexschemaInspector &oldIndexschemaInspector, const IDocumentTypeInspector &inspector, AttributeSpecs &specs, AttributesConfigBuilder &config) @@ -121,7 +89,7 @@ handleNewAttributes(const AttributesConfig &oldAttributesConfig, auto oldAttr = oldAttrs.lookup(newAttr.name); if (oldAttr != nullptr) { search::attribute::Config oldCfg = ConfigConverter::convert(*oldAttr); - if (willTriggerReprocessOnAttributeAspectRemoval(oldCfg, oldIndexes, newAttr.name) || !oldAttr->fastaccess) { + if (willTriggerReprocessOnAttributeAspectRemoval(oldCfg, oldIndexschemaInspector, newAttr.name) || !oldAttr->fastaccess) { // Delay change of fast access flag newCfg.setFastAccess(oldAttr->fastaccess); specs.emplace_back(newAttr.name, newCfg); @@ -150,7 +118,7 @@ handleNewAttributes(const AttributesConfig &oldAttributesConfig, void handleOldAttributes(const AttributesConfig &oldAttributesConfig, const AttributesConfig &newAttributesConfig, - IndexConfigHash &oldIndexes, + const IIndexschemaInspector &oldIndexschemaInspector, const IDocumentTypeInspector &inspector, AttributeSpecs &specs, AttributesConfigBuilder &config) @@ -163,7 +131,7 @@ handleOldAttributes(const AttributesConfig &oldAttributesConfig, if (newAttr == nullptr) { // Delay removal of attribute aspect if it would trigger // reprocessing. - if (willTriggerReprocessOnAttributeAspectRemoval(oldCfg, oldIndexes, oldAttr.name)) { + if (willTriggerReprocessOnAttributeAspectRemoval(oldCfg, oldIndexschemaInspector, oldAttr.name)) { specs.emplace_back(oldAttr.name, oldCfg, true, false); config.attribute.emplace_back(oldAttr); } @@ -177,14 +145,13 @@ handleOldAttributes(const AttributesConfig &oldAttributesConfig, void AttributeSpecsBuilder::setup(const AttributesConfig &oldAttributesConfig, const AttributesConfig &newAttributesConfig, - const IndexschemaConfig &oldIndexschemaConfig, + const IIndexschemaInspector &oldIndexschemaInspector, const IDocumentTypeInspector &inspector) { - IndexConfigHash oldIndexes(oldIndexschemaConfig.indexfield); handleNewAttributes(oldAttributesConfig, newAttributesConfig, - oldIndexes, inspector, *_specs, *_config); + oldIndexschemaInspector, inspector, *_specs, *_config); handleOldAttributes(oldAttributesConfig, newAttributesConfig, - oldIndexes, inspector, *_specs, *_config); + oldIndexschemaInspector, inspector, *_specs, *_config); } } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_specs_builder.h b/searchcore/src/vespa/searchcore/proton/attribute/attribute_specs_builder.h index 9f74d37afdd..0cb8cde4400 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_specs_builder.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_specs_builder.h @@ -13,6 +13,7 @@ class InternalIndexschemaType; namespace proton { class IDocumentTypeInspector; +class IIndexschemaInspector; class AttributeSpecs; /* @@ -44,7 +45,7 @@ public: */ void setup(const AttributesConfig &oldAttributesConfig, const AttributesConfig &newAttributesConfig, - const IndexschemaConfig &oldIndexschemaConfig, + const IIndexschemaInspector &oldIndexschemaInspector, const IDocumentTypeInspector &inspector); std::shared_ptr<const AttributeSpecs> getAttributeSpecs() const; diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp index bb9a5ad0a08..c8ae63bf0ec 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp @@ -27,7 +27,6 @@ using search::TuneFileAttributes; using search::attribute::IAttributeContext; using search::attribute::IAttributeVector; using search::common::FileHeaderContext; -using search::index::Schema; using search::attribute::BasicType; using searchcorespi::IFlushTarget; diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h index d662dd5c0a5..f8fae2730f1 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h @@ -8,7 +8,7 @@ #include "i_attribute_initializer_registry.h" #include <set> #include <vespa/searchlib/common/tunefileinfo.h> -#include <vespa/searchcommon/common/schema.h> +#include <vespa/vespalib/stllike/hash_map.h> #include <vespa/searchcore/proton/common/hw_info.h> namespace search diff --git a/searchcore/src/vespa/searchcore/proton/attribute/document_field_populator.cpp b/searchcore/src/vespa/searchcore/proton/attribute/document_field_populator.cpp index 00732fcedde..390f0362800 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/document_field_populator.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/document_field_populator.cpp @@ -8,7 +8,6 @@ LOG_SETUP(".proton.attribute.document_field_populator"); using document::Document; -using search::index::Schema; using search::AttributeGuard; namespace proton { @@ -24,23 +23,23 @@ getFieldName(const vespalib::string &subDbName, } -DocumentFieldPopulator::DocumentFieldPopulator(const Schema::AttributeField &field, +DocumentFieldPopulator::DocumentFieldPopulator(const vespalib::string &fieldName, AttributeVectorSP attr, const vespalib::string &subDbName) - : _field(field), + : _fieldName(fieldName), _attr(attr), _subDbName(subDbName), _documentsPopulated(0) { if (LOG_WOULD_LOG(event)) { - EventLogger::populateDocumentFieldStart(getFieldName(subDbName, field.getName())); + EventLogger::populateDocumentFieldStart(getFieldName(subDbName, fieldName)); } } DocumentFieldPopulator::~DocumentFieldPopulator() { if (LOG_WOULD_LOG(event)) { - EventLogger::populateDocumentFieldComplete(getFieldName(_subDbName, _field.getName()), + EventLogger::populateDocumentFieldComplete(getFieldName(_subDbName, _fieldName), _documentsPopulated); } } @@ -48,7 +47,7 @@ DocumentFieldPopulator::~DocumentFieldPopulator() void DocumentFieldPopulator::handleExisting(uint32_t lid, Document &doc) { - DocumentFieldRetriever::populate(lid, doc, _field, *_attr, false); + DocumentFieldRetriever::populate(lid, doc, _fieldName, *_attr, false); ++_documentsPopulated; } diff --git a/searchcore/src/vespa/searchcore/proton/attribute/document_field_populator.h b/searchcore/src/vespa/searchcore/proton/attribute/document_field_populator.h index 36de783cd0f..bc59b7d642c 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/document_field_populator.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/document_field_populator.h @@ -2,7 +2,6 @@ #pragma once -#include <vespa/searchcommon/common/schema.h> #include <vespa/searchcore/proton/reprocessing/i_reprocessing_rewriter.h> #include <vespa/searchlib/attribute/attributeguard.h> @@ -15,13 +14,13 @@ class DocumentFieldPopulator : public IReprocessingRewriter { private: using AttributeVectorSP = std::shared_ptr<search::AttributeVector>; - search::index::Schema::AttributeField _field; + vespalib::string _fieldName; AttributeVectorSP _attr; vespalib::string _subDbName; int64_t _documentsPopulated; public: - DocumentFieldPopulator(const search::index::Schema::AttributeField &field, + DocumentFieldPopulator(const vespalib::string &fieldName, AttributeVectorSP attr, const vespalib::string &subDbName); diff --git a/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.cpp b/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.cpp index dbe23f16e57..00eba5014b3 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.cpp @@ -20,13 +20,12 @@ using document::TensorFieldValue; using document::WeightedSetFieldValue; using search::DocumentIdT; using search::attribute::AttributeContent; +using search::attribute::BasicType; +using search::attribute::CollectionType; using search::attribute::IAttributeVector; using search::attribute::WeightedType; -using search::index::schema::CollectionType; -using search::index::schema::DataType; using search::tensor::TensorAttribute; using vespalib::IllegalStateException; -using namespace search::index; namespace proton { @@ -36,18 +35,18 @@ template <typename T> void setValue(DocumentIdT lid, Document &doc, - const Schema::AttributeField &field, + const vespalib::string &fieldName, const IAttributeVector &attr) { - switch (field.getCollectionType()) { + switch (attr.getCollectionType()) { case CollectionType::SINGLE: { if ( ! attr.isUndefined(lid) ) { AttributeContent<T> content; content.fill(attr, lid); - doc.set(field.getName(), content[0]); + doc.set(fieldName, content[0]); } else { - doc.remove(field.getName()); + doc.remove(fieldName); } break; } @@ -55,13 +54,13 @@ setValue(DocumentIdT lid, { AttributeContent<T> content; content.fill(attr, lid); - Field f = doc.getField(field.getName()); + Field f = doc.getField(fieldName); if (!doc.getValue(f) && content.size() == 0) { break; } FieldValue::UP fv = f.getDataType().createFieldValue(); if (fv.get() && fv->getClass().id() != ArrayFieldValue::classId) { - throw IllegalStateException("Field " + field.getName() + " does not contain an array.", VESPA_STRLOC); + throw IllegalStateException("Field " + fieldName + " does not contain an array.", VESPA_STRLOC); } ArrayFieldValue &array = static_cast<ArrayFieldValue &>(*fv.get()); array.resize(content.size()); @@ -71,17 +70,17 @@ setValue(DocumentIdT lid, doc.setValue(f, *fv); break; } - case CollectionType::WEIGHTEDSET: + case CollectionType::WSET: { AttributeContent<WeightedType<T> > content; content.fill(attr, lid); - Field f = doc.getField(field.getName()); + Field f = doc.getField(fieldName); if (!doc.getValue(f) && content.size() == 0) { break; } FieldValue::UP fv = f.getDataType().createFieldValue(); if (fv.get() && fv->getClass().id() != WeightedSetFieldValue::classId) { - throw IllegalStateException("Field " + field.getName() + " does not contain a wset.", VESPA_STRLOC); + throw IllegalStateException("Field " + fieldName + " does not contain a wset.", VESPA_STRLOC); } WeightedSetFieldValue & wset(static_cast<WeightedSetFieldValue &>(*fv.get())); wset.resize(content.size()); @@ -94,7 +93,7 @@ setValue(DocumentIdT lid, break; } default: - LOG(warning, "Unknown attribute collection type in Schema."); + LOG(warning, "Unknown attribute collection type in attribute."); break; } } @@ -104,44 +103,46 @@ setValue(DocumentIdT lid, void DocumentFieldRetriever::populate(DocumentIdT lid, Document &doc, - const Schema::AttributeField &field, + const vespalib::string &fieldName, const IAttributeVector &attr, bool isIndexField) { - switch (field.getDataType()) { - case DataType::UINT1: - case DataType::UINT2: - case DataType::UINT4: - case DataType::INT8: - case DataType::INT16: - case DataType::INT32: - case DataType::INT64: + switch (attr.getBasicType()) { + case BasicType::UINT1: + case BasicType::UINT2: + case BasicType::UINT4: + case BasicType::INT8: + case BasicType::INT16: + case BasicType::INT32: + case BasicType::INT64: setValue<IAttributeVector::largeint_t>( - lid, doc, field, attr); + lid, doc, fieldName, attr); break; - case DataType::FLOAT: - case DataType::DOUBLE: - setValue<double>(lid, doc, field, attr); + case BasicType::FLOAT: + case BasicType::DOUBLE: + setValue<double>(lid, doc, fieldName, attr); break; - case DataType::STRING: + case BasicType::STRING: // If it is a stringfield we also need to check if // it is an index field. In that case we shall // keep the original in order to preserve annotations. if (isIndexField) { break; } - case DataType::RAW: - setValue<const char *>(lid, doc, field, attr); + setValue<const char *>(lid, doc, fieldName, attr); break; - case DataType::BOOLEANTREE: + case BasicType::PREDICATE: // Predicate attribute doesn't store documents, it only indexes them. break; - case DataType::TENSOR: + case BasicType::TENSOR: // Tensor attribute is not authorative. Partial updates must update // document store. break; + case BasicType::REFERENCE: + // Reference attribute doesn't store full document id. + break; default: - LOG(warning, "Unknown attribute data type in Schema."); + LOG(warning, "Unknown attribute data type in attribute."); } } diff --git a/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.h b/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.h index d91acb7c00b..a510da272cb 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/document_field_retriever.h @@ -4,7 +4,6 @@ #include <vespa/document/fieldvalue/document.h> #include <vespa/searchcommon/attribute/iattributevector.h> -#include <vespa/searchcommon/common/schema.h> #include <vespa/searchlib/query/base.h> namespace proton { @@ -16,7 +15,7 @@ struct DocumentFieldRetriever { static void populate(search::DocumentIdT lid, document::Document &doc, - const search::index::Schema::AttributeField &field, + const vespalib::string &fieldName, const search::attribute::IAttributeVector &attr, bool isIndexField); }; diff --git a/searchcore/src/vespa/searchcore/proton/attribute/i_attribute_manager.h b/searchcore/src/vespa/searchcore/proton/attribute/i_attribute_manager.h index 1935e85dcc4..b3295c4a36a 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/i_attribute_manager.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/i_attribute_manager.h @@ -5,7 +5,6 @@ #include "attribute_collection_spec.h" #include "exclusive_attribute_read_accessor.h" #include "i_attribute_factory.h" -#include <vespa/searchcommon/common/schema.h> #include <vespa/searchcorespi/flush/iflushtarget.h> #include <vespa/searchlib/attribute/iattributemanager.h> #include <vespa/searchlib/common/serialnum.h> diff --git a/searchcore/src/vespa/searchcore/proton/common/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/common/CMakeLists.txt index 889b3eb33b8..a6c9435ec0e 100644 --- a/searchcore/src/vespa/searchcore/proton/common/CMakeLists.txt +++ b/searchcore/src/vespa/searchcore/proton/common/CMakeLists.txt @@ -13,6 +13,7 @@ vespa_add_library(searchcore_pcommon STATIC feeddebugger.cpp feedtoken.cpp hw_info_sampler.cpp + indexschema_inspector.cpp monitored_refcount.cpp schemautil.cpp selectpruner.cpp diff --git a/searchcore/src/vespa/searchcore/proton/common/cachedselect.cpp b/searchcore/src/vespa/searchcore/proton/common/cachedselect.cpp index 7b09a9a750b..25bb9bf0f21 100644 --- a/searchcore/src/vespa/searchcore/proton/common/cachedselect.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/cachedselect.cpp @@ -14,7 +14,6 @@ LOG_SETUP(".proton.common.cachedselect"); namespace proton { -using search::index::Schema; using search::AttributeVector; using search::AttributeGuard; using document::select::FieldValueNode; @@ -28,7 +27,6 @@ public: AttrMap _amap; const search::IAttributeManager &_amgr; CachedSelect &_cached; - const Schema &_schema; uint32_t _svAttrs; uint32_t _mvAttrs; uint32_t _complexAttrs; @@ -45,8 +43,7 @@ public: return std::numeric_limits<uint32_t>::max(); } - AttrVisitor(const Schema &schema, - const search::IAttributeManager &amgr, + AttrVisitor(const search::IAttributeManager &amgr, CachedSelect &cachedSelect); /* @@ -58,14 +55,12 @@ public: }; -AttrVisitor::AttrVisitor(const Schema &schema, - const search::IAttributeManager &amgr, +AttrVisitor::AttrVisitor(const search::IAttributeManager &amgr, CachedSelect &cachedSelect) : CloningVisitor(), _amap(), _amgr(amgr), _cached(cachedSelect), - _schema(schema), _svAttrs(0u), _mvAttrs(0u), _complexAttrs(0u) @@ -89,22 +84,14 @@ AttrVisitor::visitFieldValueNode(const FieldValueNode &expr) break; } } - if (_schema.isAttributeField(name)) { + AttributeGuard::UP ag(_amgr.getAttribute(name)); + if (ag->valid()) { if (complex) { ++_complexAttrs; // Don't try to optimize complex attribute references yet. _valueNode = expr.clone(); return; } - AttributeGuard::UP ag(_amgr.getAttribute(name)); - assert(ag.get() != NULL); - if (!ag->valid()) { - // Fast access document sub where attribute is not marked as - // fast-access. Disable optimization. - ++_complexAttrs; - _valueNode = expr.clone(); - return; - } AttributeVector::SP av(ag->getSP()); if (av->getCollectionType() == CollectionType::SINGLE) { ++_svAttrs; @@ -171,7 +158,6 @@ CachedSelect::set(const vespalib::string &selection, const vespalib::string &docTypeName, const document::Document &emptyDoc, const document::DocumentTypeRepo &repo, - const search::index::Schema &schema, const search::IAttributeManager *amgr, bool hasFields) { @@ -182,7 +168,7 @@ CachedSelect::set(const vespalib::string &selection, if (parsed.get() == NULL) return; SelectPruner pruner(docTypeName, - schema, + amgr, emptyDoc, repo, hasFields); @@ -196,7 +182,7 @@ CachedSelect::set(const vespalib::string &selection, _attrFieldNodes = pruner.getAttrFieldNodes(); if (amgr == NULL || _attrFieldNodes == 0u) return; - AttrVisitor av(schema, *amgr, *this); + AttrVisitor av(*amgr, *this); _select->visit(av); assert(_fieldNodes == av.getFieldNodes()); assert(_attrFieldNodes == av._mvAttrs + av._svAttrs + av._complexAttrs); diff --git a/searchcore/src/vespa/searchcore/proton/common/cachedselect.h b/searchcore/src/vespa/searchcore/proton/common/cachedselect.h index b76068db8f8..53ee30bacea 100644 --- a/searchcore/src/vespa/searchcore/proton/common/cachedselect.h +++ b/searchcore/src/vespa/searchcore/proton/common/cachedselect.h @@ -13,7 +13,6 @@ namespace document { namespace search { class AttributeVector; class IAttributeManager; - namespace index { class Schema; } } namespace proton { @@ -59,7 +58,6 @@ public: const vespalib::string &docTypeName, const document::Document &emptyDoc, const document::DocumentTypeRepo &repo, - const search::index::Schema &schema, const search::IAttributeManager *amgr, bool hasFields); }; diff --git a/searchcore/src/vespa/searchcore/proton/common/config_hash.h b/searchcore/src/vespa/searchcore/proton/common/config_hash.h new file mode 100644 index 00000000000..8c229ca475d --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/common/config_hash.h @@ -0,0 +1,24 @@ +// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <vespa/vespalib/stllike/string.h> +#include <vespa/vespalib/stllike/hash_map.h> +#include <vector> + +namespace proton { + +/* + * Utility class to access a config vector based on name instead of index. + * The vector must remain valid during the lifetime of the config hash. + */ +template <class Elem> +class ConfigHash { + vespalib::hash_map<vespalib::string, const Elem *> _hash; +public: + ConfigHash(const std::vector<Elem> &config); + ~ConfigHash(); + const Elem *lookup(const vespalib::string &name) const; +}; + +} // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/common/config_hash.hpp b/searchcore/src/vespa/searchcore/proton/common/config_hash.hpp new file mode 100644 index 00000000000..85b7eecc150 --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/common/config_hash.hpp @@ -0,0 +1,34 @@ +// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "config_hash.h" +#include <vespa/vespalib/stllike/hash_map.hpp> +#include <assert.h> + +namespace proton { + +template <class Elem> +ConfigHash<Elem>::ConfigHash(const std::vector<Elem> &config) + : _hash() +{ + for (const auto &elem : config) { + auto insres = _hash.insert(std::make_pair(elem.name, &elem)); + assert(insres.second); + } +} + +template <class Elem> +ConfigHash<Elem>::~ConfigHash() +{ +} + +template <class Elem> +const Elem * +ConfigHash<Elem>::lookup(const vespalib::string &name) const +{ + auto itr = _hash.find(name); + return ((itr == _hash.end()) ? nullptr : itr->second); +} + +} // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/common/i_indexschema_inspector.h b/searchcore/src/vespa/searchcore/proton/common/i_indexschema_inspector.h new file mode 100644 index 00000000000..754f1c39299 --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/common/i_indexschema_inspector.h @@ -0,0 +1,18 @@ +// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <vespa/vespalib/stllike/string.h> + +namespace proton { + +/** + * Interface for inspector for an indexschema config. + */ +class IIndexschemaInspector { +public: + virtual ~IIndexschemaInspector() { } + virtual bool isStringIndex(const vespalib::string &name) const = 0; +}; + +} // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/common/indexschema_inspector.cpp b/searchcore/src/vespa/searchcore/proton/common/indexschema_inspector.cpp new file mode 100644 index 00000000000..da836278b7c --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/common/indexschema_inspector.cpp @@ -0,0 +1,31 @@ +// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "indexschema_inspector.h" +#include <vespa/config-indexschema.h> +#include "config_hash.hpp" + +namespace proton { + +IndexschemaInspector::IndexschemaInspector(const IndexschemaConfig &config) + : IIndexschemaInspector(), + _hash(config.indexfield) +{ +} + +IndexschemaInspector::~IndexschemaInspector() +{ +} + +bool +IndexschemaInspector::isStringIndex(const vespalib::string &name) const +{ + auto index = _hash.lookup(name); + if (index != nullptr) { + if (index->datatype == IndexschemaConfig::Indexfield::Datatype::STRING) { + return true; + } + } + return false; +} + +} // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/common/indexschema_inspector.h b/searchcore/src/vespa/searchcore/proton/common/indexschema_inspector.h new file mode 100644 index 00000000000..9faa58d7216 --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/common/indexschema_inspector.h @@ -0,0 +1,23 @@ +// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "i_indexschema_inspector.h" +#include "config_hash.h" +#include <vespa/config-indexschema.h> + +namespace proton { + +/** + * Inspector for an indexschema config. + */ +class IndexschemaInspector : public IIndexschemaInspector { + using IndexschemaConfig = const vespa::config::search::internal::InternalIndexschemaType; + ConfigHash<IndexschemaConfig::Indexfield> _hash; +public: + IndexschemaInspector(const IndexschemaConfig &config); + ~IndexschemaInspector(); + bool isStringIndex(const vespalib::string &name) const override; +}; + +} // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/common/selectpruner.cpp b/searchcore/src/vespa/searchcore/proton/common/selectpruner.cpp index f4ae3dc0dd4..12acfdcfd7e 100644 --- a/searchcore/src/vespa/searchcore/proton/common/selectpruner.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/selectpruner.cpp @@ -14,6 +14,7 @@ LOG_SETUP(".proton.common.selectpruner"); #include <vespa/document/select/doctype.h> #include <vespa/document/select/invalidconstant.h> #include <vespa/document/select/constant.h> +#include <vespa/searchlib/attribute/iattributemanager.h> using document::select::And; @@ -46,17 +47,18 @@ using document::select::ValueNode; using document::FieldPath; using document::Field; using document::FieldNotFoundException; +using search::AttributeGuard; namespace proton { SelectPrunerBase::SelectPrunerBase(const vespalib::string &docType, - const search::index::Schema &schema, + const search::IAttributeManager *amgr, const document::Document &emptyDoc, const document::DocumentTypeRepo &repo, bool hasFields) : _docType(docType), - _schema(schema), + _amgr(amgr), _emptyDoc(emptyDoc), _repo(repo), _hasFields(hasFields) @@ -65,7 +67,7 @@ SelectPrunerBase::SelectPrunerBase(const vespalib::string &docType, SelectPrunerBase::SelectPrunerBase(const SelectPrunerBase &rhs) : _docType(rhs._docType), - _schema(rhs._schema), + _amgr(rhs._amgr), _emptyDoc(rhs._emptyDoc), _repo(rhs._repo), _hasFields(rhs._hasFields) @@ -73,12 +75,12 @@ SelectPrunerBase::SelectPrunerBase(const SelectPrunerBase &rhs) } SelectPruner::SelectPruner(const vespalib::string &docType, - const search::index::Schema &schema, + const search::IAttributeManager *amgr, const document::Document &emptyDoc, const document::DocumentTypeRepo &repo, bool hasFields) : CloningVisitor(), - SelectPrunerBase(docType, schema, emptyDoc, repo, hasFields), + SelectPrunerBase(docType, amgr, emptyDoc, repo, hasFields), _inverted(false), _wantInverted(false), _attrFieldNodes(0u) @@ -426,8 +428,11 @@ SelectPruner::visitFieldValueNode(const FieldValueNode &expr) _valueNode = expr.clone(); // Replace with different node type for attrs ? _valueNode->clearParentheses(); ++_fieldNodes; - if (_schema.isAttributeField(name)) { - ++_attrFieldNodes; + if (_amgr != nullptr) { + AttributeGuard::UP ag(_amgr->getAttribute(name)); + if (ag->valid()) { + ++_attrFieldNodes; + } } _priority = FieldValuePriority; } diff --git a/searchcore/src/vespa/searchcore/proton/common/selectpruner.h b/searchcore/src/vespa/searchcore/proton/common/selectpruner.h index 9a7cd35627d..92bbb435349 100644 --- a/searchcore/src/vespa/searchcore/proton/common/selectpruner.h +++ b/searchcore/src/vespa/searchcore/proton/common/selectpruner.h @@ -6,7 +6,8 @@ #include <vespa/document/select/cloningvisitor.h> #include <vespa/document/select/operator.h> #include <vespa/document/select/resultset.h> -#include <vespa/searchcommon/common/schema.h> + +namespace search { class IAttributeManager; } namespace proton { @@ -15,14 +16,14 @@ class SelectPrunerBase { protected: const vespalib::string &_docType; - const search::index::Schema &_schema; + const search::IAttributeManager *_amgr; const document::Document &_emptyDoc; const document::DocumentTypeRepo &_repo; bool _hasFields; public: SelectPrunerBase(const vespalib::string &docType, - const search::index::Schema &schema, + const search::IAttributeManager *amgr, const document::Document &emptyDoc, const document::DocumentTypeRepo &repo, bool hasFields); @@ -43,7 +44,7 @@ private: uint32_t _attrFieldNodes; public: SelectPruner(const vespalib::string &docType, - const search::index::Schema &schema, + const search::IAttributeManager *amgr, const document::Document &emptyDoc, const document::DocumentTypeRepo &repo, bool hasFields); diff --git a/searchcore/src/vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.cpp b/searchcore/src/vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.cpp index e572a5494f3..c5c46b7f1af 100644 --- a/searchcore/src/vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.cpp +++ b/searchcore/src/vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.cpp @@ -5,6 +5,7 @@ #include <vespa/searchcore/proton/attribute/attribute_populator.h> #include <vespa/searchcore/proton/attribute/document_field_populator.h> #include <vespa/searchcore/proton/attribute/filter_attribute_manager.h> +#include <vespa/searchcore/proton/common/i_indexschema_inspector.h> #include <vespa/searchlib/attribute/attributevector.h> #include <vespa/log/log.h> @@ -15,6 +16,7 @@ using search::AttributeGuard; using search::AttributeVector; using search::SerialNum; using search::index::schema::DataType; +using search::attribute::BasicType; namespace proton { @@ -30,9 +32,11 @@ toStr(bool value) return (value ? "true" : "false"); } -bool fastPartialUpdateAttribute(const schema::DataType &attrType) { +bool fastPartialUpdateAttribute(BasicType::Type attrType) { // Partial update to tensor or predicate attribute must update document - return ((attrType != DataType::BOOLEANTREE) && (attrType != DataType::TENSOR) && (attrType != DataType::REFERENCE)); + return ((attrType != BasicType::Type::PREDICATE) && + (attrType != BasicType::Type::TENSOR) && + (attrType != BasicType::Type::REFERENCE)); } @@ -90,6 +94,7 @@ std::vector<IReprocessingRewriter::SP> getFieldsToPopulate(const ARIConfig &newCfg, const ARIConfig &oldCfg, const IDocumentTypeInspector &inspector, + const IIndexschemaInspector &oldIndexschemaInspector, const vespalib::string &subDbName) { std::vector<IReprocessingRewriter::SP> fieldsToPopulate; @@ -98,24 +103,23 @@ getFieldsToPopulate(const ARIConfig &newCfg, for (const auto &guard : attrList) { const vespalib::string &name = guard->getName(); Schema::AttributeField attrField = getAttributeField(oldCfg.getSchema(), name); - Schema::DataType attrType(attrField.getDataType()); + BasicType attrType(guard->getConfig().basicType()); bool inNewAttrMgr = newCfg.getAttrMgr()->getAttribute(name)->valid(); bool unchangedField = inspector.hasUnchangedField(name); // NOTE: If it is a string and index field we shall // keep the original in order to preserve annotations. - bool isStringIndexField = attrField.getDataType() == DataType::STRING && - newCfg.getSchema().isIndexField(name); - bool populateField = !inNewAttrMgr && unchangedField && !isStringIndexField && - fastPartialUpdateAttribute(attrType); + bool wasStringIndexField = oldIndexschemaInspector.isStringIndex(name); + bool populateField = !inNewAttrMgr && unchangedField && !wasStringIndexField && + fastPartialUpdateAttribute(attrType.type()); LOG(debug, "getFieldsToPopulate(): name='%s', inNewAttrMgr=%s, unchangedField=%s, " - "isStringIndexField=%s, dataType=%s, populate=%s", + "wasStringIndexField=%s, dataType=%s, populate=%s", name.c_str(), toStr(inNewAttrMgr), toStr(unchangedField), - toStr(isStringIndexField), - schema::getTypeName(attrType).c_str(), + toStr(wasStringIndexField), + attrType.asString(), toStr(populateField)); if (populateField) { fieldsToPopulate.push_back(IReprocessingRewriter::SP - (new DocumentFieldPopulator(attrField, + (new DocumentFieldPopulator(name, guard.getSP(), subDbName))); } } @@ -128,10 +132,11 @@ AttributeReprocessingInitializer:: AttributeReprocessingInitializer(const Config &newCfg, const Config &oldCfg, const IDocumentTypeInspector &inspector, + const IIndexschemaInspector &oldIndexschemaInspector, const vespalib::string &subDbName, search::SerialNum serialNum) : _attrsToPopulate(getAttributesToPopulate(newCfg, oldCfg, inspector, subDbName, serialNum)), - _fieldsToPopulate(getFieldsToPopulate(newCfg, oldCfg, inspector, subDbName)) + _fieldsToPopulate(getFieldsToPopulate(newCfg, oldCfg, inspector, oldIndexschemaInspector, subDbName)) { } diff --git a/searchcore/src/vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.h b/searchcore/src/vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.h index 05aa10db4e5..dd58d704b0f 100644 --- a/searchcore/src/vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.h +++ b/searchcore/src/vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.h @@ -11,6 +11,8 @@ namespace proton { +class IIndexschemaInspector; + /** * Class responsible for initialize reprocessing of attribute vectors if needed. */ @@ -43,6 +45,7 @@ public: AttributeReprocessingInitializer(const Config &newCfg, const Config &oldCfg, const IDocumentTypeInspector &inspector, + const IIndexschemaInspector &oldIndexschemaInspector, const vespalib::string &subDbName, search::SerialNum serialNum); diff --git a/searchcore/src/vespa/searchcore/proton/server/documentretriever.cpp b/searchcore/src/vespa/searchcore/proton/server/documentretriever.cpp index cf16498b3be..a661cb371bc 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentretriever.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentretriever.cpp @@ -128,7 +128,7 @@ void DocumentRetriever::populate(DocumentIdT lid, Document & doc) const const Schema::AttributeField &field = _schema.getAttributeField(i); AttributeGuard::UP attr = _attr_manager.getAttribute(field.getName()); if (attr.get() && attr->valid()) { - DocumentFieldRetriever::populate(lid, doc, field, **attr, _schema.isIndexField(field.getName())); + DocumentFieldRetriever::populate(lid, doc, field.getName(), **attr, _schema.isIndexField(field.getName())); } } fillInPositionFields(doc, lid, _possiblePositionFields, _attr_manager); diff --git a/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.cpp b/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.cpp index 5c77d573788..7a49085e42c 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentretrieverbase.cpp @@ -91,7 +91,6 @@ DocumentRetrieverBase::parseSelect(const vespalib::string &selection) const _docTypeName.getName(), *_emptyDoc, getDocumentTypeRepo(), - getSchema(), getAttrMgr(), _hasFields); diff --git a/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.cpp b/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.cpp index 5aa608607a3..daee4aa818a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentsubdbcollection.cpp @@ -128,11 +128,10 @@ DocumentSubDBCollection::~DocumentSubDBCollection() void DocumentSubDBCollection::createRetrievers() { - RetrieversSP retrievers(new std::vector<IDocumentRetriever::SP>); - retrievers->resize(_subDBs.size()); - uint32_t i = 0; + RetrieversSP retrievers(std::make_shared<std::vector<IDocumentRetriever::SP>>()); + retrievers->reserve(_subDBs.size()); for (auto subDb : _subDBs) { - (*retrievers)[i++].reset(subDb->getDocumentRetriever().release()); + retrievers->emplace_back(subDb->getDocumentRetriever()); } _retrievers.set(retrievers); } diff --git a/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb_configurer.cpp b/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb_configurer.cpp index cbd49784669..2d59191a162 100644 --- a/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb_configurer.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb_configurer.cpp @@ -8,6 +8,7 @@ LOG_SETUP(".proton.server.fast_access_doc_subdb_configurer"); #include "i_attribute_writer_factory.h" #include <vespa/searchcore/proton/attribute/attribute_writer.h> #include <vespa/searchcore/proton/common/document_type_inspector.h> +#include <vespa/searchcore/proton/common/indexschema_inspector.h> #include <vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.h> using document::DocumentTypeRepo; @@ -60,10 +61,11 @@ FastAccessDocSubDBConfigurer::reconfigure(const DocumentDBConfig &newConfig, assert(newDocType != nullptr); assert(oldDocType != nullptr); DocumentTypeInspector inspector(*oldDocType, *newDocType); + IndexschemaInspector oldIndexschemaInspector(oldConfig.getIndexschemaConfig()); return std::make_unique<AttributeReprocessingInitializer> (ARIConfig(writer->getAttributeManager(), *newConfig.getSchemaSP()), ARIConfig(oldView->getAttributeWriter()->getAttributeManager(), *oldConfig.getSchemaSP()), - inspector, _subDbName, attrSpec.getCurrentSerialNum()); + inspector, oldIndexschemaInspector, _subDbName, attrSpec.getCurrentSerialNum()); } } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp index c6a6a4529a8..5aec05ce1de 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp @@ -5,6 +5,7 @@ #include <vespa/searchcore/proton/attribute/attribute_writer.h> #include <vespa/searchcore/proton/attribute/imported_attributes_repo.h> #include <vespa/searchcore/proton/common/document_type_inspector.h> +#include <vespa/searchcore/proton/common/indexschema_inspector.h> #include <vespa/searchcore/proton/reference/i_document_db_reference_resolver.h> #include <vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.h> @@ -172,10 +173,11 @@ createAttributeReprocessingInitializer(const DocumentDBConfig &newConfig, assert(newDocType != nullptr); assert(oldDocType != nullptr); DocumentTypeInspector inspector(*oldDocType, *newDocType); + IndexschemaInspector oldIndexschemaInspector(oldConfig.getIndexschemaConfig()); return std::make_unique<AttributeReprocessingInitializer> (ARIConfig(newAttrMgr, *newConfig.getSchemaSP()), ARIConfig(oldAttrMgr, *oldConfig.getSchemaSP()), - inspector, subDbName, serialNum); + inspector, oldIndexschemaInspector, subDbName, serialNum); } } |