diff options
author | Tor Egge <Tor.Egge@oath.com> | 2018-01-08 12:15:48 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2018-01-08 12:15:48 +0000 |
commit | 27284d45e6d1d5aaba508d5dba438617a4e5403a (patch) | |
tree | 4f9b212efefb3c897813135ea97a82f950cc8117 /searchcore | |
parent | dd269359308af49ec4ffd73e7cd0fc4659e8a506 (diff) |
Don't connect reference attribute to referenced document type while replaying
transaction log.
Diffstat (limited to 'searchcore')
4 files changed, 39 insertions, 14 deletions
diff --git a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp index 40f9ed9b749..4b126a6d7c3 100644 --- a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp +++ b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp @@ -224,15 +224,21 @@ struct Fixture { oldAttrMgr.addReferenceAttribute("parent2_ref"); oldAttrMgr.addReferenceAttribute("parent3_ref"); } - ImportedAttributesRepo::UP resolve(fastos::TimeStamp visibilityDelay) { - DocumentDBReferenceResolver resolver(registry, docModel.childDocType, importedFieldsCfg, docModel.childDocType, _gidToLidChangeListenerRefCount, _attributeFieldWriter); + ImportedAttributesRepo::UP resolve(fastos::TimeStamp visibilityDelay, bool useReferences) { + DocumentDBReferenceResolver resolver(registry, docModel.childDocType, importedFieldsCfg, docModel.childDocType, _gidToLidChangeListenerRefCount, _attributeFieldWriter, useReferences); return resolver.resolve(attrMgr, oldAttrMgr, std::shared_ptr<search::IDocumentMetaStoreContext>(), visibilityDelay); } + ImportedAttributesRepo::UP resolve(fastos::TimeStamp visibilityDelay) { + return resolve(visibilityDelay, true); + } + ImportedAttributesRepo::UP resolveReplay() { + return resolve(fastos::TimeStamp(0), false); + } ImportedAttributesRepo::UP resolve() { return resolve(fastos::TimeStamp(0)); } void teardown() { - DocumentDBReferenceResolver resolver(registry, docModel.childDocType, importedFieldsCfg, docModel.childDocType, _gidToLidChangeListenerRefCount, _attributeFieldWriter); + DocumentDBReferenceResolver resolver(registry, docModel.childDocType, importedFieldsCfg, docModel.childDocType, _gidToLidChangeListenerRefCount, _attributeFieldWriter, false); resolver.teardown(attrMgr); } const IGidToLidMapperFactory *getMapperFactoryPtr(const vespalib::string &attrName) { @@ -277,6 +283,13 @@ TEST_F("require that reference attributes are connected to gid mapper", Fixture) EXPECT_EQUAL(f.factory.get(), f.getMapperFactoryPtr("other_ref")); } +TEST_F("require that reference attributes are not connected to gid mapper during replay", Fixture) +{ + f.resolveReplay(); + EXPECT_EQUAL(static_cast<IGidToLidMapperFactory *>(nullptr), f.getMapperFactoryPtr("ref")); + EXPECT_EQUAL(static_cast<IGidToLidMapperFactory *>(nullptr), f.getMapperFactoryPtr("other_ref")); +} + TEST_F("require that imported attributes are instantiated without search cache as default", Fixture) { auto repo = f.resolve(); diff --git a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp index 5932742baf9..9abe8181282 100644 --- a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp +++ b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp @@ -140,12 +140,14 @@ DocumentDBReferenceResolver::createImportedAttributesRepo(const IAttributeManage bool useSearchCache) { auto result = std::make_unique<ImportedAttributesRepo>(); - for (const auto &attr : _importedFieldsCfg.attribute) { - ReferenceAttribute::SP refAttr = getReferenceAttribute(attr.referencefield, attrMgr); - AttributeVector::SP targetAttr = getTargetDocumentDB(refAttr->getName())->getAttribute(attr.targetfield); - ImportedAttributeVector::SP importedAttr = + if (_useReferences) { + for (const auto &attr : _importedFieldsCfg.attribute) { + ReferenceAttribute::SP refAttr = getReferenceAttribute(attr.referencefield, attrMgr); + AttributeVector::SP targetAttr = getTargetDocumentDB(refAttr->getName())->getAttribute(attr.targetfield); + ImportedAttributeVector::SP importedAttr = std::make_shared<ImportedAttributeVector>(attr.name, refAttr, targetAttr, documentMetaStore, useSearchCache); - result->add(importedAttr->getName(), importedAttr); + result->add(importedAttr->getName(), importedAttr); + } } return result; } @@ -156,13 +158,15 @@ DocumentDBReferenceResolver::DocumentDBReferenceResolver(const IDocumentDBRefere const document::DocumentType &prevThisDocType, MonitoredRefCount &refCount, - ISequencedTaskExecutor &attributeFieldWriter) + ISequencedTaskExecutor &attributeFieldWriter, + bool useReferences) : _registry(registry), _thisDocType(thisDocType), _importedFieldsCfg(importedFieldsCfg), _prevThisDocType(prevThisDocType), _refCount(refCount), _attributeFieldWriter(attributeFieldWriter), + _useReferences(useReferences), _registrators() { } @@ -177,9 +181,11 @@ DocumentDBReferenceResolver::resolve(const IAttributeManager &newAttrMgr, const std::shared_ptr<search::IDocumentMetaStoreContext> &documentMetaStore, fastos::TimeStamp visibilityDelay) { - connectReferenceAttributesToGidMapper(newAttrMgr); detectOldListeners(oldAttrMgr); - listenToGidToLidChanges(newAttrMgr); + if (_useReferences) { + connectReferenceAttributesToGidMapper(newAttrMgr); + listenToGidToLidChanges(newAttrMgr); + } return createImportedAttributesRepo(newAttrMgr, documentMetaStore, (visibilityDelay > 0)); } diff --git a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h index fc8b3751ea2..71b869801e4 100644 --- a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h +++ b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h @@ -32,6 +32,7 @@ private: const document::DocumentType &_prevThisDocType; MonitoredRefCount &_refCount; search::ISequencedTaskExecutor &_attributeFieldWriter; + bool _useReferences; std::map<vespalib::string, std::unique_ptr<GidToLidChangeRegistrator>> _registrators; GidToLidChangeRegistrator &getRegistrator(const vespalib::string &docTypeName); @@ -49,7 +50,8 @@ public: const ImportedFieldsConfig &importedFieldsCfg, const document::DocumentType &prevThisDocType, MonitoredRefCount &refCount, - search::ISequencedTaskExecutor &attributeFieldWriter); + search::ISequencedTaskExecutor &attributeFieldWriter, + bool useReferencdes); ~DocumentDBReferenceResolver(); virtual std::unique_ptr<ImportedAttributesRepo> resolve(const search::IAttributeManager &newAttrMgr, diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp index 4dbff7c8e58..2cc2517fe2a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp @@ -353,7 +353,7 @@ DocumentDB::applySubDBConfig(const DocumentDBConfig &newConfigSnapshot, auto newDocType = newRepo->getDocumentType(_docTypeName.getName()); assert(newDocType != nullptr); DocumentDBReferenceResolver resolver(*registry, *newDocType, newConfigSnapshot.getImportedFieldsConfig(), - *oldDocType, _refCount, _writeService.attributeFieldWriter()); + *oldDocType, _refCount, _writeService.attributeFieldWriter(), _state.getAllowReconfig()); _subDBs.applyConfig(newConfigSnapshot, *_activeConfigSnapshot, serialNum, params, resolver); } @@ -385,6 +385,9 @@ DocumentDB::applyConfig(DocumentDBConfig::SP configSnapshot, SerialNum serialNum } cmpres = _activeConfigSnapshot->compare(*configSnapshot); } + if (_state.getState() == DDBState::State::APPLY_LIVE_CONFIG) { + cmpres.importedFieldsChanged = true; + } const ReconfigParams params(cmpres); // Save config via config manager if replay is done. bool equalReplayConfig = @@ -496,7 +499,8 @@ DocumentDB::tearDownReferences() activeConfig->getImportedFieldsConfig(), *docType, _refCount, - _writeService.attributeFieldWriter()); + _writeService.attributeFieldWriter(), + false); _subDBs.tearDownReferences(resolver); registry->remove(_docTypeName.getName()); } |