diff options
author | Tor Egge <Tor.Egge@yahoo-inc.com> | 2017-04-21 10:51:40 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@yahoo-inc.com> | 2017-04-21 10:51:40 +0000 |
commit | 294b178e55aa778107a16f37e67fe989830df46f (patch) | |
tree | aef47f47db03565a70e5a346ac32a36af200f0c8 /searchcore | |
parent | 7b6ca3c1e2fa23d72a820add54f6ce4d4ac8a882 (diff) |
Add factory method for delaying attribute aspect changes in document db config.
Diffstat (limited to 'searchcore')
3 files changed, 129 insertions, 3 deletions
diff --git a/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp b/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp index a1f5b606415..cc953423604 100644 --- a/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp +++ b/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp @@ -7,6 +7,8 @@ #include <vespa/searchcore/proton/test/documentdb_config_builder.h> #include <vespa/vespalib/testkit/testapp.h> #include <vespa/config-summarymap.h> +#include <vespa/document/repo/configbuilder.h> +#include <vespa/document/repo/documenttyperepo.h> using namespace document; using namespace proton; @@ -17,9 +19,32 @@ using proton::matching::RankingConstants; using std::make_shared; using std::shared_ptr; using vespa::config::search::core::RankingConstantsConfig; +using document::config_builder::DocumenttypesConfigBuilderHelper; +using document::config_builder::Struct; using ConfigSP = shared_ptr<DocumentDBConfig>; +namespace { + +const int32_t doc_type_id = 787121340; +const vespalib::string type_name = "test"; +const vespalib::string header_name = type_name + ".header"; +const vespalib::string body_name = type_name + ".body"; + +DocumentTypeRepo::SP +makeDocTypeRepo(bool hasField) +{ + DocumenttypesConfigBuilderHelper builder; + Struct body(body_name); + if (hasField) { + body.addField("my_attribute", DataType::T_INT); + } + builder.document(doc_type_id, type_name, Struct(header_name), body); + return make_shared<DocumentTypeRepo>(builder.config()); +} + +} + class MyConfigBuilder { private: test::DocumentDBConfigBuilder _builder; @@ -58,13 +83,15 @@ public: builder.attribute.resize(1); AttributesConfigBuilder::Attribute &attribute = builder.attribute.back(); attribute.name = "my_attribute"; + attribute.datatype = AttributesConfigBuilder::Attribute::Datatype::INT32; _builder.attributes(make_shared<AttributesConfig>(builder)); return *this; } MyConfigBuilder &addSummarymap() { SummarymapConfigBuilder builder; builder.override.resize(1); - builder.override.back().field = "my_summary_field"; + builder.override.back().field = "my_attribute"; + builder.override.back().command = "attribute"; _builder.summarymap(make_shared<SummarymapConfig>(builder)); return *this; } @@ -113,4 +140,53 @@ TEST_F("require that makeReplayConfig() drops unneeded configs", Fixture) EXPECT_TRUE(DDBC::preferOriginalConfig(f.nullCfg).get() == nullptr); } +struct DelayAttributeAspectFixture { + Schema::SP schema; + ConfigSP attrCfg; + ConfigSP noAttrCfg; + DelayAttributeAspectFixture(bool hasDocField) + : schema(make_shared<Schema>()), + attrCfg(), + noAttrCfg() + { + attrCfg = MyConfigBuilder(4, schema, makeDocTypeRepo(true)).addAttribute(). + addRankProfile(). + addRankingConstant(). + addImportedField(). + addSummarymap(). + build(); + noAttrCfg = MyConfigBuilder(4, schema, makeDocTypeRepo(hasDocField)).addRankProfile(). + addRankingConstant(). + addImportedField(). + build(); + } + + void assertDelayedConfig(const DocumentDBConfig &testCfg) { + EXPECT_FALSE(noAttrCfg->getAttributesConfig() == testCfg.getAttributesConfig()); + EXPECT_FALSE(noAttrCfg->getSummarymapConfig() == testCfg.getSummarymapConfig()); + EXPECT_TRUE(attrCfg->getAttributesConfig() == testCfg.getAttributesConfig()); + EXPECT_TRUE(attrCfg->getSummarymapConfig() == testCfg.getSummarymapConfig()); + EXPECT_TRUE(testCfg.getDelayedAttributeAspects()); + } + void assertNotDelayedConfig(const DocumentDBConfig &testCfg) { + EXPECT_TRUE(noAttrCfg->getAttributesConfig() == testCfg.getAttributesConfig()); + EXPECT_TRUE(noAttrCfg->getSummarymapConfig() == testCfg.getSummarymapConfig()); + EXPECT_FALSE(attrCfg->getAttributesConfig() == testCfg.getAttributesConfig()); + EXPECT_FALSE(attrCfg->getSummarymapConfig() == testCfg.getSummarymapConfig()); + EXPECT_FALSE(testCfg.getDelayedAttributeAspects()); + } +}; + +TEST_F("require that makeDelayedAttributeAspectConfig works, field remains when attribute removed", DelayAttributeAspectFixture(true)) +{ + auto delayedRemove = DocumentDBConfig::makeDelayedAttributeAspectConfig(f.noAttrCfg, *f.attrCfg); + TEST_DO(f.assertDelayedConfig(*delayedRemove)); +} + +TEST_F("require that makeDelayedAttributeAspectConfig works, field removed with attribute", DelayAttributeAspectFixture(false)) +{ + auto removed = DocumentDBConfig::makeDelayedAttributeAspectConfig(f.noAttrCfg, *f.attrCfg); + TEST_DO(f.assertNotDelayedConfig(*removed)); +} + TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.cpp index dc1379ee316..9ce65468b54 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.cpp @@ -9,6 +9,9 @@ #include <vespa/config-summarymap.h> #include <vespa/searchsummary/config/config-juniperrc.h> #include <vespa/document/config/config-documenttypes.h> +#include <vespa/searchcore/proton/attribute/attribute_aspect_delayer.h> +#include <vespa/searchcore/proton/common/document_type_inspector.h> +#include <vespa/searchcore/proton/common/indexschema_inspector.h> using namespace config; using namespace vespa::config::search::summary; @@ -74,7 +77,8 @@ DocumentDBConfig::DocumentDBConfig( _schema(schema), _maintenance(maintenance), _extraConfigs(extraConfigs), - _orig() + _orig(), + _delayedAttributeAspects(false) { } @@ -97,7 +101,8 @@ DocumentDBConfig(const DocumentDBConfig &cfg) _schema(cfg._schema), _maintenance(cfg._maintenance), _extraConfigs(cfg._extraConfigs), - _orig(cfg._orig) + _orig(cfg._orig), + _delayedAttributeAspects(false) { } DocumentDBConfig::~DocumentDBConfig() { } @@ -270,4 +275,41 @@ DocumentDBConfig::newFromAttributesConfig(const AttributesConfigSP &attributes) _extraConfigs); } +DocumentDBConfig::SP +DocumentDBConfig::makeDelayedAttributeAspectConfig(const SP &orig, const DocumentDBConfig &old) +{ + const DocumentDBConfig &o = *orig; + AttributeAspectDelayer attributeAspectDelayer; + DocumentTypeInspector inspector(*old.getDocumentType(), *o.getDocumentType()); + IndexschemaInspector oldIndexschemaInspector(old.getIndexschemaConfig()); + attributeAspectDelayer.setup(old.getAttributesConfig(), old.getSummarymapConfig(), + o.getAttributesConfig(), o.getSummarymapConfig(), + oldIndexschemaInspector, inspector); + bool delayedAttributeAspects = (o.getAttributesConfig() != *attributeAspectDelayer.getAttributesConfig()) || + (o.getSummarymapConfig() != *attributeAspectDelayer.getSummarymapConfig()); + if (!delayedAttributeAspects) { + return orig; + } + auto result = std::make_shared<DocumentDBConfig> + (o._generation, + o._rankProfiles, + o._rankingConstants, + o._indexschema, + attributeAspectDelayer.getAttributesConfig(), + o._summary, + attributeAspectDelayer.getSummarymapConfig(), + o._juniperrc, + o._documenttypes, + o._repo, + o._importedFields, + o._tuneFileDocumentDB, + o._schema, + o._maintenance, + o._configId, + o._docTypeName, + o._extraConfigs); + result->_delayedAttributeAspects = true; + return result; +} + } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.h b/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.h index b581655330d..06943a7c415 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.h +++ b/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.h @@ -93,6 +93,7 @@ private: MaintenanceConfigSP _maintenance; config::ConfigSnapshot _extraConfigs; SP _orig; + bool _delayedAttributeAspects; template <typename T> @@ -155,6 +156,7 @@ public: const search::index::Schema::SP &getSchemaSP() const { return _schema; } const MaintenanceConfigSP &getMaintenanceConfigSP() const { return _maintenance; } const search::TuneFileDocumentDB::SP &getTuneFileDocumentDBSP() const { return _tuneFileDocumentDB; } + bool getDelayedAttributeAspects() const { return _delayedAttributeAspects; } bool operator==(const DocumentDBConfig &rhs) const; @@ -189,6 +191,12 @@ public: * Create modified attributes config. */ SP newFromAttributesConfig(const AttributesConfigSP &attributes) const; + + /** + * Create config with delayed attribute aspect changes if they require + * reprocessing. + */ + static SP makeDelayedAttributeAspectConfig(const SP &orig, const DocumentDBConfig &old); }; } // namespace proton |