diff options
author | Tor Egge <Tor.Egge@yahoo-inc.com> | 2017-04-07 09:43:05 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@yahoo-inc.com> | 2017-04-07 09:43:05 +0000 |
commit | b7b3ed8cf039f7fc68043fd77c7844f572e02738 (patch) | |
tree | 46bf6217a94d0fe8d0da53375c99f67df581d20b /searchcore | |
parent | 7f74f37a09ae1d387e7d0dce97680084613d568d (diff) |
Factor out index schema inspector.
Diffstat (limited to 'searchcore')
7 files changed, 82 insertions, 26 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/vespa/searchcore/proton/attribute/attribute_specs_builder.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attribute_specs_builder.cpp index f7e232345b3..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,15 +3,14 @@ #include "attribute_specs_builder.h" #include <vespa/searchlib/attribute/configconverter.h> #include <vespa/searchcore/proton/common/i_document_type_inspector.h> +#include <vespa/searchcore/proton/common/i_indexschema_inspector.h> #include <vespa/searchcore/proton/common/config_hash.hpp> -#include <vespa/config-indexschema.h> #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 { @@ -19,7 +18,6 @@ namespace proton { namespace { using AttributesConfigHash = ConfigHash<AttributesConfig::Attribute>; -using IndexConfigHash = ConfigHash<IndexschemaConfig::Indexfield>; bool fastPartialUpdateAttribute(const search::attribute::Config &cfg) { auto basicType = cfg.basicType().type(); @@ -28,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); } @@ -86,7 +73,7 @@ namespace { void handleNewAttributes(const AttributesConfig &oldAttributesConfig, const AttributesConfig &newAttributesConfig, - IndexConfigHash &oldIndexes, + const IIndexschemaInspector &oldIndexschemaInspector, const IDocumentTypeInspector &inspector, AttributeSpecs &specs, AttributesConfigBuilder &config) @@ -102,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); @@ -131,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) @@ -144,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); } @@ -158,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/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/i_indexschema_inspector.h b/searchcore/src/vespa/searchcore/proton/common/i_indexschema_inspector.h new file mode 100644 index 00000000000..db12ed70c97 --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/common/i_indexschema_inspector.h @@ -0,0 +1,15 @@ +// 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 { + +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..4bb1cbd8e62 --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/common/indexschema_inspector.h @@ -0,0 +1,20 @@ +// 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 { + +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 |