diff options
author | Tor Egge <Tor.Egge@oath.com> | 2017-08-30 13:57:25 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2017-08-30 13:58:13 +0000 |
commit | 42a9e2b3bfdd95e3dd835526ec818a79084c0b89 (patch) | |
tree | 47ace8bee5aa8c3fd5f79ea2f20089a8ee899732 /searchlib | |
parent | 66aa89e733c9cf033352a3e32202b7b1b49bac77 (diff) |
Propagate API changes to GidToLidChangeListener and ReferenceAttribute:
Split put and remove notifications into separate methods.
Diffstat (limited to 'searchlib')
5 files changed, 47 insertions, 17 deletions
diff --git a/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp b/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp index 7e2e8904170..1b1bc1f8796 100644 --- a/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp +++ b/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp @@ -182,8 +182,11 @@ struct Fixture iter, oldStatus.getUsed(), newStatus.getUsed()); } - void notifyGidToLidChange(const GlobalId &gid, uint32_t referencedDoc) { - _attr->notifyGidToLidChange(gid, referencedDoc); + void notifyReferencedPut(const GlobalId &gid, uint32_t referencedDoc) { + _attr->notifyReferencedPut(gid, referencedDoc); + } + void notifyReferencedRemove(const GlobalId &gid) { + _attr->notifyReferencedRemove(gid); } void populateReferencedLids() { _attr->populateReferencedLids(); @@ -300,7 +303,7 @@ TEST_F("require that update() uses gid-mapper to set referenced lid", Fixture) TEST_DO(f.assertRefLid(5, 0)); } -TEST_F("require that notifyGidToLidChange() updates lid-2-lid mapping", Fixture) +TEST_F("require that notifyReferencedPut() updates lid-2-lid mapping", Fixture) { f.ensureDocIdLimit(4); f.set(1, toGid(doc1)); @@ -310,9 +313,9 @@ TEST_F("require that notifyGidToLidChange() updates lid-2-lid mapping", Fixture) TEST_DO(f.assertRefLid(1, 0)); TEST_DO(f.assertRefLid(2, 0)); TEST_DO(f.assertRefLid(3, 0)); - f.notifyGidToLidChange(toGid(doc1), 10); - f.notifyGidToLidChange(toGid(doc2), 20); - f.notifyGidToLidChange(toGid(doc3), 30); + f.notifyReferencedPut(toGid(doc1), 10); + f.notifyReferencedPut(toGid(doc2), 20); + f.notifyReferencedPut(toGid(doc3), 30); TEST_DO(f.assertRefLid(1, 10)); TEST_DO(f.assertRefLid(2, 20)); TEST_DO(f.assertRefLid(3, 10)); @@ -369,18 +372,18 @@ TEST_F("require that populateReferencedLids() uses gid-mapper to update lid-2-li EXPECT_TRUE(vespalib::unlink("test.udat")); } -TEST_F("Require that notifyGidToLidChange changes reverse mapping", Fixture) +TEST_F("Require that notifyReferencedPut and notifyReferencedRemove changes reverse mapping", Fixture) { TEST_DO(preparePopulateReferencedLids(f)); TEST_DO(f.assertLids(10, { })); TEST_DO(f.assertLids(11, { })); - f.notifyGidToLidChange(toGid(doc1), 10); + f.notifyReferencedPut(toGid(doc1), 10); TEST_DO(f.assertLids(10, { 1, 3})); TEST_DO(f.assertLids(11, { })); - f.notifyGidToLidChange(toGid(doc1), 11); + f.notifyReferencedPut(toGid(doc1), 11); TEST_DO(f.assertLids(10, { })); TEST_DO(f.assertLids(11, { 1, 3})); - f.notifyGidToLidChange(toGid(doc1), 0); + f.notifyReferencedRemove(toGid(doc1)); TEST_DO(f.assertLids(10, { })); TEST_DO(f.assertLids(11, { })); } @@ -406,8 +409,8 @@ TEST_F("Require that reverse mapping recovers from temporary out of order glitch TEST_DO(f.assertRefLid(2, 17)); TEST_DO(f.assertRefLid(3, 10)); // Notify reference attribute about gid to lid mapping changes - f.notifyGidToLidChange(toGid(doc1), 0); - f.notifyGidToLidChange(toGid(doc3), 10); + f.notifyReferencedRemove(toGid(doc1)); + f.notifyReferencedPut(toGid(doc3), 10); TEST_DO(f.assertRefLid(1, 0)); TEST_DO(f.assertRefLid(2, 17)); TEST_DO(f.assertRefLid(3, 10)); diff --git a/searchlib/src/vespa/searchlib/attribute/reference_attribute.cpp b/searchlib/src/vespa/searchlib/attribute/reference_attribute.cpp index 7e17ba3a808..2cb05b14503 100644 --- a/searchlib/src/vespa/searchlib/attribute/reference_attribute.cpp +++ b/searchlib/src/vespa/searchlib/attribute/reference_attribute.cpp @@ -320,12 +320,23 @@ ReferenceAttribute::setGidToLidMapperFactory(std::shared_ptr<IGidToLidMapperFact } void -ReferenceAttribute::notifyGidToLidChange(const GlobalId &gid, DocId referencedLid) +ReferenceAttribute::notifyReferencedPut(const GlobalId &gid, DocId referencedLid) { EntryRef ref = _store.find(gid); if (ref.valid()) { const auto &entry = _store.get(ref); - _referenceMappings.notifyGidToLidChange(entry, referencedLid); + _referenceMappings.notifyReferencedPut(entry, referencedLid); + commit(); + } +} + +void +ReferenceAttribute::notifyReferencedRemove(const GlobalId &gid) +{ + EntryRef ref = _store.find(gid); + if (ref.valid()) { + const auto &entry = _store.get(ref); + _referenceMappings.notifyReferencedRemove(entry); commit(); } } diff --git a/searchlib/src/vespa/searchlib/attribute/reference_attribute.h b/searchlib/src/vespa/searchlib/attribute/reference_attribute.h index 4ee277b8733..ce7c908db99 100644 --- a/searchlib/src/vespa/searchlib/attribute/reference_attribute.h +++ b/searchlib/src/vespa/searchlib/attribute/reference_attribute.h @@ -78,7 +78,8 @@ public: ReverseMappingRefs getReverseMappingRefs() const { return _referenceMappings.getReverseMappingRefs(); } const ReverseMapping &getReverseMapping() const { return _referenceMappings.getReverseMapping(); } - void notifyGidToLidChange(const GlobalId &gid, DocId referencedLid); + void notifyReferencedPut(const GlobalId &gid, DocId referencedLid); + void notifyReferencedRemove(const GlobalId &gid); void populateReferencedLids(); virtual void clearDocs(DocId lidLow, DocId lidLimit) override; virtual void onShrinkLidSpace() override; diff --git a/searchlib/src/vespa/searchlib/attribute/reference_mappings.cpp b/searchlib/src/vespa/searchlib/attribute/reference_mappings.cpp index 4edd9d45e60..f2462cdc40d 100644 --- a/searchlib/src/vespa/searchlib/attribute/reference_mappings.cpp +++ b/searchlib/src/vespa/searchlib/attribute/reference_mappings.cpp @@ -93,7 +93,7 @@ ReferenceMappings::buildReverseMapping(const Reference &entry, const std::vector } void -ReferenceMappings::notifyGidToLidChange(const Reference &entry, uint32_t referencedLid) +ReferenceMappings::notifyReferencedPut(const Reference &entry, uint32_t referencedLid) { uint32_t oldReferencedLid = entry.lid(); if (oldReferencedLid != referencedLid) { @@ -107,6 +107,20 @@ ReferenceMappings::notifyGidToLidChange(const Reference &entry, uint32_t referen } void +ReferenceMappings::notifyReferencedRemove(const Reference &entry) +{ + uint32_t oldReferencedLid = entry.lid(); + if (oldReferencedLid != 0) { + if (oldReferencedLid < _reverseMappingIndices.size()) { + _reverseMappingIndices[oldReferencedLid] = EntryRef(); + } + entry.setLid(0); + } + syncReverseMappingIndices(entry); + syncForwardMapping(entry); +} + +void ReferenceMappings::onAddDocs(uint32_t docIdLimit) { _referencedLids.reserve(docIdLimit); diff --git a/searchlib/src/vespa/searchlib/attribute/reference_mappings.h b/searchlib/src/vespa/searchlib/attribute/reference_mappings.h index 3190e1b5a83..73754d9cb13 100644 --- a/searchlib/src/vespa/searchlib/attribute/reference_mappings.h +++ b/searchlib/src/vespa/searchlib/attribute/reference_mappings.h @@ -57,7 +57,8 @@ public: void transferHoldLists(generation_t generation) { _reverseMapping.transferHoldLists(generation); } // Handle mapping changes - void notifyGidToLidChange(const Reference &entry, uint32_t referencedLid); + void notifyReferencedPut(const Reference &entry, uint32_t referencedLid); + void notifyReferencedRemove(const Reference &entry); void removeReverseMapping(const Reference &entry, uint32_t lid); void addReverseMapping(const Reference &entry, uint32_t lid); void syncMappings(const Reference &entry); |