// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "i_document_db_reference_resolver.h" #include #include #include namespace document { class DocumentType; class DocumentTypeRepo; } namespace search { class IAttributeManager; struct IDocumentMetaStoreContext; } namespace search::attribute { class IAttributeVector; class ReferenceAttribute; } namespace vespa::config::search::internal { class InternalImportedFieldsType; } namespace vespalib { class ISequencedTaskExecutor; class MonitoredRefCount; } namespace proton { class IDocumentDBReference; class IDocumentDBReferenceRegistry; class ImportedAttributesRepo; class GidToLidChangeRegistrator; /** * Class that for a given document db resolves all references to parent document dbs: * 1) Connects all reference attributes to gid mappers of parent document dbs. */ class DocumentDBReferenceResolver : public IDocumentDBReferenceResolver { private: using ImportedFieldsConfig = const vespa::config::search::internal::InternalImportedFieldsType; const IDocumentDBReferenceRegistry &_registry; const document::DocumentType &_thisDocType; const ImportedFieldsConfig &_importedFieldsCfg; const document::DocumentType &_prevThisDocType; vespalib::MonitoredRefCount &_refCount; vespalib::ISequencedTaskExecutor &_attributeFieldWriter; bool _useReferences; std::map> _registrators; GidToLidChangeRegistrator &getRegistrator(const vespalib::string &docTypeName); std::shared_ptr getTargetDocumentDB(const vespalib::string &refAttrName) const; void connectReferenceAttributesToGidMapper(const search::IAttributeManager &attrMgr); std::unique_ptr createImportedAttributesRepo(const search::IAttributeManager &attrMgr, const std::shared_ptr &documentMetaStore, bool useSearchCache); void detectOldListeners(const search::IAttributeManager &attrMgr); void listenToGidToLidChanges(const search::IAttributeManager &attrMgr); public: DocumentDBReferenceResolver(const IDocumentDBReferenceRegistry ®istry, const document::DocumentType &thisDocType, const ImportedFieldsConfig &importedFieldsCfg, const document::DocumentType &prevThisDocType, vespalib::MonitoredRefCount &refCount, vespalib::ISequencedTaskExecutor &attributeFieldWriter, bool useReferences); ~DocumentDBReferenceResolver() override; std::unique_ptr resolve(const search::IAttributeManager &newAttrMgr, const search::IAttributeManager &oldAttrMgr, const std::shared_ptr &documentMetaStore, vespalib::duration visibilityDelay) override; void teardown(const search::IAttributeManager &oldAttrMgr) override; }; }