From 763987523a542bc2440f359dfa3cd38b46327c88 Mon Sep 17 00:00:00 2001 From: Andrija Antonijevic Date: Fri, 31 Jan 2025 16:02:37 -0800 Subject: [PATCH 1/2] Comment out non-threadsafe error message output that can cause crashes The method would be called many times per second, so printing an error message is not appropriate, there's already a return code. --- src/index.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.cpp b/src/index.cpp index 17a285992..bc346c3de 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -796,7 +796,7 @@ template int Index std::shared_lock lock(_tag_lock); if (_tag_to_location.find(tag) == _tag_to_location.end()) { - diskann::cout << "Tag " << tag << " does not exist" << std::endl; + // diskann::cout << "Tag " << tag << " does not exist" << std::endl; return -1; } From b9923f2b6b005386e73dbb1d8600a5ef8870b772 Mon Sep 17 00:00:00 2001 From: Denis Deyneko Date: Wed, 2 Jul 2025 14:07:12 -0700 Subject: [PATCH 2/2] Comment out the non-thread-safe code when vector is not found. Use iterator instead of operator[] to access the found tag. --- src/index.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.cpp b/src/index.cpp index bc346c3de..29153d7a2 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -794,13 +794,14 @@ size_t Index::load_graph(std::string filename, size_t expected_ template int Index::get_vector_by_tag(TagT &tag, T *vec) { std::shared_lock lock(_tag_lock); - if (_tag_to_location.find(tag) == _tag_to_location.end()) + const auto tagIt = _tag_to_location.find(tag); + if (tagIt == _tag_to_location.end()) { // diskann::cout << "Tag " << tag << " does not exist" << std::endl; return -1; } - size_t location = _tag_to_location[tag]; + const unsigned location = tagIt->second; memcpy((void *)vec, (void *)(_data + location * _aligned_dim), (size_t)_dim * sizeof(T)); return 0; }