diff options
author | Henning Baldersheim <balder@oath.com> | 2018-11-13 13:24:03 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-11-13 13:24:03 +0100 |
commit | 4cc373dcca6ae9f2f3d2d0fce7c6f2760c78efd3 (patch) | |
tree | 990991da3b7c87f5e8ba891d3beb3bba36bc836e | |
parent | 03c01d5476f9884b31328e8301e5e6e7bf7752ab (diff) |
Add test and fix that repeated reconfigs works for schema changes.
4 files changed, 32 insertions, 51 deletions
diff --git a/config/src/vespa/config/retriever/configretriever.cpp b/config/src/vespa/config/retriever/configretriever.cpp index 1d79e59c968..2056ae6351d 100644 --- a/config/src/vespa/config/retriever/configretriever.cpp +++ b/config/src/vespa/config/retriever/configretriever.cpp @@ -22,7 +22,7 @@ ConfigRetriever::ConfigRetriever(const ConfigKeySet & bootstrapSet, { } -ConfigRetriever::~ConfigRetriever() {} +ConfigRetriever::~ConfigRetriever() = default; ConfigSnapshot ConfigRetriever::getBootstrapConfigs(int timeoutInMillis) @@ -50,11 +50,11 @@ ConfigRetriever::getConfigs(const ConfigKeySet & keySet, int timeoutInMillis) vespalib::LockGuard guard(_lock); if (_closed) return ConfigSnapshot(); - _configSubscriber.reset(new GenericConfigSubscriber(_context)); + _configSubscriber = std::make_unique<GenericConfigSubscriber>(_context); } _subscriptionList.clear(); - for (ConfigKeySet::const_iterator it(keySet.begin()), mt(keySet.end()); it != mt; it++) { - _subscriptionList.push_back(_configSubscriber->subscribe(*it, _subscribeTimeout)); + for (const auto & key : keySet) { + _subscriptionList.push_back(_configSubscriber->subscribe(key, _subscribeTimeout)); } } // Try update the subscribers generation if older than bootstrap @@ -81,7 +81,7 @@ ConfigRetriever::close() vespalib::LockGuard guard(_lock); _closed = true; _bootstrapSubscriber.close(); - if (_configSubscriber.get() != NULL) + if (_configSubscriber) _configSubscriber->close(); } diff --git a/config/src/vespa/config/retriever/configsnapshot.cpp b/config/src/vespa/config/retriever/configsnapshot.cpp index 7a095cacc3c..c5246aab9c9 100644 --- a/config/src/vespa/config/retriever/configsnapshot.cpp +++ b/config/src/vespa/config/retriever/configsnapshot.cpp @@ -21,13 +21,9 @@ ConfigSnapshot::ConfigSnapshot() : _valueMap(), _generation(0) {} -ConfigSnapshot::~ConfigSnapshot() { -} +ConfigSnapshot::~ConfigSnapshot() = default; -ConfigSnapshot::ConfigSnapshot(const ConfigSnapshot &rhs) : - _valueMap(rhs._valueMap), - _generation(rhs._generation) { -} +ConfigSnapshot::ConfigSnapshot(const ConfigSnapshot &rhs) = default; ConfigSnapshot & ConfigSnapshot::operator=(const ConfigSnapshot &rhs) { diff --git a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp index 2817ddb1b85..d09f8141008 100644 --- a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp +++ b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp @@ -267,16 +267,22 @@ TEST_FF("require that documentdb config manager builds schema with imported attr docType->attributesBuilder.attribute[0].name = "imported"; docType->attributesBuilder.attribute[0].imported = true; docType->attributesBuilder.attribute[1].name = "regular"; - - const auto &schema = getDocumentDBConfig(f1, f2)->getSchemaSP(); - EXPECT_EQUAL(1u, schema->getNumImportedAttributeFields()); - EXPECT_EQUAL("imported", schema->getImportedAttributeFields()[0].getName()); - EXPECT_EQUAL(1u, schema->getNumAttributeFields()); - EXPECT_EQUAL("regular", schema->getAttributeFields()[0].getName()); - - const auto &attrCfg = getDocumentDBConfig(f1, f2)->getAttributesConfig(); - EXPECT_EQUAL(1u, attrCfg.attribute.size()); - EXPECT_EQUAL("regular", attrCfg.attribute[0].name); + docType->summaryBuilder.classes.resize(1); + docType->summaryBuilder.classes[0].id = 1; + docType->summaryBuilder.classes[0].name = "a"; + + for (size_t i(0); i < 3; i++) { + const auto &schema = getDocumentDBConfig(f1, f2)->getSchemaSP(); + EXPECT_EQUAL(1u, schema->getNumImportedAttributeFields()); + EXPECT_EQUAL("imported", schema->getImportedAttributeFields()[0].getName()); + EXPECT_EQUAL(1u, schema->getNumAttributeFields()); + EXPECT_EQUAL("regular", schema->getAttributeFields()[0].getName()); + + const auto &attrCfg = getDocumentDBConfig(f1, f2)->getAttributesConfig(); + EXPECT_EQUAL(1u, attrCfg.attribute.size()); + EXPECT_EQUAL("regular", attrCfg.attribute[0].name); + docType->summaryBuilder.classes[0].id = i+2; + } } TEST_FFF("require that proton config fetcher follows changes to bootstrap", diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp index f2230215c3d..99c4cfb8130 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp @@ -234,11 +234,6 @@ DocumentDBConfigManager::update(const ConfigSnapshot &snapshot) RankProfilesConfigSP newRankProfilesConfig; matching::RankingConstants::SP newRankingConstants; IndexschemaConfigSP newIndexschemaConfig; - AttributesConfigSP newAttributesConfig; - SummaryConfigSP newSummaryConfig; - SummarymapConfigSP newSummarymapConfig; - JuniperrcConfigSP newJuniperrcConfig; - ImportedFieldsConfigSP newImportedFieldsConfig; MaintenanceConfigSP oldMaintenanceConfig; MaintenanceConfigSP newMaintenanceConfig; @@ -262,11 +257,6 @@ DocumentDBConfigManager::update(const ConfigSnapshot &snapshot) newRankProfilesConfig = current->getRankProfilesConfigSP(); newRankingConstants = current->getRankingConstantsSP(); newIndexschemaConfig = current->getIndexschemaConfigSP(); - newAttributesConfig = current->getAttributesConfigSP(); - newSummaryConfig = current->getSummaryConfigSP(); - newSummarymapConfig = current->getSummarymapConfigSP(); - newJuniperrcConfig = current->getJuniperrcConfigSP(); - newImportedFieldsConfig = current->getImportedFieldsConfigSP(); oldMaintenanceConfig = current->getMaintenanceConfigSP(); currentGeneration = current->getGeneration(); } @@ -307,31 +297,20 @@ DocumentDBConfigManager::update(const ConfigSnapshot &snapshot) LOG_ABORT("Cannot use bad index schema, validation failed"); } } - if (snapshot.isChanged<AttributesConfig>(_configId, currentGeneration)) { - newAttributesConfig = snapshot.getConfig<AttributesConfig>(_configId); - } - if (snapshot.isChanged<SummaryConfig>(_configId, currentGeneration)) { - newSummaryConfig = snapshot.getConfig<SummaryConfig>(_configId); - } - if (snapshot.isChanged<SummarymapConfig>(_configId, currentGeneration)) { - newSummarymapConfig = snapshot.getConfig<SummarymapConfig>(_configId); - } - if (snapshot.isChanged<JuniperrcConfig>(_configId, currentGeneration)) { - newJuniperrcConfig = snapshot.getConfig<JuniperrcConfig>(_configId); - } - if (snapshot.isChanged<ImportedFieldsConfig>(_configId, currentGeneration)) { - newImportedFieldsConfig = snapshot.getConfig<ImportedFieldsConfig>(_configId); - } + AttributesConfigSP newAttributesConfig = snapshot.getConfig<AttributesConfig>(_configId); + SummaryConfigSP newSummaryConfig = snapshot.getConfig<SummaryConfig>(_configId); + SummarymapConfigSP newSummarymapConfig = snapshot.getConfig<SummarymapConfig>(_configId); + JuniperrcConfigSP newJuniperrcConfig = snapshot.getConfig<JuniperrcConfig>(_configId); + ImportedFieldsConfigSP newImportedFieldsConfig = snapshot.getConfig<ImportedFieldsConfig>(_configId); Schema::SP schema(buildSchema(*newAttributesConfig, *newSummaryConfig, *newIndexschemaConfig)); newMaintenanceConfig = buildMaintenanceConfig(_bootstrapConfig, _docTypeName); search::LogDocumentStore::Config storeConfig = buildStoreConfig(_bootstrapConfig->getProtonConfig(), _bootstrapConfig->getHwInfo()); - if (newMaintenanceConfig && oldMaintenanceConfig && *newMaintenanceConfig == *oldMaintenanceConfig) { + if (newMaintenanceConfig && oldMaintenanceConfig && (*newMaintenanceConfig == *oldMaintenanceConfig)) { newMaintenanceConfig = oldMaintenanceConfig; } - DocumentDBConfig::SP newSnapshot( - new DocumentDBConfig(generation, + auto newSnapshot = std::make_shared<DocumentDBConfig>(generation, newRankProfilesConfig, newRankingConstants, newIndexschemaConfig, @@ -347,7 +326,7 @@ DocumentDBConfigManager::update(const ConfigSnapshot &snapshot) newMaintenanceConfig, storeConfig, _configId, - _docTypeName)); + _docTypeName); assert(newSnapshot->valid()); { std::lock_guard<std::mutex> lock(_pendingConfigMutex); @@ -366,7 +345,7 @@ DocumentDBConfigManager(const vespalib::string &configId, const vespalib::string _pendingConfigMutex() { } -DocumentDBConfigManager::~DocumentDBConfigManager() { } +DocumentDBConfigManager::~DocumentDBConfigManager() = default; DocumentDBConfig::SP DocumentDBConfigManager::getConfig() const { |