summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2023-06-16 11:09:11 +0200
committerGitHub <noreply@github.com>2023-06-16 11:09:11 +0200
commit2c87f86b047c461142a7bc9c5332480ca3948894 (patch)
tree075a6baa101b288316415e9bb5514470374a87f8
parentae3e30955bd9031496d9ef466f1a68223184a376 (diff)
parent4d2c66a03b6c9748490723ee5b3666f9ba766db8 (diff)
Merge pull request #27451 from vespa-engine/toregge/handle-removal-of-docid-with-empty-tensor-after-restart
Handle removal of docid with empty tensor in HNSW index after restart.
-rw-r--r--searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp11
-rw-r--r--searchlib/src/vespa/searchlib/tensor/hnsw_nodeid_mapping.cpp8
2 files changed, 17 insertions, 2 deletions
diff --git a/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp b/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
index f59c16c76f9..b238044a67b 100644
--- a/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
+++ b/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
@@ -855,6 +855,17 @@ TEST_F(HnswMultiIndexTest, docid_with_empty_tensor_can_be_removed)
this->remove_document(1);
}
+TEST_F(HnswMultiIndexTest, docid_with_empty_tensor_can_be_removed_after_restart)
+{
+ this->init(false);
+ this->vectors.set(1, {});
+ this->add_document(1);
+ auto data = this->save_index();
+ this->init(false);
+ this->load_index(data);
+ this->remove_document(1);
+}
+
TEST(LevelGeneratorTest, gives_various_levels)
{
InvLogLevelGenerator generator(4);
diff --git a/searchlib/src/vespa/searchlib/tensor/hnsw_nodeid_mapping.cpp b/searchlib/src/vespa/searchlib/tensor/hnsw_nodeid_mapping.cpp
index 8c169e63f9a..a908ebd7210 100644
--- a/searchlib/src/vespa/searchlib/tensor/hnsw_nodeid_mapping.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/hnsw_nodeid_mapping.cpp
@@ -82,14 +82,18 @@ HnswNodeidMapping::allocate_ids(uint32_t docid, uint32_t subspaces)
vespalib::ConstArrayRef<uint32_t>
HnswNodeidMapping::get_ids(uint32_t docid) const
{
- assert(docid < _refs.size());
+ if (docid >= _refs.size()) {
+ return {};
+ }
return _nodeids.get(_refs[docid]);
}
void
HnswNodeidMapping::free_ids(uint32_t docid)
{
- assert(docid < _refs.size());
+ if (docid >= _refs.size()) {
+ return;
+ }
EntryRef ref = _refs[docid];
if (!ref.valid()) {
return;