diff options
author | Tor Egge <Tor.Egge@yahoo-inc.com> | 2017-03-23 20:10:51 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@yahoo-inc.com> | 2017-03-23 20:10:51 +0000 |
commit | 7971e04a4086aef8a953e94117d948df26de3839 (patch) | |
tree | 638e0ace3fc1ca03dcf3591237306b69847f7715 /searchcore | |
parent | a4eb2a0311c15d9d8ed1ed8534737b9b9cea23e3 (diff) |
Don't transfer attribute from old to new attribute manager if data type
or collection type has changed.
Diffstat (limited to 'searchcore')
-rw-r--r-- | searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp | 30 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp | 16 |
2 files changed, 45 insertions, 1 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 a030c65954d..5ccab84b4ad 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 @@ -111,6 +111,19 @@ fillAttribute(const AttributeVector::SP &attr, uint32_t from, uint32_t to, int64 test::AttributeUtils::fillAttribute(attr, from, to, value, lastSyncToken); } +search::SerialNum getCreateSerialNum(const AttributeGuard::UP &guard) +{ + if (!guard || !guard->valid()) { + return 0; + } else { + return (*guard)->getCreateSerialNum(); + } +} + +void assertCreateSerialNum(const AttributeManager &am, const vespalib::string &name, search::SerialNum expCreateSerialNum) { + EXPECT_EQUAL(expCreateSerialNum, getCreateSerialNum(am.getAttribute(name))); +} + struct ImportedAttributesRepoBuilder { ImportedAttributesRepo::UP _repo; ImportedAttributesRepoBuilder() : _repo(std::make_unique<ImportedAttributesRepo>()) {} @@ -740,6 +753,23 @@ TEST_F("require that imported attributes are exposed via attribute context toget EXPECT_EQUAL("imported", all[1]->getName()); } +TEST_F("require that attribute vector of wrong type is dropped", BaseFixture) +{ + auto am1(std::make_shared<proton::AttributeManager> + (test_dir, "test.subdb", TuneFileAttributes(), + f._fileHeaderContext, f._attributeFieldWriter, f._hwInfo)); + am1->addAttribute("a1", INT32_SINGLE, 1); + am1->addAttribute("a2", INT32_SINGLE, 2); + AttrSpecList newSpec; + newSpec.push_back(AttrSpec("a1", INT32_SINGLE)); + newSpec.push_back(AttrSpec("a2", INT32_ARRAY)); + SequentialAttributeManager am2(*am1, AttrMgrSpec(newSpec, 5, 20)); + TEST_DO(assertCreateSerialNum(*am1, "a1", 1)); + TEST_DO(assertCreateSerialNum(*am1, "a2", 2)); + TEST_DO(assertCreateSerialNum(am2.mgr, "a1", 1)); + TEST_DO(assertCreateSerialNum(am2.mgr, "a2", 20)); +} + TEST_MAIN() { vespalib::rmdir(test_dir, true); diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp index 6ddd018c179..5a44d87861d 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp @@ -30,6 +30,20 @@ using search::index::Schema; namespace proton { +namespace { + +bool matchingTypes(const AttributeVector::SP &av, const search::attribute::Config &newConfig) { + if (av) { + const auto &oldConfig = av->getConfig(); + return ((oldConfig.basicType() == newConfig.basicType()) && + (oldConfig.collectionType() == newConfig.collectionType())); + } else { + return false; + } +} + +} + AttributeVector::SP AttributeManager::internalAddAttribute(const vespalib::string &name, const Config &cfg, @@ -86,7 +100,7 @@ AttributeManager::transferExistingAttributes(const AttributeManager &currMgr, { for (const auto &aspec : newSpec.getAttributes()) { AttributeVector::SP av = currMgr.findAttribute(aspec.getName()); - if (av.get() != NULL) { // transfer attribute + if (matchingTypes(av, aspec.getConfig())) { // transfer attribute LOG(debug, "Transferring attribute vector '%s' with %u docs and serial number %lu from current manager", av->getName().c_str(), av->getNumDocs(), av->getStatus().getLastSyncToken()); addAttribute(av); |