diff options
author | Tor Egge <Tor.Egge@online.no> | 2023-02-07 21:07:20 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2023-02-07 21:07:20 +0100 |
commit | e01009d71d7fa61a7e1542acfd4e135f0e973b21 (patch) | |
tree | ec78c465a11ce0f6a77c1674dffd1d3243403e3b | |
parent | b54fcbf62f49e617d4cc453a5368cc864be54c36 (diff) |
Prepare new attribute manager in prepare_reconfig.
25 files changed, 139 insertions, 160 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 88d0752461b..8dc2551d96b 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 @@ -867,7 +867,7 @@ TEST_F("require that shrink flushtarget is handed over to new attribute manager" am1->addAttribute({"a1", INT32_SINGLE}, 4); AttrSpecList newSpec; newSpec.emplace_back("a1", INT32_SINGLE); - auto am2 = am1->create(AttrMgrSpec(std::move(newSpec), 5, 20)); + auto am2 = am1->prepare_create(AttrMgrSpec(std::move(newSpec), 5, 20))->create(5, 20); auto am3 = std::dynamic_pointer_cast<AttributeManager>(am2); TEST_DO(assertShrinkTargetSerial(*am3, "a1", 3)); EXPECT_EQUAL(am1->getShrinker("a1"), am3->getShrinker("a1")); diff --git a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp index d7ce042a4d3..60f6c02d45a 100644 --- a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp +++ b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp @@ -15,7 +15,6 @@ #include <vespa/searchcore/proton/matching/sessionmanager.h> #include <vespa/searchcore/proton/reference/dummy_gid_to_lid_change_handler.h> #include <vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.h> -#include <vespa/searchcore/proton/server/attribute_writer_factory.h> #include <vespa/searchcore/proton/server/document_subdb_reconfig.h> #include <vespa/searchcore/proton/server/fast_access_doc_subdb_configurer.h> #include <vespa/searchcore/proton/server/reconfig_params.h> @@ -246,7 +245,11 @@ Fixture::reconfigure(const DocumentDBConfig& new_config_snapshot, IDocumentDBReferenceResolver& resolver, SerialNum serial_num) { - auto prepared_reconfig = _configurer->prepare_reconfig(new_config_snapshot, old_config_snapshot, reconfig_params, serial_num); + EXPECT_FALSE(reconfig_params.shouldAttributeManagerChange()); + uint32_t docid_limit = 1; + AttributeCollectionSpec attr_spec(AttributeCollectionSpec::AttributeList(), docid_limit, serial_num); + auto prepared_reconfig = _configurer->prepare_reconfig(new_config_snapshot, old_config_snapshot, std::move(attr_spec), reconfig_params, serial_num); + prepared_reconfig->complete(docid_limit, serial_num); _configurer->reconfigure(new_config_snapshot, old_config_snapshot, reconfig_params, resolver, *prepared_reconfig, serial_num); } @@ -258,8 +261,10 @@ Fixture::reconfigure(const DocumentDBConfig& new_config_snapshot, IDocumentDBReferenceResolver& resolver, SerialNum serial_num) { - auto prepared_reconfig = _configurer->prepare_reconfig(new_config_snapshot, old_config_snapshot, reconfig_params, serial_num); - return _configurer->reconfigure(new_config_snapshot, old_config_snapshot, std::move(attr_spec), reconfig_params, resolver, *prepared_reconfig, serial_num); + auto docid_limit = attr_spec.getDocIdLimit(); + auto prepared_reconfig = _configurer->prepare_reconfig(new_config_snapshot, old_config_snapshot, std::move(attr_spec), reconfig_params, serial_num); + prepared_reconfig->complete(docid_limit, serial_num); + return _configurer->reconfigure(new_config_snapshot, old_config_snapshot, reconfig_params, resolver, *prepared_reconfig, serial_num); } using MySummaryAdapter = test::MockSummaryAdapter; @@ -318,7 +323,7 @@ struct FastAccessFixture FastAccessFixture() : _service(1), _view(_service.write()), - _configurer(_view._feedView, std::make_unique<AttributeWriterFactory>(), "test") + _configurer(_view._feedView, "test") { std::filesystem::remove_all(std::filesystem::path(BASE_DIR)); std::filesystem::create_directory(std::filesystem::path(BASE_DIR)); @@ -341,8 +346,10 @@ FastAccessFixture::reconfigure(const DocumentDBConfig& new_config_snapshot, SerialNum serial_num) { ReconfigParams reconfig_params{CCR()}; - auto prepared_reconfig = _configurer.prepare_reconfig(new_config_snapshot, old_config_snapshot, reconfig_params, serial_num); - return _configurer.reconfigure(new_config_snapshot, old_config_snapshot, std::move(attr_spec), *prepared_reconfig, serial_num); + auto docid_limit = attr_spec.getDocIdLimit(); + auto prepared_reconfig = _configurer.prepare_reconfig(new_config_snapshot, old_config_snapshot, std::move(attr_spec), reconfig_params, serial_num); + prepared_reconfig->complete(docid_limit, serial_num); + return _configurer.reconfigure(new_config_snapshot, old_config_snapshot, *prepared_reconfig, serial_num); } DocumentDBConfig::SP diff --git a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp index f49c46d81e8..db70aaaf200 100644 --- a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp +++ b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp @@ -380,6 +380,7 @@ struct FixtureBase MyDocumentDBReferenceResolver resolver; ReconfigParams reconfig_params(cmpResult); auto prepared_reconfig = _subDb.prepare_reconfig(*newCfg->_cfg, *_snapshot->_cfg, reconfig_params, serialNum); + _subDb.complete_prepare_reconfig(*prepared_reconfig, serialNum); auto tasks = _subDb.applyConfig(*newCfg->_cfg, *_snapshot->_cfg, serialNum, reconfig_params, resolver, *prepared_reconfig); prepared_reconfig.reset(); diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_reconfig.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_reconfig.cpp index 06c03c80785..4638dd476b0 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_reconfig.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_reconfig.cpp @@ -16,7 +16,7 @@ AttributeManagerReconfig::AttributeManagerReconfig(std::shared_ptr<AttributeMana AttributeManagerReconfig::~AttributeManagerReconfig() = default; -std::shared_ptr<AttributeManager> +std::shared_ptr<IAttributeManager> AttributeManagerReconfig::create(uint32_t docid_limit, search::SerialNum serial_num) { assert(_mgr); diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_reconfig.h b/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_reconfig.h index 9e4f8b71a7a..027b96b4f63 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_reconfig.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_reconfig.h @@ -2,9 +2,8 @@ #pragma once -#include <vespa/searchlib/common/serialnum.h> +#include "i_attribute_manager_reconfig.h" #include <memory> -#include <optional> namespace proton { @@ -15,14 +14,14 @@ class SequentialAttributesInitializer; * Class representing the result of the prepare step of an AttributeManager * reconfig. */ -class AttributeManagerReconfig { +class AttributeManagerReconfig : public IAttributeManagerReconfig { std::shared_ptr<AttributeManager> _mgr; std::unique_ptr<SequentialAttributesInitializer> _initializer; public: AttributeManagerReconfig(std::shared_ptr<AttributeManager> mgr, std::unique_ptr<SequentialAttributesInitializer> initializer); - ~AttributeManagerReconfig(); - std::shared_ptr<AttributeManager> create(uint32_t docid_limit, search::SerialNum serial_num); + ~AttributeManagerReconfig() override; + std::shared_ptr<IAttributeManager> create(uint32_t docid_limit, search::SerialNum serial_num) override; }; } diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp index dd6cc1bdb85..161a4294908 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp @@ -499,7 +499,7 @@ AttributeManager::createContext() const return std::make_unique<AttributeContext>(*this); } -std::unique_ptr<AttributeManagerReconfig> +std::unique_ptr<IAttributeManagerReconfig> AttributeManager::prepare_create(Spec&& spec) const { auto initializer = std::make_unique<SequentialAttributesInitializer>(spec.getDocIdLimit()); @@ -507,16 +507,6 @@ AttributeManager::prepare_create(Spec&& spec) const return std::make_unique<AttributeManagerReconfig>(std::move(result), std::move(initializer)); } -proton::IAttributeManager::SP -AttributeManager::create(Spec&& spec) const -{ - assert(spec.getCurrentSerialNum().has_value()); - auto docid_limit = spec.getDocIdLimit(); - auto serial_num = spec.getCurrentSerialNum().value(); - auto prepared_result = prepare_create(std::move(spec)); - return prepared_result->create(docid_limit, serial_num); -} - std::vector<IFlushTarget::SP> AttributeManager::getFlushTargets() const { diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h index c8c5da7f4e4..cb9f6da436f 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.h @@ -151,8 +151,7 @@ public: // Implements proton::IAttributeManager - std::unique_ptr<AttributeManagerReconfig> prepare_create(Spec && spec) const override; - proton::IAttributeManager::SP create(Spec && spec) const override; + std::unique_ptr<IAttributeManagerReconfig> prepare_create(Spec&& spec) const override; std::vector<IFlushTargetSP> getFlushTargets() const override; 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 8f57546d3c5..6f6cd01b4a4 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.cpp @@ -77,17 +77,12 @@ FilterAttributeManager::createContext() const { throw vespalib::IllegalArgumentException("Not implemented"); } -std::unique_ptr<AttributeManagerReconfig> +std::unique_ptr<IAttributeManagerReconfig> FilterAttributeManager::prepare_create(AttributeCollectionSpec&&) const { throw vespalib::IllegalArgumentException("Not implemented"); } -IAttributeManager::SP -FilterAttributeManager::create(AttributeCollectionSpec &&) const { - throw vespalib::IllegalArgumentException("Not implemented"); -} - std::vector<searchcorespi::IFlushTarget::SP> FilterAttributeManager::getFlushTargets() const { std::vector<searchcorespi::IFlushTarget::SP> completeList = _mgr->getFlushTargets(); 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 4397bf81107..dff18290330 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.h @@ -38,8 +38,7 @@ public: std::unique_ptr<search::attribute::AttributeReadGuard> getAttributeReadGuard(const vespalib::string &name, bool stableEnumGuard) const override; // Implements proton::IAttributeManager - std::unique_ptr<AttributeManagerReconfig> prepare_create(AttributeCollectionSpec&& spec) const override; - IAttributeManager::SP create(AttributeCollectionSpec &&) const override; + std::unique_ptr<IAttributeManagerReconfig> prepare_create(AttributeCollectionSpec&& spec) const override; std::vector<searchcorespi::IFlushTarget::SP> getFlushTargets() const override; search::SerialNum getOldestFlushedSerialNumber() const override; search::SerialNum getNewestFlushedSerialNumber() const override; 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 00a95607010..43f7eab8a6c 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/i_attribute_manager.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/i_attribute_manager.h @@ -21,7 +21,7 @@ namespace vespalib { namespace proton { -class AttributeManagerReconfig; +class IAttributeManagerReconfig; class ImportedAttributesRepo; /** @@ -37,13 +37,11 @@ struct IAttributeManager : public search::IAttributeManager using IAttributeFunctor = search::attribute::IAttributeFunctor; using IConstAttributeFunctor = search::attribute::IConstAttributeFunctor; - virtual std::unique_ptr<AttributeManagerReconfig> prepare_create(AttributeCollectionSpec&& spec) const = 0; - /** - * Create a new attribute manager based on the content of the current one and + * Prepare to create a new attribute manager based on the content of the current one and * the given attribute collection spec. */ - virtual IAttributeManager::SP create(AttributeCollectionSpec && spec) const = 0; + virtual std::unique_ptr<IAttributeManagerReconfig> prepare_create(AttributeCollectionSpec&& spec) const = 0; /** * Return the list of flush targets for this attribute manager. diff --git a/searchcore/src/vespa/searchcore/proton/attribute/i_attribute_manager_reconfig.h b/searchcore/src/vespa/searchcore/proton/attribute/i_attribute_manager_reconfig.h new file mode 100644 index 00000000000..13080163071 --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/attribute/i_attribute_manager_reconfig.h @@ -0,0 +1,22 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <vespa/searchlib/common/serialnum.h> +#include <memory> + +namespace proton { + +struct IAttributeManager; + +/** + * Interface class representing the result of the prepare step of an IAttributeManager + * reconfig. + */ +class IAttributeManagerReconfig { +public: + virtual ~IAttributeManagerReconfig() = default; + virtual std::shared_ptr<IAttributeManager> create(uint32_t docid_limit, search::SerialNum serial_num) = 0; +}; + +} diff --git a/searchcore/src/vespa/searchcore/proton/server/attribute_writer_factory.h b/searchcore/src/vespa/searchcore/proton/server/attribute_writer_factory.h deleted file mode 100644 index 6ca4556d666..00000000000 --- a/searchcore/src/vespa/searchcore/proton/server/attribute_writer_factory.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include "i_attribute_writer_factory.h" -#include <vespa/searchcore/proton/attribute/attribute_writer.h> -#include <vespa/searchcore/proton/attribute/attributemanager.h> - -namespace proton { - -/** - * Factory for creating new IAttributeWriter instances during reconfig. - */ -struct AttributeWriterFactory : public IAttributeWriterFactory -{ - AttributeWriterFactory() {} - IAttributeWriter::SP create(const IAttributeWriter::SP &old, - AttributeCollectionSpec && attrSpec) const override - { - const AttributeWriter &oldAdapter = dynamic_cast<const AttributeWriter &>(*old.get()); - const proton::IAttributeManager::SP &oldMgr = oldAdapter.getAttributeManager(); - proton::IAttributeManager::SP newMgr = oldMgr->create(std::move(attrSpec)); - return std::make_shared<AttributeWriter>(newMgr); - } -}; - -} // namespace proton - diff --git a/searchcore/src/vespa/searchcore/proton/server/document_subdb_reconfig.cpp b/searchcore/src/vespa/searchcore/proton/server/document_subdb_reconfig.cpp index 60514b91aab..dd1ba597287 100644 --- a/searchcore/src/vespa/searchcore/proton/server/document_subdb_reconfig.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/document_subdb_reconfig.cpp @@ -1,23 +1,34 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "document_subdb_reconfig.h" +#include <vespa/searchcore/proton/attribute/i_attribute_manager_reconfig.h> namespace proton { -DocumentSubDBReconfig::DocumentSubDBReconfig(std::shared_ptr<Matchers> matchers_in) +DocumentSubDBReconfig::DocumentSubDBReconfig(std::shared_ptr<Matchers> matchers_in, std::shared_ptr<IAttributeManager> attribute_manager_in) : _old_matchers(matchers_in), - _new_matchers(matchers_in) + _new_matchers(matchers_in), + _old_attribute_manager(attribute_manager_in), + _new_attribute_manager(attribute_manager_in), + _attribute_manager_reconfig() { } DocumentSubDBReconfig::~DocumentSubDBReconfig() = default; void -DocumentSubDBReconfig::complete(uint32_t docid_limit, search::SerialNum serial_num) +DocumentSubDBReconfig::set_attribute_manager_reconfig(std::unique_ptr<IAttributeManagerReconfig> attribute_manager_reconfig) { - (void) docid_limit; - (void) serial_num; + _attribute_manager_reconfig = std::move(attribute_manager_reconfig); } +void +DocumentSubDBReconfig::complete(uint32_t docid_limit, search::SerialNum serial_num) +{ + if (_attribute_manager_reconfig) { + _new_attribute_manager = _attribute_manager_reconfig->create(docid_limit, serial_num); + _attribute_manager_reconfig.reset(); + } } +} diff --git a/searchcore/src/vespa/searchcore/proton/server/document_subdb_reconfig.h b/searchcore/src/vespa/searchcore/proton/server/document_subdb_reconfig.h index 0554056100e..e2fc01aa600 100644 --- a/searchcore/src/vespa/searchcore/proton/server/document_subdb_reconfig.h +++ b/searchcore/src/vespa/searchcore/proton/server/document_subdb_reconfig.h @@ -6,6 +6,8 @@ namespace proton { +struct IAttributeManager; +class IAttributeManagerReconfig; class Matchers; /** @@ -15,9 +17,12 @@ class DocumentSubDBReconfig { private: std::shared_ptr<Matchers> _old_matchers; std::shared_ptr<Matchers> _new_matchers; + std::shared_ptr<IAttributeManager> _old_attribute_manager; + std::shared_ptr<IAttributeManager> _new_attribute_manager; + std::unique_ptr<IAttributeManagerReconfig> _attribute_manager_reconfig; public: - DocumentSubDBReconfig(std::shared_ptr<Matchers> matchers_in); + DocumentSubDBReconfig(std::shared_ptr<Matchers> matchers_in, std::shared_ptr<IAttributeManager> attribute_manager_in); ~DocumentSubDBReconfig(); void set_matchers(std::shared_ptr<Matchers> value) { @@ -26,7 +31,12 @@ public: bool has_matchers_changed() const noexcept { return _old_matchers != _new_matchers; } - std::shared_ptr<Matchers> matchers() const { return _new_matchers; } + std::shared_ptr<Matchers> matchers() const noexcept { return _new_matchers; } + bool has_attribute_manager_changed() const noexcept { + return _old_attribute_manager != _new_attribute_manager; + } + std::shared_ptr<IAttributeManager> attribute_manager() const noexcept { return _new_attribute_manager; } + void set_attribute_manager_reconfig(std::unique_ptr<IAttributeManagerReconfig> attribute_manager_reconfig); void complete(uint32_t docid_limit, search::SerialNum serial_num); }; diff --git a/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb.cpp b/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb.cpp index eef605cea3c..ea968a60322 100644 --- a/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb.cpp @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "fast_access_doc_subdb.h" -#include "attribute_writer_factory.h" #include "document_subdb_reconfig.h" #include "emptysearchview.h" #include "fast_access_document_retriever.h" @@ -11,6 +10,7 @@ #include <vespa/searchcore/proton/attribute/attribute_collection_spec_factory.h> #include <vespa/searchcore/proton/attribute/attribute_factory.h> #include <vespa/searchcore/proton/attribute/attribute_manager_initializer.h> +#include <vespa/searchcore/proton/attribute/attribute_writer.h> #include <vespa/searchcore/proton/attribute/filter_attribute_manager.h> #include <vespa/searchcore/proton/common/alloc_config.h> #include <vespa/searchcore/proton/reprocessing/attribute_reprocessing_initializer.h> @@ -198,7 +198,6 @@ FastAccessDocSubDB::FastAccessDocSubDB(const Config &cfg, const Context &ctx) _initAttrMgr(), _fastAccessFeedView(), _configurer(_fastAccessFeedView, - std::make_unique<AttributeWriterFactory>(), getSubDbName()), _subAttributeMetrics(ctx._subAttributeMetrics), _addMetrics(cfg._addMetrics), @@ -246,7 +245,9 @@ FastAccessDocSubDB::initViews(const DocumentDBConfig &configSnapshot) std::unique_ptr<DocumentSubDBReconfig> FastAccessDocSubDB::prepare_reconfig(const DocumentDBConfig& new_config_snapshot, const DocumentDBConfig& old_config_snapshot, const ReconfigParams& reconfig_params, std::optional<SerialNum> serial_num) { - return _configurer.prepare_reconfig(new_config_snapshot, old_config_snapshot, reconfig_params, serial_num); + auto alloc_strategy = new_config_snapshot.get_alloc_config().make_alloc_strategy(_subDbType); + auto attr_spec = createAttributeSpec(new_config_snapshot.getAttributesConfig(), alloc_strategy, serial_num); + return _configurer.prepare_reconfig(new_config_snapshot, old_config_snapshot, std::move(*attr_spec), reconfig_params, serial_num); } IReprocessingTask::List @@ -267,10 +268,8 @@ FastAccessDocSubDB::applyConfig(const DocumentDBConfig &newConfigSnapshot, const params.shouldAttributeWriterChange() || newConfigSnapshot.getDocumentTypeRepoSP().get() != oldConfigSnapshot.getDocumentTypeRepoSP().get()) { proton::IAttributeManager::SP oldMgr = extractAttributeManager(_fastAccessFeedView.get()); - std::unique_ptr<AttributeCollectionSpec> attrSpec = - createAttributeSpec(newConfigSnapshot.getAttributesConfig(), alloc_strategy, serialNum); IReprocessingInitializer::UP initializer = - _configurer.reconfigure(newConfigSnapshot, oldConfigSnapshot, std::move(*attrSpec), prepared_reconfig, serialNum); + _configurer.reconfigure(newConfigSnapshot, oldConfigSnapshot, prepared_reconfig, serialNum); if (initializer->hasReprocessors()) { tasks.push_back(IReprocessingTask::SP(createReprocessingTask(*initializer, newConfigSnapshot.getDocumentTypeRepoSP()).release())); diff --git a/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb.h b/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb.h index e4c140e43e6..cc82f863e80 100644 --- a/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb.h +++ b/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb.h @@ -3,6 +3,7 @@ #include "fast_access_doc_subdb_configurer.h" #include "storeonlydocsubdb.h" +#include <vespa/config-attributes.h> #include <vespa/searchcore/proton/attribute/attributemanager.h> #include <vespa/searchcore/proton/common/docid_limit.h> #include <vespa/searchcore/proton/metrics/attribute_metrics.h> 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 0a88b591f9f..ad7ef2f0dc0 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 @@ -2,8 +2,10 @@ #include "fast_access_doc_subdb_configurer.h" #include "document_subdb_reconfig.h" -#include "i_attribute_writer_factory.h" #include "documentdbconfig.h" +#include "reconfig_params.h" +#include <vespa/searchcore/proton/attribute/attributemanager.h> +#include <vespa/searchcore/proton/attribute/attribute_manager_reconfig.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> @@ -35,10 +37,8 @@ FastAccessDocSubDBConfigurer::reconfigureFeedView(FastAccessFeedView & curr, } FastAccessDocSubDBConfigurer::FastAccessDocSubDBConfigurer(FeedViewVarHolder &feedView, - IAttributeWriterFactory::UP factory, const vespalib::string &subDbName) : _feedView(feedView), - _factory(std::move(factory)), _subDbName(subDbName) { } @@ -46,27 +46,32 @@ FastAccessDocSubDBConfigurer::FastAccessDocSubDBConfigurer(FeedViewVarHolder &fe FastAccessDocSubDBConfigurer::~FastAccessDocSubDBConfigurer() = default; std::unique_ptr<DocumentSubDBReconfig> -FastAccessDocSubDBConfigurer::prepare_reconfig(const DocumentDBConfig& new_config_snapshot, const DocumentDBConfig& old_config_snapshot, const ReconfigParams& reconfig_params, std::optional<search::SerialNum> serial_num) +FastAccessDocSubDBConfigurer::prepare_reconfig(const DocumentDBConfig& new_config_snapshot, + const DocumentDBConfig& old_config_snapshot, + AttributeCollectionSpec && attr_spec, + const ReconfigParams& reconfig_params, + std::optional<search::SerialNum> serial_num) { (void) new_config_snapshot; (void) old_config_snapshot; - (void) reconfig_params; (void) serial_num; - return std::make_unique<DocumentSubDBReconfig>(std::shared_ptr<Matchers>()); + auto old_attribute_writer = _feedView.get()->getAttributeWriter(); + auto old_attribute_manager = old_attribute_writer->getAttributeManager(); + auto reconfig = std::make_unique<DocumentSubDBReconfig>(std::shared_ptr<Matchers>(), old_attribute_manager); + if (reconfig_params.shouldAttributeManagerChange()) { + reconfig->set_attribute_manager_reconfig(old_attribute_manager->prepare_create(std::move(attr_spec))); + } + return reconfig; } IReprocessingInitializer::UP FastAccessDocSubDBConfigurer::reconfigure(const DocumentDBConfig &newConfig, const DocumentDBConfig &oldConfig, - AttributeCollectionSpec && attrSpec, const DocumentSubDBReconfig& prepared_reconfig, search::SerialNum serial_num) { - (void) prepared_reconfig; FastAccessFeedView::SP oldView = _feedView.get(); - auto& attr_spec_serial_num = attrSpec.getCurrentSerialNum(); - assert(!attr_spec_serial_num.has_value() || attr_spec_serial_num.value() == serial_num); - IAttributeWriter::SP writer = _factory->create(oldView->getAttributeWriter(), std::move(attrSpec)); + auto writer = std::make_shared<AttributeWriter>(prepared_reconfig.attribute_manager()); reconfigureFeedView(*oldView, newConfig.getSchemaSP(), newConfig.getDocumentTypeRepoSP(), writer); const document::DocumentType *newDocType = newConfig.getDocumentType(); diff --git a/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb_configurer.h b/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb_configurer.h index 7a50aa35c81..e1a374366d2 100644 --- a/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb_configurer.h +++ b/searchcore/src/vespa/searchcore/proton/server/fast_access_doc_subdb_configurer.h @@ -1,13 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include "searchable_doc_subdb_configurer.h" #include "fast_access_feed_view.h" -#include "i_attribute_writer_factory.h" #include <vespa/searchcore/proton/reprocessing/i_reprocessing_initializer.h> +#include <vespa/vespalib/util/varholder.h> namespace proton { +class DocumentSubDBReconfig; +class ReconfigParams; + /** * Class used to reconfig the feed view used in a fast-access sub database * when the set of fast-access attributes change. @@ -19,7 +21,6 @@ public: private: FeedViewVarHolder &_feedView; - IAttributeWriterFactory::UP _factory; vespalib::string _subDbName; void reconfigureFeedView(FastAccessFeedView & curr, @@ -29,15 +30,18 @@ private: public: FastAccessDocSubDBConfigurer(FeedViewVarHolder &feedView, - IAttributeWriterFactory::UP factory, const vespalib::string &subDbName); ~FastAccessDocSubDBConfigurer(); - std::unique_ptr<DocumentSubDBReconfig> prepare_reconfig(const DocumentDBConfig& new_config_snapshot, const DocumentDBConfig& old_config_snapshot, const ReconfigParams& reconfig_params, std::optional<search::SerialNum> serial_num); + std::unique_ptr<DocumentSubDBReconfig> + prepare_reconfig(const DocumentDBConfig& new_config_snapshot, + const DocumentDBConfig& old_config_snapshot, + AttributeCollectionSpec&& attr_spec, + const ReconfigParams& reconfig_params, + std::optional<search::SerialNum> serial_num); IReprocessingInitializer::UP reconfigure(const DocumentDBConfig &newConfig, const DocumentDBConfig &oldConfig, - AttributeCollectionSpec && attrSpec, const DocumentSubDBReconfig& prepared_reconfig, search::SerialNum serial_num); }; diff --git a/searchcore/src/vespa/searchcore/proton/server/i_attribute_writer_factory.h b/searchcore/src/vespa/searchcore/proton/server/i_attribute_writer_factory.h deleted file mode 100644 index 7662d1cb164..00000000000 --- a/searchcore/src/vespa/searchcore/proton/server/i_attribute_writer_factory.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include <vespa/searchcore/proton/attribute/attribute_collection_spec.h> -#include <vespa/searchcore/proton/attribute/i_attribute_writer.h> - -namespace proton { - -/** - * Interface for a factory for creating new IAttributeWriter instances during reconfig. - */ -struct IAttributeWriterFactory -{ - using UP = std::unique_ptr<IAttributeWriterFactory>; - virtual ~IAttributeWriterFactory() = default; - virtual IAttributeWriter::SP create(const IAttributeWriter::SP &old, - AttributeCollectionSpec && attrSpec) const = 0; -}; - -} // 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 fa4340f7659..73faf03990d 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 @@ -4,6 +4,7 @@ #include "document_subdb_reconfig.h" #include "reconfig_params.h" #include <vespa/searchcore/proton/matching/matcher.h> +#include <vespa/searchcore/proton/attribute/attribute_manager_reconfig.h> #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> @@ -141,32 +142,26 @@ SearchableDocSubDBConfigurer::reconfigureIndexSearchable() } std::unique_ptr<DocumentSubDBReconfig> -SearchableDocSubDBConfigurer::prepare_reconfig(const DocumentDBConfig& new_config_snapshot, const DocumentDBConfig& old_config_snapshot, const ReconfigParams& reconfig_params, std::optional<search::SerialNum> serial_num) +SearchableDocSubDBConfigurer::prepare_reconfig(const DocumentDBConfig& new_config_snapshot, + const DocumentDBConfig& old_config_snapshot, + AttributeCollectionSpec&& attr_spec, + const ReconfigParams& reconfig_params, + std::optional<search::SerialNum> serial_num) { (void) old_config_snapshot; (void) serial_num; auto old_matchers = _searchView.get()->getMatchers(); - auto reconfig = std::make_unique<DocumentSubDBReconfig>(std::move(old_matchers)); + auto old_attribute_manager = _searchView.get()->getAttributeManager(); + auto reconfig = std::make_unique<DocumentSubDBReconfig>(std::move(old_matchers), old_attribute_manager); if (reconfig_params.shouldMatchersChange()) { reconfig->set_matchers(createMatchers(new_config_snapshot)); } + if (reconfig_params.shouldAttributeManagerChange()) { + reconfig->set_attribute_manager_reconfig(old_attribute_manager->prepare_create(std::move(attr_spec))); + } return reconfig; } -void -SearchableDocSubDBConfigurer:: -reconfigure(const DocumentDBConfig &newConfig, - const DocumentDBConfig &oldConfig, - const ReconfigParams ¶ms, - IDocumentDBReferenceResolver &resolver, - const DocumentSubDBReconfig& prepared_reconfig, - search::SerialNum serial_num) -{ - assert(!params.shouldAttributeManagerChange()); - AttributeCollectionSpec attrSpec(AttributeCollectionSpec::AttributeList(), 0, 0); - reconfigure(newConfig, oldConfig, std::move(attrSpec), params, resolver, prepared_reconfig, serial_num); -} - namespace { IReprocessingInitializer::UP @@ -194,7 +189,6 @@ createAttributeReprocessingInitializer(const DocumentDBConfig &newConfig, IReprocessingInitializer::UP SearchableDocSubDBConfigurer::reconfigure(const DocumentDBConfig &newConfig, const DocumentDBConfig &oldConfig, - AttributeCollectionSpec && attrSpec, const ReconfigParams ¶ms, IDocumentDBReferenceResolver &resolver, const DocumentSubDBReconfig& prepared_reconfig, @@ -208,10 +202,8 @@ SearchableDocSubDBConfigurer::reconfigure(const DocumentDBConfig &newConfig, IReprocessingInitializer::UP initializer; IAttributeManager::SP attrMgr = searchView->getAttributeManager(); IAttributeWriter::SP attrWriter = _feedView.get()->getAttributeWriter(); - if (params.shouldAttributeManagerChange()) { - auto attr_spec_serial_num = attrSpec.getCurrentSerialNum(); - assert(!attr_spec_serial_num.has_value() || attr_spec_serial_num.value() == serial_num); - IAttributeManager::SP newAttrMgr = attrMgr->create(std::move(attrSpec)); + if (prepared_reconfig.has_attribute_manager_changed()) { + auto newAttrMgr = prepared_reconfig.attribute_manager(); newAttrMgr->setImportedAttributes(resolver.resolve(*newAttrMgr, *attrMgr, searchView->getDocumentMetaStore(), newConfig.getMaintenanceConfigSP()->getVisibilityDelay())); diff --git a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h index e6b0ebda7c1..196c48120c6 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h +++ b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h @@ -78,19 +78,16 @@ public: void reconfigureIndexSearchable(); - std::unique_ptr<DocumentSubDBReconfig> prepare_reconfig(const DocumentDBConfig& new_config_snapshot, const DocumentDBConfig& old_config_snapshot, const ReconfigParams& reconfig_params, std::optional<search::SerialNum> serial_num); - - void reconfigure(const DocumentDBConfig &newConfig, - const DocumentDBConfig &oldConfig, - const ReconfigParams ¶ms, - IDocumentDBReferenceResolver &resolver, - const DocumentSubDBReconfig& prepared_reconfig, - search::SerialNum serial_num); + std::unique_ptr<DocumentSubDBReconfig> + prepare_reconfig(const DocumentDBConfig& new_config_snapshot, + const DocumentDBConfig& old_config_snapshot, + AttributeCollectionSpec&& attr_spec, + const ReconfigParams& reconfig_params, + std::optional<search::SerialNum> serial_num); IReprocessingInitializer::UP reconfigure(const DocumentDBConfig &newConfig, const DocumentDBConfig &oldConfig, - AttributeCollectionSpec && attrSpec, const ReconfigParams ¶ms, IDocumentDBReferenceResolver &resolver, const DocumentSubDBReconfig& prepared_reconfig, diff --git a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp index 187be079d03..33e4560d542 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp @@ -135,7 +135,9 @@ reconfigureMatchingMetrics(const RankProfilesConfig &cfg) std::unique_ptr<DocumentSubDBReconfig> SearchableDocSubDB::prepare_reconfig(const DocumentDBConfig& new_config_snapshot, const DocumentDBConfig& old_config_snapshot, const ReconfigParams& reconfig_params, std::optional<SerialNum> serial_num) { - return _configurer.prepare_reconfig(new_config_snapshot, old_config_snapshot, reconfig_params, serial_num); + auto alloc_strategy = new_config_snapshot.get_alloc_config().make_alloc_strategy(_subDbType); + auto attr_spec = createAttributeSpec(new_config_snapshot.getAttributesConfig(), alloc_strategy, serial_num); + return _configurer.prepare_reconfig(new_config_snapshot, old_config_snapshot, std::move(*attr_spec), reconfig_params, serial_num); } IReprocessingTask::List @@ -146,15 +148,13 @@ SearchableDocSubDB::applyConfig(const DocumentDBConfig &newConfigSnapshot, const StoreOnlyDocSubDB::reconfigure(newConfigSnapshot.getStoreConfig(), alloc_strategy); IReprocessingTask::List tasks; applyFlushConfig(newConfigSnapshot.getMaintenanceConfigSP()->getFlushConfig()); - if (params.shouldMatchersChange() && _addMetrics) { + if (prepared_reconfig.has_matchers_changed() && _addMetrics) { reconfigureMatchingMetrics(newConfigSnapshot.getRankProfilesConfig()); } - if (params.shouldAttributeManagerChange()) { + if (prepared_reconfig.has_attribute_manager_changed()) { proton::IAttributeManager::SP oldMgr = getAttributeManager(); - std::unique_ptr<AttributeCollectionSpec> attrSpec = - createAttributeSpec(newConfigSnapshot.getAttributesConfig(), alloc_strategy, serialNum); IReprocessingInitializer::UP initializer = - _configurer.reconfigure(newConfigSnapshot, oldConfigSnapshot, std::move(*attrSpec), params, resolver, prepared_reconfig, serialNum); + _configurer.reconfigure(newConfigSnapshot, oldConfigSnapshot, params, resolver, prepared_reconfig, serialNum); if (initializer && initializer->hasReprocessors()) { tasks.emplace_back(createReprocessingTask(*initializer, newConfigSnapshot.getDocumentTypeRepoSP())); } diff --git a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp index e3cf394c143..da2f24250e1 100644 --- a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp @@ -412,7 +412,7 @@ StoreOnlyDocSubDB::prepare_reconfig(const DocumentDBConfig& new_config_snapshot, (void) old_config_snapshot; (void) reconfig_params; (void) serial_num; - return std::make_unique<DocumentSubDBReconfig>(std::shared_ptr<Matchers>()); + return std::make_unique<DocumentSubDBReconfig>(std::shared_ptr<Matchers>(), std::shared_ptr<IAttributeManager>()); } void diff --git a/searchcore/src/vespa/searchcore/proton/test/dummy_document_sub_db.h b/searchcore/src/vespa/searchcore/proton/test/dummy_document_sub_db.h index 5ab0109578c..16ec38a2ec6 100644 --- a/searchcore/src/vespa/searchcore/proton/test/dummy_document_sub_db.h +++ b/searchcore/src/vespa/searchcore/proton/test/dummy_document_sub_db.h @@ -53,7 +53,7 @@ struct DummyDocumentSubDb : public IDocumentSubDB void setup(const DocumentSubDbInitializerResult &) override {} void initViews(const DocumentDBConfig &) override {} std::unique_ptr<DocumentSubDBReconfig> prepare_reconfig(const DocumentDBConfig&, const DocumentDBConfig&, const ReconfigParams&, std::optional<SerialNum>) override { - return std::make_unique<DocumentSubDBReconfig>(std::shared_ptr<Matchers>()); + return std::make_unique<DocumentSubDBReconfig>(std::shared_ptr<Matchers>(), std::shared_ptr<IAttributeManager>()); } void complete_prepare_reconfig(DocumentSubDBReconfig&, SerialNum) override { } IReprocessingTask::List applyConfig(const DocumentDBConfig &, const DocumentDBConfig &, diff --git a/searchcore/src/vespa/searchcore/proton/test/mock_attribute_manager.h b/searchcore/src/vespa/searchcore/proton/test/mock_attribute_manager.h index 2261fccd628..f85baa8c0ac 100644 --- a/searchcore/src/vespa/searchcore/proton/test/mock_attribute_manager.h +++ b/searchcore/src/vespa/searchcore/proton/test/mock_attribute_manager.h @@ -2,7 +2,7 @@ #pragma once #include <vespa/searchcore/proton/attribute/i_attribute_manager.h> -#include <vespa/searchcore/proton/attribute/attribute_manager_reconfig.h> +#include <vespa/searchcore/proton/attribute/i_attribute_manager_reconfig.h> #include <vespa/searchcore/proton/attribute/imported_attributes_repo.h> #include <vespa/searchlib/test/mock_attribute_manager.h> #include <vespa/vespalib/util/hdr_abort.h> @@ -50,12 +50,9 @@ public: search::attribute::IAttributeContext::UP createContext() const override { return _mock.createContext(); } - std::unique_ptr<AttributeManagerReconfig> prepare_create(AttributeCollectionSpec&&) const override { + std::unique_ptr<IAttributeManagerReconfig> prepare_create(AttributeCollectionSpec&&) const override { return {}; } - IAttributeManager::SP create(AttributeCollectionSpec &&) const override { - return IAttributeManager::SP(); - } std::vector<searchcorespi::IFlushTarget::SP> getFlushTargets() const override { return std::vector<searchcorespi::IFlushTarget::SP>(); } |