Skip to content

Commit 0a74ed0

Browse files
d4matortheantonyDenis Deyneko
authored
Remove non-thread-safe code that may lead to crashes when a vector is not found by tag (#656)
* 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. * Comment out the non-thread-safe code when vector is not found. Use iterator instead of operator[] to access the found tag. --------- Co-authored-by: Andrija Antonijevic <anantoni@microsoft.com> Co-authored-by: Denis Deyneko <denisdey@microsoft.com>
1 parent 66c4253 commit 0a74ed0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/index.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,13 +794,14 @@ size_t Index<T, TagT, LabelT>::load_graph(std::string filename, size_t expected_
794794
template <typename T, typename TagT, typename LabelT> int Index<T, TagT, LabelT>::get_vector_by_tag(TagT &tag, T *vec)
795795
{
796796
std::shared_lock<std::shared_timed_mutex> lock(_tag_lock);
797-
if (_tag_to_location.find(tag) == _tag_to_location.end())
797+
const auto tagIt = _tag_to_location.find(tag);
798+
if (tagIt == _tag_to_location.end())
798799
{
799-
diskann::cout << "Tag " << tag << " does not exist" << std::endl;
800+
// diskann::cout << "Tag " << tag << " does not exist" << std::endl;
800801
return -1;
801802
}
802803

803-
size_t location = _tag_to_location[tag];
804+
const unsigned location = tagIt->second;
804805
memcpy((void *)vec, (void *)(_data + location * _aligned_dim), (size_t)_dim * sizeof(T));
805806
return 0;
806807
}

0 commit comments

Comments
 (0)